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