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

[RFC PATCH] wt-status: show amended content when verbose

From
Pratyush Yadav <me@yadavpratyush.com>
Date
Nov 16, 2019, 16:18 UTC
Message-ID
<20191116161856.28883-1-me@yadavpratyush.com>
Hi,

I am working on a simple little feature which shows the "amended content" when running 'git-commit -v'. Currently, only the changes in the _entire_ commit are shown. In a large commit, it is difficult to spot a line or two that were amended. So, show just the amended content in a different section.

I'm having trouble working with the internal diff API. 'rev' in the function here is used to diff against HEAD^1. I want to do the exact same thing, but against HEAD instead.

The diff below works, but it is obviously an ugly hack that just resets 'rev' and duplicates all the initialization code. I added it here as a "proof of concept". What would be the cleaner way to do it?

I tried a bunch of things, but they either end up in me hitting
  BUG("run_diff_index must be passed exactly one tree");

in 'run_diff_index', or just doing something completely unexpected/useless.

Some help/pointers would be appreciated. Thanks.

Regards, Pratyush Yadav

-- 8< --
Signed-off-by: Pratyush Yadav <me@yadavpratyush.com>
---
 wt-status.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
diff --git a/wt-status.c b/wt-status.c
index cc6f94504d..efa01c7ed6 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -1086,6 +1086,27 @@ static void wt_longstatus_print_verbose(struct wt_status *s)
 		rev.diffopt.b_prefix = "w/";
 		run_diff_files(&rev, 0);
 	}
+
+	if (s->amend) {
+		repo_init_revisions(s->repo, &rev, NULL);
+		rev.diffopt.flags.allow_textconv = 1;
+		rev.diffopt.ita_invisible_in_index = 1;
+
+		memset(&opt, 0, sizeof(opt));
+		opt.def = "HEAD";
+		setup_revisions(0, NULL, &rev, &opt);
+
+		rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
+		rev.diffopt.detect_rename = s->detect_rename >= 0 ? s->detect_rename : rev.diffopt.detect_rename;
+		rev.diffopt.rename_limit = s->rename_limit >= 0 ? s->rename_limit : rev.diffopt.rename_limit;
+		rev.diffopt.rename_score = s->rename_score >= 0 ? s->rename_score : rev.diffopt.rename_score;
+		rev.diffopt.file = s->fp;
+		rev.diffopt.close_file = 0;
+		rev.diffopt.use_color = 0;
+		status_printf_ln(s, c, "Changes to amend:\n");
+
+		run_diff_index(&rev, 1);
+	}
 }

 static void wt_longstatus_print_tracking(struct wt_status *s)
--
2.24.0
Next: Junio C Hamano
Message 1 of 6 in “wt-status: show amended content when verbose”
  1. wt-status: show amended content when verbosePratyush Yadav, Nov 16, 2019
  2. Junio C HamanoNov 18, 2019
  3. Junio C HamanoNov 18, 2019
  4. Pratyush YadavNov 19, 2019
  5. Aaron SchrabNov 20, 2019
  6. Junio C HamanoNov 20, 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.