Mercurial > public > mercurial-scm > hg-stable
diff mercurial/cmdutil.py @ 13121:bf763946f8b0
make_file: always return a fresh file handle that can be closed
Currently, cmdutil.make_file() will return a freshly made file handle,
except when given a pattern of '-'. If callers would want to close the
handle, they would have to make sure that it's neither sys.stdin or
sys.stdout. Instead, returning a duplicate of either of the two
ensures that make_file() lives up to its name and creates a new
file handle regardless of the input.
author | Dan Villiom Podlaski Christiansen <danchr@gmail.com> |
---|---|
date | Tue, 07 Dec 2010 16:08:16 +0100 |
parents | 79184986658c |
children | f78bc5ddbe4f |
line wrap: on
line diff
--- a/mercurial/cmdutil.py Fri Dec 10 19:20:11 2010 -0600 +++ b/mercurial/cmdutil.py Tue Dec 07 16:08:16 2010 +0100 @@ -233,7 +233,8 @@ writable = 'w' in mode or 'a' in mode if not pat or pat == '-': - return writable and sys.stdout or sys.stdin + fp = writable and sys.stdout or sys.stdin + return os.fdopen(os.dup(fp.fileno()), mode) if hasattr(pat, 'write') and writable: return pat if hasattr(pat, 'read') and 'r' in mode: