comparison mercurial/crecord.py @ 28637:4874b8efe7d2

crecord: break out the help message for editing hunks This help message can be useful for other situations, such as for the review extension. It's also easier to write it at the top-level indentation with triple-quoted strings instead of inserting comment characters and newlines programmatically.
author Jordi Gutiérrez Hermoso <jordigh@octave.org>
date Sun, 20 Mar 2016 18:24:59 -0400
parents de64020bb4ec
children 44319097e7b9
comparison
equal deleted inserted replaced
28636:de64020bb4ec 28637:4874b8efe7d2
28 28
29 # This is required for ncurses to display non-ASCII characters in default user 29 # This is required for ncurses to display non-ASCII characters in default user
30 # locale encoding correctly. --immerrr 30 # locale encoding correctly. --immerrr
31 locale.setlocale(locale.LC_ALL, '') 31 locale.setlocale(locale.LC_ALL, '')
32 32
33 # patch comments based on the git one
34 diffhelptext = _("""# To remove '-' lines, make them ' ' lines (context).
35 # To remove '+' lines, delete them.
36 # Lines starting with # will be removed from the patch.
37 """)
38
39 hunkhelptext = _("""#
40 # If the patch applies cleanly, the edited hunk will immediately be
41 # added to the record list. If it does not apply cleanly, a rejects file
42 # will be generated. You can use that when you try again. If all lines
43 # of the hunk are removed, then the edit is aborted and the hunk is left
44 # unchanged.
45 """)
33 try: 46 try:
34 import curses 47 import curses
35 import fcntl 48 import fcntl
36 import termios 49 import termios
37 curses.error 50 curses.error
1482 return None 1495 return None
1483 if chunk.header.binary(): 1496 if chunk.header.binary():
1484 self.ui.write(_('cannot edit patch for binary file')) 1497 self.ui.write(_('cannot edit patch for binary file'))
1485 self.ui.write("\n") 1498 self.ui.write("\n")
1486 return None 1499 return None
1487 # patch comment based on the git one (based on comment at end of 1500
1488 # https://mercurial-scm.org/wiki/recordextension)
1489 phelp = '---' + _("""
1490 to remove '-' lines, make them ' ' lines (context).
1491 to remove '+' lines, delete them.
1492 lines starting with # will be removed from the patch.
1493
1494 if the patch applies cleanly, the edited hunk will immediately be
1495 added to the record list. if it does not apply cleanly, a rejects
1496 file will be generated: you can use that when you try again. if
1497 all lines of the hunk are removed, then the edit is aborted and
1498 the hunk is left unchanged.
1499 """)
1500 # write the initial patch 1501 # write the initial patch
1501 patch = cStringIO.StringIO() 1502 patch = cStringIO.StringIO()
1502 patch.write(''.join(['# %s\n' % i for i in phelp.splitlines()])) 1503 patch.write(diffhelptext + hunkhelptext)
1503 chunk.header.write(patch) 1504 chunk.header.write(patch)
1504 chunk.write(patch) 1505 chunk.write(patch)
1505 1506
1506 # start the editor and wait for it to complete 1507 # start the editor and wait for it to complete
1507 try: 1508 try: