Skip to content

Commit 6466854

Browse files
committed
Merge branch 'en/rename-progress'
Historically, the diff machinery for rename detection had a hardcoded limit of 32k paths; this is being lifted to allow users trade cycles with a (possibly) easier to read result. * en/rename-progress: diffcore-rename: make diff-tree -l0 mean -l<large> sequencer: show rename progress during cherry picks diff: remove silent clamp of renameLimit progress: fix progress meters when dealing with lots of work sequencer: warn when internal merge may be suboptimal due to renameLimit
2 parents 52015aa + 8997355 commit 6466854

File tree

6 files changed

+44
-27
lines changed

6 files changed

+44
-27
lines changed

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5454,7 +5454,7 @@ void diff_warn_rename_limit(const char *varname, int needed, int degraded_cc)
54545454
warning(_(rename_limit_warning));
54555455
else
54565456
return;
5457-
if (0 < needed && needed < 32767)
5457+
if (0 < needed)
54585458
warning(_(rename_limit_advice), varname, needed);
54595459
}
54605460

diffcore-rename.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -391,14 +391,12 @@ static int too_many_rename_candidates(int num_create,
391391
* growing larger than a "rename_limit" square matrix, ie:
392392
*
393393
* num_create * num_src > rename_limit * rename_limit
394-
*
395-
* but handles the potential overflow case specially (and we
396-
* assume at least 32-bit integers)
397394
*/
398-
if (rename_limit <= 0 || rename_limit > 32767)
395+
if (rename_limit <= 0)
399396
rename_limit = 32767;
400397
if ((num_create <= rename_limit || num_src <= rename_limit) &&
401-
(num_create * num_src <= rename_limit * rename_limit))
398+
((uint64_t)num_create * (uint64_t)num_src
399+
<= (uint64_t)rename_limit * (uint64_t)rename_limit))
402400
return 0;
403401

404402
options->needed_rename_limit =
@@ -415,7 +413,8 @@ static int too_many_rename_candidates(int num_create,
415413
num_src++;
416414
}
417415
if ((num_create <= rename_limit || num_src <= rename_limit) &&
418-
(num_create * num_src <= rename_limit * rename_limit))
416+
((uint64_t)num_create * (uint64_t)num_src
417+
<= (uint64_t)rename_limit * (uint64_t)rename_limit))
419418
return 2;
420419
return 1;
421420
}
@@ -534,7 +533,7 @@ void diffcore_rename(struct diff_options *options)
534533
if (options->show_rename_progress) {
535534
progress = start_delayed_progress(
536535
_("Performing inexact rename detection"),
537-
rename_dst_nr * rename_src_nr);
536+
(uint64_t)rename_dst_nr * (uint64_t)rename_src_nr);
538537
}
539538

540539
mx = xcalloc(st_mult(NUM_CANDIDATE_PER_DST, num_create), sizeof(*mx));
@@ -571,7 +570,7 @@ void diffcore_rename(struct diff_options *options)
571570
diff_free_filespec_blob(two);
572571
}
573572
dst_cnt++;
574-
display_progress(progress, (i+1)*rename_src_nr);
573+
display_progress(progress, (uint64_t)(i+1)*(uint64_t)rename_src_nr);
575574
}
576575
stop_progress(&progress);
577576

