##// END OF EJS Templates
crecord: refactor hunk edit action to use ui.edit...
Jordi Gutiérrez Hermoso -
r28636:de64020b default
parent child Browse files
Show More
@@ -17,7 +17,6 import re
17 import signal
17 import signal
18 import struct
18 import struct
19 import sys
19 import sys
20 import tempfile
21
20
22 from .i18n import _
21 from .i18n import _
23 from . import (
22 from . import (
@@ -1498,36 +1497,25 are you sure you want to review/edit and
1498 all lines of the hunk are removed, then the edit is aborted and
1497 all lines of the hunk are removed, then the edit is aborted and
1499 the hunk is left unchanged.
1498 the hunk is left unchanged.
1500 """)
1499 """)
1501 (patchfd, patchfn) = tempfile.mkstemp(prefix="hg-editor-",
1502 suffix=".diff", text=True)
1503 ncpatchfp = None
1504 try:
1505 # write the initial patch
1500 # write the initial patch
1506 f = os.fdopen(patchfd, "w")
1501 patch = cStringIO.StringIO()
1507 chunk.header.write(f)
1502 patch.write(''.join(['# %s\n' % i for i in phelp.splitlines()]))
1508 chunk.write(f)
1503 chunk.header.write(patch)
1509 f.write('\n'.join(['# ' + i for i in phelp.splitlines()]))
1504 chunk.write(patch)
1510 f.close()
1505
1511 # start the editor and wait for it to complete
1506 # start the editor and wait for it to complete
1512 editor = self.ui.geteditor()
1507 try:
1513 ret = self.ui.system("%s \"%s\"" % (editor, patchfn),
1508 patch = self.ui.edit(patch.getvalue(), "",
1514 environ={'hguser': self.ui.username()})
1509 extra={"suffix": ".diff"})
1515 if ret != 0:
1510 except error.Abort as exc:
1516 self.errorstr = "Editor exited with status %d" % ret
1511 self.errorstr = str(exc)
1517 return None
1512 return None
1513
1518 # remove comment lines
1514 # remove comment lines
1519 patchfp = open(patchfn)
1515 patch = [line + '\n' for line in patch.splitlines()
1520 ncpatchfp = cStringIO.StringIO()
1516 if not line.startswith('#')]
1521 for line in patchfp:
1517 return patchmod.parsepatch(patch)
1522 if not line.startswith('#'):
1518
1523 ncpatchfp.write(line)
1524 patchfp.close()
1525 ncpatchfp.seek(0)
1526 newpatches = patchmod.parsepatch(ncpatchfp)
1527 finally:
1528 os.unlink(patchfn)
1529 del ncpatchfp
1530 return newpatches
1531 if item is None:
1519 if item is None:
1532 item = self.currentselecteditem
1520 item = self.currentselecteditem
1533 if isinstance(item, uiheader):
1521 if isinstance(item, uiheader):
General Comments 0
You need to be logged in to leave comments. Login now