git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <junkio@cox.net>
To: git@vger.kernel.org
Subject: [PATCH 2/3] blame: -C -C -C
Date: Sat,  5 May 2007 23:02:42 -0700	[thread overview]
Message-ID: <11784313642492-git-send-email-junkio@cox.net> (raw)
In-Reply-To: <11784313631165-git-send-email-junkio@cox.net>

Existing "blame -C -C" would not find that the latter half of
the file2 came from the existing file1:

	... both file1 and file2 are tracked ...
	$ cat file1 >>file2
	$ git add file1 file2
	$ git commit

This is because we avoid the expensive find-copies-harder code
that makes unchanged file (in this case, file1) as a candidate
for copy & paste source when annotating an existing file
(file2).  The third -C now allows it.  However, this obviously
makes the process very expensive.  We've actually seen this
patch before, but I dismissed it because it covers such a narrow
(and arguably stupid) corner case.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 builtin-blame.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/builtin-blame.c b/builtin-blame.c
index f8843e6..65d029a 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -55,6 +55,7 @@ static int num_commits;
 #define PICKAXE_BLAME_MOVE		01
 #define PICKAXE_BLAME_COPY		02
 #define PICKAXE_BLAME_COPY_HARDER	04
+#define PICKAXE_BLAME_COPY_HARDEST	010
 
 /*
  * blame for a blame_entry with score lower than these thresholds
@@ -1079,8 +1080,9 @@ static int find_copy_in_parent(struct scoreboard *sb,
 	 * and this code needs to be after diff_setup_done(), which
 	 * usually makes find-copies-harder imply copy detection.
 	 */
-	if ((opt & PICKAXE_BLAME_COPY_HARDER) &&
-	    (!porigin || strcmp(target->path, porigin->path)))
+	if ((opt & PICKAXE_BLAME_COPY_HARDEST)
+	    || ((opt & PICKAXE_BLAME_COPY_HARDER)
+		&& (!porigin || strcmp(target->path, porigin->path))))
 		diff_opts.find_copies_harder = 1;
 
 	if (is_null_sha1(target->commit->object.sha1))
@@ -2127,6 +2129,15 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
 			blame_move_score = parse_score(arg+2);
 		}
 		else if (!prefixcmp(arg, "-C")) {
+			/*
+			 * -C enables copy from removed files;
+			 * -C -C enables copy from existing files, but only
+			 *       when blaming a new file;
+			 * -C -C -C enables copy from existing files for
+			 *          everybody
+			 */
+			if (opt & PICKAXE_BLAME_COPY_HARDER)
+				opt |= PICKAXE_BLAME_COPY_HARDEST;
 			if (opt & PICKAXE_BLAME_COPY)
 				opt |= PICKAXE_BLAME_COPY_HARDER;
 			opt |= PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE;
-- 
1.5.2.rc1.709.g9462

  reply	other threads:[~2007-05-06  6:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-06  6:02 [PATCH 1/3] blame: handle the tail-match correctly in -C/-M Junio C Hamano
2007-05-06  6:02 ` Junio C Hamano [this message]
2007-05-06  6:02 ` [PATCH 3/3] Add test for blame corner cases Junio C Hamano

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=11784313642492-git-send-email-junkio@cox.net \
    --to=junkio@cox.net \
    --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.
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 NNTP newsgroup(s).