[PATCH 1 of 6] scmutil.addremove: factor out dirstate walk into another function

Siddharth Agarwal sid0 at fb.com
Mon May 6 19:12:27 CDT 2013


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1364948376 25200
#      Tue Apr 02 17:19:36 2013 -0700
# Node ID 01f24c137497e182dd0fe2c76e67896be2a2f529
# Parent  b7ceaf830c5b6b3034200d27ed7af272757e7c1f
scmutil.addremove: factor out dirstate walk into another function

Upcoming patches will reuse and expand on this function for other purposes.

diff -r b7ceaf830c5b -r 01f24c137497 mercurial/scmutil.py
--- a/mercurial/scmutil.py	Tue Oct 02 15:32:21 2012 -0700
+++ b/mercurial/scmutil.py	Tue Apr 02 17:19:36 2013 -0700
@@ -685,26 +685,11 @@ def addremove(repo, pats=[], opts={}, dr
     if similarity is None:
         similarity = float(opts.get('similarity') or 0)
     # we'd use status here, except handling of symlinks and ignore is tricky
-    added, unknown, deleted, removed = [], [], [], []
-    audit_path = pathauditor(repo.root)
     m = match(repo[None], pats, opts)
     rejected = []
     m.bad = lambda x, y: rejected.append(x)
 
-    ctx = repo[None]
-    dirstate = repo.dirstate
-    walkresults = dirstate.walk(m, sorted(ctx.substate), True, False)
-    for abs, st in walkresults.iteritems():
-        dstate = dirstate[abs]
-        if dstate == '?' and audit_path.check(abs):
-            unknown.append(abs)
-        elif dstate != 'r' and not st:
-            deleted.append(abs)
-        # for finding renames
-        elif dstate == 'r':
-            removed.append(abs)
-        elif dstate == 'a':
-            added.append(abs)
+    added, unknown, deleted, removed = _interestingfiles(repo, m)
 
     unknownset = set(unknown)
     toprint = unknownset.copy()
@@ -744,6 +729,32 @@ def addremove(repo, pats=[], opts={}, dr
             return 1
     return 0
 
+def _interestingfiles(repo, matcher):
+    '''Walk dirstate with matcher, looking for files that addremove would care
+    about.
+
+    This is different from dirstate.status because it doesn't care about
+    whether files are modified or clean.'''
+    added, unknown, deleted, removed = [], [], [], []
+    audit_path = pathauditor(repo.root)
+
+    ctx = repo[None]
+    dirstate = repo.dirstate
+    walkresults = dirstate.walk(matcher, sorted(ctx.substate), True, False)
+    for abs, st in walkresults.iteritems():
+        dstate = dirstate[abs]
+        if dstate == '?' and audit_path.check(abs):
+            unknown.append(abs)
+        elif dstate != 'r' and not st:
+            deleted.append(abs)
+        # for finding renames
+        elif dstate == 'r':
+            removed.append(abs)
+        elif dstate == 'a':
+            added.append(abs)
+
+    return added, unknown, deleted, removed
+
 def dirstatecopy(ui, repo, wctx, src, dst, dryrun=False, cwd=None):
     """Update the dirstate to reflect the intent of copying src to dst. For
     different reasons it might not end with dst being marked as copied from src.


More information about the Mercurial-devel mailing list