Skip to content

Commit 350410f

Browse files
newrengitster
authored andcommitted
diffcore-rename: remove unnecessary duplicate entry checks
Commit 25d5ea4 ("[PATCH] Redo rename/copy detection logic.", 2005-05-24) added a duplicate entry check on rename_src in order to avoid segfaults; the code at the time was prone to double free()s and an easy way to avoid it was just to turn off rename detection for any duplicate entries. Note that the form of the check was modified two commits ago in this series. Similarly, commit 4d6be03 ("diffcore-rename: avoid processing duplicate destinations", 2015-02-26) added a duplicate entry check on rename_dst for the exact same reason -- the code was prone to double free()s, and an easy way to avoid it was just to turn off rename detection entirely. Note that the form of the check was modified in the commit just before this one. In the original code in both places, the code was dealing with individual diff_filespecs and trying to match things up, instead of just keeping the original diff_filepairs around as we do now. The intervening change in structure has fixed the accounting problems and the associated double free()s that used to occur, and thus we already have a better fix. As such, we can remove the band-aid checks for duplicate entries. Due to the last two patches, the diffcore_rename() setup is no longer a sizeable chunk of overall runtime. Thus, in a large rebase of many commits with lots of renames and several optimizations to inexact rename detection, this patch only speeds up the overall code by about half a percent or so and is pretty close to the run-to-run variability making it hard to get an exact measurement. However, with some trace2 regions around the setup code in diffcore_rename() so that I can focus on just it, I measure that this patch consistently saves almost a third of the remaining time spent in diffcore_rename() setup. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9db2ac5 commit 350410f

File tree

2 files changed

+1
-24
lines changed

2 files changed

+1
-24
lines changed

diffcore-rename.c

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,6 @@ static struct diff_rename_dst *locate_rename_dst(struct diff_filepair *p)
3434
*/
3535
static int add_rename_dst(struct diff_filepair *p)
3636
{
37-
/*
38-
* If we have multiple entries at the same path in the destination
39-
* tree (an invalid tree, to be sure), turn off rename detection
40-
* entirely. Once upon a time, diffcore-rename had double free()
41-
* issues due to such duplicate paths, resulting in segfaults. See
42-
* commit 4d6be03b95 ("diffcore-rename: avoid processing duplicate
43-
* destinations", 2015-02-26).
44-
*/
45-
if (rename_dst_nr > 0 &&
46-
!strcmp(rename_dst[rename_dst_nr-1].p->two->path, p->two->path))
47-
return -1;
48-
4937
ALLOC_GROW(rename_dst, rename_dst_nr + 1, rename_dst_alloc);
5038
rename_dst[rename_dst_nr].p = p;
5139
rename_dst[rename_dst_nr].filespec_to_free = NULL;
@@ -63,17 +51,6 @@ static int rename_src_nr, rename_src_alloc;
6351

6452
static void register_rename_src(struct diff_filepair *p)
6553
{
66-
/*
67-
* If we have multiple entries at the same path in the source tree
68-
* (an invalid tree, to be sure), avoid using more more than one
69-
* such entry in rename detection. Once upon a time, doing so
70-
* caused segfaults; see commit 25d5ea410f ("[PATCH] Redo
71-
* rename/copy detection logic.", 2005-05-24).
72-
*/
73-
if (rename_src_nr > 0 &&
74-
!strcmp(rename_src[rename_src_nr-1].p->one->path, p->one->path))
75-
return;
76-
7754
if (p->broken_pair) {
7855
if (!break_idx) {
7956
break_idx = xmalloc(sizeof(*break_idx));

t/t4058-diff-duplicates.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ test_expect_success 'diff-tree between duplicate trees' '
9191
test_expect_success 'diff-tree with renames' '
9292
# See NOTICE at top of file.
9393
git diff-tree -M -r --no-abbrev one two >actual &&
94-
test_cmp expect actual
94+
test_must_be_empty actual
9595
'
9696

9797
test_expect_success 'diff-tree FROM duplicate tree' '

0 commit comments

Comments
 (0)