cmdutil: fix makefileobj not to clobber default modemap dict stable
authorYuya Nishihara <yuya@tcha.org>
Tue, 22 Oct 2013 23:38:58 +0900
branchstable
changeset 19944 b7f76db06dc0
parent 19943 4de116871044
child 19945 3d42a85f6922
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'.
mercurial/cmdutil.py
--- 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):