[PATCH 01 of 11] merge: split out mostly-non-interactive working dir updates

Bryan O'Sullivan bos at serpentine.com
Sat Feb 9 08:06:41 CST 2013


# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1360418465 0
# Node ID 8cf626e958d3dd67e45bc4b1ef59ce328c37e123
# Parent  341868ef0cf6bb3fc9fc4f5b4f34047ba57b5a77
merge: split out mostly-non-interactive working dir updates

In a later patch, we'll run these updates in parallel.

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -314,6 +314,34 @@ def manifestmerge(repo, p1, p2, pa, over
 def actionkey(a):
     return a[1] == "r" and -1 or 0, a
 
+def getremove(repo, wctx, mctx, overwrite, args):
+    """apply usually-non-interactive updates to the working directory
+
+    wctx is the working copy context
+    mctx is the context to be merged into the working copy
+
+    yields tuples for progress updates
+    """
+    audit = repo.wopener.audit
+    for i, arg in enumerate(args):
+        f = arg[0]
+        if arg[1] == 'r':
+            repo.ui.note(_("removing %s\n") % f)
+            if f == '.hgsubstate': # subrepo states need updating
+                subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
+            audit(f)
+            try:
+                util.unlinkpath(repo.wjoin(f), ignoremissing=True)
+            except OSError, inst:
+                repo.ui.warn(_("update failed to remove %s: %s!\n") %
+                             (f, inst.strerror))
+        else:
+            repo.ui.note(_("getting %s\n") % f)
+            repo.wwrite(f, mctx.filectx(f).data(), arg[2][0])
+            if f == '.hgsubstate': # subrepo states need updating
+                subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
+        yield i, f
+
 def applyupdates(repo, actions, wctx, mctx, actx, overwrite):
     """apply the merge action list to the working directory
 
@@ -365,22 +393,22 @@ def applyupdates(repo, actions, wctx, mc
             util.unlinkpath(repo.wjoin(f))
 
     numupdates = len(actions)
+    workeractions = [a for a in actions if a[1] in 'gr']
+    updated = len([a for a in workeractions if a[1] == 'g'])
+    removed = len([a for a in workeractions if a[1] == 'r'])
+    actions = [a for a in actions if a[1] not in 'gr']
+
+    for i, item in getremove(repo, wctx, mctx, overwrite, workeractions):
+        repo.ui.progress(_('updating'), i + 1, item=item, total=numupdates,
+                         unit=_('files'))
+
+    z = len(workeractions)
+
     for i, a in enumerate(actions):
         f, m, args, msg = a
-        repo.ui.progress(_('updating'), i + 1, item=f, total=numupdates,
+        repo.ui.progress(_('updating'), z + i + 1, item=f, total=numupdates,
                          unit=_('files'))
-        if m == "r": # remove
-            repo.ui.note(_("removing %s\n") % f)
-            audit(f)
-            if f == '.hgsubstate': # subrepo states need updating
-                subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
-            try:
-                util.unlinkpath(repo.wjoin(f), ignoremissing=True)
-            except OSError, inst:
-                repo.ui.warn(_("update failed to remove %s: %s!\n") %
-                             (f, inst.strerror))
-            removed += 1
-        elif m == "m": # merge
+        if m == "m": # merge
             if fd == '.hgsubstate': # subrepo states need updating
                 subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx),
                                  overwrite)
@@ -395,13 +423,6 @@ def applyupdates(repo, actions, wctx, mc
                     updated += 1
                 else:
                     merged += 1
-        elif m == "g": # get
-            flags, = args
-            repo.ui.note(_("getting %s\n") % f)
-            repo.wwrite(f, mctx.filectx(f).data(), flags)
-            updated += 1
-            if f == '.hgsubstate': # subrepo states need updating
-                subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
         elif m == "d": # directory rename
             f2, fd, flags = args
             if f:


More information about the Mercurial-devel mailing list