Skip to content

Commit

Permalink
Optimize sparse checkout
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed Jun 19, 2024
1 parent 8b505b6 commit 944b6b3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
10 changes: 9 additions & 1 deletion modules/FindConfigurePackage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ macro(FindConfigurePackage)
CMAKE_INHERIT_FIND_ROOT_PATH
CMAKE_INHERIT_SYSTEM_LINKS
GIT_ENABLE_SUBMODULE
GIT_SUBMODULE_RECURSIVE)
GIT_SUBMODULE_RECURSIVE
GIT_FORCE_RESET
GIT_ALWAYS_UPDATE_REMOTE)
set(oneValueArgs
PACKAGE
PORT_PREFIX
Expand Down Expand Up @@ -416,6 +418,12 @@ macro(FindConfigurePackage)
list(APPEND FindConfigurePackage_GIT_CLONE_ARGS RESET_SUBMODULE_URLS
"${FindConfigurePackage_GIT_RESET_SUBMODULE_URLS}")
endif()
if(FindConfigurePackage_GIT_FORCE_RESET)
list(APPEND FindConfigurePackage_GIT_CLONE_ARGS FORCE_RESET)
endif()
if(FindConfigurePackage_GIT_ALWAYS_UPDATE_REMOTE)
list(APPEND FindConfigurePackage_GIT_CLONE_ARGS ALWAYS_UPDATE_REMOTE)
endif()
if(FindConfigurePackage_GIT_PATCH_FILES)
list(APPEND FindConfigurePackage_GIT_CLONE_ARGS PATCH_FILES "${FindConfigurePackage_GIT_PATCH_FILES}")
endif()
Expand Down
34 changes: 18 additions & 16 deletions modules/ProjectBuildTools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -698,20 +698,19 @@ function(project_git_get_ambiguous_name OUTPUT_VAR_NAME GIT_WORKSPACE)
endfunction()

function(project_git_clone_repository)
set(optionArgs ENABLE_SUBMODULE SUBMODULE_RECURSIVE REQUIRED FORCE_RESET)
set(optionArgs ENABLE_SUBMODULE SUBMODULE_RECURSIVE REQUIRED FORCE_RESET ALWAYS_UPDATE_REMOTE)
set(oneValueArgs
URL
WORKING_DIRECTORY
REPO_DIRECTORY
DEPTH
BRANCH
COMMIT
SPARSE_CHECKOUT
TAG
CHECK_PATH
LOCK_TIMEOUT
LOCK_FILE)
set(multiValueArgs PATCH_FILES SUBMODULE_PATH RESET_SUBMODULE_URLS GIT_CONFIG FETCH_FILTER)
set(multiValueArgs PATCH_FILES SUBMODULE_PATH RESET_SUBMODULE_URLS GIT_CONFIG FETCH_FILTER SPARSE_CHECKOUT)
cmake_parse_arguments(project_git_clone_repository "${optionArgs}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})

if(ATFRAMEWORK_CMAKE_TOOLSET_PACKAGE_PATCH_LOG)
Expand Down Expand Up @@ -868,26 +867,29 @@ function(project_git_clone_repository)
endif()
endif()

if(NOT EXISTS "${project_git_clone_repository_REPO_DIRECTORY}/${project_git_clone_repository_CHECK_PATH}")
if(NOT EXISTS "${project_git_clone_repository_REPO_DIRECTORY}/${project_git_clone_repository_CHECK_PATH}"
OR (project_git_clone_repository_ALWAYS_UPDATE_REMOTE AND project_git_clone_repository_GIT_BRANCH))
if(NOT EXISTS "${project_git_clone_repository_REPO_DIRECTORY}")
file(MAKE_DIRECTORY "${project_git_clone_repository_REPO_DIRECTORY}")
endif()

if(GIT_VERSION_STRING VERSION_GREATER_EQUAL "2.28.0")
execute_process(
COMMAND "${GIT_EXECUTABLE}" ${git_global_options} init -b main
WORKING_DIRECTORY "${project_git_clone_repository_REPO_DIRECTORY}"
${ATFRAMEWORK_CMAKE_TOOLSET_EXECUTE_PROCESS_OUTPUT_OPTIONS})
else()
if(NOT EXISTS "${project_git_clone_repository_REPO_DIRECTORY}/.git")
if(GIT_VERSION_STRING VERSION_GREATER_EQUAL "2.28.0")
execute_process(
COMMAND "${GIT_EXECUTABLE}" ${git_global_options} init -b main
WORKING_DIRECTORY "${project_git_clone_repository_REPO_DIRECTORY}"
${ATFRAMEWORK_CMAKE_TOOLSET_EXECUTE_PROCESS_OUTPUT_OPTIONS})
else()
execute_process(
COMMAND "${GIT_EXECUTABLE}" ${git_global_options} init
WORKING_DIRECTORY "${project_git_clone_repository_REPO_DIRECTORY}"
${ATFRAMEWORK_CMAKE_TOOLSET_EXECUTE_PROCESS_OUTPUT_OPTIONS})
endif()
execute_process(
COMMAND "${GIT_EXECUTABLE}" ${git_global_options} init
COMMAND "${GIT_EXECUTABLE}" ${git_global_options} remote add origin "${project_git_clone_repository_URL}"
WORKING_DIRECTORY "${project_git_clone_repository_REPO_DIRECTORY}"
${ATFRAMEWORK_CMAKE_TOOLSET_EXECUTE_PROCESS_OUTPUT_OPTIONS})
endif()
execute_process(
COMMAND "${GIT_EXECUTABLE}" ${git_global_options} remote add origin "${project_git_clone_repository_URL}"
WORKING_DIRECTORY "${project_git_clone_repository_REPO_DIRECTORY}"
${ATFRAMEWORK_CMAKE_TOOLSET_EXECUTE_PROCESS_OUTPUT_OPTIONS})

if(project_git_clone_repository_SPARSE_CHECKOUT)
if(GIT_VERSION_STRING VERSION_GREATER_EQUAL "2.25.0")
Expand All @@ -897,7 +899,7 @@ function(project_git_clone_repository)
${ATFRAMEWORK_CMAKE_TOOLSET_EXECUTE_PROCESS_OUTPUT_OPTIONS})
execute_process(
COMMAND "${GIT_EXECUTABLE}" ${git_global_options} sparse-checkout set
"${project_git_clone_repository_SPARSE_CHECKOUT}"
${project_git_clone_repository_SPARSE_CHECKOUT}
WORKING_DIRECTORY "${project_git_clone_repository_REPO_DIRECTORY}"
${ATFRAMEWORK_CMAKE_TOOLSET_EXECUTE_PROCESS_OUTPUT_OPTIONS})
else()
Expand Down

0 comments on commit 944b6b3

Please sign in to comment.