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

login
register
mail settings
Submitter Siddharth Agarwal
Date April 2, 2013, 9:52 p.m.
Message ID <6253706ef464e15fb371.1364939576@sid0x220>
Download mbox | patch
Permalink /patch/1250/
State Accepted
Commit 1b70e5941ad7cefbcf045e8dade0f7f87bc3a400
Headers show

Comments

Siddharth Agarwal - April 2, 2013, 9:52 p.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1364925384 25200
#      Tue Apr 02 10:56:24 2013 -0700
# Node ID 6253706ef464e15fb371d64b6e2d4cc5d8424d9f
# Parent  0ea7f5083797d6513b8b8498c55fc7b64a752f23
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 = dirstate[abs]
         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,