git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/6] diff: add diff_line_prefix function

From
John Keeping <john@keeping.me.uk>
Date
Feb 7, 2013, 20:15 UTC
Message-ID
<dfb0c8fc336ae6e125e5307311e8b49425d06aa5.1360267849.git.john@keeping.me.uk>
In-Reply-To
<cover.1360267849.git.john@keeping.me.uk>

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>
---
 diff.c | 10 ++++++++++
 diff.h |  3 +++
 2 files changed, 13 insertions(+)
diff --git a/diff.c b/diff.c
index 73ae02d..ed14d5d 100644
--- 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 a47bae4..76830e2 100644
--- 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 *);
-- 
1.8.1.2
Previous: John KeepingNext: John Keeping
Message 6 of 9 in “Improve "git log --graph" output of merges”
  1. 0/6 Improve "git log --graph" output of mergesJohn Keeping, Feb 7, 2013
  2. 1/6 graph: output padding for merge subsequent parentsJohn Keeping, Feb 7, 2013
  3. John KeepingFeb 8, 2013
  4. 2/6 diff: write prefix to the correct fileJohn Keeping, Feb 7, 2013
  5. 3/6 diff.c: make constant string arguments constJohn Keeping, Feb 7, 2013
  6. 4/6 diff: add diff_line_prefix functionJohn Keeping, Feb 7, 2013
  7. 5/6 diff.c: use diff_line_prefix() where applicableJohn Keeping, Feb 7, 2013
  8. 6/6 combine-diff.c: teach combined diffs about line prefixJohn Keeping, Feb 7, 2013
  9. Junio C HamanoFeb 7, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.