fetch: pass the full local reference name to `format_display`

Before printing the name of the local references that would be updated by a fetch we first prettify the reference name. This is done at the calling side so that `format_display()` never sees the full name of the local reference. This restricts our ability to introduce new output formats that might want to print the full reference name. Right now, all callsites except one are prettifying the reference name anyway. And the only callsite that doesn't passes `FETCH_HEAD` as the hardcoded reference name to `format_display()`, which would never be changed by a call to `prettify_refname()` anyway. So let's refactor the code to pass in the full local reference name and then prettify it in the formatting code. 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 7c978db889f2a0eddf0799268f57b9457ef9ab3d
1 file changed +11 -12
builtin/fetch.c
+11 -12
@@ -887,9 +887,9 @@ static void format_display(struct display_state *display_state,
887
888 strbuf_addf(display_buffer, "%c %-*s ", code, width, summary);
889 if (!display_state->compact_format)
890 - print_remote_to_local(display_state, display_buffer, remote, local);
890 + print_remote_to_local(display_state, display_buffer, remote, prettify_refname(local));
891 else
892 - print_compact(display_state, display_buffer, remote, local);
892 + print_compact(display_state, display_buffer, remote, prettify_refname(local));
893 if (error)
894 strbuf_addf(display_buffer, " (%s)", error);
895 }
@@ -901,7 +901,6 @@ static int update_local_ref(struct ref *ref,
901 struct strbuf *display, int summary_width)
902 {
903 struct commit *current = NULL, *updated;
904 - const char *pretty_ref = prettify_refname(ref->name);
904 int fast_forward = 0;
905
906 if (!repo_has_object_file(the_repository, &ref->new_oid))
@@ -910,7 +909,7 @@ static int update_local_ref(struct ref *ref,
909 if (oideq(&ref->old_oid, &ref->new_oid)) {
910 if (verbosity > 0)
911 format_display(display_state, display, '=', _("[up to date]"), NULL,
913 - remote, pretty_ref, summary_width);
912 + remote, ref->name, summary_width);
913 return 0;
914 }
915
@@ -923,7 +922,7 @@ static int update_local_ref(struct ref *ref,
922 */
923 format_display(display_state, display, '!', _("[rejected]"),
924 _("can't fetch into checked-out branch"),
926 - remote, pretty_ref, summary_width);
925 + remote, ref->name, summary_width);
926 return 1;
927 }
928
@@ -934,12 +933,12 @@ static int update_local_ref(struct ref *ref,
933 r = s_update_ref("updating tag", ref, transaction, 0);
934 format_display(display_state, display, r ? '!' : 't', _("[tag update]"),
935 r ? _("unable to update local ref") : NULL,
937 - remote, pretty_ref, summary_width);
936 + remote, ref->name, summary_width);
937 return r;
938 } else {
939 format_display(display_state, display, '!', _("[rejected]"),
940 _("would clobber existing tag"),
942 - remote, pretty_ref, summary_width);
941 + remote, ref->name, summary_width);
942 return 1;
943 }
944 }
@@ -972,7 +971,7 @@ static int update_local_ref(struct ref *ref,
971 r = s_update_ref(msg, ref, transaction, 0);
972 format_display(display_state, display, r ? '!' : '*', what,
973 r ? _("unable to update local ref") : NULL,
975 - remote, pretty_ref, summary_width);
974 + remote, ref->name, summary_width);
975 return r;
976 }
977
@@ -994,7 +993,7 @@ static int update_local_ref(struct ref *ref,
993 r = s_update_ref("fast-forward", ref, transaction, 1);
994 format_display(display_state, display, r ? '!' : ' ', quickref.buf,
995 r ? _("unable to update local ref") : NULL,
997 - remote, pretty_ref, summary_width);
996 + remote, ref->name, summary_width);
997 strbuf_release(&quickref);
998 return r;
999 } else if (force || ref->force) {
@@ -1006,12 +1005,12 @@ static int update_local_ref(struct ref *ref,
1005 r = s_update_ref("forced-update", ref, transaction, 1);
1006 format_display(display_state, display, r ? '!' : '+', quickref.buf,
1007 r ? _("unable to update local ref") : _("forced update"),
1009 - remote, pretty_ref, summary_width);
1008 + remote, ref->name, summary_width);
1009 strbuf_release(&quickref);
1010 return r;
1011 } else {
1012 format_display(display_state, display, '!', _("[rejected]"), _("non-fast-forward"),
1014 - remote, pretty_ref, summary_width);
1013 + remote, ref->name, summary_width);
1014 return 1;
1015 }
1016 }
@@ -1431,7 +1430,7 @@ static int prune_refs(struct display_state *display_state,
1430 shown_url = 1;
1431 }
1432 format_display(display_state, &sb, '-', _("[deleted]"), NULL,
1434 - _("(none)"), prettify_refname(ref->name),
1433 + _("(none)"), ref->name,
1434 summary_width);
1435 fprintf(stderr, " %s\n",sb.buf);
1436 strbuf_release(&sb);