cmdutil: fix makefileobj not to clobber default modemap dict
Problem occurs if "hg cat -o" is invoked more than once in the same process.
The output of "hg cat" will be appended because of modemap[fn] = 'ab'.
--- a/mercurial/cmdutil.py Tue Oct 22 12:41:05 2013 +0900
+++ b/mercurial/cmdutil.py Tue Oct 22 23:38:58 2013 +0900
@@ -170,7 +170,7 @@
inst.args[0])
def makefileobj(repo, pat, node=None, desc=None, total=None,
- seqno=None, revwidth=None, mode='wb', modemap={},
+ seqno=None, revwidth=None, mode='wb', modemap=None,
pathname=None):
writable = mode not in ('r', 'rb')
@@ -198,9 +198,10 @@
if util.safehasattr(pat, 'read') and 'r' in mode:
return pat
fn = makefilename(repo, pat, node, desc, total, seqno, revwidth, pathname)
- mode = modemap.get(fn, mode)
- if mode == 'wb':
- modemap[fn] = 'ab'
+ if modemap is not None:
+ mode = modemap.get(fn, mode)
+ if mode == 'wb':
+ modemap[fn] = 'ab'
return open(fn, mode)
def openrevlog(repo, cmd, file_, opts):