# HG changeset patch # User Yuya Nishihara # Date 2015-12-13 10:47:46 # Node ID 9d04b4da6773ee0b9b354fec29ca0a938d7dcf18 # Parent f4ca33e33781baed10e3aa3273c4e95bd86c9824 export: do not print '' 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. diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -1056,7 +1056,7 @@ def export(repo, revs, template='hg-%h.p 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', '').startswith('<'): repo.ui.note("%s\n" % fp.name) if not fp: diff --git a/tests/test-export.t b/tests/test-export.t --- a/tests/test-export.t +++ b/tests/test-export.t @@ -137,6 +137,25 @@ Exporting revision -2 to a file: 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