diff: add diff_line_prefix function
authorJohn Keeping <john@keeping.me.uk>
Thu, 7 Feb 2013 20:15:26 +0000 (20:15 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 12 Feb 2013 19:42:07 +0000 (11:42 -0800)
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>
diff.c
diff.h

diff --git a/diff.c b/diff.c
index e00fc9053892f0923fc9c6ae7f9ac47968c0a8be..b768b7d38425e24286fad4e224d4c7157154ec1c 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -1105,6 +1105,16 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix)
        return "";
 }
 
+const char *diff_line_prefix(struct diff_options *opt)
+{
+       struct strbuf *msgbuf;
+       if (!opt->output_prefix)
+               return "";
+
+       msgbuf = opt->output_prefix(opt, opt->output_prefix_data);
+       return msgbuf->buf;
+}
+
 static unsigned long sane_truncate_line(struct emit_callback *ecb, char *line, unsigned long len)
 {
        const char *cp;
diff --git a/diff.h b/diff.h
index a47bae48d5d14a321108aac3b3de3892587b264f..76830e28b42ab623ef9dc1d23c4b82b952fadd3a 100644 (file)
--- a/diff.h
+++ b/diff.h
@@ -174,6 +174,9 @@ const char *diff_get_color(int diff_use_color, enum color_diff ix);
        diff_get_color((o)->use_color, ix)
 
 
+const char *diff_line_prefix(struct diff_options *);
+
+
 extern const char mime_boundary_leader[];
 
 extern void diff_tree_setup_paths(const char **paths, struct diff_options *);