Patchwork [STABLE] cmdutil: fix makefileobj not to clobber default modemap dict

login
register
mail settings
Submitter Yuya Nishihara
Date Oct. 22, 2013, 3:19 p.m.
Message ID <20131023001901.553cfc77747794ae2e74659a@tcha.org>
Download mbox | patch
Permalink /patch/2803/
State Accepted
Commit b7f76db06dc0f1c85f05256eaba7ac7559e811e9
Headers show

Comments

Yuya Nishihara - Oct. 22, 2013, 3:19 p.m.
The original bug report is
https://bitbucket.org/tortoisehg/thg/issue/3420/

# HG changeset patch
# User Yuya Nishihara <yuya@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'.
Augie Fackler - Oct. 22, 2013, 6:31 p.m.
On Wed, Oct 23, 2013 at 12:19:01AM +0900, Yuya Nishihara wrote:
> The original bug report is
> https://bitbucket.org/tortoisehg/thg/issue/3420/
>
> # HG changeset patch
> # User Yuya Nishihara <yuya@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

queued for stable, thanks

>
> 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):
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel

Patch

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):