From: Jeff King <peff@peff.net>
To: Jonas Fonseca <fonseca@diku.dk>
Cc: git@vger.kernel.org
Subject: Re: [tig PATCH] fix off-by-one on parent selection
Date: Sun, 23 May 2010 03:55:03 -0400 [thread overview]
Message-ID: <20100523075503.GA24598@coredump.intra.peff.net> (raw)
In-Reply-To: <20100523074051.GA16730@coredump.intra.peff.net>
On Sun, May 23, 2010 at 03:40:52AM -0400, Jeff King wrote:
> Now try "tig blame new". For all of the lines but the first, blaming the
> parent gets you the correct "The selected commit has no parents". But
> parent-blaming the first line will correctly re-blame using the filename
> "old".
By the way, there is one minor bug remaining after this patch:
> case REQ_PARENT:
> if (check_blame_commit(blame, TRUE) &&
> - select_commit_parent(blame->commit->id, opt_ref,
> - blame->commit->filename)) {
> - string_copy(opt_file, blame->commit->filename);
> + select_commit_parent(blame->commit->id, opt_ref) &&
> + follow_parent_rename(blame->commit->id, opt_ref,
> + blame->commit->filename, opt_file)) {
> setup_blame_parent_line(view, blame);
> open_view(view, REQ_VIEW_BLAME, OPEN_REFRESH);
> }
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;
next prev parent reply other threads:[~2010-05-23 7:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-10 8:55 [tig PATCH] fix off-by-one on parent selection Jeff King
2010-05-22 17:19 ` Jonas Fonseca
2010-05-23 7:40 ` Jeff King
2010-05-23 7:55 ` Jeff King [this message]
2010-06-05 19:56 ` [PATCH] Improve parent blame to detect renames by using the previous information Jonas Fonseca
2010-06-05 19:57 ` [TIG PATCH] " Jonas Fonseca
2010-06-06 22:35 ` [PATCH] " Jeff King
2010-06-09 16:10 ` Jonas Fonseca
2010-06-10 2:23 ` Jonas Fonseca
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100523075503.GA24598@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=fonseca@diku.dk \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).