Git development
 help / color / mirror / Atom feed
From: Karthik Nayak <karthik.188@gmail.com>
To: git@vger.kernel.org
Cc: ps@pks.im, gitster@pobox.com, jltobler@gmail.com,
	 kristofferhaugsbakk@fastmail.com,
	Phillip Wood <phillip.wood@dunelm.org.uk>,
	 Karthik Nayak <karthik.188@gmail.com>
Subject: [PATCH v8 2/4] receive-pack: drop static variables to track report status version
Date: Tue, 08 Sep 2026 12:27:02 +0200	[thread overview]
Message-ID: <20260908-758-introduce-hook-v8-2-be88a671ae1f@gmail.com> (raw)
In-Reply-To: <20260908-758-introduce-hook-v8-0-be88a671ae1f@gmail.com>

In 'git-receive-pack(1)', to track the report status version, we use the
static variables `report_status` and `report_status_v2`. As the report
status version is mutually exclusive, using an enum better suits the
requirement. switch to using a new `enum report_status_version`, while
also dropping the static variable to make the flow easier to understand.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
---
 builtin/receive-pack.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index e6e54ba55f..f7ff6a9abe 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -53,6 +53,12 @@ enum deny_action {
 	DENY_UPDATE_INSTEAD
 };
 
+enum report_status_version {
+	REPORT_STATUS_UNKNOWN = 0,
+	REPORT_STATUS_V0,
+	REPORT_STATUS_V2,
+};
+
 static int deny_deletes;
 static int deny_non_fast_forwards;
 static enum deny_action deny_current_branch = DENY_UNCONFIGURED;
@@ -64,8 +70,6 @@ static int advertise_atomic_push = 1;
 static int advertise_push_options;
 static int advertise_sid;
 static off_t max_input_size;
-static int report_status;
-static int report_status_v2;
 static int use_sideband;
 static int use_atomic;
 static int use_push_options;
