[PATCH 6 of 8 RFC] merge: use file context objects instead of acting directly on localrepo

Sean Farley sean.michael.farley at gmail.com
Thu Aug 7 14:52:13 CDT 2014


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1406339242 18000
#      Fri Jul 25 20:47:22 2014 -0500
# Node ID 3bfc7e57998670bac7c9bc0f822d8b581e61cd01
# Parent  3c10f9fb5f87c984d1c9fc91c821f45fd29a1b93
merge: use file context objects instead of acting directly on localrepo

Arguably, one might say that there is a regression by removing the function
caching, but that was slowed down by disk I/O anyway so there will be a net
speed up when acting directly on memory.

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -553,53 +553,49 @@ def manifestmerge(repo, wctx, p2, pa, br
         else:
             _checkcollision(repo, m1, actions)
 
     return actions
 
-def batchremove(repo, actions):
+def batchremove(repo, wctx, actions):
     """apply removes to the working directory
 
     yields tuples for progress updates
     """
     verbose = repo.ui.verbose
-    unlink = util.unlinkpath
-    wjoin = repo.wjoin
     audit = repo.wopener.audit
     i = 0
     for f, args, msg in actions:
         repo.ui.debug(" %s: %s -> r\n" % (f, msg))
         if verbose:
             repo.ui.note(_("removing %s\n") % f)
         audit(f)
         try:
-            unlink(wjoin(f), ignoremissing=True)
+            wctx[f].remove(ignoremissing=True)
         except OSError, inst:
             repo.ui.warn(_("update failed to remove %s: %s!\n") %
                          (f, inst.strerror))
         if i == 100:
             yield i, f
             i = 0
         i += 1
     if i > 0:
         yield i, f
 
-def batchget(repo, mctx, actions):
+def batchget(repo, wctx, mctx, actions):
     """apply gets to the working directory
 
     mctx is the context to get from
 
     yields tuples for progress updates
     """
     verbose = repo.ui.verbose
-    fctx = mctx.filectx
-    wwrite = repo.wwrite
     i = 0
     for f, args, msg in actions:
         repo.ui.debug(" %s: %s -> g\n" % (f, msg))
         if verbose:
             repo.ui.note(_("getting %s\n") % f)
-        wwrite(f, fctx(f).data(), args[0])
+        wctx[f].write(mctx[f].data(), args[0])
         if i == 100:
             yield i, f
             i = 0
         i += 1
     if i > 0:
@@ -656,18 +652,18 @@ def applyupdates(repo, actions, wctx, mc
     if [a for a in actions['r'] if a[0] == '.hgsubstate']:
         subrepo.submerge(repo, wctx, mctx, wctx, overwrite)
 
     # remove in parallel (must come first)
     z = 0
-    prog = worker.worker(repo.ui, 0.001, batchremove, (repo,), actions['r'])
+    prog = worker.worker(repo.ui, 0.001, batchremove, (repo, wctx), actions['r'])
     for i, item in prog:
         z += i
         progress(_updating, z, item=item, total=numupdates, unit=_files)
     removed = len(actions['r'])
 
     # get in parallel
-    prog = worker.worker(repo.ui, 0.001, batchget, (repo, mctx), actions['g'])
+    prog = worker.worker(repo.ui, 0.001, batchget, (repo, wctx, mctx), actions['g'])
     for i, item in prog:
         z += i
         progress(_updating, z, item=item, total=numupdates, unit=_files)
     updated = len(actions['g'])
 
@@ -717,22 +713,22 @@ def applyupdates(repo, actions, wctx, mc
         z += 1
         progress(_updating, z, item=f, total=numupdates, unit=_files)
         f0, flags = args
         repo.ui.note(_("moving %s to %s\n") % (f0, f))
         audit(f)
-        repo.wwrite(f, wctx.filectx(f0).data(), flags)
-        util.unlinkpath(repo.wjoin(f0))
+        wctx.write(f, wctx.filectx(f0).data(), flags)
+        wctx.remove(f0)
         updated += 1
 
     # local directory rename, get
     for f, args, msg in actions['dg']:
         repo.ui.debug(" %s: %s -> dg\n" % (f, msg))
         z += 1
         progress(_updating, z, item=f, total=numupdates, unit=_files)
         f0, flags = args
         repo.ui.note(_("getting %s to %s\n") % (f0, f))
-        repo.wwrite(f, mctx.filectx(f0).data(), flags)
+        wctx.write(f, mctx.filectx(f0).data(), flags)
         updated += 1
 
     # divergent renames
     for f, args, msg in actions['dr']:
         repo.ui.debug(" %s: %s -> dr\n" % (f, msg))


More information about the Mercurial-devel mailing list