Skip to content

Commit 64a6151

Browse files
pks-tgitster
authored andcommitted
repack: refactor to avoid double-negation of update-server-info
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4c53a8c commit 64a6151

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

builtin/repack.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
620620
const char *unpack_unreachable = NULL;
621621
int keep_unreachable = 0;
622622
struct string_list keep_pack_list = STRING_LIST_INIT_NODUP;
623-
int no_update_server_info = 0;
623+
int run_update_server_info = 1;
624624
struct pack_objects_args po_args = {NULL};
625625
int geometric_factor = 0;
626626
int write_midx = 0;
@@ -637,8 +637,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
637637
N_("pass --no-reuse-delta to git-pack-objects")),
638638
OPT_BOOL('F', NULL, &po_args.no_reuse_object,
639639
N_("pass --no-reuse-object to git-pack-objects")),
640-
OPT_BOOL('n', NULL, &no_update_server_info,
641-
N_("do not run git-update-server-info")),
640+
OPT_NEGBIT('n', NULL, &run_update_server_info,
641+
N_("do not run git-update-server-info"), 1),
642642
OPT__QUIET(&po_args.quiet, N_("be quiet")),
643643
OPT_BOOL('l', "local", &po_args.local,
644644
N_("pass --local to git-pack-objects")),
@@ -939,7 +939,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix)
939939
prune_shallow(PRUNE_QUICK);
940940
}
941941

942-
if (!no_update_server_info)
942+
if (run_update_server_info)
943943
update_server_info(0);
944944
remove_temporary_files();
945945

t/t7700-repack.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,36 @@ test_expect_success TTY '--quiet disables progress' '
385385
test_must_be_empty stderr
386386
'
387387

388+
test_expect_success 'setup for update-server-info' '
389+
git init update-server-info &&
390+
test_commit -C update-server-info message
391+
'
392+
393+
test_server_info_present () {
394+
test_path_is_file update-server-info/.git/objects/info/packs &&
395+
test_path_is_file update-server-info/.git/info/refs
396+
}
397+
398+
test_server_info_missing () {
399+
test_path_is_missing update-server-info/.git/objects/info/packs &&
400+
test_path_is_missing update-server-info/.git/info/refs
401+
}
402+
403+
test_server_info_cleanup () {
404+
rm -f update-server-info/.git/objects/info/packs update-server-info/.git/info/refs &&
405+
test_server_info_missing
406+
}
407+
408+
test_expect_success 'updates server info by default' '
409+
test_server_info_cleanup &&
410+
git -C update-server-info repack &&
411+
test_server_info_present
412+
'
413+
414+
test_expect_success '-n skips updating server info' '
415+
test_server_info_cleanup &&
416+
git -C update-server-info repack -n &&
417+
test_server_info_missing
418+
'
419+
388420
test_done

0 commit comments

Comments
 (0)