]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repack: add --name-hash-version option
authorDerrick Stolee <stolee@gmail.com>
Mon, 27 Jan 2025 19:02:30 +0000 (19:02 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 27 Jan 2025 21:21:43 +0000 (13:21 -0800)
The new '--name-hash-version' option for 'git repack' is a simple
pass-through to the underlying 'git pack-objects' subcommand. However,
this subcommand may have other options and a temporary filename as part
of the subcommand execution that may not be predictable or could change
over time.

The existing test_subcommand method requires an exact list of arguments
for the subcommand. This is too rigid for our needs here, so create a
new method, test_subcommand_flex. Use it to check that the
--name-hash-version option is passing through.

Since we are modifying the 'git repack' command, let's bring its usage
in line with the Documentation's synopsis. This removes it from the
allow list in t0450 so it will remain in sync in the future.

Signed-off-by: Derrick Stolee <stolee@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-repack.txt
builtin/repack.c
t/t0450/txt-help-mismatches
t/t7700-repack.sh
t/test-lib-functions.sh

index c902512a9e89b07446a606b95cdff52ecc385c44..5852a5c9736875889a71a3820e2d98e3f4826b2f 100644 (file)
@@ -9,7 +9,9 @@ git-repack - Pack unpacked objects in a repository
 SYNOPSIS
 --------
 [verse]
-'git repack' [-a] [-A] [-d] [-f] [-F] [-l] [-n] [-q] [-b] [-m] [--window=<n>] [--depth=<n>] [--threads=<n>] [--keep-pack=<pack-name>] [--write-midx]
+'git repack' [-a] [-A] [-d] [-f] [-F] [-l] [-n] [-q] [-b] [-m]
+       [--window=<n>] [--depth=<n>] [--threads=<n>] [--keep-pack=<pack-name>]
+       [--write-midx] [--name-hash-version=<n>]
 
 DESCRIPTION
 -----------
@@ -249,6 +251,11 @@ linkgit:git-multi-pack-index[1]).
        Write a multi-pack index (see linkgit:git-multi-pack-index[1])
        containing the non-redundant packs.
 
+--name-hash-version=<n>::
+       Provide this argument to the underlying `git pack-objects` process.
+       See linkgit:git-pack-objects[1] for full details.
+
+
 CONFIGURATION
 -------------
 
index d6bb37e84ae2e3715c48791b97f6798177629684..5e7ff919c1acd41f7e0e1ee359b638f2482daafd 100644 (file)
@@ -39,7 +39,9 @@ static int run_update_server_info = 1;
 static char *packdir, *packtmp_name, *packtmp;
 
 static const char *const git_repack_usage[] = {
-       N_("git repack [<options>]"),
+       N_("git repack [-a] [-A] [-d] [-f] [-F] [-l] [-n] [-q] [-b] [-m]\n"
+          "[--window=<n>] [--depth=<n>] [--threads=<n>] [--keep-pack=<pack-name>]\n"
+          "[--write-midx] [--name-hash-version=<n>]"),
        NULL
 };
 
@@ -58,6 +60,7 @@ struct pack_objects_args {
        int no_reuse_object;
        int quiet;
        int local;
+       int name_hash_version;
        struct list_objects_filter_options filter_options;
 };
 
@@ -306,6 +309,8 @@ static void prepare_pack_objects(struct child_process *cmd,
                strvec_pushf(&cmd->args, "--no-reuse-delta");
        if (args->no_reuse_object)
                strvec_pushf(&cmd->args, "--no-reuse-object");
+       if (args->name_hash_version)
+               strvec_pushf(&cmd->args, "--name-hash-version=%d", args->name_hash_version);
        if (args->local)
                strvec_push(&cmd->args,  "--local");
        if (args->quiet)
@@ -1203,6 +1208,8 @@ int cmd_repack(int argc,
                                N_("pass --no-reuse-delta to git-pack-objects")),
                OPT_BOOL('F', NULL, &po_args.no_reuse_object,
                                N_("pass --no-reuse-object to git-pack-objects")),
+               OPT_INTEGER(0, "name-hash-version", &po_args.name_hash_version,
+                               N_("specify the name hash version to use for grouping similar objects by path")),
                OPT_NEGBIT('n', NULL, &run_update_server_info,
                                N_("do not run git-update-server-info"), 1),
                OPT__QUIET(&po_args.quiet, N_("be quiet")),
index 28003f18c924bb88a4a5d6c7e18d15e97eb43a91..c4a15fd0cb885a3779165a22915b75b587ae6603 100644 (file)
@@ -45,7 +45,6 @@ rebase
 remote
 remote-ext
 remote-fd
-repack
 reset
 restore
 rev-parse
index c4c3d1a15d9abc44f682480803226b18c97c1fb8..b9a5759e01d57b05d5387f7f082bb9f9ed2cf46a 100755 (executable)
@@ -777,6 +777,12 @@ test_expect_success 'repack -ad cleans up old .tmp-* packs' '
        test_must_be_empty tmpfiles
 '
 
+test_expect_success '--name-hash-version option passes through to pack-objects' '
+       GIT_TRACE2_EVENT="$(pwd)/hash-trace.txt" \
+               git repack -a --name-hash-version=2 &&
+       test_subcommand_flex git pack-objects --name-hash-version=2 <hash-trace.txt
+'
+
 test_expect_success 'setup for update-server-info' '
        git init update-server-info &&
        test_commit -C update-server-info message
index 78e054ab503a6573ca9810a19d89afff334c6ba2..af47247f25fd3f64182da1a379df9ee19245b492 100644 (file)
@@ -1886,6 +1886,32 @@ test_subcommand () {
        fi
 }
 
+# Check that the given subcommand was run with the given set of
+# arguments in order (but with possible extra arguments).
+#
+#      test_subcommand_flex [!] <command> <args>... < <trace>
+#
+# If the first parameter passed is !, this instead checks that
+# the given command was not called.
+#
+test_subcommand_flex () {
+       local negate=
+       if test "$1" = "!"
+       then
+               negate=t
+               shift
+       fi
+
+       local expr="$(printf '"%s".*' "$@")"
+
+       if test -n "$negate"
+       then
+               ! grep "\[$expr\]"
+       else
+               grep "\[$expr\]"
+       fi
+}
+
 # Check that the given command was invoked as part of the
 # trace2-format trace on stdin.
 #