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 <gitster@pobox.com>

Junio C Hamano committed Oct 21, 2016 at 15:22 UTC 901f3d403ef2416fb287399f8ed9c5dc5fb632f9
1 file changed +21 -16
builtin/fetch.c
+21 -16
@@ -17,9 +17,6 @@
17 #include "argv-array.h"
18 #include "utf8.h"
19
20 -#define TRANSPORT_SUMMARY(x) \
21 - (int)(TRANSPORT_SUMMARY_WIDTH + strlen(x) - gettext_width(x)), (x)
22 -
20 static const char * const builtin_fetch_usage[] = {
21 N_("git fetch [<options>] [<repository> [<refspec>...]]"),
22 N_("git fetch [<options>] <group>"),
@@ -569,9 +566,12 @@ static void print_compact(struct strbuf *display,
566
567 static void format_display(struct strbuf *display, char code,
568 const char *summary, const char *error,
572 - const char *remote, const char *local)
569 + const char *remote, const char *local,
570 + int summary_width)
571 {
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);
575 if (!compact_format)
576 print_remote_to_local(display, remote, local);
577 else
@@ -583,7 +583,8 @@ static void format_display(struct strbuf *display, char code,
583 static int update_local_ref(struct ref *ref,
584 const char *remote,
585 const struct ref *remote_ref,
586 - struct strbuf *display)
586 + struct strbuf *display,
587 + int summary_width)
588 {
589 struct commit *current = NULL, *updated;
590 enum object_type type;
@@ -597,7 +598,7 @@ static int update_local_ref(struct ref *ref,
598 if (!oidcmp(&ref->old_oid, &ref->new_oid)) {
599 if (verbosity > 0)
600 format_display(display, '=', _("[up to date]"), NULL,
600 - remote, pretty_ref);
601 + remote, pretty_ref, summary_width);
602 return 0;
603 }
604
@@ -611,7 +612,7 @@ static int update_local_ref(struct ref *ref,
612 */
613 format_display(display, '!', _("[rejected]"),
614 _("can't fetch in current branch"),
614 - remote, pretty_ref);
615 + remote, pretty_ref, summary_width);
616 return 1;
617 }
618
@@ -621,7 +622,7 @@ static int update_local_ref(struct ref *ref,
622 r = s_update_ref("updating tag", ref, 0);
623 format_display(display, r ? '!' : 't', _("[tag update]"),
624 r ? _("unable to update local ref") : NULL,
624 - remote, pretty_ref);
625 + remote, pretty_ref, summary_width);
626 return r;
627 }
628
@@ -654,7 +655,7 @@ static int update_local_ref(struct ref *ref,
655 r = s_update_ref(msg, ref, 0);
656 format_display(display, r ? '!' : '*', what,
657 r ? _("unable to update local ref") : NULL,
657 - remote, pretty_ref);
658 + remote, pretty_ref, summary_width);
659 return r;
660 }
661
@@ -670,7 +671,7 @@ static int update_local_ref(struct ref *ref,
671 r = s_update_ref("fast-forward", ref, 1);
672 format_display(display, r ? '!' : ' ', quickref.buf,
673 r ? _("unable to update local ref") : NULL,
673 - remote, pretty_ref);
674 + remote, pretty_ref, summary_width);
675 strbuf_release(&quickref);
676 return r;
677 } else if (force || ref->force) {
@@ -685,12 +686,12 @@ static int update_local_ref(struct ref *ref,
686 r = s_update_ref("forced-update", ref, 1);
687 format_display(display, r ? '!' : '+', quickref.buf,
688 r ? _("unable to update local ref") : _("forced update"),
688 - remote, pretty_ref);
689 + remote, pretty_ref, summary_width);
690 strbuf_release(&quickref);
691 return r;
692 } else {
693 format_display(display, '!', _("[rejected]"), _("non-fast-forward"),
693 - remote, pretty_ref);
694 + remote, pretty_ref, summary_width);
695 return 1;
696 }
697 }
@@ -721,6 +722,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
722 char *url;
723 const char *filename = dry_run ? "/dev/null" : git_path_fetch_head();
724 int want_status;
725 + int summary_width = TRANSPORT_SUMMARY_WIDTH;
726
727 fp = fopen(filename, "a");
728 if (!fp)
@@ -830,13 +832,14 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
832
833 strbuf_reset(&note);
834 if (ref) {
833 - rc |= update_local_ref(ref, what, rm, &note);
835 + rc |= update_local_ref(ref, what, rm, &note,
836 + summary_width);
837 free(ref);
838 } else
839 format_display(&note, '*',
840 *kind ? kind : "branch", NULL,
841 *what ? what : "HEAD",
839 - "FETCH_HEAD");
842 + "FETCH_HEAD", summary_width);
843 if (note.len) {
844 if (verbosity >= 0 && !shown_url) {
845 fprintf(stderr, _("From %.*s\n"),
@@ -903,6 +906,7 @@ static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map,
906 int url_len, i, result = 0;
907 struct ref *ref, *stale_refs = get_stale_heads(refs, ref_count, ref_map);
908 char *url;
909 + int summary_width = TRANSPORT_SUMMARY_WIDTH;
910 const char *dangling_msg = dry_run
911 ? _(" (%s will become dangling)")
912 : _(" (%s has become dangling)");
@@ -938,7 +942,8 @@ static int prune_refs(struct refspec *refs, int ref_count, struct ref *ref_map,
942 shown_url = 1;
943 }
944 format_display(&sb, '-', _("[deleted]"), NULL,
941 - _("(none)"), prettify_refname(ref->name));
945 + _("(none)"), prettify_refname(ref->name),
946 + summary_width);
947 fprintf(stderr, " %s\n",sb.buf);
948 strbuf_release(&sb);
949 warn_dangling_symref(stderr, dangling_msg, ref->name);