Skip to content

Commit 38bdf62

Browse files
rscharfegitster
authored andcommitted
graph: use strbuf_addchars() to add spaces
strbuf_addf() can be used to add a specific number of space characters by using the format "%*s" with an empty string and specifying the desired width. Use strbuf_addchars() instead as it's shorter, makes the intent clearer and is a bit more efficient. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 72d4a9a commit 38bdf62

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

graph.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -696,12 +696,8 @@ static void graph_pad_horizontally(struct git_graph *graph, struct strbuf *sb,
696696
* This way, fields printed to the right of the graph will remain
697697
* aligned for the entire commit.
698698
*/
699-
int extra;
700-
if (chars_written >= graph->width)
701-
return;
702-
703-
extra = graph->width - chars_written;
704-
strbuf_addf(sb, "%*s", (int) extra, "");
699+
if (chars_written < graph->width)
700+
strbuf_addchars(sb, ' ', graph->width - chars_written);
705701
}
706702

707703
static void graph_output_padding_line(struct git_graph *graph,
@@ -787,7 +783,7 @@ static void graph_output_pre_commit_line(struct git_graph *graph,
787783
if (col->commit == graph->commit) {
788784
seen_this = 1;
789785
strbuf_write_column(sb, col, '|');
790-
strbuf_addf(sb, "%*s", graph->expansion_row, "");
786+
strbuf_addchars(sb, ' ', graph->expansion_row);
791787
chars_written += 1 + graph->expansion_row;
792788
} else if (seen_this && (graph->expansion_row == 0)) {
793789
/*

0 commit comments

Comments
 (0)