Patchwork [3,of,3] extdiff: move single file handling inside `not per-file` conditional

login
register
mail settings
Submitter Pulkit Goyal
Date Sept. 1, 2020, 12:18 p.m.
Message ID <c1f593d4d608fe9180c3.1598962733@workspace>
Download mbox | patch
Permalink /patch/47078/
State Accepted
Headers show

Comments

Pulkit Goyal - Sept. 1, 2020, 12:18 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1598691918 -19800
#      Sat Aug 29 14:35:18 2020 +0530
# Node ID c1f593d4d608fe9180c3e7b2c4cb8eb179d1c468
# Parent  28e81de5f83624341454eea6ef5973cd7db10675
# EXP-Topic extdiff-refactor
extdiff: move single file handling inside `not per-file` conditional

If `--per-file` is passed, we will diffing files one by one, hence there is no
need to make this optimization around single file in that case. This
optimization is only required when `--per-file` is not passed and we will be
opening directory-diff for a single file.

Differential Revision: https://phab.mercurial-scm.org/D8971

Patch

diff --git a/hgext/extdiff.py b/hgext/extdiff.py
--- a/hgext/extdiff.py
+++ b/hgext/extdiff.py
@@ -456,23 +456,23 @@  def diffrevs(
     label1b = rev1b
     label2 = rev2
 
-    # If only one change, diff the files instead of the directories
-    # Handle bogus modifies correctly by checking if the files exist
-    if len(common) == 1:
-        common_file = util.localpath(common.pop())
-        dir1a = os.path.join(tmproot, dir1a, common_file)
-        label1a = common_file + rev1a
-        if not os.path.isfile(dir1a):
-            dir1a = pycompat.osdevnull
-        if do3way:
-            dir1b = os.path.join(tmproot, dir1b, common_file)
-            label1b = common_file + rev1b
-            if not os.path.isfile(dir1b):
-                dir1b = pycompat.osdevnull
-        dir2 = os.path.join(dir2root, dir2, common_file)
-        label2 = common_file + rev2
+    if not opts.get(b'per_file'):
+        # If only one change, diff the files instead of the directories
+        # Handle bogus modifies correctly by checking if the files exist
+        if len(common) == 1:
+            common_file = util.localpath(common.pop())
+            dir1a = os.path.join(tmproot, dir1a, common_file)
+            label1a = common_file + rev1a
+            if not os.path.isfile(dir1a):
+                dir1a = pycompat.osdevnull
+            if do3way:
+                dir1b = os.path.join(tmproot, dir1b, common_file)
+                label1b = common_file + rev1b
+                if not os.path.isfile(dir1b):
+                    dir1b = pycompat.osdevnull
+            dir2 = os.path.join(dir2root, dir2, common_file)
+            label2 = common_file + rev2
 
-    if not opts.get(b'per_file'):
         # Run the external tool on the 2 temp directories or the patches
         cmdline = formatcmdline(
             cmdline,