[PATCH v7 2/4] receive-pack: drop static variables to track report status version
From: Karthik Nayak <hidden>
Date: 2026-09-04 21:29:01
Subsystem:
the rest · Maintainer:
Linus Torvalds
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 [off-list ref] Signed-off-by: Karthik Nayak <redacted> --- 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..c356e34cd8 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_UNKOWN = 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_UNKOWN; 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