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>
John Keeping committed
Feb 7, 2013 at 20:15 UTC
f192223447746a503bf664135a0e537d15876ebe
2 files changed
+13
diff.c
+10
@@ -1105,6 +1105,16 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix)
1105
return "";
1106
}
1107
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
+
1118
static unsigned long sane_truncate_line(struct emit_callback *ecb, char *line, unsigned long len)
1119
{
1120
const char *cp;
diff.h
+3
@@ -174,6 +174,9 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix);
174
diff_get_color((o)->use_color, ix)
175
176
177
+const char *diff_line_prefix(struct diff_options *);
178
+
179
+
180
extern const char mime_boundary_leader[];
181
182
extern void diff_tree_setup_paths(const char **paths, struct diff_options *);