# HG changeset patch # User Mark Edgington # Date 1272233305 -7200 # Node ID a77a8002662f70fc8b99e59897e19dbb659e80a8 # Parent ea893a5729653dc612c962d85c95fa0f54d0bc40 - add ability to review / edit patch prior to committing diff --git a/crecord/chunk_selector.py b/crecord/chunk_selector.py --- a/crecord/chunk_selector.py +++ b/crecord/chunk_selector.py @@ -826,6 +826,7 @@ F : fold / unfold parent item and all of its ancestors m : edit / resume editing the commit message c : commit selected changes + r : review/edit and commit selected changes q : quit without committing (no changes will be made) ? : help (what you're currently reading)""" @@ -866,13 +867,24 @@ self.commentText = t.edit(keyFilter, self.commentText).rstrip(" \n") curses.cbreak() - def confirmCommit(self): + def confirmCommit(self, review=False): "Ask for 'Y' to be pressed to confirm commit. Return True if confirmed." - confirmText = "Are you sure you want to commit the selected changes [yN]? " + if review: + confirmText = \ +"""If you answer yes to the following, the your currently chosen patch chunks +will be loaded into an editor. You may modify the patch from the editor, and +save the changes if you wish to change the patch. Otherwise, you can just +close the editor without saving to accept the current patch as-is. + +Are you sure you want to review/edit and commit the selected changes [yN]? """ + else: + confirmText = "Are you sure you want to commit the selected changes [yN]? " confirmWin = curses.newwin(self.yScreenSize,0,0,0) try: - self.printString(confirmWin, confirmText, pairName="selected") + lines = confirmText.split("\n") + for line in lines: + self.printString(confirmWin, line, pairName="selected") except curses.error: pass self.stdscr.refresh() @@ -918,6 +930,9 @@ # initialize selecteItemEndLine (initial start-line is 0) self.selectedItemEndLine = self.getNumLinesDisplayed(self.currentSelectedItem, recurseChildren=False) + + # option which enables/disables patch-review (in editor) step + opts['crecord_reviewpatch'] = False try: self.commentText = opts['message'] @@ -948,6 +963,10 @@ elif keyPressed in ["c"]: if self.confirmCommit(): break + elif keyPressed in ["r"]: + if self.confirmCommit(review=True): + opts['crecord_reviewpatch'] = True + break elif keyPressed in [' ']: self.toggleApply() elif keyPressed in ["f"]: diff --git a/crecord/crecord_core.py b/crecord/crecord_core.py --- a/crecord/crecord_core.py +++ b/crecord/crecord_core.py @@ -105,6 +105,14 @@ dopatch = fp.tell() fp.seek(0) + # 2.5 optionally review / modify patch in text editor + if opts['crecord_reviewpatch']: + patchtext = fp.read() + reviewedpatch = ui.edit(patchtext, "") + fp.truncate(0) + fp.write(reviewedpatch) + fp.seek(0) + # 3a. apply filtered patch to clean repo (clean) if backups: hg.revert(repo, repo.dirstate.parents()[0], backups.has_key)