Patchwork [1,of,4] revert: cache working context into a variable

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 10, 2014, 1:05 a.m.
Message ID <5d57e90b2b72e6dc712b.1410311138@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5760/
State Accepted
Headers show

Comments

Pierre-Yves David - Sept. 10, 2014, 1:05 a.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1409356328 -7200
#      Sat Aug 30 01:52:08 2014 +0200
# Node ID 5d57e90b2b72e6dc712bc9ec27240485f7208ac5
# Parent  293930a1fa0a52d9bef832e72ef4c505b74e0c64
revert: cache working context into a variable

During the silicon age human on planetearth discovered the use of variable.
This marvelous invention let them improve both code readability and
performance.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2539,10 +2539,11 @@  def revert(ui, repo, ctx, parents, *pats
             )
 
         needdata = ('revert', 'add', 'undelete')
         _revertprefetch(repo, ctx, *[actions[name][0] for name in needdata])
 
+        wctx = repo[None]
         for abs, (rel, exact) in sorted(names.items()):
             # target file to be touch on disk (relative to cwd)
             target = repo.wjoin(abs)
             # search the entry in the dispatch table.
             # if the file is in any of these sets, it was touched in the working
@@ -2551,11 +2552,11 @@  def revert(ui, repo, ctx, parents, *pats
                 if abs not in table:
                     continue
                 if xlist is not None:
                     xlist.append(abs)
                     if (dobackup and os.path.lexists(target)
-                        and repo[None][abs].cmp(ctx[abs])):
+                        and wctx[abs].cmp(ctx[abs])):
                         bakname = "%s.orig" % rel
                         ui.note(_('saving current version of %s as %s\n') %
                                 (rel, bakname))
                         if not opts.get('dry_run'):
                             util.rename(target, bakname)