D7545: py3: make a pycompat.osdevnull, use it in extdiff

spectral (Kyle Lippincott) phabricator at mercurial-scm.org
Wed Dec 4 01:36:13 UTC 2019


spectral created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D7545

AFFECTED FILES
  hgext/extdiff.py
  mercurial/pycompat.py
  tests/test-extdiff.t

CHANGE DETAILS

diff --git a/tests/test-extdiff.t b/tests/test-extdiff.t
--- a/tests/test-extdiff.t
+++ b/tests/test-extdiff.t
@@ -515,3 +515,27 @@
   $ LC_MESSAGES=ja_JP.UTF-8 hg --config hgext.extdiff= --config extdiff.cmd.td=$U help td \
   > | grep "^      '"
         '\xa5\xa5'
+
+  $ cd $TESTTMP
+
+Test that diffing a single file works, even if that file is new
+
+  $ hg init testsinglefile
+  $ cd testsinglefile
+  $ echo a > a
+  $ hg add a
+  $ hg falabala
+  diffing * */a (glob)
+  [1]
+  $ hg ci -qm a
+  $ hg falabala -c .
+  diffing * */a (glob)
+  [1]
+  $ echo a >> a
+  $ hg falabala
+  diffing */a */a (glob)
+  [1]
+  $ hg ci -qm 2a
+  $ hg falabala -c .
+  diffing */a */a (glob)
+  [1]
diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -118,6 +118,7 @@
     osaltsep = os.altsep
     if osaltsep:
         osaltsep = osaltsep.encode('ascii')
+    osdevnull = os.devnull.encode('ascii')
 
     sysplatform = sys.platform.encode('ascii')
     sysexecutable = sys.executable
@@ -456,6 +457,7 @@
     ospardir = os.pardir
     ossep = os.sep
     osaltsep = os.altsep
+    osdevnull = os.devnull
     long = long
     stdin = sys.stdin
     stdout = sys.stdout
diff --git a/hgext/extdiff.py b/hgext/extdiff.py
--- a/hgext/extdiff.py
+++ b/hgext/extdiff.py
@@ -271,7 +271,7 @@
         path1a = os.path.join(tmproot, dir1a, commonfile)
         label1a = commonfile + rev1a
         if not os.path.isfile(path1a):
-            path1a = os.devnull
+            path1a = pycompat.osdevnull
 
         path1b = b''
         label1b = b''
@@ -279,7 +279,7 @@
             path1b = os.path.join(tmproot, dir1b, commonfile)
             label1b = commonfile + rev1b
             if not os.path.isfile(path1b):
-                path1b = os.devnull
+                path1b = pycompat.osdevnull
 
         path2 = os.path.join(dir2root, dir2, commonfile)
         label2 = commonfile + rev2
@@ -468,12 +468,12 @@
                 dir1a = os.path.join(tmproot, dir1a, common_file)
                 label1a = common_file + rev1a
                 if not os.path.isfile(dir1a):
-                    dir1a = os.devnull
+                    dir1a = pycompat.osdevnull
                 if do3way:
                     dir1b = os.path.join(tmproot, dir1b, common_file)
                     label1b = common_file + rev1b
                     if not os.path.isfile(dir1b):
-                        dir1b = os.devnull
+                        dir1b = pycompat.osdevnull
                 dir2 = os.path.join(dir2root, dir2, common_file)
                 label2 = common_file + rev2
         else:



To: spectral, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list