changeset 816:03587920dfd9

evolve: add relevant marker exchange machinery This is going to be needed for obsolescence marker exchange.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Thu, 27 Feb 2014 18:30:55 -0800
parents 916bebf91c41
children c2bf0eb727f1
files hgext/evolve.py tests/test-obsolete.t
diffstat 2 files changed, 173 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/evolve.py	Thu Feb 27 17:20:34 2014 -0800
+++ b/hgext/evolve.py	Thu Feb 27 18:30:55 2014 -0800
@@ -682,7 +682,6 @@
     except KeyError:
         pass  # rebase not found
 
-
 #####################################################################
 ### Old Evolve extension content                                  ###
 #####################################################################
@@ -2031,3 +2030,47 @@
     entry[1].append(('O', 'old-obsolete', False,
                      _("make graft obsoletes its source")))
 
+#####################################################################
+### Obsolescence marker exchange experimenation                   ###
+#####################################################################
+
+@command('debugobsoleterelevant',
+         [],
+         'REVSET')
+def debugobsoleterelevant(ui, repo, *revsets):
+    """print allobsolescence marker relevant to a set of revision"""
+    nodes = [ctx.node() for ctx in repo.set('%lr', revsets)]
+    markers = repo.obsstore.relevantmarkers(nodes)
+    for rawmarker in sorted(markers):
+        marker = obsolete.marker(repo, rawmarker)
+        cmdutil.showmarker(ui, marker)
+
+@eh.addattr(obsolete.obsstore, 'relevantmarkers')
+def relevantmarkers(self, nodes):
+    """return a set of all obsolescence marker relevant to a set of node.
+
+    "relevant" to a set of node mean:
+
+    - marker that use this changeset as successors
+    - prune marker of direct children on this changeset.
+    - recursive application of the two rules on precursors of these markers
+
+    It  a set so you cannot rely on order"""
+    seennodes = set(nodes)
+    seenmarkers = set()
+    pendingnodes = set(nodes)
+    precursorsmarkers = self.precursors
+    prunedchildren = self.prunedchildren
+    while pendingnodes:
+        direct = set()
+        for current in pendingnodes:
+            direct.update(precursorsmarkers.get(current, ()))
+            direct.update(prunedchildren.get(current, ()))
+        direct -= seenmarkers
+        pendingnodes = set([m[0] for m in direct])
+        seenmarkers |= direct
+        pendingnodes -= seennodes
+        seennodes |= pendingnodes
+    return seenmarkers
+
+
--- a/tests/test-obsolete.t	Thu Feb 27 17:20:34 2014 -0800
+++ b/tests/test-obsolete.t	Thu Feb 27 18:30:55 2014 -0800
@@ -687,3 +687,132 @@
   $ hg export 9468a5f5d8b2 | hg import -
   applying patch from stdin
   1 new unstable changesets
