comparison mercurial/cmdutil.py @ 28861:86db5cb55d46

pycompat: switch to util.stringio for py3 compat
author timeless <timeless@mozdev.org>
date Sun, 10 Apr 2016 20:55:37 +0000
parents d54a7410307f
children ac30adb260ea
comparison
equal deleted inserted replaced
28860:50d11dd8ac02 28861:86db5cb55d46
5 # This software may be used and distributed according to the terms of the 5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from __future__ import absolute_import 8 from __future__ import absolute_import
9 9
10 import cStringIO
11 import errno 10 import errno
12 import os 11 import os
13 import re 12 import re
14 import sys 13 import sys
15 import tempfile 14 import tempfile
44 scmutil, 43 scmutil,
45 templatekw, 44 templatekw,
46 templater, 45 templater,
47 util, 46 util,
48 ) 47 )
48 stringio = util.stringio
49 49
50 def ishunk(x): 50 def ishunk(x):
51 hunkclasses = (crecordmod.uihunk, patch.recordhunk) 51 hunkclasses = (crecordmod.uihunk, patch.recordhunk)
52 return isinstance(x, hunkclasses) 52 return isinstance(x, hunkclasses)
53 53
209 os.close(fd) 209 os.close(fd)
210 ui.debug('backup %r as %r\n' % (f, tmpname)) 210 ui.debug('backup %r as %r\n' % (f, tmpname))
211 util.copyfile(repo.wjoin(f), tmpname, copystat=True) 211 util.copyfile(repo.wjoin(f), tmpname, copystat=True)
212 backups[f] = tmpname 212 backups[f] = tmpname
213 213
214 fp = cStringIO.StringIO() 214 fp = stringio()
215 for c in chunks: 215 for c in chunks:
216 fname = c.filename() 216 fname = c.filename()
217 if fname in backups: 217 if fname in backups:
218 c.write(fp) 218 c.write(fp)
219 dopatch = fp.tell() 219 dopatch = fp.tell()
3296 except patch.PatchError as err: 3296 except patch.PatchError as err:
3297 raise error.Abort(_('error parsing patch: %s') % err) 3297 raise error.Abort(_('error parsing patch: %s') % err)
3298 3298
3299 newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks) 3299 newlyaddedandmodifiedfiles = newandmodified(chunks, originalchunks)
3300 # Apply changes 3300 # Apply changes
3301 fp = cStringIO.StringIO() 3301 fp = stringio()
3302 for c in chunks: 3302 for c in chunks:
3303 c.write(fp) 3303 c.write(fp)
3304 dopatch = fp.tell() 3304 dopatch = fp.tell()
3305 fp.seek(0) 3305 fp.seek(0)
3306 if dopatch: 3306 if dopatch: