git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 1/2] repack: refactor to avoid double-negation of update-server-info

From
Patrick Steinhardt <ps@pks.im>
Date
Mar 14, 2022, 07:42 UTC
Message-ID
<feaa4615e2dcc3bc644d12bb2dba1ab28d5ecc1c.1647243508.git.ps@pks.im>
In-Reply-To
<cover.1647243508.git.ps@pks.im>

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>
---
 builtin/repack.c  |  8 ++++----
 t/t7700-repack.sh | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/builtin/repack.c b/builtin/repack.c
index da1e364a75..f2ac8ad14b 100644
--- a/builtin/repack.c
+++ b/builtin/repack.c
@@ -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();
 
diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh
index 5922fb5bdd..6b387bbdbe 100755
--- a/t/t7700-repack.sh
+++ b/t/t7700-repack.sh
@@ -381,4 +381,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
-- 
2.35.1
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 5 of 7 in “repack: add config to skip updating server info”
  1. repack: add config to skip updating server infoPatrick Steinhardt, Mar 11, 2022
  2. Taylor BlauMar 11, 2022
  3. Patrick SteinhardtMar 14, 2022
  4. 0/2 repack: add config to skip updating server infoPatrick Steinhardt, Mar 14, 2022
  5. 1/2 repack: refactor to avoid double-negation of update-server-infoPatrick Steinhardt, Mar 14, 2022
  6. 2/2 repack: add config to skip updating server infoPatrick Steinhardt, Mar 14, 2022
  7. Junio C HamanoMar 14, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.