fetch: move output format into `display_state`

The git-fetch(1) command supports printing references either in "full" or "compact" format depending on the `fetch.ouput` config key. The format that is to be used is tracked in a global variable. De-globalize the variable by moving it into the `display_state` structure. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Mar 20, 2023 at 13:35 UTC 5cab51ff7156edca8cb9eba30205efa11900e49c
1 file changed +6 -7
builtin/fetch.c
+6 -7
@@ -49,6 +49,7 @@ enum {
49
50 struct display_state {
51 int refcol_width;
52 + int compact_format;
53 };
54
55 static int fetch_prune_config = -1; /* unspecified */
@@ -745,9 +746,7 @@ out:
746 return ret;
747 }
748
748 -static int compact_format;
749 -
750 -static int refcol_width(const struct ref *ref)
749 +static int refcol_width(const struct ref *ref, int compact_format)
750 {
751 int max, rlen, llen, len;
752
@@ -789,9 +788,9 @@ static void display_state_init(struct display_state *display_state, struct ref *
788
789 git_config_get_string_tmp("fetch.output", &format);
790 if (!strcasecmp(format, "full"))
792 - compact_format = 0;
791 + display_state->compact_format = 0;
792 else if (!strcasecmp(format, "compact"))
794 - compact_format = 1;
793 + display_state->compact_format = 1;
794 else
795 die(_("invalid value for '%s': '%s'"),
796 "fetch.output", format);
@@ -805,7 +804,7 @@ static void display_state_init(struct display_state *display_state, struct ref *
804 !strcmp(rm->name, "HEAD"))
805 continue;
806
808 - width = refcol_width(rm);
807 + width = refcol_width(rm, display_state->compact_format);
808
809 /*
810 * Not precise calculation for compact mode because '*' can
@@ -887,7 +886,7 @@ static void format_display(struct display_state *display_state,
886 width = (summary_width + strlen(summary) - gettext_width(summary));
887
888 strbuf_addf(display_buffer, "%c %-*s ", code, width, summary);
890 - if (!compact_format)
889 + if (!display_state->compact_format)
890 print_remote_to_local(display_state, display_buffer, remote, local);
891 else
892 print_compact(display_state, display_buffer, remote, local);