Mercurial > evolve
changeset 2486:cd4290f923b7
template: add precursors template
The precursors templates display the closest visible precursors of each
changeset, we may have gap, like in this case:
A -> B -> C
If we display A and C but not B, we can't display than B is the closest
precursor of C because it's not displayed. We display A as the closest
precursor of C instead.
Add a new test file as we will need to generate theses gaps and modifying
test-evolve-obshistory.t will lead to many unrelated lines changes.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Fri, 26 May 2017 10:05:27 +0200 |
parents | e6ecd35e99ec |
children | 590da9c523ae |
files | README hgext3rd/evolve/templatekw.py tests/test-evolve-templates.t |
diffstat | 3 files changed, 690 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/README Fri May 26 16:00:05 2017 +0200 +++ b/README Fri May 26 10:05:27 2017 +0200 @@ -117,6 +117,7 @@ - olog: add an 'obslog' alias - olog: add an '--all' option to show the whole obsolescence history tree. + - template: add a 'precursors' template that display the closests precursors of changesets 6.2.2 - in progress -------------------
--- a/hgext3rd/evolve/templatekw.py Fri May 26 16:00:05 2017 +0200 +++ b/hgext3rd/evolve/templatekw.py Fri May 26 10:05:27 2017 +0200 @@ -14,6 +14,7 @@ from mercurial import ( templatekw, + node, ) eh = exthelper.exthelper() @@ -41,3 +42,35 @@ except TypeError: return templatekw.showlist('trouble', ctx.troubles(), plural='troubles', **args) + +def closestprecursors(repo, nodeid): + """ Yield the list of next precursors pointing on visible changectx nodes + """ + + precursors = repo.obsstore.precursors + stack = [nodeid] + + while stack: + current = stack.pop() + currentpreccs = precursors.get(current, ()) + + for prec in currentpreccs: + precnodeid = prec[0] + + if precnodeid in repo: + yield precnodeid + else: + stack.append(precnodeid) + +@eh.templatekw("precursors") +def shownextvisibleprecursors(repo, ctx, templ, **args): + """Returns a string containing the list if the closest successors + displayed + """ + # XXX-review: I've added a couple of 'XXX' for future work. + + # XXX: template logic supports lists, so we should more to using a list at some point + + # XXX: I think we could returns something close to a "changectx" that would allow template to alter the way we render this. + shortnodes = map(node.short, sorted(closestprecursors(repo, ctx.node()))) + return ', '.join(shortnodes)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-evolve-templates.t Fri May 26 10:05:27 2017 +0200 @@ -0,0 +1,656 @@ +This test file test the various templates for precursors and successors. + +Global setup +============ + + $ . $TESTDIR/testlib/common.sh + $ cat >> $HGRCPATH <<EOF + > [ui] + > interactive = true + > [phases] + > publish=False + > [extensions] + > evolve = + > [alias] + > tlog = log -G -T '{node|short} Precursors: {precursors}\n' + > EOF + +Test templates on amended commit +================================ + +Test setup +---------- + + $ hg init $TESTTMP/templates-local-amend + $ cd $TESTTMP/templates-local-amend + $ mkcommit ROOT + $ mkcommit A0 + $ echo 42 >> A0 + $ hg amend -m "A1 + > + > Better commit message" + $ hg log --hidden -G + @ changeset: 3:4ae3a4151de9 + | tag: tip + | parent: 0:ea207398892e + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A1 + | + | x changeset: 2:f137d23bb3e1 + | | user: test + | | date: Thu Jan 01 00:00:00 1970 +0000 + | | summary: temporary amend commit for 471f378eab4c + | | + | x changeset: 1:471f378eab4c + |/ user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A0 + | + o changeset: 0:ea207398892e + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: ROOT + +Check templates +--------------- + $ hg up 'desc(A0)' --hidden + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + working directory parent is obsolete! (471f378eab4c) + (use 'hg evolve' to update to its successor: 4ae3a4151de9) + +Precursors template should show current revision as it is the working copy + $ hg tlog + o 4ae3a4151de9 Precursors: 471f378eab4c + | + | @ 471f378eab4c Precursors: + |/ + o ea207398892e Precursors: + + $ hg up 'desc(A1)' + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + +Precursors template should not show a precursor as it's not displayed in the +log + $ hg tlog + @ 4ae3a4151de9 Precursors: + | + o ea207398892e Precursors: + +Precursors template should show the precursor as we force its display with +--hidden + $ hg tlog --hidden + @ 4ae3a4151de9 Precursors: 471f378eab4c + | + | x f137d23bb3e1 Precursors: + | | + | x 471f378eab4c Precursors: + |/ + o ea207398892e Precursors: + + +Test templates with splitted commit +=================================== + + $ hg init $TESTTMP/templates-local-split + $ cd $TESTTMP/templates-local-split + $ mkcommit ROOT + $ echo 42 >> a + $ echo 43 >> b + $ hg commit -A -m "A0" + adding a + adding b + $ hg log --hidden -G + @ changeset: 1:471597cad322 + | tag: tip + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A0 + | + o changeset: 0:ea207398892e + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: ROOT + + $ hg split -r 'desc(A0)' -d "0 0" << EOF + > y + > y + > n + > n + > y + > y + > EOF + 0 files updated, 0 files merged, 2 files removed, 0 files unresolved + adding a + adding b + diff --git a/a b/a + new file mode 100644 + examine changes to 'a'? [Ynesfdaq?] y + + @@ -0,0 +1,1 @@ + +42 + record change 1/2 to 'a'? [Ynesfdaq?] y + + diff --git a/b b/b + new file mode 100644 + examine changes to 'b'? [Ynesfdaq?] n + + created new head + Done splitting? [yN] n + diff --git a/b b/b + new file mode 100644 + examine changes to 'b'? [Ynesfdaq?] y + + @@ -0,0 +1,1 @@ + +43 + record this change to 'b'? [Ynesfdaq?] y + + no more change to split + + $ hg log --hidden -G + @ changeset: 3:f257fde29c7a + | tag: tip + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A0 + | + o changeset: 2:337fec4d2edc + | parent: 0:ea207398892e + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A0 + | + | x changeset: 1:471597cad322 + |/ user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A0 + | + o changeset: 0:ea207398892e + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: ROOT + + +Check templates +--------------- + + $ hg up 'obsolete()' --hidden + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + working directory parent is obsolete! (471597cad322) + (use 'hg evolve' to update to its tipmost successor: 337fec4d2edc, f257fde29c7a) + +Precursors template should show current revision as it is the working copy + $ hg tlog + o f257fde29c7a Precursors: 471597cad322 + | + o 337fec4d2edc Precursors: 471597cad322 + | + | @ 471597cad322 Precursors: + |/ + o ea207398892e Precursors: + + $ hg up f257fde29c7a + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + +Precursors template should not show a precursor as it's not displayed in the +log + $ hg tlog + @ f257fde29c7a Precursors: + | + o 337fec4d2edc Precursors: + | + o ea207398892e Precursors: + +Precursors template should show the precursor as we force its display with +--hidden + $ hg tlog --hidden + @ f257fde29c7a Precursors: 471597cad322 + | + o 337fec4d2edc Precursors: 471597cad322 + | + | x 471597cad322 Precursors: + |/ + o ea207398892e Precursors: + +Test templates with folded commit +============================== + +Test setup +---------- + + $ hg init $TESTTMP/templates-local-fold + $ cd $TESTTMP/templates-local-fold + $ mkcommit ROOT + $ mkcommit A0 + $ mkcommit B0 + $ hg log --hidden -G + @ changeset: 2:0dec01379d3b + | tag: tip + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: B0 + | + o changeset: 1:471f378eab4c + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A0 + | + o changeset: 0:ea207398892e + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: ROOT + + $ hg fold --exact -r 'desc(A0) + desc(B0)' --date "0 0" -m "C0" + 2 changesets folded + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg log --hidden -G + @ changeset: 3:eb5a0daa2192 + | tag: tip + | parent: 0:ea207398892e + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: C0 + | + | x changeset: 2:0dec01379d3b + | | user: test + | | date: Thu Jan 01 00:00:00 1970 +0000 + | | summary: B0 + | | + | x changeset: 1:471f378eab4c + |/ user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A0 + | + o changeset: 0:ea207398892e + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: ROOT + +Check templates +--------------- + + $ hg up 'desc(A0)' --hidden + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + working directory parent is obsolete! (471f378eab4c) + (use 'hg evolve' to update to its successor: eb5a0daa2192) + +Precursors template should show current revision as it is the working copy + $ hg tlog + o eb5a0daa2192 Precursors: 471f378eab4c + | + | @ 471f378eab4c Precursors: + |/ + o ea207398892e Precursors: + + $ hg up 'desc(B0)' --hidden + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + working directory parent is obsolete! (0dec01379d3b) + (use 'hg evolve' to update to its successor: eb5a0daa2192) + +Precursors template should show both precursors as they should be both +displayed + $ hg tlog + o eb5a0daa2192 Precursors: 0dec01379d3b, 471f378eab4c + | + | @ 0dec01379d3b Precursors: + | | + | x 471f378eab4c Precursors: + |/ + o ea207398892e Precursors: + + $ hg up 'desc(C0)' + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + +Precursors template should not show precursors as it's not displayed in the +log + $ hg tlog + @ eb5a0daa2192 Precursors: + | + o ea207398892e Precursors: + +Precursors template should show both precursors as we force its display with +--hidden + $ hg tlog --hidden + @ eb5a0daa2192 Precursors: 0dec01379d3b, 471f378eab4c + | + | x 0dec01379d3b Precursors: + | | + | x 471f378eab4c Precursors: + |/ + o ea207398892e Precursors: + + +Test templates with divergence +============================== + +Test setup +---------- + + $ hg init $TESTTMP/templates-local-divergence + $ cd $TESTTMP/templates-local-divergence + $ mkcommit ROOT + $ mkcommit A0 + $ hg amend -m "A1" + $ hg log --hidden -G + @ changeset: 2:fdf9bde5129a + | tag: tip + | parent: 0:ea207398892e + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A1 + | + | x changeset: 1:471f378eab4c + |/ user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A0 + | + o changeset: 0:ea207398892e + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: ROOT + + $ hg update --hidden 'desc(A0)' + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + working directory parent is obsolete! (471f378eab4c) + (use 'hg evolve' to update to its successor: fdf9bde5129a) + $ hg amend -m "A2" + 2 new divergent changesets + $ hg log --hidden -G + @ changeset: 3:65b757b745b9 + | tag: tip + | parent: 0:ea207398892e + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | trouble: divergent + | summary: A2 + | + | o changeset: 2:fdf9bde5129a + |/ parent: 0:ea207398892e + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | trouble: divergent + | summary: A1 + | + | x changeset: 1:471f378eab4c + |/ user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A0 + | + o changeset: 0:ea207398892e + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: ROOT + +Check templates +--------------- + + $ hg up 'desc(A0)' --hidden + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + working directory parent is obsolete! (471f378eab4c) + (471f378eab4c has diverged, use 'hg evolve -list --divergent' to resolve the issue) + +Precursors template should show current revision as it is the working copy + $ hg tlog + o 65b757b745b9 Precursors: 471f378eab4c + | + | o fdf9bde5129a Precursors: 471f378eab4c + |/ + | @ 471f378eab4c Precursors: + |/ + o ea207398892e Precursors: + + $ hg up 'desc(A1)' + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved +Precursors template should not show precursors as it's not displayed in the +log + $ hg tlog + o 65b757b745b9 Precursors: + | + | @ fdf9bde5129a Precursors: + |/ + o ea207398892e Precursors: + +Precursors template should a precursor as we force its display with --hidden + $ hg tlog --hidden + o 65b757b745b9 Precursors: 471f378eab4c + | + | @ fdf9bde5129a Precursors: 471f378eab4c + |/ + | x 471f378eab4c Precursors: + |/ + o ea207398892e Precursors: + +Test templates with amended + folded commit +=========================================== + +Test setup +---------- + + $ hg init $TESTTMP/templates-local-amend-fold + $ cd $TESTTMP/templates-local-amend-fold + $ mkcommit ROOT + $ mkcommit A0 + $ mkcommit B0 + $ hg amend -m "B1" + $ hg log --hidden -G + @ changeset: 3:b7ea6d14e664 + | tag: tip + | parent: 1:471f378eab4c + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: B1 + | + | x changeset: 2:0dec01379d3b + |/ user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: B0 + | + o changeset: 1:471f378eab4c + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A0 + | + o changeset: 0:ea207398892e + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: ROOT + + $ hg fold --exact -r 'desc(A0) + desc(B1)' --date "0 0" -m "C0" + 2 changesets folded + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg log --hidden -G + @ changeset: 4:eb5a0daa2192 + | tag: tip + | parent: 0:ea207398892e + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: C0 + | + | x changeset: 3:b7ea6d14e664 + | | parent: 1:471f378eab4c + | | user: test + | | date: Thu Jan 01 00:00:00 1970 +0000 + | | summary: B1 + | | + | | x changeset: 2:0dec01379d3b + | |/ user: test + | | date: Thu Jan 01 00:00:00 1970 +0000 + | | summary: B0 + | | + | x changeset: 1:471f378eab4c + |/ user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A0 + | + o changeset: 0:ea207398892e + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: ROOT + +Check templates +--------------- + + $ hg up 'desc(A0)' --hidden + 0 files updated, 0 files merged, 1 files removed, 0 files unresolved + working directory parent is obsolete! (471f378eab4c) + (use 'hg evolve' to update to its successor: eb5a0daa2192) + $ hg tlog + o eb5a0daa2192 Precursors: 471f378eab4c + | + | @ 471f378eab4c Precursors: + |/ + o ea207398892e Precursors: + + $ hg up 'desc(B0)' --hidden + 1 files updated, 0 files merged, 0 files removed, 0 files unresolved + working directory parent is obsolete! (0dec01379d3b) + (use 'hg evolve' to update to its successor: eb5a0daa2192) + $ hg tlog + o eb5a0daa2192 Precursors: 0dec01379d3b, 471f378eab4c + | + | @ 0dec01379d3b Precursors: + | | + | x 471f378eab4c Precursors: + |/ + o ea207398892e Precursors: + + $ hg up 'desc(B1)' --hidden + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + working directory parent is obsolete! (b7ea6d14e664) + (use 'hg evolve' to update to its successor: eb5a0daa2192) + $ hg tlog + o eb5a0daa2192 Precursors: 471f378eab4c, b7ea6d14e664 + | + | @ b7ea6d14e664 Precursors: + | | + | x 471f378eab4c Precursors: + |/ + o ea207398892e Precursors: + + $ hg up 'desc(C0)' + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg tlog + @ eb5a0daa2192 Precursors: + | + o ea207398892e Precursors: + + $ hg tlog --hidden + @ eb5a0daa2192 Precursors: 471f378eab4c, b7ea6d14e664 + | + | x b7ea6d14e664 Precursors: 0dec01379d3b + | | + | | x 0dec01379d3b Precursors: + | |/ + | x 471f378eab4c Precursors: + |/ + o ea207398892e Precursors: + + +Test template with pushed and pulled obs markers +============================================== + +Test setup +---------- + + $ hg init $TESTTMP/templates-local-remote-markers-1 + $ cd $TESTTMP/templates-local-remote-markers-1 + $ mkcommit ROOT + $ mkcommit A0 + $ hg clone $TESTTMP/templates-local-remote-markers-1 $TESTTMP/templates-local-remote-markers-2 + updating to branch default + 2 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ cd $TESTTMP/templates-local-remote-markers-2 + $ hg log --hidden -G + @ changeset: 1:471f378eab4c + | tag: tip + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A0 + | + o changeset: 0:ea207398892e + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: ROOT + + $ cd $TESTTMP/templates-local-remote-markers-1 + $ hg amend -m "A1" + $ hg amend -m "A2" + $ hg log --hidden -G + @ changeset: 3:7a230b46bf61 + | tag: tip + | parent: 0:ea207398892e + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A2 + | + | x changeset: 2:fdf9bde5129a + |/ parent: 0:ea207398892e + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A1 + | + | x changeset: 1:471f378eab4c + |/ user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A0 + | + o changeset: 0:ea207398892e + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: ROOT + + $ cd $TESTTMP/templates-local-remote-markers-2 + $ hg pull + pulling from $TESTTMP/templates-local-remote-markers-1 + searching for changes + adding changesets + adding manifests + adding file changes + added 1 changesets with 0 changes to 1 files (+1 heads) + 2 new obsolescence markers + (run 'hg heads' to see heads, 'hg merge' to merge) + working directory parent is obsolete! (471f378eab4c) + (use 'hg evolve' to update to its successor: 7a230b46bf61) + $ hg log --hidden -G + o changeset: 2:7a230b46bf61 + | tag: tip + | parent: 0:ea207398892e + | user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A2 + | + | @ changeset: 1:471f378eab4c + |/ user: test + | date: Thu Jan 01 00:00:00 1970 +0000 + | summary: A0 + | + o changeset: 0:ea207398892e + user: test + date: Thu Jan 01 00:00:00 1970 +0000 + summary: ROOT + + +Check templates +--------------- + + $ hg tlog + o 7a230b46bf61 Precursors: 471f378eab4c + | + | @ 471f378eab4c Precursors: + |/ + o ea207398892e Precursors: + + $ hg up 'desc(A2)' + 0 files updated, 0 files merged, 0 files removed, 0 files unresolved + $ hg tlog + @ 7a230b46bf61 Precursors: + | + o ea207398892e Precursors: + + $ hg tlog --hidden + @ 7a230b46bf61 Precursors: 471f378eab4c + | + | x 471f378eab4c Precursors: + |/ + o ea207398892e Precursors: +