@@ -2191,7 +2195,8 @@ static void queue_commands_from_cert(struct command **tail,
 }
 
 static struct command *read_head_info(struct packet_reader *reader,
-				      struct oid_array *shallow)
+				      struct oid_array *shallow,
+				      enum report_status_version *version)
 {
 	struct command *commands = NULL;
 	struct command **p = &commands;
@@ -2217,9 +2222,9 @@ static struct command *read_head_info(struct packet_reader *reader,
 			const char *client_sid;
 			size_t len = 0;
 			if (parse_feature_request(feature_list, "report-status"))
-				report_status = 1;
+				*version = REPORT_STATUS_V0;
 			if (parse_feature_request(feature_list, "report-status-v2"))
-				report_status_v2 = 1;
+				*version = REPORT_STATUS_V2;
 			if (parse_feature_request(feature_list, "side-band-64k"))
 				use_sideband = LARGE_PACKET_MAX;
 			if (parse_feature_request(feature_list, "quiet"))
@@ -2500,6 +2505,7 @@ int cmd_receive_pack(int argc,
 	struct shallow_info si;
 	struct packet_reader reader;
 	struct odb_transaction *transaction = NULL;
+	enum report_status_version version = REPORT_STATUS_UNKNOWN;
 
 	struct option options[] = {
 		OPT__QUIET(&quiet, N_("quiet")),
@@ -2563,7 +2569,7 @@ int cmd_receive_pack(int argc,
 			   PACKET_READ_CHOMP_NEWLINE |
 			   PACKET_READ_DIE_ON_ERR_PACKET);
 
-	if ((commands = read_head_info(&reader, &shallow))) {
+	if ((commands = read_head_info(&reader, &shallow, &version))) {
 		struct string_list push_options = STRING_LIST_INIT_DUP;
 		struct strbuf unpack_status = STRBUF_INIT;
 
@@ -2596,10 +2602,18 @@ int cmd_receive_pack(int argc,
 				 &push_options);
 		odb_transaction_finalize(transaction);
 		sigchain_push(SIGPIPE, SIG_IGN);
-		if (report_status_v2)
+
+		switch (version) {
+		case REPORT_STATUS_V2:
 			report_v2(commands, &unpack_status);
-		else if (report_status)
+			break;
+		case REPORT_STATUS_V0:
 			report(commands, &unpack_status);
+			break;
+		default:
+			BUG("unknown report status version");
+		}
+
 		sigchain_pop(SIGPIPE);
 		run_receive_hook(commands, "post-receive", 1, NULL,
 				 &push_options);

-- 
2.55.GIT


  parent reply	other threads:[~2026-09-08 10:27 UTC|newest]

Thread overview: 96+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-18  7:55 [PATCH] hook: introduce the report hook for git-receive-pack(1) Karthik Nayak
2026-08-18 20:54 ` Junio C Hamano
2026-08-19  7:03 ` Kristoffer Haugsbakk
2026-08-19 12:11   ` Karthik Nayak
2026-08-19 14:47     ` Kristoffer Haugsbakk
2026-08-19  7:39 ` Patrick Steinhardt
2026-08-19 13:13   ` Karthik Nayak
2026-08-19 13:20     ` Patrick Steinhardt
2026-08-19 13:24       ` Karthik Nayak
2026-08-20  9:50 ` Phillip Wood
2026-08-20 15:43   ` Junio C Hamano
2026-08-21 12:51   ` Karthik Nayak
2026-08-21 13:34 ` [PATCH v2] " Karthik Nayak
2026-08-21 13:49   ` Patrick Steinhardt
2026-08-21 16:08     ` Karthik Nayak
2026-08-24  5:32       ` Patrick Steinhardt
2026-08-24  8:14         ` Karthik Nayak
2026-08-21 16:55     ` Junio C Hamano
2026-08-24 10:20 ` [PATCH v3 0/3] " Karthik Nayak
2026-08-24 10:20   ` [PATCH v3 1/3] doc: add proc-receive hook info in 'git-receive-pack.adoc' Karthik Nayak
2026-08-24 10:21   ` [PATCH v3 2/3] receive-pack: move message generation to separate function Karthik Nayak
2026-08-24 10:21   ` [PATCH v3 3/3] hook: introduce the report hook for git-receive-pack(1) Karthik Nayak
2026-08-24 15:35   ` [PATCH v3 0/3] " Junio C Hamano
2026-08-24 15:57     ` Junio C Hamano
2026-08-24 17:00       ` Patrick Steinhardt
2026-08-26  8:35     ` Karthik Nayak
2026-08-26 14:39       ` Junio C Hamano
2026-08-26 10:19 ` [PATCH v4 0/3] hook: introduce the receive-report hook Karthik Nayak
2026-08-26 10:19   ` [PATCH v4 1/3] doc: add proc-receive hook info in 'git-receive-pack.adoc' Karthik Nayak
2026-08-31  6:44     ` Patrick Steinhardt
2026-08-31 18:22       ` Karthik Nayak
2026-08-26 10:19   ` [PATCH v4 2/3] receive-pack: move message generation to separate function Karthik Nayak
2026-08-31  6:44     ` Patrick Steinhardt
2026-08-31 19:05       ` Karthik Nayak
2026-08-26 10:19   ` [PATCH v4 3/3] hook: introduce the receive-report hook Karthik Nayak
2026-08-31  6:45     ` Patrick Steinhardt
2026-09-01 15:19 ` [PATCH v5 0/3] " Karthik Nayak
2026-09-01 15:19   ` [PATCH v5 1/3] doc: add proc-receive hook info in 'git-receive-pack.adoc' Karthik Nayak
2026-09-01 15:19   ` [PATCH v5 2/3] receive-pack: move message generation to separate function Karthik Nayak
2026-09-01 16:23     ` Junio C Hamano
2026-09-02 11:23       ` Karthik Nayak
2026-09-01 15:19   ` [PATCH v5 3/3] hook: introduce the receive-report hook Karthik Nayak
2026-09-01 17:03     ` Junio C Hamano
2026-09-02 14:42       ` Karthik Nayak
2026-09-02 19:14         ` Junio C Hamano
2026-09-03  9:27 ` [PATCH v6 0/4] " Karthik Nayak
2026-09-03  9:27   ` [PATCH v6 1/4] doc: add proc-receive hook info in 'git-receive-pack.adoc' Karthik Nayak
2026-09-03  9:27   ` [PATCH v6 2/4] receive-pack: drop static variables to track report status version Karthik Nayak
2026-09-03 10:03     ` Patrick Steinhardt
2026-09-03 16:31       ` Karthik Nayak
2026-09-03  9:28   ` [PATCH v6 3/4] receive-pack: move message generation to separate function Karthik Nayak
2026-09-03 10:03     ` Patrick Steinhardt
2026-09-03 16:32       ` Karthik Nayak
2026-09-03  9:28   ` [PATCH v6 4/4] hook: introduce the receive-report hook Karthik Nayak
2026-09-03 10:03     ` Patrick Steinhardt
2026-09-03 16:32       ` Karthik Nayak
2026-09-04 21:28 ` [PATCH v7 0/4] " Karthik Nayak
2026-09-04 21:28   ` [PATCH v7 1/4] doc: add proc-receive hook info in 'git-receive-pack.adoc' Karthik Nayak
2026-09-04 21:28   ` [PATCH v7 2/4] receive-pack: drop static variables to track report status version Karthik Nayak
2026-09-07 20:58     ` Junio C Hamano
2026-09-08  9:22       ` Karthik Nayak
2026-09-04 21:28   ` [PATCH v7 3/4] receive-pack: move message generation to separate function Karthik Nayak
2026-09-07 20:58     ` Junio C Hamano
2026-09-08  9:22       ` Karthik Nayak
2026-09-04 21:28   ` [PATCH v7 4/4] hook: introduce the receive-report hook Karthik Nayak
2026-09-07 20:58     ` Junio C Hamano
2026-09-08  9:57       ` Karthik Nayak
2026-09-07  6:06   ` [PATCH v7 0/4] " Patrick Steinhardt
2026-09-08 11:48     ` Karthik Nayak
2026-09-08 10:27 ` [PATCH v8 " Karthik Nayak
2026-09-08 10:27   ` [PATCH v8 1/4] doc: add proc-receive hook info in 'git-receive-pack.adoc' Karthik Nayak
2026-09-08 10:27   ` Karthik Nayak [this message]
2026-09-08 19:50     ` [PATCH v8 2/4] receive-pack: drop static variables to track report status version Junio C Hamano
2026-09-08 10:27   ` [PATCH v8 3/4] receive-pack: move message generation to separate function Karthik Nayak
2026-09-08 10:27   ` [PATCH v8 4/4] hook: introduce the receive-report hook Karthik Nayak
2026-09-09 14:51 ` [PATCH v9 0/4] " Karthik Nayak
2026-09-09 14:51   ` [PATCH v9 1/4] doc: add proc-receive hook info in 'git-receive-pack.adoc' Karthik Nayak
2026-09-09 14:51   ` [PATCH v9 2/4] receive-pack: drop static variables to track report status version Karthik Nayak
2026-09-09 14:51   ` [PATCH v9 3/4] receive-pack: move message generation to separate function Karthik Nayak
2026-09-09 14:51   ` [PATCH v9 4/4] hook: introduce the receive-report hook Karthik Nayak
2026-09-10  3:15     ` Junio C Hamano
2026-09-10 16:32       ` Karthik Nayak
2026-09-11 13:54     ` Oswald Buddenhagen
2026-09-11 21:23       ` Karthik Nayak
2026-09-09 15:00   ` [PATCH v9 0/4] " Patrick Steinhardt
2026-09-09 17:20     ` Junio C Hamano
2026-09-10  4:02       ` Jeff King
2026-09-10 16:40         ` Karthik Nayak
2026-09-10 13:43       ` Karthik Nayak
2026-09-10 21:54 ` [PATCH v10 " Karthik Nayak
2026-09-10 21:54   ` [PATCH v10 1/4] doc: add proc-receive hook info in 'git-receive-pack.adoc' Karthik Nayak
2026-09-10 21:54   ` [PATCH v10 2/4] receive-pack: drop static variables to track report status version Karthik Nayak
2026-09-10 21:54   ` [PATCH v10 3/4] receive-pack: move message generation to separate function Karthik Nayak
2026-09-10 21:54   ` [PATCH v10 4/4] hook: introduce the receive-report hook Karthik Nayak
2026-09-11 21:39     ` Junio C Hamano
2026-09-11 21:58       ` Karthik Nayak

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=20260908-758-introduce-hook-v8-2-be88a671ae1f@gmail.com \
    --to=karthik.188@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jltobler@gmail.com \
    --cc=kristofferhaugsbakk@fastmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=ps@pks.im \
    /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