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

login
register
mail settings
Submitter Siddharth Agarwal
Date May 7, 2013, 12:12 a.m.
Message ID <01f24c137497e182dd0f.1367885547@sid0x220>
Download mbox | patch
Permalink /patch/1575/
State Accepted, archived
Commit 7a4eab2456de9b869ec93eeac5c4e34c17769d45
Delegated to: Augie Fackler
Headers show

Comments

Siddharth Agarwal - May 7, 2013, 12:12 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@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.

Patch

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.