From aea8ccd137c0090b9d1fe1eb94a837aed8e5ddcd Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Mon, 17 Aug 2026 15:22:18 +0800 Subject: [PATCH] init-repository: add --depth argument There are cases when someone may only want to do a shallow clone, e.g. in CI scenarios. Adding a --depth argument to reflect to allow shallow clones of the (sub)modules. Change-Id: Ia57f6d70c61eeb8f9828c467c8a4cf31c1d9c573 Reviewed-by: Alexandru Croitor --- cmake/QtIRGitHelpers.cmake | 7 +++++++ cmake/QtIRHelp.txt | 10 ++++++++++ cmake/QtIRHelpers.cmake | 2 ++ cmake/QtIROptionsHelpers.cmake | 1 + 4 files changed, 20 insertions(+) diff --git a/cmake/QtIRGitHelpers.cmake b/cmake/QtIRGitHelpers.cmake index 19d19584..5b7f8dc0 100644 --- a/cmake/QtIRGitHelpers.cmake +++ b/cmake/QtIRGitHelpers.cmake @@ -181,6 +181,7 @@ function(qt_ir_clone_one_submodule submodule_name) set(oneValueArgs ALTERNATES BASE_URL + DEPTH WORKING_DIRECTORY ) set(multiValueArgs "") @@ -263,6 +264,9 @@ function(qt_ir_clone_one_submodule submodule_name) else() list(APPEND clone_args --no-checkout) endif() + if(arg_DEPTH) + list(APPEND clone_args --depth "${arg_DEPTH}") + endif() list(APPEND clone_args ${progress_args}) qt_ir_execute_process_and_log_and_handle_error( COMMAND_ARGS git clone ${clone_args} "${mirror_or_original_url}" "${submodule_path}" @@ -1063,6 +1067,7 @@ function(qt_ir_handle_init_submodules prefix) set(oneValueArgs ALTERNATES BASE_URL + DEPTH PARENT_REPO_BASE_GIT_PATH WORKING_DIRECTORY ) @@ -1123,6 +1128,7 @@ function(qt_ir_handle_init_submodules prefix) qt_ir_clone_one_submodule(${submodule_name} ALTERNATES ${arg_ALTERNATES} BASE_URL ${arg_BASE_URL} + DEPTH "${arg_DEPTH}" WORKING_DIRECTORY "${working_directory}" ${branch_flag} ${fetch_flag} @@ -1163,6 +1169,7 @@ function(qt_ir_handle_init_submodules prefix) SUBMODULES "all" BASE_URL "${base_url}" + DEPTH "${arg_DEPTH}" PARENT_REPO_BASE_GIT_PATH "${submodule_base_git_path}" WORKING_DIRECTORY "${working_directory}/${submodule_name}" diff --git a/cmake/QtIRHelp.txt b/cmake/QtIRHelp.txt index d366c9d6..9c4c17ab 100644 --- a/cmake/QtIRHelp.txt +++ b/cmake/QtIRHelp.txt @@ -122,6 +122,16 @@ Options: Note that this negates the disk usage benefits gained from the use of `--alternates'. + + --depth + Creates a shallow clone with a history truncated to commits for + each submodule that is cloned, by passing `--depth ' to `git + clone'. This also applies recursively to submodules of submodules + (e.g. qtwebengine's third-party dependencies). + + This option only affects submodules that are freshly cloned; it has + no effect on already-cloned submodules that are merely updated or + fetched. --mirror Uses as the base URL for submodule git mirrors. diff --git a/cmake/QtIRHelpers.cmake b/cmake/QtIRHelpers.cmake index ea929374..ed353650 100644 --- a/cmake/QtIRHelpers.cmake +++ b/cmake/QtIRHelpers.cmake @@ -312,6 +312,7 @@ function(qt_ir_run_after_args_parsed top_level_src_path out_var_exit_reason) # Get some additional options to pass down. qt_ir_get_option_as_existing_absolute_path(alternates alternates) qt_ir_get_option_as_cmake_flag_option(branch "CHECKOUT_BRANCH" checkout_branch_option) + qt_ir_get_option_value(depth depth) # The prefix for the cmake-style 'dictionary' that will be used by various functions. set(prefix "ir_top") @@ -321,6 +322,7 @@ function(qt_ir_run_after_args_parsed top_level_src_path out_var_exit_reason) ALTERNATES "${alternates}" ALREADY_INITIALIZED_SUBMODULES "${already_initialized_submodules}" BASE_URL "${base_url}" + DEPTH "${depth}" PARENT_REPO_BASE_GIT_PATH "${qt5_repo_name}" PROCESS_SUBMODULES_FROM_COMMAND_LINE WORKING_DIRECTORY "${working_directory}" diff --git a/cmake/QtIROptionsHelpers.cmake b/cmake/QtIROptionsHelpers.cmake index 2b3ff1c4..e4052fe3 100644 --- a/cmake/QtIROptionsHelpers.cmake +++ b/cmake/QtIROptionsHelpers.cmake @@ -16,6 +16,7 @@ macro(qt_ir_set_known_command_line_options) qt_ir_commandline_option(codereview-username TYPE string) qt_ir_commandline_option(codereview-https TYPE boolean) qt_ir_commandline_option(copy-objects TYPE boolean) + qt_ir_commandline_option(depth TYPE string) qt_ir_commandline_option(fetch TYPE boolean DEFAULT_VALUE yes) qt_ir_commandline_option(force SHORT_NAME f TYPE boolean) qt_ir_commandline_option(force-hooks TYPE boolean)