From patchwork Tue Aug 19 02:42:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2, of, 4] merge: use file context objects instead of acting directly on localrepo From: Sean Farley X-Patchwork-Id: 5491 Message-Id: To: mercurial-devel@selenic.com Date: Mon, 18 Aug 2014 19:42:39 -0700 # HG changeset patch # User Sean Farley # Date 1406339242 18000 # Fri Jul 25 20:47:22 2014 -0500 # Node ID d1a21cc0bc4ba5764a1f8760fd041a91939b4d00 # Parent 594d00e49cea6cd2ebb92c0570e7502f8797e232 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[f].write(wctx.filectx(f0).data(), flags) + wctx[f0].remove() 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[f].write(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))