Re: [tig PATCH] fix off-by-one on parent selection

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Jeff King
Date: Sunday, May 23, 2010 - 12:55 am

On Sun, May 23, 2010 at 03:40:52AM -0400, Jeff King wrote:


By the way, there is one minor bug remaining after this patch:


We may write some new filename into opt_file in the follow_parent_rename
call, but setup_blame_parent_line always diffs the original file. Which
means we lose the line position when following a rename.

We need to do the equivalent of:

  git diff -U0 \
    opt_ref:opt_file \
    blame->commit->id:blame->commit->filename

IOW, to blame directly between the two blobs. Sadly, I don't think there
is a plumbing command to do this, so we are stuck using regular "git
diff", which may have surprises in the config.

The patch below works for my simple tests.  I think we probably want to
be doing this anyway for the multiple-parent case. I didn't test, but I
don't think that diff-tree invocation is going to produce any output for
a merge commit.

diff --git a/tig.c b/tig.c
index cfa26ce..4388c2f 100644
--- a/tig.c
+++ b/tig.c
@@ -5177,15 +5177,21 @@ check_blame_commit(struct blame *blame, bool check_null_id)
 static void
 setup_blame_parent_line(struct view *view, struct blame *blame)
 {
+	char from[SIZEOF_REF+SIZEOF_STR];
+	char to[SIZEOF_REF+SIZEOF_STR];
 	const char *diff_tree_argv[] = {
-		"git", "diff-tree", "-U0", blame->commit->id,
-			"--", blame->commit->filename, NULL
+		"git", "diff", "--no-textconv", "--no-extdiff", "--no-color",
+		"-U0", from, to, "--", NULL
 	};
 	struct io io = {};
 	int parent_lineno = -1;
 	int blamed_lineno = -1;
 	char *line;
 
+	snprintf(from, sizeof(from), "%s:%s", opt_ref, opt_file);
+	snprintf(to, sizeof(to), "%s:%s", blame->commit->id,
+		 blame->commit->filename);
+
 	if (!io_run(&io, diff_tree_argv, NULL, IO_RD))
 		return;
 
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[tig PATCH] fix off-by-one on parent selection, Jeff King, (Mon May 10, 1:55 am)
Re: [tig PATCH] fix off-by-one on parent selection, Jonas Fonseca, (Sat May 22, 10:19 am)
Re: [tig PATCH] fix off-by-one on parent selection, Jeff King, (Sun May 23, 12:40 am)
Re: [tig PATCH] fix off-by-one on parent selection, Jeff King, (Sun May 23, 12:55 am)