All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Willard <benwillard@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com
Subject: [PATCH 2/2] blame: Fix corner case when a directory becomes a file
Date: Tue, 2 Jun 2009 15:29:17 -0400	[thread overview]
Message-ID: <4a257d91.0407560a.04d2.ffffe775@mx.google.com> (raw)
In-Reply-To: <cover.1243969358.git.benwillard@gmail.com>

find_origin() assumes that there will be only one listing in
diff_queued_diff, but this is not the case when a directory becomes a
file in a single commit.  So, don't fail in this case.

Signed-off-by: Ben Willard <benwillard@gmail.com>
---
 builtin-blame.c  |   12 ++++++++----
 t/t8006-blame.sh |    2 +-
 2 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/builtin-blame.c b/builtin-blame.c
index cf74a92..3e217af 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -363,16 +363,14 @@ static struct origin *find_origin(struct scoreboard *sb,
 	diffcore_std(&diff_opts);
 
 	/* It is either one entry that says "modified", or "created",
-	 * or nothing.
+	 * or nothing, or two entries (a "deleted" and an "add").
 	 */
 	if (!diff_queued_diff.nr) {
 		/* The path is the same as parent */
 		porigin = get_origin(sb, parent, origin->path);
 		hashcpy(porigin->blob_sha1, origin->blob_sha1);
 	}
-	else if (diff_queued_diff.nr != 1)
-		die("internal error in blame::find_origin");
-	else {
+	else if (diff_queued_diff.nr == 1) {
 		struct diff_filepair *p = diff_queued_diff.queue[0];
 		switch (p->status) {
 		default:
@@ -388,6 +386,12 @@ static struct origin *find_origin(struct scoreboard *sb,
 			break;
 		}
 	}
+	else if (diff_queued_diff.nr == 2) {
+		/* Both added and removed, (ie. directory became a file) */
+	}
+	else {
+		die("internal error in blame::find_origin");
+	}
 	diff_flush(&diff_opts);
 	diff_tree_release_paths(&diff_opts);
 	if (porigin) {
diff --git a/t/t8006-blame.sh b/t/t8006-blame.sh
index 7c271f0..17f38ff 100755
--- a/t/t8006-blame.sh
+++ b/t/t8006-blame.sh
@@ -14,7 +14,7 @@ test_expect_success 'setup' '
 	git commit -m "Add dir as a file"
 '
 
-test_expect_failure 'blame runs on dir' '
+test_expect_success 'blame runs on dir' '
 	git blame dir
 '
 
-- 
1.6.3.1.279.gd4bf4

  parent reply	other threads:[~2009-06-02 19:29 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-02 19:28 [PATCH 0/2] git-blame bug Ben Willard
2009-06-02 19:28 ` [PATCH 1/2] t8006: Add test to show blame failure Ben Willard
2009-06-02 19:29 ` Ben Willard [this message]
2009-06-03  7:43   ` [PATCH 2/2] blame: Fix corner case when a directory becomes a file Junio C Hamano
2009-06-03 12:40     ` Ben Willard

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4a257d91.0407560a.04d2.ffffe775@mx.google.com \
    --to=benwillard@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.