Patchwork [2,of,3] revert: precompute arguments of patch.diff() in _performrevert()

login
register
mail settings
Submitter Denis Laxalde
Date Feb. 13, 2018, 8:46 p.m.
Message ID <4b8c889eb9d0b7ca6883.1518554813@marimba>
Download mbox | patch
Permalink /patch/27844/
State Superseded
Headers show

Comments

Denis Laxalde - Feb. 13, 2018, 8:46 p.m.
# HG changeset patch
# User Denis Laxalde <denis@laxalde.org>
# Date 1518554320 -3600
#      Tue Feb 13 21:38:40 2018 +0100
# Node ID 4b8c889eb9d0b7ca6883b93dbd476323c94f677f
# Parent  75a4598a4375d80d240c19625e2c43a069ba9618
# EXP-Topic revert-interactive-pats
revert: precompute arguments of patch.diff() in _performrevert()

By factoring out arguments ordering for patch.diff() call, we can only
keep one diff = patch.diff(...) statement thus reducing code duplication.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -2969,9 +2969,10 @@  def _performrevert(repo, parents, ctx, a
             operation = 'apply'
             reversehunks = False
         if reversehunks:
-            diff = patch.diff(repo, ctx.node(), None, m, opts=diffopts)
+            node1, node2 = ctx.node(), None
         else:
-            diff = patch.diff(repo, None, ctx.node(), m, opts=diffopts)
+            node1, node2 = None, ctx.node()
+        diff = patch.diff(repo, node1, node2, m, opts=diffopts)
         originalchunks = patch.parsepatch(diff)
 
         try: