changeset 27416:9d04b4da6773

export: do not print '<fdopen>' as an output filename Because makefileobj() duplicates or wraps stdout, "fp != sys.stdout" didn't work correctly. Python doc states that special file objects are named in the form '<...>', and absolute filenames should never start with '<', we can ignore names start with '<'. We can't test fp.fileno() because fp may be a command-server channel. https://docs.python.org/2.7/library/stdtypes.html#file.name In the test output, "exporting patch:" line is printed after patch content. This is caused by fdopen() and will be fixed by the subsequent patch.
author Yuya Nishihara <yuya@tcha.org>
date Sun, 13 Dec 2015 19:47:46 +0900
parents f4ca33e33781
children 9073a1e457c9
files mercurial/cmdutil.py tests/test-export.t
diffstat 2 files changed, 20 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Sun Dec 13 19:32:01 2015 +0900
+++ b/mercurial/cmdutil.py	Sun Dec 13 19:47:46 2015 +0900
@@ -1056,7 +1056,7 @@
                              modemap=filemode)
             if fp != template:
                 shouldclose = True
-        if fp and fp != sys.stdout and util.safehasattr(fp, 'name'):
+        if fp and not getattr(fp, 'name', '<unnamed>').startswith('<'):
             repo.ui.note("%s\n" % fp.name)
 
         if not fp:
--- a/tests/test-export.t	Sun Dec 13 19:32:01 2015 +0900
+++ b/tests/test-export.t	Sun Dec 13 19:47:46 2015 +0900
@@ -137,6 +137,25 @@
    foo-9
   +foo-10
 
+No filename should be printed if stdout is specified explicitly:
+
+  $ hg export -v 1 -o -
+  # HG changeset patch
+  # User test
+  # Date 0 0
+  #      Thu Jan 01 00:00:00 1970 +0000
+  # Node ID d1c9656e973cfb5aebd5499bbd2cb350e3b12266
+  # Parent  871558de6af2e8c244222f8eea69b782c94ce3df
+  foo-1
+  
+  diff -r 871558de6af2 -r d1c9656e973c foo
+  --- a/foo	Thu Jan 01 00:00:00 1970 +0000
+  +++ b/foo	Thu Jan 01 00:00:00 1970 +0000
+  @@ -1,1 +1,2 @@
+   foo-0
+  +foo-1
+  exporting patch:
+
 Checking if only alphanumeric characters are used in the file name (%m option):
 
   $ echo "line" >> foo