sapling/tests/test-context-metadata.t
Ryan McElroy 9e51fdef40 context: fix sanity check in metadataonlyctx
Summary:
Previously, this check was subtly wrong, causing it to fail for empty
commits (which have the same manifest as their parents). Update the check to
ensure the actual thing we want to ensure -- that the caller isn't creating
incorrect commits.

The failure would happen in this case:

```
  B  empty commit (manifest Am)
  |
  A  draft commit (manifest Am)
 /
M  master (manifest Mm)
```

When metaediting `A`, `metaedit` would then "rebase" `B` onto `A'` to create
`B'`, with both `A'` and `B'` reusing `Am` as their manifest. The old check
would fail here because the parent of `Am` is `Mm`, but the manifest of `A'`
(the parent of `B'`) is `Am`, so when checking the manifest of the parent
against the parent of the manifest, we would find that `Am != Mm` and fail.

The actual check we wanted was that the manifest of the parent of `B'` is the
same as the manifest of the parent of `B` -- which the old check approximated
as long as no manifests were reused in the stack. As this is not sufficient
with empty commits, we instead want to check that the manifest of the old
parent matches the manifest of the new parent, which we now do.

By avoid reading `manifest.parents`, this would also avoid some lazy tree
fetches, therefore speed up metaedit in certain cases.

Reviewed By: quark-zju

Differential Revision: D9013995

fbshipit-source-id: 4d0b05fc9bb81d115cd87ba2bf98aa253ae6f88b
2018-07-27 02:49:19 -07:00

51 lines
1.6 KiB
Perl

Tests about metadataonlyctx
$ hg init
$ echo A > A
$ hg commit -A A -m 'Add A'
$ echo B > B
$ hg commit -A B -m 'Add B'
$ hg rm A
$ echo C > C
$ echo B2 > B
$ hg add C -q
$ hg commit -m 'Remove A'
$ cat > metaedit.py <<EOF
> from __future__ import absolute_import
> from mercurial import context, registrar
> cmdtable = {}
> command = registrar.command(cmdtable)
> @command('metaedit')
> def metaedit(ui, repo, arg):
> # Modify commit message to "FOO"
> with repo.wlock(), repo.lock(), repo.transaction('metaedit'):
> old = repo['.']
> kwargs = dict(s.split('=', 1) for s in arg.split(';'))
> if 'parents' in kwargs:
> kwargs['parents'] = kwargs['parents'].split(',')
> new = context.metadataonlyctx(repo, old, **kwargs)
> new.commit()
> EOF
$ hg --config extensions.metaedit=$TESTTMP/metaedit.py metaedit 'text=Changed'
$ hg log -r tip
changeset: 3:ad83e9e00ec9
tag: tip
parent: 1:3afb7afe6632
user: test
date: Thu Jan 01 00:00:00 1970 +0000
summary: Changed
$ hg --config extensions.metaedit=$TESTTMP/metaedit.py metaedit 'parents=0' 2>&1 | egrep '^RuntimeError'
RuntimeError: new p1 manifest (007d8c9d88841325f5c6b06371b35b4e8a2b1a83) is not the old p1 manifest (cb5cbbc1bfbf24cc34b9e8c16914e9caa2d2a7fd)
$ hg --config extensions.metaedit=$TESTTMP/metaedit.py metaedit 'user=foo <foo@example.com>'
$ hg log -r tip
changeset: 4:1f86eaeca92b
tag: tip
parent: 1:3afb7afe6632
user: foo <foo@example.com>
date: Thu Jan 01 00:00:00 1970 +0000
summary: Remove A