Diff: -l<num> to limit rename/copy detection.
When many paths are modified, rename detection takes a lot of time. The new option -l<num> can be used to disable rename detection when more than <num> paths are possibly created as renames. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Sep 21, 2005 at 00:18 UTC
8082d8d3050e3fdd7b0f13c7a7b3ad68af7f478a
5 files changed
+34
-20
Documentation/diff-options.txt
+7
@@ -35,6 +35,13 @@
35
copy. This is a very expensive operation for large
36
projects, so use it with caution.
37
38
+-l<num>::
39
+ -M and -C options require O(n^2) processing time where n
40
+ in the number of potential rename/copy targets. This
41
+ option prevents rename/copy detection from running if
42
+ the number of rename/copy targets exceed the specified
43
+ number.
44
+
45
-S<string>::
46
Look for differences that contains the change in <string>.
47
diff.c
+5
-2
@@ -674,11 +674,12 @@ void diff_setup(struct diff_options *options)
674
options->output_format = DIFF_FORMAT_RAW;
675
options->line_termination = '\n';
676
options->break_opt = -1;
677
+ options->rename_limit = -1;
678
}
679
680
int diff_setup_done(struct diff_options *options)
681
{
681
- if (options->find_copies_harder &&
682
+ if ((options->find_copies_harder || 0 <= options->rename_limit) &&
683
options->detect_rename != DIFF_DETECT_COPY)
684
return -1;
685
if (options->setup & DIFF_SETUP_USE_CACHE) {
@@ -704,6 +705,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
705
options->output_format = DIFF_FORMAT_PATCH;
706
else if (!strcmp(arg, "-z"))
707
options->line_termination = 0;
708
+ else if (!strncmp(arg, "-l", 2))
709
+ options->rename_limit = strtoul(arg+2, NULL, 10);
710
else if (!strcmp(arg, "--name-only"))
711
options->output_format = DIFF_FORMAT_NAME;
712
else if (!strcmp(arg, "-R"))
@@ -1141,7 +1144,7 @@ void diffcore_std(struct diff_options *options)
1144
if (options->break_opt != -1)
1145
diffcore_break(options->break_opt);
1146
if (options->detect_rename)
1144
- diffcore_rename(options->detect_rename, options->rename_score);
1147
+ diffcore_rename(options);
1148
if (options->break_opt != -1)
1149
diffcore_merge_broken();
1150
if (options->pickaxe)
diff.h
+15
-15
@@ -21,6 +21,7 @@ struct diff_options {
21
int pickaxe_opts;
22
int rename_score;
23
int reverse_diff;
24
+ int rename_limit;
25
int setup;
26
};
27
@@ -61,23 +62,22 @@ extern void diffcore_std_no_resolve(struct diff_options *);
62
63
#define COMMON_DIFF_OPTIONS_HELP \
64
"\ncommon diff options:\n" \
64
-" -r diff recursively (only meaningful in diff-tree)\n" \
65
-" -z output diff-raw with lines terminated with NUL.\n" \
66
-" -p output patch format.\n" \
67
-" -u synonym for -p.\n" \
68
-" --name-only show only names of changed files.\n" \
69
-" --name-only-z\n" \
70
-" same as --name-only but terminate lines with NUL.\n" \
71
-" -R swap input file pairs.\n" \
72
-" -B detect complete rewrites.\n" \
73
-" -M detect renames.\n" \
74
-" -C detect copies.\n" \
65
+" -r diff recursively (only meaningful in diff-tree)\n" \
66
+" -z output diff-raw with lines terminated with NUL.\n" \
67
+" -p output patch format.\n" \
68
+" -u synonym for -p.\n" \
69
+" --name-only show only names of changed files.\n" \
70
+" -R swap input file pairs.\n" \
71
+" -B detect complete rewrites.\n" \
72
+" -M detect renames.\n" \
73
+" -C detect copies.\n" \
74
" --find-copies-harder\n" \
76
-" try unchanged files as candidate for copy detection.\n" \
77
-" -O<file> reorder diffs according to the <file>.\n" \
78
-" -S<string> find filepair whose only one side contains the string.\n" \
75
+" try unchanged files as candidate for copy detection.\n" \
76
+" -l<n> limit rename attempts up to <n> paths.\n" \
77
+" -O<file> reorder diffs according to the <file>.\n" \
78
+" -S<string> find filepair whose only one side contains the string.\n" \
79
" --pickaxe-all\n" \
80
-" show all files diff when -S is used and hit is found.\n"
80
+" show all files diff when -S is used and hit is found.\n"
81
82
extern int diff_queue_is_empty(void);
83
diffcore-rename.c
+6
-2
@@ -249,8 +249,11 @@ static int compute_stays(struct diff_queue_struct *q,
249
return 1;
250
}
251
252
-void diffcore_rename(int detect_rename, int minimum_score)
252
+void diffcore_rename(struct diff_options *options)
253
{
254
+ int detect_rename = options->detect_rename;
255
+ int minimum_score = options->rename_score;
256
+ int rename_limit = options->rename_limit;
257
struct diff_queue_struct *q = &diff_queued_diff;
258
struct diff_queue_struct outq;
259
struct diff_score *mx;
@@ -279,7 +282,8 @@ void diffcore_rename(int detect_rename, int minimum_score)
282
else if (detect_rename == DIFF_DETECT_COPY)
283
register_rename_src(p->one, 1);
284
}
282
- if (rename_dst_nr == 0)
285
+ if (rename_dst_nr == 0 ||
286
+ (0 <= rename_limit && rename_limit < rename_dst_nr))
287
goto cleanup; /* nothing to do */
288
289
/* We really want to cull the candidates list early
diffcore.h
+1
-1
@@ -85,7 +85,7 @@ extern void diff_q(struct diff_queue_struct *, struct diff_filepair *);
85
86
extern void diffcore_pathspec(const char **pathspec);
87
extern void diffcore_break(int);
88
-extern void diffcore_rename(int rename_copy, int);
88
+extern void diffcore_rename(struct diff_options *);
89
extern void diffcore_merge_broken(void);
90
extern void diffcore_pickaxe(const char *needle, int opts);
91
extern void diffcore_order(const char *orderfile);