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

login
register
mail settings
Submitter Siddharth Agarwal
Date April 2, 2013, 7:36 p.m.
Message ID <699722e60e7cd5aab766.1364931395@sid0x220>
Download mbox | patch
Permalink /patch/1242/
State Superseded
Commit 1b70e5941ad7cefbcf045e8dade0f7f87bc3a400
Headers show

Comments

Siddharth Agarwal - April 2, 2013, 7:36 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@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.

Patch

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,