{"thread":{"id":"46870","subject":"[PATCH] graph: use strbuf_addchars() to add spaces","startedAt":"2017-10-01T14:45:52Z","lastAt":"2017-10-02T05:11:24Z","messageCount":2,"participants":["René Scharfe","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"329285","messageId":"16d71d5b-6abf-4dcf-0a0b-c09fda7407f7@web.de","threadId":"46870","inReplyTo":null,"subject":"[PATCH] graph: use strbuf_addchars() to add spaces","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2017-10-01T14:45:45Z","receivedAt":"2017-10-01T14:45:52Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"strbuf_addf() can be used to add a specific number of space characters\nby using the format \"%*s\" with an empty string and specifying the\ndesired width.  Use strbuf_addchars() instead as it's shorter, makes the\nintent clearer and is a bit more efficient.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n graph.c | 10 +++-------\n 1 file changed, 3 insertions(+), 7 deletions(-)\n\ndiff --git a/graph.c b/graph.c\nindex e7e20650da..e1f6d3bddb 100644\n--- a/graph.c\n+++ b/graph.c\n@@ -696,12 +696,8 @@ static void graph_pad_horizontally(struct git_graph *graph, struct strbuf *sb,\n \t * This way, fields printed to the right of the graph will remain\n \t * aligned for the entire commit.\n \t */\n-\tint extra;\n-\tif (chars_written >= graph->width)\n-\t\treturn;\n-\n-\textra = graph->width - chars_written;\n-\tstrbuf_addf(sb, \"%*s\", (int) extra, \"\");\n+\tif (chars_written < graph->width)\n+\t\tstrbuf_addchars(sb, ' ', graph->width - chars_written);\n }\n \n static void graph_output_padding_line(struct git_graph *graph,\n@@ -787,7 +783,7 @@ static void graph_output_pre_commit_line(struct git_graph *graph,\n \t\tif (col->commit == graph->commit) {\n \t\t\tseen_this = 1;\n \t\t\tstrbuf_write_column(sb, col, '|');\n-\t\t\tstrbuf_addf(sb, \"%*s\", graph->expansion_row, \"\");\n+\t\t\tstrbuf_addchars(sb, ' ', graph->expansion_row);\n \t\t\tchars_written += 1 + graph->expansion_row;\n \t\t} else if (seen_this && (graph->expansion_row == 0)) {\n \t\t\t/*\n-- \n2.14.2\n\n"},{"id":"329386","messageId":"20171002051118.zuiwb4jvl6duq4pv@sigill.intra.peff.net","threadId":"46870","inReplyTo":"16d71d5b-6abf-4dcf-0a0b-c09fda7407f7@web.de","subject":"Re: [PATCH] graph: use strbuf_addchars() to add spaces","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-10-02T05:11:19Z","receivedAt":"2017-10-02T05:11:24Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Oct 01, 2017 at 04:45:45PM +0200, René Scharfe wrote:\n\n> strbuf_addf() can be used to add a specific number of space characters\n> by using the format \"%*s\" with an empty string and specifying the\n> desired width.  Use strbuf_addchars() instead as it's shorter, makes the\n> intent clearer and is a bit more efficient.\n\nNice. The result looks much clearer to me.\n\n(I won't respond individually to the coccinelle transform patches you\nposted earlier, but they also all look obviously correct to me).\n\n-Peff\n"}]}