Mercurial > hg
comparison mercurial/cmdutil.py @ 19944:b7f76db06dc0 stable
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'.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Tue, 22 Oct 2013 23:38:58 +0900 |
parents | df91e2df6ba3 |
children | f962870712da 64b4f0cd7336 |
comparison
equal
deleted
inserted
replaced
19943:4de116871044 | 19944:b7f76db06dc0 |
---|---|
168 except KeyError, inst: | 168 except KeyError, inst: |
169 raise util.Abort(_("invalid format spec '%%%s' in output filename") % | 169 raise util.Abort(_("invalid format spec '%%%s' in output filename") % |
170 inst.args[0]) | 170 inst.args[0]) |
171 | 171 |
172 def makefileobj(repo, pat, node=None, desc=None, total=None, | 172 def makefileobj(repo, pat, node=None, desc=None, total=None, |
173 seqno=None, revwidth=None, mode='wb', modemap={}, | 173 seqno=None, revwidth=None, mode='wb', modemap=None, |
174 pathname=None): | 174 pathname=None): |
175 | 175 |
176 writable = mode not in ('r', 'rb') | 176 writable = mode not in ('r', 'rb') |
177 | 177 |
178 if not pat or pat == '-': | 178 if not pat or pat == '-': |
196 if util.safehasattr(pat, 'write') and writable: | 196 if util.safehasattr(pat, 'write') and writable: |
197 return pat | 197 return pat |
198 if util.safehasattr(pat, 'read') and 'r' in mode: | 198 if util.safehasattr(pat, 'read') and 'r' in mode: |
199 return pat | 199 return pat |
200 fn = makefilename(repo, pat, node, desc, total, seqno, revwidth, pathname) | 200 fn = makefilename(repo, pat, node, desc, total, seqno, revwidth, pathname) |
201 mode = modemap.get(fn, mode) | 201 if modemap is not None: |
202 if mode == 'wb': | 202 mode = modemap.get(fn, mode) |
203 modemap[fn] = 'ab' | 203 if mode == 'wb': |
204 modemap[fn] = 'ab' | |
204 return open(fn, mode) | 205 return open(fn, mode) |
205 | 206 |
206 def openrevlog(repo, cmd, file_, opts): | 207 def openrevlog(repo, cmd, file_, opts): |
207 """opens the changelog, manifest, a filelog or a given revlog""" | 208 """opens the changelog, manifest, a filelog or a given revlog""" |
208 cl = opts['changelog'] | 209 cl = opts['changelog'] |