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

[RFC PATCH 4/4] range-diff: add section headers to the outer hunk header

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Apr 14, 2019, 21:09 UTC
Message-ID
<20190414210933.20875-5-t.gummerer@gmail.com>
In-Reply-To
<20190414210933.20875-1-t.gummerer@gmail.com>

Add the section headers we introduced in the previous commit to the outer diff's hunk headers. This makes it easier to understand which change we are actually looking at. For example an outer hunk header might now look like:

    @@ -77,15 +78,43 @@ modified file Documentation/config/interactive.txt
while previously it would have only been
    @@ -77,15 +78,43 @@
which doesn't give a lot of context for the change that follows.

For completeness also add section headers for the commit metadata and the commit message, although they are arguably less important.

Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
---
 range-diff.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/range-diff.c b/range-diff.c
index aa466060ef..15ac54f369 100644
--- a/range-diff.c
+++ b/range-diff.c
@@ -124,8 +124,10 @@ static int read_patches(const char *range, struct string_list *list)
 			strbuf_addstr(&buf, " ##\n");
 		} else if (in_header) {
 			if (starts_with(line.buf, "Author: ")) {
+				strbuf_addstr(&buf, " ## Metadata ##\n");
 				strbuf_addbuf(&buf, &line);
 				strbuf_addstr(&buf, "\n\n");
+				strbuf_addstr(&buf, " ## Commit message ##\n");
 			} else if (starts_with(line.buf, "    ")) {
 				strbuf_rtrim(&line);
 				strbuf_addbuf(&buf, &line);
@@ -387,8 +389,8 @@ static void output_pair_header(struct diff_options *diffopt,
 	fwrite(buf->buf, buf->len, 1, diffopt->file);
 }
 
-static struct userdiff_driver no_func_name = {
-	.funcname = { "$^", 0 }
+static struct userdiff_driver section_headers = {
+	.funcname = { "^ ## (.*) ##$", REG_EXTENDED }
 };
 
 static struct diff_filespec *get_filespec(const char *name, const char *p)
@@ -400,7 +402,7 @@ static struct diff_filespec *get_filespec(const char *name, const char *p)
 	spec->size = strlen(p);
 	spec->should_munmap = 0;
 	spec->is_stdin = 1;
-	spec->driver = &no_func_name;
+	spec->driver = &section_headers;
 
 	return spec;
 }
-- 
2.21.0.593.g511ec345e1
Previous: Thomas GummererNext: Johannes Schindelin
Message 25 of 29 in “incorrect range-diff output?”
  1. Duy NguyenApr 11, 2019
  2. Thomas GummererApr 11, 2019
  3. Johannes SchindelinApr 12, 2019
  4. Thomas GummererApr 14, 2019
  5. Duy NguyenApr 12, 2019
  6. Junio C HamanoApr 12, 2019
  7. Thomas GummererApr 14, 2019
  8. Junio C HamanoApr 15, 2019
  9. Johannes SchindelinApr 15, 2019
  10. 0/4 output improvements for git range-diffThomas Gummerer, Apr 14, 2019
  11. 1/4 range-diff: fix function parameter indentationThomas Gummerer, Apr 14, 2019
  12. 2/4 range-diff: don't remove funcname from inner diffThomas Gummerer, Apr 14, 2019
  13. Eric SunshineApr 14, 2019
  14. Johannes SchindelinApr 15, 2019
  15. Thomas GummererApr 15, 2019
  16. Johannes SchindelinApr 17, 2019
  17. Thomas GummererApr 24, 2019
  18. Johannes SchindelinApr 15, 2019
  19. Thomas GummererApr 15, 2019
  20. 3/4 range-diff: add section header instead of diff headerThomas Gummerer, Apr 14, 2019
  21. Eric SunshineApr 14, 2019
  22. Johannes SixtApr 15, 2019
  23. Johannes SchindelinApr 15, 2019
  24. Thomas GummererApr 15, 2019
  25. 4/4 range-diff: add section headers to the outer hunk headerThomas Gummerer, Apr 14, 2019
  26. Johannes SchindelinApr 15, 2019
  27. Thomas GummererApr 15, 2019
  28. Johannes SchindelinApr 15, 2019
  29. Thomas GummererApr 15, 2019

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.