Skip to content

Commit 7c978db

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

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

builtin/fetch.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -887,9 +887,9 @@ static void format_display(struct display_state *display_state,
887887

888888
strbuf_addf(display_buffer, "%c %-*s ", code, width, summary);
889889
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));
891891
else
892-
print_compact(display_state, display_buffer, remote, local);
892+
print_compact(display_state, display_buffer, remote, prettify_refname(local));
893893
if (error)
894894
strbuf_addf(display_buffer, " (%s)", error);
895895
}
@@ -901,7 +901,6 @@ static int update_local_ref(struct ref *ref,
901901
struct strbuf *display, int summary_width)
902902
{
903903
struct commit *current = NULL, *updated;
904-
const char *pretty_ref = prettify_refname(ref->name);
905904
int fast_forward = 0;
906905

907906
if (!repo_has_object_file(the_repository, &ref->new_oid))
@@ -910,7 +909,7 @@ static int update_local_ref(struct ref *ref,
910909
if (oideq(&ref->old_oid, &ref->new_oid)) {
911910
if (verbosity > 0)
912911
format_display(display_state, display, '=', _("[up to date]"), NULL,
913-
remote, pretty_ref, summary_width);
912+
remote, ref->name, summary_width);
914913
return 0;
915914
}
916915

@@ -923,7 +922,7 @@ static int update_local_ref(struct ref *ref,
923922
*/
924923
format_display(display_state, display, '!', _("[rejected]"),
925924
_("can't fetch into checked-out branch"),
926-
remote, pretty_ref, summary_width);
925+
remote, ref->name, summary_width);
927926
return 1;
928927
}
929928

@@ -934,12 +933,12 @@ static int update_local_ref(struct ref *ref,
934933
r = s_update_ref("updating tag", ref, transaction, 0);
935934
format_display(display_state, display, r ? '!' : 't', _("[tag update]"),
936935
r ? _("unable to update local ref") : NULL,
937-
remote, pretty_ref, summary_width);
936+
remote, ref->name, summary_width);
938937
return r;
939938
} else {
940939
format_display(display_state, display, '!', _("[rejected]"),
941940
_("would clobber existing tag"),
942-
remote, pretty_ref, summary_width);
941+
remote, ref->name, summary_width);
943942
return 1;
944943
}
945944
}
@@ -972,7 +971,7 @@ static int update_local_ref(struct ref *ref,
972971
r = s_update_ref(msg, ref, transaction, 0);
973972
format_display(display_state, display, r ? '!' : '*', what,
974973
r ? _("unable to update local ref") : NULL,
975-
remote, pretty_ref, summary_width);
974+
remote, ref->name, summary_width);
976975
return r;
977976
}
978977

@@ -994,7 +993,7 @@ static int update_local_ref(struct ref *ref,
994993
r = s_update_ref("fast-forward", ref, transaction, 1);
995994
format_display(display_state, display, r ? '!' : ' ', quickref.buf,
996995
r ? _("unable to update local ref") : NULL,
997-
remote, pretty_ref, summary_width);
996+
remote, ref->name, summary_width);
998997
strbuf_release(&quickref);
999998
return r;
1000999
} else if (force || ref->force) {
@@ -1006,12 +1005,12 @@ static int update_local_ref(struct ref *ref,
10061005
r = s_update_ref("forced-update", ref, transaction, 1);
10071006
format_display(display_state, display, r ? '!' : '+', quickref.buf,
10081007
r ? _("unable to update local ref") : _("forced update"),
1009-
remote, pretty_ref, summary_width);
1008+
remote, ref->name, summary_width);
10101009
strbuf_release(&quickref);
10111010
return r;
10121011
} else {
10131012
format_display(display_state, display, '!', _("[rejected]"), _("non-fast-forward"),
1014-
remote, pretty_ref, summary_width);
1013+
remote, ref->name, summary_width);
10151014
return 1;
10161015
}
10171016
}
@@ -1431,7 +1430,7 @@ static int prune_refs(struct display_state *display_state,
14311430
shown_url = 1;
14321431
}
14331432
format_display(display_state, &sb, '-', _("[deleted]"), NULL,
1434-
_("(none)"), prettify_refname(ref->name),
1433+
_("(none)"), ref->name,
14351434
summary_width);
14361435
fprintf(stderr, " %s\n",sb.buf);
14371436
strbuf_release(&sb);

0 commit comments

Comments
 (0)