# HG changeset patch # User Benoit Boissinot # Date 2009-05-17 20:51:17 # Node ID 1a96f1d9599b96cfa220606b9a758a6032b29cea # Parent 4e1795cf6e94b53b6a54677ddc7e377cc1789cc7 addremove/findrenames: find renames according to the match object (issue1527) Instead of only finding similarities in the added/removed files found by the addremove step, follow the match object: hg addremove -s80 foo -> add and removes files in foo + find similarities between files in foo hg addremove -s80 -> add and removes files in the whole repo + find similarities between files in the whole repo hg import --similarity will still work correctly (only find similarities between files found in the patch). diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -252,10 +252,9 @@ def matchall(repo): def matchfiles(repo, files): return _match.exact(repo.root, repo.getcwd(), files) -def findrenames(repo, added=None, removed=None, threshold=0.5): +def findrenames(repo, match=None, threshold=0.5): '''find renamed files -- yields (before, after, score) tuples''' - if added is None or removed is None: - added, removed = repo.status()[1:3] + added, removed = repo.status(match=match)[1:3] ctx = repo['.'] for a in added: aa = repo.wread(a) @@ -310,7 +309,7 @@ def addremove(repo, pats=[], opts={}, dr repo.remove(remove) repo.add(add) if similarity > 0: - for old, new, score in findrenames(repo, add, remove, similarity): + for old, new, score in findrenames(repo, m, similarity): oldexact, newexact = m.exact(old), m.exact(new) if repo.ui.verbose or not oldexact or not newexact: oldrel, newrel = m.rel(old), m.rel(new) diff --git a/tests/test-addremove-similar b/tests/test-addremove-similar --- a/tests/test-addremove-similar +++ b/tests/test-addremove-similar @@ -46,4 +46,22 @@ hg addremove -s foo hg addremove -s -1 hg addremove -s 1e6 +cd .. + +echo '% issue 1527' +hg init rep3; cd rep3 +mkdir d +echo a > d/a +hg add d/a +hg commit -m 1 + +mv d/a d/b +hg addremove -s80 +hg debugstate +mv d/b c +echo "% no copies found here (since the target isn't in d" +hg addremove -s80 d +echo "% copies here" +hg addremove -s80 + true diff --git a/tests/test-addremove-similar.out b/tests/test-addremove-similar.out --- a/tests/test-addremove-similar.out +++ b/tests/test-addremove-similar.out @@ -18,3 +18,15 @@ recording removal of tiny-file as rename abort: similarity must be a number abort: similarity must be between 0 and 100 abort: similarity must be between 0 and 100 +% issue 1527 +removing d/a +adding d/b +recording removal of d/a as rename to d/b (100% similar) +r 0 0 1970-01-01 00:00:00 d/a +a 0 -1 unset d/b +copy: d/a -> d/b +% no copies found here (since the target isn't in d +removing d/b +% copies here +adding c +recording removal of d/a as rename to c (100% similar)