Skip to content

Commit f192223

Browse files
johnkeepinggitster
authored andcommitted
diff: add diff_line_prefix function
This is a helper function to call the diff output_prefix function and return its value as a C string, allowing us to greatly simplify everywhere that needs to get the output prefix. Signed-off-by: John Keeping <john@keeping.me.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 32b367e commit f192223

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

diff.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,16 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix)
11051105
return "";
11061106
}
11071107

1108+
const char *diff_line_prefix(struct diff_options *opt)
1109+
{
1110+
struct strbuf *msgbuf;
1111+
if (!opt->output_prefix)
1112+
return "";
1113+
1114+
msgbuf = opt->output_prefix(opt, opt->output_prefix_data);
1115+
return msgbuf->buf;
1116+
}
1117+
11081118
static unsigned long sane_truncate_line(struct emit_callback *ecb, char *line, unsigned long len)
11091119
{
11101120
const char *cp;

diff.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix);
174174
diff_get_color((o)->use_color, ix)
175175

176176

177+
const char *diff_line_prefix(struct diff_options *);
178+
179+
177180
extern const char mime_boundary_leader[];
178181

179182
extern void diff_tree_setup_paths(const char **paths, struct diff_options *);

0 commit comments

Comments
 (0)