From patchwork Mon Aug 21 08:43:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [5,of,9,V3] template: compute verb in obsfateverb From: Boris Feld X-Patchwork-Id: 23172 Message-Id: <66a2b0407c8cffedfae4.1503305037@FB> To: mercurial-devel@mercurial-scm.org Cc: boris.feld@octobus.net Date: Mon, 21 Aug 2017 10:43:57 +0200 # HG changeset patch # User Boris Feld # Date 1499088807 -7200 # Mon Jul 03 15:33:27 2017 +0200 # Node ID 66a2b0407c8cffedfae4897bd7a2f0e2d6a22363 # Parent 84a35f753f9ab500902f5c06ce3845ce85e5b5a9 # EXP-Topic obsfatetemplate template: compute verb in obsfateverb Add a template function obsfateverb which use the markers information to compute a better obsfate verb. The current logic behind the obsfate verb is simple for the moment: - If the successorsets is empty, the changeset has been pruned, for example: Obsfate: pruned - If the successorsets length is 1, the changeset has been rewritten without divergence, for example: Obsfate: rewritten as 2:337fec4d2edc, 3:f257fde29c7a - If the successorsets length is more than 1, the changeset has diverged, for example: Obsfate: split as 2:337fec4d2edc, 3:f257fde29c7a As the divergence might occurs on a subset of successors, we might see some successors twice: Obsfate: split as 9:0b997eb7ceee, 5:dd800401bd8c, 10:eceed8f98ffc; split as 8:b18bc8331526, 5:dd800401bd8c, 10:eceed8f98ffc diff -r 84a35f753f9a -r 66a2b0407c8c mercurial/obsutil.py --- a/mercurial/obsutil.py Thu Aug 17 18:26:11 2017 +0200 +++ b/mercurial/obsutil.py Mon Jul 03 15:33:27 2017 +0200 @@ -568,6 +568,17 @@ cache[current] = final return cache[initialnode] +def _successorsetverb(successorset, markers): + """ Return the verb summarizing the successorset + """ + if not successorset: + verb = 'pruned' + elif len(successorset) == 1: + verb = 'rewritten' + else: + verb = 'split' + return {'verb': verb} + def successorsandmarkers(repo, ctx): """compute the raw data needed for computing obsfate Returns a list of dict, one dict per successors set diff -r 84a35f753f9a -r 66a2b0407c8c mercurial/templater.py --- a/mercurial/templater.py Thu Aug 17 18:26:11 2017 +0200 +++ b/mercurial/templater.py Mon Jul 03 15:33:27 2017 +0200 @@ -18,6 +18,7 @@ encoding, error, minirst, + obsutil, parser, pycompat, registrar, @@ -849,6 +850,15 @@ func = lambda a, b: a % b return runarithmetic(context, mapping, (func, args[0], args[1])) +@templatefunc('obsfateverb(successors, markers)') +def obsfateverb(context, mapping, args): + """ Compute obsfate related information based on successors and markers + """ + successors = evalfuncarg(context, mapping, args[0]) + markers = evalfuncarg(context, mapping, args[1]) + + return obsutil._successorsetverb(successors, markers)['verb'] + @templatefunc('relpath(path)') def relpath(context, mapping, args): """Convert a repository-absolute path into a filesystem path relative to diff -r 84a35f753f9a -r 66a2b0407c8c tests/test-obsmarker-template.t --- a/tests/test-obsmarker-template.t Thu Aug 17 18:26:11 2017 +0200 +++ b/tests/test-obsmarker-template.t Mon Jul 03 15:33:27 2017 +0200 @@ -13,7 +13,8 @@ > stabilization=all > [templates] > obsfatesuccessors = " as {join(successors, ", ")}" - > obsfate = "rewritten{obsfatesuccessors}; " + > obsfateverb = "{obsfateverb(successors, markers)}" + > obsfate = "{obsfateverb}{obsfatesuccessors}; " > [alias] > tlog = log -G -T '{node|short}\ > {if(predecessors, "\n Predecessors: {predecessors}")}\ @@ -318,7 +319,7 @@ o 337fec4d2edc | | @ 471597cad322 - |/ Obsfate: rewritten as 2:337fec4d2edc, 3:f257fde29c7a; + |/ Obsfate: split as 2:337fec4d2edc, 3:f257fde29c7a; o ea207398892e $ hg up f257fde29c7a @@ -359,7 +360,7 @@ o 337fec4d2edc | | x 471597cad322 - |/ Obsfate: rewritten as 2:337fec4d2edc, 3:f257fde29c7a; + |/ Obsfate: split as 2:337fec4d2edc, 3:f257fde29c7a; o ea207398892e $ hg fatelogjson --hidden @@ -1528,7 +1529,7 @@ o dd800401bd8c | | x 9bd10a0775e4 - |/ Obsfate: rewritten as 5:dd800401bd8c, 6:4a004186e638, 7:ba2ed02b0c9a; + |/ Obsfate: split as 5:dd800401bd8c, 6:4a004186e638, 7:ba2ed02b0c9a; o f897c6137566 | | x 0dec01379d3b @@ -1603,7 +1604,7 @@ o dd800401bd8c | | @ 9bd10a0775e4 - |/ Obsfate: rewritten as 5:dd800401bd8c, 9:0b997eb7ceee, 10:eceed8f98ffc; rewritten as 5:dd800401bd8c, 8:b18bc8331526, 10:eceed8f98ffc; + |/ Obsfate: split as 5:dd800401bd8c, 9:0b997eb7ceee, 10:eceed8f98ffc; split as 5:dd800401bd8c, 8:b18bc8331526, 10:eceed8f98ffc; o f897c6137566 | o ea207398892e