git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [RFC PATCH] wt-status: show amended content when verbose
@ 2019-11-16 16:18 Pratyush Yadav
  2019-11-18  3:36 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Pratyush Yadav @ 2019-11-16 16:18 UTC (permalink / raw)
  To: git

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-11-20  1:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-16 16:18 [RFC PATCH] wt-status: show amended content when verbose Pratyush Yadav
2019-11-18  3:36 ` Junio C Hamano
2019-11-18  4:02   ` Junio C Hamano
2019-11-19 14:56     ` Pratyush Yadav
2019-11-20  0:27       ` Aaron Schrab
2019-11-20  1:04       ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).