Mercurial > hg
changeset 33912:e278d6d2d7d2
template: add minimal obsfate template function
The goal of this series is to have templates capable of displaying the
evolution of a changeset in a clean and human-readable way.
Add the succsandmarkers template return successors and markers so it can be
used separately like this:
> {succsandmarkers % "{get(succsandmarkers, "markers")|json};"}
The following patches will add template functions that takes successors and
markers as inputs and compute various obsfate fields from them.
author | Boris Feld <boris.feld@octobus.net> |
---|---|
date | Thu, 17 Aug 2017 18:26:11 +0200 |
parents | 34e10e09afa5 |
children | 5cd6d4826f9f |
files | mercurial/obsutil.py mercurial/templatekw.py tests/test-obsmarker-template.t |
diffstat | 3 files changed, 432 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/obsutil.py Mon Jul 03 03:27:58 2017 +0200 +++ b/mercurial/obsutil.py Thu Aug 17 18:26:11 2017 +0200 @@ -567,3 +567,18 @@ final.reverse() # put small successors set first cache[current] = final return cache[initialnode] + +def successorsandmarkers(repo, ctx): + """compute the raw data needed for computing obsfate + Returns a list of dict, one dict per successors set + """ + if not ctx.obsolete(): + return None + + ssets = successorssets(repo, ctx.node(), closest=True) + + values = [] + for sset in ssets: + values.append({'successors': sset, 'markers': sset.markers}) + + return values
--- a/mercurial/templatekw.py Mon Jul 03 03:27:58 2017 +0200 +++ b/mercurial/templatekw.py Thu Aug 17 18:26:11 2017 +0200 @@ -674,6 +674,48 @@ return _hybrid(gen(data), data, lambda x: {'successorset': x}, lambda d: d["successorset"]) +@templatekeyword("succsandmarkers") +def showsuccsandmarkers(repo, ctx, **args): + """Returns a list of dict for each final successor of ctx. + + The dict contains successors node id in "successors" keys and the list of + obs-markers from ctx to the set of successors in "markers" + + (EXPERIMENTAL) + """ + + values = obsutil.successorsandmarkers(repo, ctx) + + if values is None: + values = [] + + # Format successors and markers to avoid exposing binary to templates + data = [] + for i in values: + # Format successors + successors = i['successors'] + + successors = [hex(n) for n in successors] + successors = _hybrid(None, successors, + lambda x: {'ctx': repo[x], 'revcache': {}}, + lambda d: _formatrevnode(d['ctx'])) + + # Format markers + finalmarkers = [] + for m in i['markers']: + hexprec = hex(m[0]) + hexsucs = tuple(hex(n) for n in m[1]) + hexparents = None + if m[5] is not None: + hexparents = tuple(hex(n) for n in m[5]) + newmarker = (hexprec, hexsucs) + m[2:5] + (hexparents,) + m[6:] + finalmarkers.append(newmarker) + + data.append({'successors': successors, 'markers': finalmarkers}) + + f = _showlist('succsandmarkers', data, args) + return _hybrid(f, data, lambda x: x, lambda d: d) + @templatekeyword('p1rev') def showp1rev(repo, ctx, templ, **args): """Integer. The repository-local revision number of the changeset's
--- a/tests/test-obsmarker-template.t Mon Jul 03 03:27:58 2017 +0200 +++ b/tests/test-obsmarker-template.t Thu Aug 17 18:26:11 2017 +0200 @@ -11,6 +11,9 @@ > publish=False > [experimental] > stabilization=all + > [templates] + > obsfatesuccessors = " as {join(successors, ", ")}" + > obsfate = "rewritten{obsfatesuccessors}; " > [alias] > tlog = log -G -T '{node|short}\ > {if(predecessors, "\n Predecessors: {predecessors}")}\ @@ -20,6 +23,8 @@ > {if(successorssets, "\n Successors: {successorssets}")}\ > {if(successorssets, "\n multi-line: {join(successorssets, "\n multi-line: ")}")}\ > {if(successorssets, "\n json: {successorssets|json}")}\n' + > fatelog = log -G -T '{node|short}\n{if(succsandmarkers, " Obsfate: {succsandmarkers % "{obsfate}"} \n" )}' + > fatelogjson = log -G -T '{node|short}\n{if(succsandmarkers, " Obsfate: {succsandmarkers|json}\n")}' > EOF Test templates on amended commit @@ -33,8 +38,8 @@ $ mkcommit ROOT $ mkcommit A0 $ echo 42 >> A0 - $ hg commit --amend -m "A1" - $ hg commit --amend -m "A2" + $ HGUSER=test1 hg commit --amend -m "A1" --config devel.default-date="1234567890 0" + $ HGUSER=test2 hg commit --amend -m "A2" --config devel.default-date="987654321 0" $ hg log --hidden -G @ changeset: 4:d004c8f274b9 @@ -83,6 +88,27 @@ | json: [["d004c8f274b9ec480a47a93c10dac5eee63adb78"]] o ea207398892e + $ hg fatelog -q --traceback + o d004c8f274b9 + | + | @ 471f378eab4c + |/ Obsfate: rewritten as 4:d004c8f274b9; + o ea207398892e + + $ hg fatelog + o d004c8f274b9 + | + | @ 471f378eab4c + |/ Obsfate: rewritten as 4:d004c8f274b9; + o ea207398892e + + $ hg fatelog -v + o d004c8f274b9 + | + | @ 471f378eab4c + |/ Obsfate: rewritten as 4:d004c8f274b9; + o ea207398892e + $ hg up 'desc(A1)' --hidden 1 files updated, 0 files merged, 0 files removed, 0 files unresolved @@ -99,6 +125,13 @@ | json: [["d004c8f274b9ec480a47a93c10dac5eee63adb78"]] o ea207398892e + $ hg fatelog -v + o d004c8f274b9 + | + | @ a468dc9b3633 + |/ Obsfate: rewritten as 4:d004c8f274b9; + o ea207398892e + Predecessors template should show all the predecessors as we force their display with --hidden $ hg tlog --hidden @@ -123,6 +156,17 @@ | json: [["a468dc9b36338b14fdb7825f55ce3df4e71517ad"]] o ea207398892e + $ hg fatelog --hidden -q + o d004c8f274b9 + | + | @ a468dc9b3633 + |/ Obsfate: rewritten as 4:d004c8f274b9; + | x f137d23bb3e1 + | | + | x 471f378eab4c + |/ Obsfate: rewritten as 3:a468dc9b3633; + o ea207398892e + Predecessors template shouldn't show anything as all obsolete commit are not visible. @@ -155,7 +199,35 @@ | json: [["a468dc9b36338b14fdb7825f55ce3df4e71517ad"]] o ea207398892e + $ hg fatelog -v + @ d004c8f274b9 + | + o ea207398892e + + $ hg fatelog -v --hidden + @ d004c8f274b9 + | + | x a468dc9b3633 + |/ Obsfate: rewritten as 4:d004c8f274b9; + | x f137d23bb3e1 + | | + | x 471f378eab4c + |/ Obsfate: rewritten as 3:a468dc9b3633; + o ea207398892e + + + $ hg fatelogjson --hidden + @ d004c8f274b9 + | + | x a468dc9b3633 + |/ Obsfate: [{"markers": [["a468dc9b36338b14fdb7825f55ce3df4e71517ad", ["d004c8f274b9ec480a47a93c10dac5eee63adb78"], 0, [["user", "test2"]], [987654321.0, 0], null]], "successors": ["d004c8f274b9ec480a47a93c10dac5eee63adb78"]}] + | x f137d23bb3e1 + | | + | x 471f378eab4c + |/ Obsfate: [{"markers": [["471f378eab4c5e25f6c77f785b27c936efb22874", ["a468dc9b36338b14fdb7825f55ce3df4e71517ad"], 0, [["user", "test1"]], [1234567890.0, 0], null]], "successors": ["a468dc9b36338b14fdb7825f55ce3df4e71517ad"]}] + o ea207398892e + Test templates with splitted commit =================================== @@ -239,6 +311,16 @@ | json: [["337fec4d2edcf0e7a467e35f818234bc620068b5", "f257fde29c7a847c9b607f6e958656d0df0fb15c"]] o ea207398892e + + $ hg fatelog + o f257fde29c7a + | + o 337fec4d2edc + | + | @ 471597cad322 + |/ Obsfate: rewritten as 2:337fec4d2edc, 3:f257fde29c7a; + o ea207398892e + $ hg up f257fde29c7a 0 files updated, 0 files merged, 0 files removed, 0 files unresolved @@ -270,6 +352,25 @@ | json: [["337fec4d2edcf0e7a467e35f818234bc620068b5", "f257fde29c7a847c9b607f6e958656d0df0fb15c"]] o ea207398892e + + $ hg fatelog --hidden + @ f257fde29c7a + | + o 337fec4d2edc + | + | x 471597cad322 + |/ Obsfate: rewritten as 2:337fec4d2edc, 3:f257fde29c7a; + o ea207398892e + + $ hg fatelogjson --hidden + @ f257fde29c7a + | + o 337fec4d2edc + | + | x 471597cad322 + |/ Obsfate: [{"markers": [["471597cad322d1f659bb169751be9133dad92ef3", ["337fec4d2edcf0e7a467e35f818234bc620068b5", "f257fde29c7a847c9b607f6e958656d0df0fb15c"], 0, [["user", "test"]], [0.0, 0], null]], "successors": ["337fec4d2edcf0e7a467e35f818234bc620068b5", "f257fde29c7a847c9b607f6e958656d0df0fb15c"]}] + o ea207398892e + Test templates with folded commit ================================= @@ -354,6 +455,14 @@ | json: [["eb5a0daa21923bbf8caeb2c42085b9e463861fd0"]] o ea207398892e + + $ hg fatelog + o eb5a0daa2192 + | + | @ 471f378eab4c + |/ Obsfate: rewritten as 3:eb5a0daa2192; + o ea207398892e + $ hg up 'desc(B0)' --hidden 1 files updated, 0 files merged, 0 files removed, 0 files unresolved @@ -375,6 +484,16 @@ | json: [["eb5a0daa21923bbf8caeb2c42085b9e463861fd0"]] o ea207398892e + + $ hg fatelog + o eb5a0daa2192 + | + | @ 0dec01379d3b + | | Obsfate: rewritten as 3:eb5a0daa2192; + | x 471f378eab4c + |/ Obsfate: rewritten as 3:eb5a0daa2192; + o ea207398892e + $ hg up 'desc(C0)' 0 files updated, 0 files merged, 0 files removed, 0 files unresolved @@ -404,6 +523,26 @@ o ea207398892e + $ hg fatelog --hidden + @ eb5a0daa2192 + | + | x 0dec01379d3b + | | Obsfate: rewritten as 3:eb5a0daa2192; + | x 471f378eab4c + |/ Obsfate: rewritten as 3:eb5a0daa2192; + o ea207398892e + + + $ hg fatelogjson --hidden + @ eb5a0daa2192 + | + | x 0dec01379d3b + | | Obsfate: [{"markers": [["0dec01379d3be6318c470ead31b1fe7ae7cb53d5", ["eb5a0daa21923bbf8caeb2c42085b9e463861fd0"], 0, [["user", "test"]], [0.0, 0], null]], "successors": ["eb5a0daa21923bbf8caeb2c42085b9e463861fd0"]}] + | x 471f378eab4c + |/ Obsfate: [{"markers": [["471f378eab4c5e25f6c77f785b27c936efb22874", ["eb5a0daa21923bbf8caeb2c42085b9e463861fd0"], 0, [["user", "test"]], [0.0, 0], null]], "successors": ["eb5a0daa21923bbf8caeb2c42085b9e463861fd0"]}] + o ea207398892e + + Test templates with divergence ============================== @@ -521,6 +660,15 @@ | json: [["fdf9bde5129a28d4548fadd3f62b265cdd3b7a2e"], ["019fadeab383f6699fa83ad7bdb4d82ed2c0e5ab"]] o ea207398892e + $ hg fatelog + o 019fadeab383 + | + | o fdf9bde5129a + |/ + | @ 471f378eab4c + |/ Obsfate: rewritten as 2:fdf9bde5129a; rewritten as 4:019fadeab383; + o ea207398892e + $ hg up 'desc(A1)' 0 files updated, 0 files merged, 0 files removed, 0 files unresolved @@ -533,6 +681,14 @@ |/ o ea207398892e + + $ hg fatelog + o 019fadeab383 + | + | @ fdf9bde5129a + |/ + o ea207398892e + Predecessors template should the predecessors as we force their display with --hidden $ hg tlog --hidden @@ -562,6 +718,30 @@ o ea207398892e + $ hg fatelog --hidden + o 019fadeab383 + | + | x 65b757b745b9 + |/ Obsfate: rewritten as 4:019fadeab383; + | @ fdf9bde5129a + |/ + | x 471f378eab4c + |/ Obsfate: rewritten as 2:fdf9bde5129a; rewritten as 3:65b757b745b9; + o ea207398892e + + + $ hg fatelogjson --hidden + o 019fadeab383 + | + | x 65b757b745b9 + |/ Obsfate: [{"markers": [["65b757b745b935093c87a2bccd877521cccffcbd", ["019fadeab383f6699fa83ad7bdb4d82ed2c0e5ab"], 0, [["user", "test"]], [0.0, 0], null]], "successors": ["019fadeab383f6699fa83ad7bdb4d82ed2c0e5ab"]}] + | @ fdf9bde5129a + |/ + | x 471f378eab4c + |/ Obsfate: [{"markers": [["471f378eab4c5e25f6c77f785b27c936efb22874", ["fdf9bde5129a28d4548fadd3f62b265cdd3b7a2e"], 0, [["user", "test"]], [0.0, 0], null]], "successors": ["fdf9bde5129a28d4548fadd3f62b265cdd3b7a2e"]}, {"markers": [["471f378eab4c5e25f6c77f785b27c936efb22874", ["65b757b745b935093c87a2bccd877521cccffcbd"], 0, [["user", "test"]], [0.0, 0], null]], "successors": ["65b757b745b935093c87a2bccd877521cccffcbd"]}] + o ea207398892e + + Test templates with amended + folded commit =========================================== @@ -659,6 +839,14 @@ | json: [["eb5a0daa21923bbf8caeb2c42085b9e463861fd0"]] o ea207398892e + + $ hg fatelog + o eb5a0daa2192 + | + | @ 471f378eab4c + |/ Obsfate: rewritten as 4:eb5a0daa2192; + o ea207398892e + $ hg up 'desc(B0)' --hidden 1 files updated, 0 files merged, 0 files removed, 0 files unresolved @@ -679,6 +867,16 @@ | json: [["eb5a0daa21923bbf8caeb2c42085b9e463861fd0"]] o ea207398892e + + $ hg fatelog + o eb5a0daa2192 + | + | @ 0dec01379d3b + | | Obsfate: rewritten as 4:eb5a0daa2192; + | x 471f378eab4c + |/ Obsfate: rewritten as 4:eb5a0daa2192; + o ea207398892e + $ hg up 'desc(B1)' --hidden 0 files updated, 0 files merged, 0 files removed, 0 files unresolved @@ -699,6 +897,16 @@ | json: [["eb5a0daa21923bbf8caeb2c42085b9e463861fd0"]] o ea207398892e + + $ hg fatelog + o eb5a0daa2192 + | + | @ b7ea6d14e664 + | | Obsfate: rewritten as 4:eb5a0daa2192; + | x 471f378eab4c + |/ Obsfate: rewritten as 4:eb5a0daa2192; + o ea207398892e + $ hg up 'desc(C0)' 0 files updated, 0 files merged, 0 files removed, 0 files unresolved @@ -708,6 +916,12 @@ | o ea207398892e + + $ hg fatelog + @ eb5a0daa2192 + | + o ea207398892e + Predecessors template should show all predecessors as we force their display with --hidden $ hg tlog --hidden @@ -735,6 +949,30 @@ o ea207398892e + $ hg fatelog --hidden + @ eb5a0daa2192 + | + | x b7ea6d14e664 + | | Obsfate: rewritten as 4:eb5a0daa2192; + | | x 0dec01379d3b + | |/ Obsfate: rewritten as 3:b7ea6d14e664; + | x 471f378eab4c + |/ Obsfate: rewritten as 4:eb5a0daa2192; + o ea207398892e + + + $ hg fatelogjson --hidden + @ eb5a0daa2192 + | + | x b7ea6d14e664 + | | Obsfate: [{"markers": [["b7ea6d14e664bdc8922221f7992631b50da3fb07", ["eb5a0daa21923bbf8caeb2c42085b9e463861fd0"], 0, [["user", "test"]], [0.0, 0], null]], "successors": ["eb5a0daa21923bbf8caeb2c42085b9e463861fd0"]}] + | | x 0dec01379d3b + | |/ Obsfate: [{"markers": [["0dec01379d3be6318c470ead31b1fe7ae7cb53d5", ["b7ea6d14e664bdc8922221f7992631b50da3fb07"], 0, [["user", "test"]], [0.0, 0], null]], "successors": ["b7ea6d14e664bdc8922221f7992631b50da3fb07"]}] + | x 471f378eab4c + |/ Obsfate: [{"markers": [["471f378eab4c5e25f6c77f785b27c936efb22874", ["eb5a0daa21923bbf8caeb2c42085b9e463861fd0"], 0, [["user", "test"]], [0.0, 0], null]], "successors": ["eb5a0daa21923bbf8caeb2c42085b9e463861fd0"]}] + o ea207398892e + + Test template with pushed and pulled obs markers ================================================ @@ -838,6 +1076,14 @@ | json: [["7a230b46bf61e50b30308c6cfd7bd1269ef54702"]] o ea207398892e + + $ hg fatelog + o 7a230b46bf61 + | + | @ 471f378eab4c + |/ Obsfate: rewritten as 2:7a230b46bf61; + o ea207398892e + $ hg up 'desc(A2)' 0 files updated, 0 files merged, 0 files removed, 0 files unresolved @@ -847,6 +1093,12 @@ | o ea207398892e + + $ hg fatelog + @ 7a230b46bf61 + | + o ea207398892e + Predecessors template should show all predecessors as we force their display with --hidden $ hg tlog --hidden @@ -862,6 +1114,14 @@ o ea207398892e + $ hg fatelog --hidden + @ 7a230b46bf61 + | + | x 471f378eab4c + |/ Obsfate: rewritten as 2:7a230b46bf61; + o ea207398892e + + Test template with obsmarkers cycle =================================== @@ -895,6 +1155,12 @@ o ea207398892e + $ hg fatelog + @ f897c6137566 + | + o ea207398892e + + $ hg up -r "desc(B0)" --hidden 2 files updated, 0 files merged, 1 files removed, 0 files unresolved $ hg tlog @@ -923,6 +1189,16 @@ o ea207398892e + $ hg fatelog + o f897c6137566 + | + | @ 0dec01379d3b + | | Obsfate: rewritten as 3:f897c6137566; rewritten as 1:471f378eab4c; + | x 471f378eab4c + |/ Obsfate: rewritten as 2:0dec01379d3b; + o ea207398892e + + $ hg up -r "desc(A0)" --hidden 0 files updated, 0 files merged, 1 files removed, 0 files unresolved $ hg tlog @@ -936,6 +1212,14 @@ o ea207398892e + $ hg fatelog + o f897c6137566 + | + | @ 471f378eab4c + |/ + o ea207398892e + + $ hg up -r "desc(ROOT)" --hidden 0 files updated, 0 files merged, 1 files removed, 0 files unresolved $ hg tlog @@ -944,6 +1228,12 @@ @ ea207398892e + $ hg fatelog + o f897c6137566 + | + @ ea207398892e + + $ hg tlog --hidden o f897c6137566 | Predecessors: 2:0dec01379d3b @@ -1153,6 +1443,21 @@ | o ea207398892e + $ hg fatelog + @ 0b997eb7ceee + | + | o b18bc8331526 + |/ + | o ba2ed02b0c9a + | | + | x 4a004186e638 + |/ Obsfate: rewritten as 8:b18bc8331526; rewritten as 9:0b997eb7ceee; + o dd800401bd8c + | + o f897c6137566 + | + o ea207398892e + $ hg tlog --hidden @ 0b997eb7ceee | Predecessors: 6:4a004186e638 @@ -1211,6 +1516,48 @@ | json: [["0dec01379d3be6318c470ead31b1fe7ae7cb53d5"]] o ea207398892e + $ hg fatelog --hidden + @ 0b997eb7ceee + | + | o b18bc8331526 + |/ + | o ba2ed02b0c9a + | | + | x 4a004186e638 + |/ Obsfate: rewritten as 8:b18bc8331526; rewritten as 9:0b997eb7ceee; + o dd800401bd8c + | + | x 9bd10a0775e4 + |/ Obsfate: rewritten as 5:dd800401bd8c, 6:4a004186e638, 7:ba2ed02b0c9a; + o f897c6137566 + | + | x 0dec01379d3b + | | Obsfate: rewritten as 3:f897c6137566; rewritten as 1:471f378eab4c; + | x 471f378eab4c + |/ Obsfate: rewritten as 2:0dec01379d3b; + o ea207398892e + + $ hg fatelogjson --hidden + @ 0b997eb7ceee + | + | o b18bc8331526 + |/ + | o ba2ed02b0c9a + | | + | x 4a004186e638 + |/ Obsfate: [{"markers": [["4a004186e63889f20cb16434fcbd72220bd1eace", ["b18bc8331526a22cbb1801022bd1555bf291c48b"], 0, [["user", "test"]], [0.0, 0], null]], "successors": ["b18bc8331526a22cbb1801022bd1555bf291c48b"]}, {"markers": [["4a004186e63889f20cb16434fcbd72220bd1eace", ["0b997eb7ceeee06200a02f8aab185979092d514e"], 0, [["user", "test"]], [0.0, 0], null]], "successors": ["0b997eb7ceeee06200a02f8aab185979092d514e"]}] + o dd800401bd8c + | + | x 9bd10a0775e4 + |/ Obsfate: [{"markers": [["9bd10a0775e478708cada5f176ec6de654359ce7", ["dd800401bd8c79d815329277739e433e883f784e", "4a004186e63889f20cb16434fcbd72220bd1eace", "ba2ed02b0c9a56b9fdbc4e79c7e57866984d8a1f"], 0, [["user", "test"]], [0.0, 0], null]], "successors": ["dd800401bd8c79d815329277739e433e883f784e", "4a004186e63889f20cb16434fcbd72220bd1eace", "ba2ed02b0c9a56b9fdbc4e79c7e57866984d8a1f"]}] + o f897c6137566 + | + | x 0dec01379d3b + | | Obsfate: [{"markers": [["0dec01379d3be6318c470ead31b1fe7ae7cb53d5", ["f897c6137566320b081514b4c7227ecc3d384b39"], 0, [["user", "test"]], [0.0, 0], null]], "successors": ["f897c6137566320b081514b4c7227ecc3d384b39"]}, {"markers": [["0dec01379d3be6318c470ead31b1fe7ae7cb53d5", ["471f378eab4c5e25f6c77f785b27c936efb22874"], 0, [["user", "test"]], [0.0, 0], null]], "successors": ["471f378eab4c5e25f6c77f785b27c936efb22874"]}] + | x 471f378eab4c + |/ Obsfate: [{"markers": [["471f378eab4c5e25f6c77f785b27c936efb22874", ["0dec01379d3be6318c470ead31b1fe7ae7cb53d5"], 0, [["user", "test"]], [0.0, 0], null]], "successors": ["0dec01379d3be6318c470ead31b1fe7ae7cb53d5"]}] + o ea207398892e + $ hg up --hidden 4 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg rebase -r 7 -d 8 --config extensions.rebase= @@ -1245,6 +1592,22 @@ | o ea207398892e + + $ hg fatelog + o eceed8f98ffc + | + | o 0b997eb7ceee + | | + o | b18bc8331526 + |/ + o dd800401bd8c + | + | @ 9bd10a0775e4 + |/ Obsfate: rewritten as 5:dd800401bd8c, 9:0b997eb7ceee, 10:eceed8f98ffc; rewritten as 5:dd800401bd8c, 8:b18bc8331526, 10:eceed8f98ffc; + o f897c6137566 + | + o ea207398892e + Test templates with pruned commits ================================== @@ -1268,3 +1631,13 @@ | o ea207398892e + $ hg fatelog + @ 471f378eab4c + | + o ea207398892e + + $ hg fatelog -v + @ 471f378eab4c + | + o ea207398892e +