obshistory: add a function to group predsets by fold-id
authorAnton Shestakov <av6@dwimlabs.net>
Fri, 24 Apr 2020 01:09:30 +0800
changeset 5328 a81631766575
parent 5327 b1a564cb18d0
child 5329 0dc4c16506fc
obshistory: add a function to group predsets by fold-id
hgext3rd/evolve/obshistory.py
--- a/hgext3rd/evolve/obshistory.py	Tue Apr 21 23:40:44 2020 +0800
+++ b/hgext3rd/evolve/obshistory.py	Fri Apr 24 01:09:30 2020 +0800
@@ -136,6 +136,30 @@
     b"patch": TEMPLATE_PATCH,
 }
 
+def groupbyfoldid(predsets):
+    """ Group nodes and related obsmarkers by fold-id metadata.
+    """
+    groups = {}
+    for (nodes, markers) in predsets:
+        grouped = False
+        for marker in markers:
+            metadata = dict(marker[3])
+            foldid = metadata.get(b'fold-id')
+            if foldid is not None:
+                groups.setdefault(foldid, []).append((nodes, markers))
+                grouped = True
+
+        if not grouped:
+            yield (nodes, markers)
+
+    for foldid in sorted(groups):
+        groupnodes = set()
+        groupmarkers = set()
+        for (nodes, markers) in groups[foldid]:
+            groupnodes.update(nodes)
+            groupmarkers.update(markers)
+        yield (tuple(sorted(groupnodes)), tuple(sorted(groupmarkers)))
+
 def _nodesandmarkers(repo, ctx, filternonlocal):
     if filternonlocal:
         r = obsutil.successorsandmarkers(repo, ctx)