+
+
+Relevant marker computation
+==============================
+
+  $ hg log -G --hidden
+  @  changeset:   17:a5f7a21fe7bc
+  |  tag:         tip
+  |  parent:      2:4538525df7e2
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     add obsol_d''
+  |
+  | o  changeset:   16:50f11e5e3a63
+  | |  parent:      11:9468a5f5d8b2
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     add obsolet_conflicting_d
+  | |
+  | | o  changeset:   15:705ab2a6b72e
+  | | |  parent:      10:2033b4e49474
+  | | |  user:        test
+  | | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | | |  summary:     add f
+  | | |
+  | | | x  changeset:   14:33d458d86621
+  | | | |  user:        test
+  | | | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | | | |  summary:     temporary amend commit for 0b1b6dd009c0
+  | | | |
+  | | | x  changeset:   13:0b1b6dd009c0
+  | | |/   parent:      10:2033b4e49474
+  | | |    user:        test
+  | | |    date:        Thu Jan 01 00:00:00 1970 +0000
+  | | |    summary:     add f
+  | | |
+  | | | o  changeset:   12:6db5e282cb91
+  | | |/   parent:      10:2033b4e49474
+  | | |    user:        test
+  | | |    date:        Thu Jan 01 00:00:00 1970 +0000
+  | | |    summary:     add obsol_d'''
+  | | |
+  | o |  changeset:   11:9468a5f5d8b2
+  | |/   user:        test
+  | |    date:        Thu Jan 01 00:00:00 1970 +0000
+  | |    summary:     add obsol_d''
+  | |
+  | o  changeset:   10:2033b4e49474
+  | |  parent:      4:725c380fe99b
+  | |  user:        test
+  | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | |  summary:     add obsol_c
+  | |
+  | | x  changeset:   9:83b5778897ad
+  | |    parent:      -1:000000000000
+  | |    user:        test
+  | |    date:        Thu Jan 01 00:00:00 1970 +0000
+  | |    summary:     add toto
+  | |
+  | | x  changeset:   8:159dfc9fa5d3
+  | | |  parent:      3:0d3f46688ccc
+  | | |  user:        test
+  | | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | | |  summary:     add obsol_d''
+  | | |
+  | | | x  changeset:   7:909a0fb57e5d
+  | | |/   parent:      3:0d3f46688ccc
+  | | |    user:        test
+  | | |    date:        Thu Jan 01 00:00:00 1970 +0000
+  | | |    summary:     add obsol_d'
+  | | |
+  | | | x  changeset:   6:95de7fc6918d
+  | | |/   parent:      3:0d3f46688ccc
+  | | |    user:        test
+  | | |    date:        Thu Jan 01 00:00:00 1970 +0000
+  | | |    summary:     add obsol_d
+  | | |
+  | | | x  changeset:   5:a7a6f2b5d8a5
+  | | |/   parent:      3:0d3f46688ccc
+  | | |    user:        test
+  | | |    date:        Thu Jan 01 00:00:00 1970 +0000
+  | | |    summary:     add d
+  | | |
+  | o |  changeset:   4:725c380fe99b
+  | | |  parent:      1:7c3bad9141dc
+  | | |  user:        test
+  | | |  date:        Thu Jan 01 00:00:00 1970 +0000
+  | | |  summary:     add obsol_c'
+  | | |
+  | | x  changeset:   3:0d3f46688ccc
+  | |/   parent:      1:7c3bad9141dc
+  | |    user:        test
+  | |    date:        Thu Jan 01 00:00:00 1970 +0000
+  | |    summary:     add obsol_c
+  | |
+  x |  changeset:   2:4538525df7e2
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     add c
+  |
+  o  changeset:   1:7c3bad9141dc
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     add b
+  |
+  o  changeset:   0:1f0dee641bb7
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     add a
+  
+
+Simple rewrite
+
+  $ hg  --hidden debugobsoleterelevant 3
+  4538525df7e2b9f09423636c61ef63a4cb872a2d 0d3f46688ccc6e756c7e96cf64c391c411309597 0 {'date': '', 'user': 'test'}
+
+simple rewrite with a prune attached to it
+
+  $ hg debugobsoleterelevant 15
+  0b1b6dd009c037985363e2290a0b579819f659db 705ab2a6b72e2cd86edb799ebe15f2695f86143e 0 {'date': '* *', 'user': 'test'} (glob)
+  33d458d86621f3186c40bfccd77652f4a122743e 0 {'date': '* *', 'p1': '0b1b6dd009c037985363e2290a0b579819f659db', 'user': 'test'} (glob)
+
+Transitive rewrite
+
+  $ hg --hidden debugobsoleterelevant 8
+  909a0fb57e5d909f353d89e394ffd7e0890fec88 159dfc9fa5d334d7e03a0aecfc7f7ab4c3431fea 0 {'date': '', 'user': 'test'}
+  95de7fc6918dea4c9c8d5382f50649794b474c4a 909a0fb57e5d909f353d89e394ffd7e0890fec88 0 {'date': '', 'user': 'test'}
+  a7a6f2b5d8a54b81bc7aa2fba2934ad6d700a79e 95de7fc6918dea4c9c8d5382f50649794b474c4a 0 {'date': '', 'user': 'test'}
+