Mercurial > hg
changeset 25392:ed18f4acf435 stable 3.4.1
templatekw: compare target context and its parent exactly (issue4690)
Before this patch, template keywords `{file_mods}`, `{file_adds}` and
`{file_dels}` use values gotten by `repo.status(ctx.p1().node(),
ctx.node())`.
But this doesn't work as expected if `ctx` is `memctx` or
`workingcommitctx`. Typical case of templating with these contexts is
customization of the text shown in the commit message editor by
`[committemplate]` configuration.
In this case, `ctx.node()` returns None and it causes comparison
between `ctx.p1()` and `workingctx`. `workingctx` lists up all changed
files in the working directory even at selective committing.
BTW, `{files}` uses `ctx.files()` and it works as expected.
To compare target context and its parent exactly, this patch passes
`ctx.p1()` and `ctx` without `node()`-nize. This avoids unexpected
comparison with `workingctx`.
This patch uses a little redundant template configurations in
`test-commit.t`, but they are needed to avoid regression around
problems fixed by a4958cdb2202 and 1e6fb8db666e: accessing on `ctx`
may break `ctx._status` field.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Tue, 02 Jun 2015 02:28:33 +0900 |
parents | b3840fb03dba |
children | eb52de500d2a 0a8390250125 |
files | mercurial/templatekw.py tests/test-commit-amend.t tests/test-commit.t |
diffstat | 3 files changed, 68 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templatekw.py Mon Jun 01 10:50:15 2015 +0900 +++ b/mercurial/templatekw.py Tue Jun 02 02:28:33 2015 +0900 @@ -111,7 +111,7 @@ def getfiles(repo, ctx, revcache): if 'files' not in revcache: - revcache['files'] = repo.status(ctx.p1().node(), ctx.node())[:3] + revcache['files'] = repo.status(ctx.p1(), ctx)[:3] return revcache['files'] def getlatesttags(repo, ctx, cache):
--- a/tests/test-commit-amend.t Mon Jun 01 10:50:15 2015 +0900 +++ b/tests/test-commit-amend.t Tue Jun 02 02:28:33 2015 +0900 @@ -1000,6 +1000,37 @@ HG: @@ -0,0 +1,1 @@ HG: +y + $ echo cccc >> cc + $ hg status -amr + M cc + $ HGEDITOR=cat hg commit --amend -e -m "cc should be excluded" -X cc + cc should be excluded + + HG: M: + HG: A: foo y + HG: R: a x + HG: diff -r 6de0c1bde1c8 a + HG: --- a/a Thu Jan 01 00:00:00 1970 +0000 + HG: +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 + HG: @@ -1,2 +0,0 @@ + HG: -a + HG: -a + HG: diff -r 6de0c1bde1c8 foo + HG: --- /dev/null Thu Jan 01 00:00:00 1970 +0000 + HG: +++ b/foo Thu Jan 01 00:00:00 1970 +0000 + HG: @@ -0,0 +1,1 @@ + HG: +foo + HG: diff -r 6de0c1bde1c8 x + HG: --- a/x Thu Jan 01 00:00:00 1970 +0000 + HG: +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 + HG: @@ -1,1 +0,0 @@ + HG: -x + HG: diff -r 6de0c1bde1c8 y + HG: --- /dev/null Thu Jan 01 00:00:00 1970 +0000 + HG: +++ b/y Thu Jan 01 00:00:00 1970 +0000 + HG: @@ -0,0 +1,1 @@ + HG: +y + Check for issue4405 -------------------
--- a/tests/test-commit.t Mon Jun 01 10:50:15 2015 +0900 +++ b/tests/test-commit.t Tue Jun 02 02:28:33 2015 +0900 @@ -441,10 +441,16 @@ $ cat >> .hg/hgrc <<EOF > [committemplate] > changeset = {desc} + > HG: mods={file_mods} + > HG: adds={file_adds} + > HG: dels={file_dels} > HG: files={files} > HG: > {splitlines(diff()) % 'HG: {line}\n' > }HG: + > HG: mods={file_mods} + > HG: adds={file_adds} + > HG: dels={file_dels} > HG: files={files}\n > EOF $ hg status -amr @@ -453,6 +459,9 @@ R removed $ HGEDITOR=cat hg commit -q -e -m "foo bar" changed foo bar + HG: mods=changed + HG: adds= + HG: dels= HG: files=changed HG: HG: --- a/changed Thu Jan 01 00:00:00 1970 +0000 @@ -461,6 +470,9 @@ HG: changed HG: +changed HG: + HG: mods=changed + HG: adds= + HG: dels= HG: files=changed $ hg status -amr A added @@ -474,25 +486,43 @@ $ cat >> .hg/hgrc <<EOF > [committemplate] > changeset = {desc} + > HG: mods={file_mods} + > HG: adds={file_adds} + > HG: dels={file_dels} > HG: files={files} > HG: > {splitlines(diff("changed")) % 'HG: {line}\n' > }HG: + > HG: mods={file_mods} + > HG: adds={file_adds} + > HG: dels={file_dels} > HG: files={files} > HG: > {splitlines(diff("added")) % 'HG: {line}\n' > }HG: + > HG: mods={file_mods} + > HG: adds={file_adds} + > HG: dels={file_dels} > HG: files={files} > HG: > {splitlines(diff("removed")) % 'HG: {line}\n' > }HG: + > HG: mods={file_mods} + > HG: adds={file_adds} + > HG: dels={file_dels} > HG: files={files}\n > EOF $ HGEDITOR=cat hg commit -q -e -m "foo bar" added removed foo bar + HG: mods= + HG: adds=added + HG: dels=removed HG: files=added removed HG: HG: + HG: mods= + HG: adds=added + HG: dels=removed HG: files=added removed HG: HG: --- /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -500,6 +530,9 @@ HG: @@ -0,0 +1,1 @@ HG: +added HG: + HG: mods= + HG: adds=added + HG: dels=removed HG: files=added removed HG: HG: --- a/removed Thu Jan 01 00:00:00 1970 +0000 @@ -507,6 +540,9 @@ HG: @@ -1,1 +0,0 @@ HG: -removed HG: + HG: mods= + HG: adds=added + HG: dels=removed HG: files=added removed $ hg status -amr M changed