Skip to content

Commit 5cab51f

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ce9636d commit 5cab51f

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

builtin/fetch.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ enum {
4949

5050
struct display_state {
5151
int refcol_width;
52+
int compact_format;
5253
};
5354

5455
static int fetch_prune_config = -1; /* unspecified */
@@ -745,9 +746,7 @@ static int s_update_ref(const char *action,
745746
return ret;
746747
}
747748

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)
751750
{
752751
int max, rlen, llen, len;
753752

@@ -789,9 +788,9 @@ static void display_state_init(struct display_state *display_state, struct ref *
789788

790789
git_config_get_string_tmp("fetch.output", &format);
791790
if (!strcasecmp(format, "full"))
792-
compact_format = 0;
791+
display_state->compact_format = 0;
793792
else if (!strcasecmp(format, "compact"))
794-
compact_format = 1;
793+
display_state->compact_format = 1;
795794
else
796795
die(_("invalid value for '%s': '%s'"),
797796
"fetch.output", format);
@@ -805,7 +804,7 @@ static void display_state_init(struct display_state *display_state, struct ref *
805804
!strcmp(rm->name, "HEAD"))
806805
continue;
807806

808-
width = refcol_width(rm);
807+
width = refcol_width(rm, display_state->compact_format);
809808

810809
/*
811810
* Not precise calculation for compact mode because '*' can
@@ -887,7 +886,7 @@ static void format_display(struct display_state *display_state,
887886
width = (summary_width + strlen(summary) - gettext_width(summary));
888887

889888
strbuf_addf(display_buffer, "%c %-*s ", code, width, summary);
890-
if (!compact_format)
889+
if (!display_state->compact_format)
891890
print_remote_to_local(display_state, display_buffer, remote, local);
892891
else
893892
print_compact(display_state, display_buffer, remote, local);

0 commit comments

Comments
 (0)