]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repack: refactor to avoid double-negation of update-server-info
authorPatrick Steinhardt <ps@pks.im>
Mon, 14 Mar 2022 07:42:46 +0000 (08:42 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 14 Mar 2022 22:24:59 +0000 (22:24 +0000)
By default, git-repack(1) runs `update_server_info()` to generate info
required for the dumb HTTP protocol. This can be disabled via the `-n`
flag, which then sets the `no_update_server_info` flag. Further down the
code this leads to some double-negation logic, which is about to become
more confusing as we're about to add a new config which allows the user
to permanently disable generation of the info.

Refactor the code to avoid the double-negation and add some tests which
verify that the flag continues to work as expected.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/repack.c
t/t7700-repack.sh

index da1e364a756b9f8c74f38f8ec596798cf3ec38ad..f2ac8ad14b48472f33832436ee7e8101bcf1f9f1 100644 (file)
@@ -620,7 +620,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
        const char *unpack_unreachable = NULL;
        int keep_unreachable = 0;
        struct string_list keep_pack_list = STRING_LIST_INIT_NODUP;
-       int no_update_server_info = 0;
+       int run_update_server_info = 1;
        struct pack_objects_args po_args = {NULL};
        int geometric_factor = 0;
        int write_midx = 0;
@@ -637,8 +637,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                                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_BOOL('n', NULL, &no_update_server_info,
-                               N_("do not run git-update-server-info")),
+               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")),
                OPT_BOOL('l', "local", &po_args.local,
                                N_("pass --local to git-pack-objects")),
@@ -939,7 +939,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
                        prune_shallow(PRUNE_QUICK);
        }
 
-       if (!no_update_server_info)
+       if (run_update_server_info)
                update_server_info(0);
        remove_temporary_files();
 
index e489869dd94daf98f900d14d75a3da97f5f7ab34..73270477e4cc46d9799481eb712bcd6e3805b210 100755 (executable)
@@ -385,4 +385,36 @@ test_expect_success TTY '--quiet disables progress' '
        test_must_be_empty stderr
 '
 
+test_expect_success 'setup for update-server-info' '
+       git init update-server-info &&
+       test_commit -C update-server-info message
+'
+
+test_server_info_present () {
+       test_path_is_file update-server-info/.git/objects/info/packs &&
+       test_path_is_file update-server-info/.git/info/refs
+}
+
+test_server_info_missing () {
+       test_path_is_missing update-server-info/.git/objects/info/packs &&
+       test_path_is_missing update-server-info/.git/info/refs
+}
+
+test_server_info_cleanup () {
+       rm -f update-server-info/.git/objects/info/packs update-server-info/.git/info/refs &&
+       test_server_info_missing
+}
+
+test_expect_success 'updates server info by default' '
+       test_server_info_cleanup &&
+       git -C update-server-info repack &&
+       test_server_info_present
+'
+
+test_expect_success '-n skips updating server info' '
+       test_server_info_cleanup &&
+       git -C update-server-info repack -n &&
+       test_server_info_missing
+'
+
 test_done