Skip to content

Commit c63777c

Browse files
author
Junio C Hamano
committed
blame: -C -C -C
When you do this, 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 <[email protected]>
1 parent dd166aa commit c63777c

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

builtin-blame.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ static int num_commits;
5555
#define PICKAXE_BLAME_MOVE 01
5656
#define PICKAXE_BLAME_COPY 02
5757
#define PICKAXE_BLAME_COPY_HARDER 04
58+
#define PICKAXE_BLAME_COPY_HARDEST 010
5859

5960
/*
6061
* blame for a blame_entry with score lower than these thresholds
@@ -1079,8 +1080,9 @@ static int find_copy_in_parent(struct scoreboard *sb,
10791080
* and this code needs to be after diff_setup_done(), which
10801081
* usually makes find-copies-harder imply copy detection.
10811082
*/
1082-
if ((opt & PICKAXE_BLAME_COPY_HARDER) &&
1083-
(!porigin || strcmp(target->path, porigin->path)))
1083+
if ((opt & PICKAXE_BLAME_COPY_HARDEST)
1084+
|| ((opt & PICKAXE_BLAME_COPY_HARDER)
1085+
&& (!porigin || strcmp(target->path, porigin->path))))
10841086
diff_opts.find_copies_harder = 1;
10851087

10861088
if (is_null_sha1(target->commit->object.sha1))
@@ -2127,6 +2129,15 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
21272129
blame_move_score = parse_score(arg+2);
21282130
}
21292131
else if (!prefixcmp(arg, "-C")) {
2132+
/*
2133+
* -C enables copy from removed files;
2134+
* -C -C enables copy from existing files, but only
2135+
* when blaming a new file;
2136+
* -C -C -C enables copy from existing files for
2137+
* everybody
2138+
*/
2139+
if (opt & PICKAXE_BLAME_COPY_HARDER)
2140+
opt |= PICKAXE_BLAME_COPY_HARDEST;
21302141
if (opt & PICKAXE_BLAME_COPY)
21312142
opt |= PICKAXE_BLAME_COPY_HARDER;
21322143
opt |= PICKAXE_BLAME_COPY | PICKAXE_BLAME_MOVE;

0 commit comments

Comments
 (0)