[PATCH STABLE] cmdutil: fix makefileobj not to clobber default modemap dict
Yuya Nishihara
yuya at tcha.org
Tue Oct 22 15:19:01 UTC 2013
The original bug report is
https://bitbucket.org/tortoisehg/thg/issue/3420/
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1382452738 -32400
# Tue Oct 22 23:38:58 2013 +0900
# Branch stable
# Node ID cfd20b1285b2f5014ba5e87a789436eaf8fdfd9f
# Parent 2c886dedd9021598b6290d95ea0f068731ea4e2b
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'.
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -170,7 +170,7 @@ def makefilename(repo, pat, node, desc=N
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 @@ def makefileobj(repo, pat, node=None, de
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):
More information about the Mercurial-devel
mailing list