Skip to content

Commit 19752d9

Browse files
peffgitster
authored andcommitted
diff: return line_prefix directly when possible
We may point our output_prefix callback to diff_output_prefix_callback() in any of these cases: 1. we have a user-provided line_prefix 2. we have a graph prefix to show 3. both (1) and (2) The function combines the available elements into a strbuf and returns its pointer. In the case that we just have the line_prefix, though, there is no need for the strbuf. We can return the string directly. This is a minor optimization by itself, but also will allow us to clean up some memory ownership issues on top. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 436728f commit 19752d9

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

graph.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ static const char *diff_output_prefix_callback(struct diff_options *opt, void *d
316316

317317
assert(opt);
318318

319+
if (!graph)
320+
return opt->line_prefix;
321+
319322
strbuf_reset(&msgbuf);
320323
if (opt->line_prefix)
321324
strbuf_addstr(&msgbuf, opt->line_prefix);

0 commit comments

Comments
 (0)