[PATCH 4 of 6] scmutil.addremove: pull ui.status printing out of the loop

Siddharth Agarwal sid0 at fb.com
Tue Apr 2 14:36:35 CDT 2013


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1364925384 25200
#      Tue Apr 02 10:56:24 2013 -0700
# Node ID 699722e60e7cd5aab766cb33e3152f1d8c44e9b3
# Parent  808296ac211eca66234a2c7e5c7fcccb3d81d2ab
scmutil.addremove: pull ui.status printing out of the loop

This will let us stop sorting all the results in an upcoming patch.

This also permits future refactorings where the same code consumes
dirstate.walk results but doesn't print anything out.

An argument could be made that printing out results as we go along is more
responsive UI-wise. However, at this point iterating through walk results is
actually faster than sorting them, so once we stop sorting all the results the
argument ceases to be valid.

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -683,19 +683,26 @@ def addremove(repo, pats=[], opts={}, dr
         dstate = dget(abs, ('?',))[0]
         if dstate == '?' and audit_path.check(abs):
             unknown.append(abs)
-            if repo.ui.verbose or not m.exact(abs):
-                rel = m.rel(abs)
-                repo.ui.status(_('adding %s\n') % ((pats and rel) or abs))
         elif dstate != 'r' and not st:
             deleted.append(abs)
-            if repo.ui.verbose or not m.exact(abs):
-                rel = m.rel(abs)
-                repo.ui.status(_('removing %s\n') % ((pats and rel) or abs))
         # for finding renames
         elif dstate == 'r':
             removed.append(abs)
         elif dstate == 'a':
             added.append(abs)
+
+    unknownset = set(unknown)
+    toprint = unknownset.copy()
+    toprint.update(deleted)
+    for abs in sorted(toprint):
+        if repo.ui.verbose or not m.exact(abs):
+            rel = m.rel(abs)
+            if abs in unknownset:
+                status = _('adding %s\n') % ((pats and rel) or abs)
+            else:
+                status = _('removing %s\n') % ((pats and rel) or abs)
+            repo.ui.status(status)
+
     copies = {}
     if similarity > 0:
         for old, new, score in similar.findrenames(repo,


More information about the Mercurial-devel mailing list