# HG changeset patch # User Sean Farley # Date 1483220196 21600 # Node ID 5c85c93cdd61c46ff46aa0b678711e7a41c97643 # Parent 7e4f431206cdbc167c676a4eb51b638ad5c3187c cmdutil: add special string that ignores rest of text Similar to git, we add a special string: HG: ------------------------ >8 ------------------------ that means anything below it is ignored in a commit message. This is helpful for integrating with third-party tools that display the diff -r 7e4f431206cd -r 5c85c93cdd61 mercurial/cmdutil.py --- a/mercurial/cmdutil.py Sat May 14 20:52:44 2016 +0900 +++ b/mercurial/cmdutil.py Sat Dec 31 15:36:36 2016 -0600 @@ -49,6 +49,10 @@ ) stringio = util.stringio +# special string such that everything below this line will be ingored in the +# editor text +_linebelow = "^HG: ------------------------ >8 ------------------------$" + def ishunk(x): hunkclasses = (crecordmod.uihunk, patch.recordhunk) return isinstance(x, hunkclasses) @@ -2767,6 +2771,13 @@ editortext = repo.ui.edit(committext, ctx.user(), ctx.extra(), editform=editform, pending=pending) + + # strip away anything below this special string (used for editors that want + # to display the diff) + stripbelow = re.search(_linebelow, editortext, flags=re.MULTILINE) + if stripbelow: + editortext = editortext[:stripbelow.start()] + text = re.sub("(?m)^HG:.*(\n|$)", "", editortext) os.chdir(olddir) diff -r 7e4f431206cd -r 5c85c93cdd61 tests/test-commit.t --- a/tests/test-commit.t Sat May 14 20:52:44 2016 +0900 +++ b/tests/test-commit.t Sat Dec 31 15:36:36 2016 -0600 @@ -689,4 +689,97 @@ $ HGEDITOR="sh $TESTTMP/notouching.sh" hg commit abort: commit message unchanged [255] + +test that text below the --- >8 --- special string is ignored + + $ hg init ignore_below_special_string + $ cd ignore_below_special_string + $ echo foo > foo + $ hg add foo + $ hg commit -m "foo" + $ cat >> .hg/hgrc < [committemplate] + > changeset.commit = first line + > HG: this is customized commit template + > HG: {extramsg} + > HG: ------------------------ >8 ------------------------ + > {diff()} + > EOF + $ echo foo2 > foo2 + $ hg add foo2 + $ HGEDITOR=cat hg ci + first line + HG: this is customized commit template + HG: Leave message empty to abort commit. + HG: ------------------------ >8 ------------------------ + diff -r e63c23eaa88a foo2 + --- /dev/null Thu Jan 01 00:00:00 1970 +0000 + +++ b/foo2 Thu Jan 01 00:00:00 1970 +0000 + @@ -0,0 +1,1 @@ + +foo2 + $ hg log -T '{desc}\n' -r . + first line + +test that the special string --- >8 --- isn't used when not at the beginning of +a line + + $ cat >> .hg/hgrc < [committemplate] + > changeset.commit = first line2 + > another line HG: ------------------------ >8 ------------------------ + > HG: this is customized commit template + > HG: {extramsg} + > HG: ------------------------ >8 ------------------------ + > {diff()} + > EOF + $ echo foo >> foo + $ HGEDITOR=cat hg ci + first line2 + another line HG: ------------------------ >8 ------------------------ + HG: this is customized commit template + HG: Leave message empty to abort commit. + HG: ------------------------ >8 ------------------------ + diff -r 3661b22b0702 foo + --- a/foo Thu Jan 01 00:00:00 1970 +0000 + +++ b/foo Thu Jan 01 00:00:00 1970 +0000 + @@ -1,1 +1,2 @@ + foo + +foo + $ hg log -T '{desc}\n' -r . + first line2 + another line HG: ------------------------ >8 ------------------------ + +also test that this special string isn't accepted when there is some extra text +at the end + + $ cat >> .hg/hgrc < [committemplate] + > changeset.commit = first line3 + > HG: ------------------------ >8 ------------------------foobar + > second line + > HG: this is customized commit template + > HG: {extramsg} + > HG: ------------------------ >8 ------------------------ + > {diff()} + > EOF + $ echo foo >> foo + $ HGEDITOR=cat hg ci + first line3 + HG: ------------------------ >8 ------------------------foobar + second line + HG: this is customized commit template + HG: Leave message empty to abort commit. + HG: ------------------------ >8 ------------------------ + diff -r ce648f5f066f foo + --- a/foo Thu Jan 01 00:00:00 1970 +0000 + +++ b/foo Thu Jan 01 00:00:00 1970 +0000 + @@ -1,2 +1,3 @@ + foo + foo + +foo + $ hg log -T '{desc}\n' -r . + first line3 + second line + $ cd .. +