Skip to content

Commit 901f3d4

Browse files
committed
fetch: pass summary_width down the callchain
The leaf function on the "fetch" side that uses TRANSPORT_SUMMARY_WIDTH constant is builtin/fetch.c::format_display() and it has two distinct callchains. The one that reports the primary result of fetch originates at store_updated_refs(); the other one that reports the pruning of the remote-tracking refs originates at prune_refs(). Teach these two places to pass summary_width down the callchain, just like we did for the "push" side in the previous commit. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7101e10 commit 901f3d4

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

builtin/fetch.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
#include "argv-array.h"
1818
#include "utf8.h"
1919

20-
#define TRANSPORT_SUMMARY(x) \
21-
(int)(TRANSPORT_SUMMARY_WIDTH + strlen(x) - gettext_width(x)), (x)
22-
2320
static const char * const builtin_fetch_usage[] = {
2421
N_("git fetch [<options>] [<repository> [<refspec>...]]"),
2522
N_("git fetch [<options>] <group>"),
@@ -569,9 +566,12 @@ static void print_compact(struct strbuf *display,
569566

570567
static void format_display(struct strbuf *display, char code,
571568
const char *summary, const char *error,
572-
const char *remote, const char *local)
569+
const char *remote, const char *local,
570+
int summary_width)
573571
{
574-
strbuf_addf(display, "%c %-*s ", code, TRANSPORT_SUMMARY(summary));
572+
int width = (summary_width + strlen(summary) - gettext_width(summary));
573+
574+
strbuf_addf(display, "%c %-*s ", code, width, summary);
575575
if (!compact_format)
576576
print_remote_to_local(display, remote, local);
577577
else
@@ -583,7 +583,8 @@ static void format_display(struct strbuf *display, char code,
583583
static int update_local_ref(struct ref *ref,
584584
const char *remote,
585585
const struct ref *remote_ref,
586-
struct strbuf *display)
586+
struct strbuf *display,
587+
int summary_width)
587588
{
588589
struct commit *current = NULL, *updated;
589590
enum object_type type;
@@ -597,7 +598,7 @@ static int update_local_ref(struct ref *ref,
597598
if (!oidcmp(&ref->old_oid, &ref->new_oid)) {
598599
if (verbosity > 0)
599600
format_display(display, '=', _("[up to date]"), NULL,
600-
remote, pretty_ref);
601+
remote, pretty_ref, summary_width);
601602
return 0;
602603
}
603604

@@ -611,7 +612,7 @@ static int update_local_ref(struct ref *ref,
611612
*/
612613
format_display(display, '!', _("[rejected]"),
613614
_("can't fetch in current branch"),
614-
remote, pretty_ref);
615+
remote, pretty_ref, summary_width);
615616
return 1;
616617
}
617618

@@ -621,7 +622,7 @@ static int update_local_ref(struct ref *ref,
621622
r = s_update_ref("updating tag", ref, 0);
622623
format_display(display, r ? '!' : 't', _("[tag update]"),
623624
r ? _("unable to update local ref") : NULL,
624-
remote, pretty_ref);
625+
remote, pretty_ref, summary_width);
625626
return r;
626627
}
627628

@@ -654,7 +655,7 @@ static int update_local_ref(struct ref *ref,
654655
r = s_update_ref(msg, ref, 0);
655656
format_display(display, r ? '!' : '*', what,
656657
r ? _("unable to update local ref") : NULL,
657-
remote, pretty_ref);
658+
remote, pretty_ref, summary_width);
658659
return r;
659660
}
660661

@@ -670,7 +671,7 @@ static int update_local_ref(struct ref *ref,
670671
r = s_update_ref("fast-forward", ref, 1);
671672
format_display(display, r ? '!' : ' ', quickref.buf,
672673
r ? _("unable to update local ref") : NULL,
673-
remote, pretty_ref);
674+
remote, pretty_ref, summary_width);
674675
strbuf_release(&quickref);
675676
return r;
676677
} else if (force || ref->force) {
@@ -685,12 +686,12 @@ static int update_local_ref(struct ref *ref,
685686
r = s_update_ref("forced-update", ref, 1);
686687
format_display(display, r ? '!' : '+', quickref.buf,
687688
r ? _("unable to update local ref") : _("forced update"),
688-
remote, pretty_ref);
689+
remote, pretty_ref, summary_width);
689690
strbuf_release(&quickref);
690691
return r;
691692
} else {
692693
format_display(display, '!', _("[rejected]"), _("non-fast-forward"),
693-
remote, pretty_ref);
694+
remote, pretty_ref, summary_width);
694695
return 1;
695696
}
696697
}
@@ -721,6 +722,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
721722
char *url;
722723
const char *filename = dry_run ? "/dev/null" : git_path_fetch_head();
723724
int want_status;
725+
int summary_width = TRANSPORT_SUMMARY_WIDTH;
724726

725727
fp = fopen(filename, "a");
726728
if (!fp)
@@ -830,13 +832,14 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
830832

831833
strbuf_reset(&note);
832834
if (ref) {
833-
rc |= update_local_ref(ref, what, rm, &note);
835+
rc |= update_local_ref(ref, what, rm, &note,
836+
summary_width);
834837
free(ref);
835838
} else
836839
format_display(&note, '*',
837840
*kind ? kind : "branch", NULL,
838841
*what ? what : "HEAD",
839-
"FETCH_HEAD");
842+
"FETCH_HEAD", summary_width);
840843
if (note.len) {
841844
if (verbosity >= 0 && !shown_url) {
842845
fprintf(stderr, _("From %.*s\n"),
@@ -903,6 +906,7 @@ static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map,
903906
int url_len, i, result = 0;
904907
struct ref *ref, *stale_refs = get_stale_heads(refs, ref_count, ref_map);
905908
char *url;
909+
int summary_width = TRANSPORT_SUMMARY_WIDTH;
906910
const char *dangling_msg = dry_run
907911
? _(" (%s will become dangling)")
908912
: _(" (%s has become dangling)");
@@ -938,7 +942,8 @@ static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map,
938942
shown_url = 1;
939943
}
940944
format_display(&sb, '-', _("[deleted]"), NULL,
941-
_("(none)"), prettify_refname(ref->name));
945+
_("(none)"), prettify_refname(ref->name),
946+
summary_width);
942947
fprintf(stderr, " %s\n",sb.buf);
943948
strbuf_release(&sb);
944949
warn_dangling_symref(stderr, dangling_msg, ref->name);

0 commit comments

Comments
 (0)