Skip to content

Commit 331b7d2

Browse files
pks-tgitster
authored andcommitted
fetch: centralize handling of per-reference format
The function `format_display()` is used to print a single reference update to a buffer which will then ultimately be printed by the caller. This architecture causes us to duplicate some logic across the different callsites of this function. This makes it hard to follow the code as some parts of the logic are located in one place, while other parts of the logic are located in a different place. Furthermore, by having the logic scattered around it becomes quite hard to implement a new output format for the reference updates. We can make the logic a whole lot easier to understand by making the `format_display()` function self-contained so that it handles formatting and printing of the references. This will eventually allow us to easily implement a completely different output format, but also opens the door to conditionally print to either stdout or stderr depending on the output format. As a first step towards that goal we move the formatting directive used by both callers to print a single reference update into this function. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7c978db commit 331b7d2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

builtin/fetch.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,13 +885,14 @@ static void format_display(struct display_state *display_state,
885885

886886
width = (summary_width + strlen(summary) - gettext_width(summary));
887887

888-
strbuf_addf(display_buffer, "%c %-*s ", code, width, summary);
888+
strbuf_addf(display_buffer, " %c %-*s ", code, width, summary);
889889
if (!display_state->compact_format)
890890
print_remote_to_local(display_state, display_buffer, remote, prettify_refname(local));
891891
else
892892
print_compact(display_state, display_buffer, remote, prettify_refname(local));
893893
if (error)
894894
strbuf_addf(display_buffer, " (%s)", error);
895+
strbuf_addch(display_buffer, '\n');
895896
}
896897

897898
static int update_local_ref(struct ref *ref,
@@ -1271,7 +1272,7 @@ static int store_updated_refs(struct display_state *display_state,
12711272
url_len, url);
12721273
shown_url = 1;
12731274
}
1274-
fprintf(stderr, " %s\n", note.buf);
1275+
fputs(note.buf, stderr);
12751276
}
12761277
}
12771278
}
@@ -1432,7 +1433,7 @@ static int prune_refs(struct display_state *display_state,
14321433
format_display(display_state, &sb, '-', _("[deleted]"), NULL,
14331434
_("(none)"), ref->name,
14341435
summary_width);
1435-
fprintf(stderr, " %s\n",sb.buf);
1436+
fputs(sb.buf, stderr);
14361437
strbuf_release(&sb);
14371438
warn_dangling_symref(stderr, dangling_msg, ref->name);
14381439
}

0 commit comments

Comments
 (0)