addremove: only query dirstate once per path
authorDurham Goode <durham@fb.com>
Mon, 04 Feb 2013 14:01:40 -0800
changeset 18558 eb95cf4e219d
parent 18557 945ba91c5e16
child 18559 d1582dd6288e
addremove: only query dirstate once per path Previously the addremove code queried the dirstate 4 times per path. Now it only does so once. On a large repo this brings addremove from 9.5 seconds to 8.35 seconds (12%).
mercurial/scmutil.py
--- a/mercurial/scmutil.py	Mon Feb 04 23:48:34 2013 +0100
+++ b/mercurial/scmutil.py	Mon Feb 04 14:01:40 2013 -0800
@@ -742,20 +742,22 @@
             good = False
         rel = m.rel(abs)
         exact = m.exact(abs)
-        if good and abs not in repo.dirstate:
+
+        dstate = repo.dirstate[abs]
+        if good and dstate == '?':
             unknown.append(abs)
             if repo.ui.verbose or not exact:
                 repo.ui.status(_('adding %s\n') % ((pats and rel) or abs))
-        elif (repo.dirstate[abs] != 'r' and
+        elif (dstate != 'r' and
               (not good or not os.path.lexists(target) or
                (os.path.isdir(target) and not os.path.islink(target)))):
             deleted.append(abs)
             if repo.ui.verbose or not exact:
                 repo.ui.status(_('removing %s\n') % ((pats and rel) or abs))
         # for finding renames
-        elif repo.dirstate[abs] == 'r':
+        elif dstate == 'r':
             removed.append(abs)
-        elif repo.dirstate[abs] == 'a':
+        elif dstate == 'a':
             added.append(abs)
     copies = {}
     if similarity > 0: