mirror of
https://github.com/git/git
synced 2024-10-29 17:08:46 +00:00
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>
This commit is contained in:
parent
ce9636d645
commit
5cab51ff71
1 changed files with 6 additions and 7 deletions
|
@ -49,6 +49,7 @@ enum {
|
||||||
|
|
||||||
struct display_state {
|
struct display_state {
|
||||||
int refcol_width;
|
int refcol_width;
|
||||||
|
int compact_format;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int fetch_prune_config = -1; /* unspecified */
|
static int fetch_prune_config = -1; /* unspecified */
|
||||||
|
@ -745,9 +746,7 @@ static int s_update_ref(const char *action,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compact_format;
|
static int refcol_width(const struct ref *ref, int compact_format)
|
||||||
|
|
||||||
static int refcol_width(const struct ref *ref)
|
|
||||||
{
|
{
|
||||||
int max, rlen, llen, len;
|
int max, rlen, llen, len;
|
||||||
|
|
||||||
|
@ -789,9 +788,9 @@ static void display_state_init(struct display_state *display_state, struct ref *
|
||||||
|
|
||||||
git_config_get_string_tmp("fetch.output", &format);
|
git_config_get_string_tmp("fetch.output", &format);
|
||||||
if (!strcasecmp(format, "full"))
|
if (!strcasecmp(format, "full"))
|
||||||
compact_format = 0;
|
display_state->compact_format = 0;
|
||||||
else if (!strcasecmp(format, "compact"))
|
else if (!strcasecmp(format, "compact"))
|
||||||
compact_format = 1;
|
display_state->compact_format = 1;
|
||||||
else
|
else
|
||||||
die(_("invalid value for '%s': '%s'"),
|
die(_("invalid value for '%s': '%s'"),
|
||||||
"fetch.output", format);
|
"fetch.output", format);
|
||||||
|
@ -805,7 +804,7 @@ static void display_state_init(struct display_state *display_state, struct ref *
|
||||||
!strcmp(rm->name, "HEAD"))
|
!strcmp(rm->name, "HEAD"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
width = refcol_width(rm);
|
width = refcol_width(rm, display_state->compact_format);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Not precise calculation for compact mode because '*' can
|
* Not precise calculation for compact mode because '*' can
|
||||||
|
@ -887,7 +886,7 @@ static void format_display(struct display_state *display_state,
|
||||||
width = (summary_width + strlen(summary) - gettext_width(summary));
|
width = (summary_width + strlen(summary) - gettext_width(summary));
|
||||||
|
|
||||||
strbuf_addf(display_buffer, "%c %-*s ", code, width, summary);
|
strbuf_addf(display_buffer, "%c %-*s ", code, width, summary);
|
||||||
if (!compact_format)
|
if (!display_state->compact_format)
|
||||||
print_remote_to_local(display_state, display_buffer, remote, local);
|
print_remote_to_local(display_state, display_buffer, remote, local);
|
||||||
else
|
else
|
||||||
print_compact(display_state, display_buffer, remote, local);
|
print_compact(display_state, display_buffer, remote, local);
|
||||||
|
|
Loading…
Reference in a new issue