Mercurial > hg
changeset 47069:5b6dd0d9171b
rewriteutil: give examples of public changesets that can't be rewritten
This patch copies the feature from the evolve extension.
Differential Revision: https://phab.mercurial-scm.org/D10670
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Tue, 04 May 2021 10:16:34 -0700 |
parents | fde5bb5d1acf |
children | d90f6237b3aa |
files | mercurial/rewriteutil.py tests/test-amend.t tests/test-branch-change.t tests/test-commit-amend.t tests/test-fix.t tests/test-histedit-obsolete.t tests/test-rebase-scenario-global.t tests/test-split.t tests/test-unamend.t |
diffstat | 9 files changed, 33 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/rewriteutil.py Mon May 03 15:14:09 2021 -0400 +++ b/mercurial/rewriteutil.py Tue May 04 10:16:34 2021 -0700 @@ -17,6 +17,7 @@ from . import ( error, + node, obsolete, obsutil, revset, @@ -28,6 +29,26 @@ NODE_RE = re.compile(br'\b[0-9a-f]{6,64}\b') +def _formatrevs(repo, revs, maxrevs=4): + """returns a string summarizing revisions in a decent size + + If there are few enough revisions, we list them all. Otherwise we display a + summary of the form: + + 1ea73414a91b and 5 others + """ + tonode = repo.changelog.node + numrevs = len(revs) + if numrevs < maxrevs: + shorts = [node.short(tonode(r)) for r in revs] + summary = b', '.join(shorts) + else: + first = revs.first() + summary = _(b'%s and %d others') + summary %= (node.short(tonode(first)), numrevs - 1) + return summary + + def precheck(repo, revs, action=b'rewrite'): """check if revs can be rewritten action is used to control the error message. @@ -50,7 +71,8 @@ publicrevs = repo.revs(b'%ld and public()', revs) if publicrevs: - msg = _(b"cannot %s public changesets") % action + summary = _formatrevs(repo, publicrevs) + msg = _(b"cannot %s public changesets: %s") % (action, summary) hint = _(b"see 'hg help phases' for details") raise error.InputError(msg, hint=hint)
--- a/tests/test-amend.t Mon May 03 15:14:09 2021 -0400 +++ b/tests/test-amend.t Tue May 04 10:16:34 2021 -0700 @@ -250,7 +250,7 @@ $ hg phase -r A --public $ hg update -C -q A $ hg amend -m AMEND - abort: cannot amend public changesets + abort: cannot amend public changesets: 426bada5c675 (see 'hg help phases' for details) [10]
--- a/tests/test-branch-change.t Mon May 03 15:14:09 2021 -0400 +++ b/tests/test-branch-change.t Tue May 04 10:16:34 2021 -0700 @@ -369,7 +369,7 @@ $ hg phase -r . -p $ hg branch -r . def - abort: cannot change branch of public changesets + abort: cannot change branch of public changesets: d1c2addda4a2 (see 'hg help phases' for details) [10]
--- a/tests/test-commit-amend.t Mon May 03 15:14:09 2021 -0400 +++ b/tests/test-commit-amend.t Tue May 04 10:16:34 2021 -0700 @@ -10,7 +10,7 @@ $ hg phase -r . -p $ hg ci --amend - abort: cannot amend public changesets + abort: cannot amend public changesets: ad120869acf0 (see 'hg help phases' for details) [10] $ hg phase -r . -f -d
--- a/tests/test-fix.t Mon May 03 15:14:09 2021 -0400 +++ b/tests/test-fix.t Tue May 04 10:16:34 2021 -0700 @@ -264,11 +264,11 @@ $ hg commit -Aqm "hello" $ hg phase -r 0 --public $ hg fix -r 0 - abort: cannot fix public changesets + abort: cannot fix public changesets: 6470986d2e7b (see 'hg help phases' for details) [10] $ hg fix -r 0 --working-dir - abort: cannot fix public changesets + abort: cannot fix public changesets: 6470986d2e7b (see 'hg help phases' for details) [10] $ hg cat -r tip hello.whole
--- a/tests/test-histedit-obsolete.t Mon May 03 15:14:09 2021 -0400 +++ b/tests/test-histedit-obsolete.t Tue May 04 10:16:34 2021 -0700 @@ -307,7 +307,7 @@ o 0:cb9a9f314b8b (public) a $ hg histedit -r '.~2' - abort: cannot edit public changesets + abort: cannot edit public changesets: cb9a9f314b8b, 40db8afa467b (see 'hg help phases' for details) [10]
--- a/tests/test-rebase-scenario-global.t Mon May 03 15:14:09 2021 -0400 +++ b/tests/test-rebase-scenario-global.t Tue May 04 10:16:34 2021 -0700 @@ -328,11 +328,11 @@ nothing to rebase [1] $ hg rebase -d 5 -b 6 - abort: cannot rebase public changesets + abort: cannot rebase public changesets: e1c4361dd923 (see 'hg help phases' for details) [10] $ hg rebase -d 5 -r '1 + (6::)' - abort: cannot rebase public changesets + abort: cannot rebase public changesets: e1c4361dd923 (see 'hg help phases' for details) [10]
--- a/tests/test-split.t Mon May 03 15:14:09 2021 -0400 +++ b/tests/test-split.t Tue May 04 10:16:34 2021 -0700 @@ -77,7 +77,7 @@ $ hg phase --public -r 'all()' $ hg split . - abort: cannot split public changesets + abort: cannot split public changesets: 1df0d5c5a3ab (see 'hg help phases' for details) [10]
--- a/tests/test-unamend.t Mon May 03 15:14:09 2021 -0400 +++ b/tests/test-unamend.t Tue May 04 10:16:34 2021 -0700 @@ -298,7 +298,7 @@ $ hg phase -r . -p 1 new phase-divergent changesets $ hg unamend - abort: cannot unamend public changesets + abort: cannot unamend public changesets: 03ddd6fc5af1 (see 'hg help phases' for details) [10]