Skip to content

Commit a7ca654

Browse files
Junio C HamanoLinus Torvalds
authored andcommitted
[PATCH] diff-tree: --find-copies-harder
Normally, diff-tree does not feed unchanged filepair to diffcore for performance reasons, so copies are detected only when the source file of the copy happens to be modified in the same changeset. This adds --find-copies-harder flag to tell diff-tree to sacrifice the performance in order to find copies the same way as other commands in diff-* family. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent d327b89 commit a7ca654

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

diff-tree.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ static int show_tree_entry_in_recursive = 0;
1111
static int read_stdin = 0;
1212
static int diff_output_format = DIFF_FORMAT_HUMAN;
1313
static int detect_rename = 0;
14+
static int find_copies_harder = 0;
1415
static int diff_setup_opt = 0;
1516
static int diff_score_opt = 0;
1617
static const char *pickaxe = NULL;
@@ -115,7 +116,7 @@ static int compare_tree_entry(void *tree1, unsigned long size1, void *tree2, uns
115116
show_file("+", tree2, size2, base);
116117
return 1;
117118
}
118-
if (!memcmp(sha1, sha2, 20) && mode1 == mode2)
119+
if (!find_copies_harder && !memcmp(sha1, sha2, 20) && mode1 == mode2)
119120
return 0;
120121

121122
/*
@@ -199,7 +200,7 @@ static int interesting(void *tree, unsigned long size, const char *base)
199200
static void show_tree(const char *prefix, void *tree, unsigned long size, const char *base)
200201
{
201202
while (size) {
202-
if (interesting(tree, size, base))
203+
if (find_copies_harder || interesting(tree, size, base))
203204
show_file(prefix, tree, size, base);
204205
update_tree_entry(&tree, &size);
205206
}
@@ -267,7 +268,7 @@ static void call_diff_setup(void)
267268

268269
static int call_diff_flush(void)
269270
{
270-
diffcore_std(0,
271+
diffcore_std(find_copies_harder ? paths : 0,
271272
detect_rename, diff_score_opt,
272273
pickaxe, pickaxe_opts,
273274
diff_break_opt,
@@ -488,6 +489,10 @@ int main(int argc, const char **argv)
488489
usage(diff_tree_usage);
489490
continue;
490491
}
492+
if (!strcmp(arg, "--find-copies-harder")) {
493+
find_copies_harder = 1;
494+
continue;
495+
}
491496
if (!strcmp(arg, "-z")) {
492497
diff_output_format = DIFF_FORMAT_MACHINE;
493498
continue;
@@ -521,6 +526,8 @@ int main(int argc, const char **argv)
521526
}
522527
usage(diff_tree_usage);
523528
}
529+
if (find_copies_harder && detect_rename != DIFF_DETECT_COPY)
530+
usage(diff_tree_usage);
524531

525532
if (argc > 0) {
526533
int i;

0 commit comments

Comments
 (0)