Skip to content

Commit 4c19cf3

Browse files
Byron Boultondanvk
authored andcommitted
Fixed bug with "move" detection.
Files which were detected as moved weren't removed from the "deleted" list, so they showed up twice in the browser, once as renamed and once as deleted. Update nose test for moved files. The assetion for the nosetest was for the incorrect behavior: file.json --> renamed.json should be recognized as just a move not a move and delete.
1 parent 58503e5 commit 4c19cf3

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

tests/pair_test.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ def test_pairing_with_move():
4444
'a': 'file.json',
4545
'b': 'renamed.json',
4646
'type': 'move',
47-
},
48-
{
49-
'a': 'file.json',
50-
'b': '',
51-
'type': 'delete',
5247
}], [diff.get_thin_dict(d) for d in diffs])
5348

5449

webdiff/dirdiff.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,25 +73,24 @@ def pair_files(a_files, b_files):
7373

7474

7575
def find_moves(pairs):
76-
add_delete_pairs = defaultdict(lambda: [None,None])
76+
"""Separate the file move pairs from other file pairs"""
77+
# If a file is just moved, then the added file and the deleted file
78+
# will both put their idx into the same key of the dictionary
79+
add_delete_pairs = defaultdict(lambda: [None, None])
7780
for idx, (a, b) in enumerate(pairs):
7881
if b and not a: # add
7982
add_delete_pairs[util.contentHash(b)][1] = idx
8083
elif a and not b: # delete
8184
add_delete_pairs[util.contentHash(a)][0] = idx
8285

83-
indices_to_delete = []
86+
indices_to_omit = []
8487
moves = []
85-
for _, (aIdx, bIdx) in add_delete_pairs.iteritems():
86-
if aIdx == None or bIdx == None:
87-
continue
88+
for _, (aIdx, bIdx) in add_delete_pairs.items():
89+
if (aIdx is not None) and (bIdx is not None):
90+
# replace the "add" and "delete" with a "change"
91+
indices_to_omit.extend([aIdx, bIdx])
92+
moves.append((pairs[aIdx][0], pairs[bIdx][1]))
8893

89-
# replace the "add" with a "change"
90-
indices_to_delete.append(bIdx)
91-
moves.append((pairs[aIdx][0], pairs[bIdx][1]))
92-
93-
remaining_pairs = copy.deepcopy(pairs)
94-
for idx in reversed(sorted(indices_to_delete)):
95-
del remaining_pairs[idx]
94+
remaining_pairs = [pair for i, pair in enumerate(pairs) if i not in indices_to_omit]
9695

9796
return moves, remaining_pairs

0 commit comments

Comments
 (0)