diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -207,6 +207,17 @@ def dorecord(ui, repo, commitfunc, cmdsu dopatch = fp.tell() fp.seek(0) + # 2.5 optionally review / modify patch in text editor + if opts.get('review', False): + patchtext = (crecordmod.diffhelptext + + crecordmod.patchhelptext + + fp.read()) + reviewedpatch = ui.edit(patchtext, "", + extra={"suffix": ".diff"}) + fp.truncate(0) + fp.write(reviewedpatch) + fp.seek(0) + [os.unlink(repo.wjoin(c)) for c in newlyaddedandmodifiedfiles] # 3a. apply filtered patch to clean repo (clean) if backups: diff --git a/mercurial/crecord.py b/mercurial/crecord.py --- a/mercurial/crecord.py +++ b/mercurial/crecord.py @@ -43,6 +43,13 @@ hunkhelptext = _("""# # of the hunk are removed, then the edit is aborted and the hunk is left # unchanged. """) + +patchhelptext = _("""# +# If the patch applies cleanly, the edited patch will immediately +# be finalised. If it does not apply cleanly, rejects files will be +# generated. You can use those when you try again. +""") + try: import curses import fcntl @@ -1595,10 +1602,14 @@ are you sure you want to review/edit and elif keypressed in ["c"]: if self.confirmcommit(): return True + elif test and keypressed in ['X']: + return True elif keypressed in ["r"]: if self.confirmcommit(review=True): + self.opts['review'] = True return True - elif test and keypressed in ['X']: + elif test and keypressed in ['R']: + self.opts['review'] = True return True elif keypressed in [' '] or (test and keypressed in ["TOGGLE"]): self.toggleapply() diff --git a/tests/test-commit-interactive-curses.t b/tests/test-commit-interactive-curses.t --- a/tests/test-commit-interactive-curses.t +++ b/tests/test-commit-interactive-curses.t @@ -223,7 +223,82 @@ of the edit. foo hello world +Testing the review option. The entire final filtered patch should show +up in the editor and be editable. We will unselect the second file and +the first hunk of the third file. During review, we will decide that +"lower" sounds better than "bottom", and the final commit should +reflect this edition. + $ hg update -C . + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ echo "top" > c + $ cat x >> c + $ echo "bottom" >> c + $ mv c x + $ echo "third a" >> a + $ echo "we will unselect this" >> b + + $ cat > editor.sh < cat "\$1" + > cat "\$1" | sed s/bottom/lower/ > tmp + > mv tmp "\$1" + > EOF + $ cat > testModeCommands < KEY_DOWN + > TOGGLE + > KEY_DOWN + > f + > KEY_DOWN + > TOGGLE + > R + > EOF + + $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit -i -m "review hunks" -d "0 0" + # To remove '-' lines, make them ' ' lines (context). + # To remove '+' lines, delete them. + # Lines starting with # will be removed from the patch. + # + # If the patch applies cleanly, the edited patch will immediately + # be finalised. If it does not apply cleanly, rejects files will be + # generated. You can use those when you try again. + diff --git a/a b/a + --- a/a + +++ b/a + @@ -1,2 +1,3 @@ + a + a + +third a + diff --git a/x b/x + --- a/x + +++ b/x + @@ -1,2 +1,3 @@ + foo + hello world + +bottom + + $ hg cat -r . a + a + a + third a + + $ hg cat -r . b + x + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + y + + $ hg cat -r . x + foo + hello world + lower Check ui.interface logic for the chunkselector The default interface is text