progress.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ struct throughput {
3030

3131
struct progress {
3232
const char *title;
33-
int last_value;
34-
unsigned total;
33+
uint64_t last_value;
34+
uint64_t total;
3535
unsigned last_percent;
3636
unsigned delay;
3737
struct throughput *throughput;
@@ -78,7 +78,7 @@ static int is_foreground_fd(int fd)
7878
return tpgrp < 0 || tpgrp == getpgid(0);
7979
}
8080

81-
static int display(struct progress *progress, unsigned n, const char *done)
81+
static int display(struct progress *progress, uint64_t n, const char *done)
8282
{
8383
const char *eol, *tp;
8484

@@ -93,18 +93,19 @@ static int display(struct progress *progress, unsigned n, const char *done)
9393
if (percent != progress->last_percent || progress_update) {
9494
progress->last_percent = percent;
9595
if (is_foreground_fd(fileno(stderr)) || done) {
96-
fprintf(stderr, "%s: %3u%% (%u/%u)%s%s",
97-
progress->title, percent, n,
98-
progress->total, tp, eol);
96+
fprintf(stderr, "%s: %3u%% (%"PRIuMAX"/%"PRIuMAX")%s%s",
97+
progress->title, percent,
98+
(uintmax_t)n, (uintmax_t)progress->total,
99+
tp, eol);
99100
fflush(stderr);
100101
}
101102
progress_update = 0;
102103
return 1;
103104
}
104105
} else if (progress_update) {
105106
if (is_foreground_fd(fileno(stderr)) || done) {
106-
fprintf(stderr, "%s: %u%s%s",
107-
progress->title, n, tp, eol);
107+
fprintf(stderr, "%s: %"PRIuMAX"%s%s",
108+
progress->title, (uintmax_t)n, tp, eol);
108109
fflush(stderr);
109110
}
110111
progress_update = 0;
@@ -114,7 +115,7 @@ static int display(struct progress *progress, unsigned n, const char *done)
114115
return 0;
115116
}
116117

117-
static void throughput_string(struct strbuf *buf, off_t total,
118+
static void throughput_string(struct strbuf *buf, uint64_t total,
118119
unsigned int rate)
119120
{
120121
strbuf_reset(buf);
@@ -125,7 +126,7 @@ static void throughput_string(struct strbuf *buf, off_t total,
125126
strbuf_addstr(buf, "/s");
126127
}
127128

128-
void display_throughput(struct progress *progress, off_t total)
129+
void display_throughput(struct progress *progress, uint64_t total)
129130
{
130131
struct throughput *tp;
131132
uint64_t now_ns;
@@ -187,12 +188,12 @@ void display_throughput(struct progress *progress, off_t total)
187188
display(progress, progress->last_value, NULL);
188189
}
189190

190-
int display_progress(struct progress *progress, unsigned n)
191+
int display_progress(struct progress *progress, uint64_t n)
191192
{
192193
return progress ? display(progress, n, NULL) : 0;
193194
}
194195

195-
static struct progress *start_progress_delay(const char *title, unsigned total,
196+
static struct progress *start_progress_delay(const char *title, uint64_t total,
196197
unsigned delay)
197198
{
198199
struct progress *progress = malloc(sizeof(*progress));
@@ -213,12 +214,12 @@ static struct progress *start_progress_delay(const char *title, unsigned total,
213214
return progress;
214215
}
215216

216-
struct progress *start_delayed_progress(const char *title, unsigned total)
217+
struct progress *start_delayed_progress(const char *title, uint64_t total)
217218
{
218219
return start_progress_delay(title, total, 2);
219220
}
220221

221-
struct progress *start_progress(const char *title, unsigned total)
222+
struct progress *start_progress(const char *title, uint64_t total)
222223
{
223224
return start_progress_delay(title, total, 0);
224225
}

progress.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
struct progress;
55

6-
void display_throughput(struct progress *progress, off_t total);
7-
int display_progress(struct progress *progress, unsigned n);
8-
struct progress *start_progress(const char *title, unsigned total);
9-
struct progress *start_delayed_progress(const char *title, unsigned total);
6+
void display_throughput(struct progress *progress, uint64_t total);
7+
int display_progress(struct progress *progress, uint64_t n);
8+
struct progress *start_progress(const char *title, uint64_t total);
9+
struct progress *start_delayed_progress(const char *title, uint64_t total);
1010
void stop_progress(struct progress **progress);
1111
void stop_progress_msg(struct progress **progress, const char *msg);
1212

sequencer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
449449
o.branch2 = next ? next_label : "(empty tree)";
450450
if (is_rebase_i(opts))
451451
o.buffer_output = 2;
452+
o.show_rename_progress = 1;
452453

453454
head_tree = parse_tree_indirect(head);
454455
next_tree = next ? next->tree : empty_tree();
@@ -463,6 +464,7 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
463464
if (is_rebase_i(opts) && clean <= 0)
464465
fputs(o.obuf.buf, stdout);
465466
strbuf_release(&o.obuf);
467+
diff_warn_rename_limit("merge.renamelimit", o.needed_rename_limit, 0);
466468
if (clean < 0)
467469
return clean;
468470

t/t4001-diff-rename.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,19 @@ test_expect_success 'rename pretty print common prefix and suffix overlap' '
230230
test_i18ngrep " d/f/{ => f}/e " output
231231
'
232232

233+
test_expect_success 'diff-tree -l0 defaults to a big rename limit, not zero' '
234+
test_write_lines line1 line2 line3 >myfile &&
235+
git add myfile &&
236+
git commit -m x &&
237+
238+
test_write_lines line1 line2 line4 >myotherfile &&
239+
git rm myfile &&
240+
git add myotherfile &&
241+
git commit -m x &&
242+
243+
git diff-tree -M -l0 HEAD HEAD^ >actual &&
244+
# Verify that a rename from myotherfile to myfile was detected
245+
grep "myotherfile.*myfile" actual
246+
'
247+
233248
test_done

0 commit comments

Comments
 (0)