git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Taylor Blau <me@ttaylorr.com>
Subject: [PATCH v2 1/2] repack: refactor to avoid double-negation of update-server-info
Date: Mon, 14 Mar 2022 08:42:46 +0100	[thread overview]
Message-ID: <feaa4615e2dcc3bc644d12bb2dba1ab28d5ecc1c.1647243508.git.ps@pks.im> (raw)
In-Reply-To: <cover.1647243508.git.ps@pks.im>

[-- Attachment #1: Type: text/plain, Size: 3321 bytes --]

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


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2022-03-14  7:42 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-11 11:09 [PATCH] repack: add config to skip updating server info Patrick Steinhardt
2022-03-11 16:20 ` Taylor Blau
2022-03-14  7:19   ` Patrick Steinhardt
2022-03-14  7:42 ` [PATCH v2 0/2] " Patrick Steinhardt
2022-03-14  7:42   ` Patrick Steinhardt [this message]
2022-03-14  7:42   ` [PATCH v2 2/2] " Patrick Steinhardt
2022-03-14 22:26     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=feaa4615e2dcc3bc644d12bb2dba1ab28d5ecc1c.1647243508.git.ps@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=me@ttaylorr.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).