comparison mercurial/crecord.py @ 27156:55fa7c3900ae

commit: add amend mode for commit -i When I moved crecord into core, I didn't include the toggleAmend function (to switch from commit to amend mode). I did it because it would have made it more difficult to use record and crecord interchangably. This patch reintroduces the amend mode for commit -i as well as two tests to verify the behavior of the function.
author Laurent Charignon <lcharignon@fb.com>
date Mon, 30 Nov 2015 16:37:42 -0800
parents 8d3c5797a175
children dcdf0a52ad36
comparison
equal deleted inserted replaced
27155:8d3c5797a175 27156:55fa7c3900ae
22 from .i18n import _ 22 from .i18n import _
23 from . import ( 23 from . import (
24 encoding, 24 encoding,
25 error, 25 error,
26 patch as patchmod, 26 patch as patchmod,
27 util,
27 ) 28 )
28 29
29 # This is required for ncurses to display non-ASCII characters in default user 30 # This is required for ncurses to display non-ASCII characters in default user
30 # locale encoding correctly. --immerrr 31 # locale encoding correctly. --immerrr
31 locale.setlocale(locale.LC_ALL, '') 32 locale.setlocale(locale.LC_ALL, '')
1008 "SELECT CHUNKS: (j/k/up/dn/pgup/pgdn) move cursor; " 1009 "SELECT CHUNKS: (j/k/up/dn/pgup/pgdn) move cursor; "
1009 "(space/A) toggle hunk/all; (e)dit hunk;", 1010 "(space/A) toggle hunk/all; (e)dit hunk;",
1010 pairname="legend") 1011 pairname="legend")
1011 printstring(self.statuswin, 1012 printstring(self.statuswin,
1012 " (f)old/unfold; (c)onfirm applied; (q)uit; (?) help " 1013 " (f)old/unfold; (c)onfirm applied; (q)uit; (?) help "
1013 "| [X]=hunk applied **=folded", 1014 "| [X]=hunk applied **=folded, toggle [a]mend mode",
1014 pairname="legend") 1015 pairname="legend")
1015 except curses.error: 1016 except curses.error:
1016 pass 1017 pass
1017 1018
1018 # print out the patch in the remaining part of the window 1019 # print out the patch in the remaining part of the window
1364 shift-left-arrow [H] : go to parent header / fold selected header 1365 shift-left-arrow [H] : go to parent header / fold selected header
1365 f : fold / unfold item, hiding/revealing its children 1366 f : fold / unfold item, hiding/revealing its children
1366 F : fold / unfold parent item and all of its ancestors 1367 F : fold / unfold parent item and all of its ancestors
1367 m : edit / resume editing the commit message 1368 m : edit / resume editing the commit message
1368 e : edit the currently selected hunk 1369 e : edit the currently selected hunk
1369 a : toggle amend mode (hg rev >= 2.2) 1370 a : toggle amend mode (hg rev >= 2.2), only with commit -i
1370 c : confirm selected changes 1371 c : confirm selected changes
1371 r : review/edit and confirm selected changes 1372 r : review/edit and confirm selected changes
1372 q : quit without confirming (no changes will be made) 1373 q : quit without confirming (no changes will be made)
1373 ? : help (what you're currently reading)""" 1374 ? : help (what you're currently reading)"""
1374 1375
1430 response = "n" 1431 response = "n"
1431 if response.lower().startswith("y"): 1432 if response.lower().startswith("y"):
1432 return True 1433 return True
1433 else: 1434 else:
1434 return False 1435 return False
1436
1437 def toggleamend(self, opts, test):
1438 """Toggle the amend flag.
1439
1440 When the amend flag is set, a commit will modify the most recently
1441 committed changeset, instead of creating a new changeset. Otherwise, a
1442 new changeset will be created (the normal commit behavior).
1443
1444 """
1445 try:
1446 ver = float(util.version()[:3])
1447 except ValueError:
1448 ver = 1
1449 if ver < 2.19:
1450 msg = ("The amend option is unavailable with hg versions < 2.2\n\n"
1451 "Press any key to continue.")
1452 elif opts.get('amend') is None:
1453 opts['amend'] = True
1454 msg = ("Amend option is turned on -- commiting the currently "
1455 "selected changes will not create a new changeset, but "
1456 "instead update the most recently committed changeset.\n\n"
1457 "Press any key to continue.")
1458 elif opts.get('amend') is True:
1459 opts['amend'] = None
1460 msg = ("Amend option is turned off -- commiting the currently "
1461 "selected changes will create a new changeset.\n\n"
1462 "Press any key to continue.")
1463 if not test:
1464 self.confirmationwindow(msg)
1435 1465
1436 def recenterdisplayedarea(self): 1466 def recenterdisplayedarea(self):
1437 """ 1467 """
1438 once we scrolled with pg up pg down we can be pointing outside of the 1468 once we scrolled with pg up pg down we can be pointing outside of the
1439 display zone. we print the patch with towin=False to compute the 1469 display zone. we print the patch with towin=False to compute the
1568 self.leftarrowevent() 1598 self.leftarrowevent()
1569 elif keypressed in ["H", "KEY_SLEFT"]: 1599 elif keypressed in ["H", "KEY_SLEFT"]:
1570 self.leftarrowshiftevent() 1600 self.leftarrowshiftevent()
1571 elif keypressed in ["q"]: 1601 elif keypressed in ["q"]:
1572 raise error.Abort(_('user quit')) 1602 raise error.Abort(_('user quit'))
1603 elif keypressed in ['a']:
1604 self.toggleamend(self.opts, test)
1573 elif keypressed in ["c"]: 1605 elif keypressed in ["c"]:
1574 if self.confirmcommit(): 1606 if self.confirmcommit():
1575 return True 1607 return True
1576 elif keypressed in ["r"]: 1608 elif keypressed in ["r"]:
1577 if self.confirmcommit(review=True): 1609 if self.confirmcommit(review=True):