diff mercurial/obsutil.py @ 33252:53b3a1968aa6

obsolete: reports the number of local changeset obsoleted when unbundling This is a first basic visible usage of the changes tracking in the transaction. We adds a new function computing the pre-existing changesets obsoleted by a transaction and a transaction call back displaying this information. Example output: added 1 changesets with 1 changes to 1 files (+1 heads) 3 new obsolescence markers obsoleted 1 changesets The goal is to evolve the transaction summary into something bigger, gathering existing output there and adding new useful one. This patch is a good first step on this road. The new output is basic but give a user to the content of tr.changes['obsmarkers'] and give an idea of the new options we haves. I expect to revisit the message soon. The caller recording the transaction summary should also be moved into a more generic location but further refactoring is needed before it can happen.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Wed, 28 Jun 2017 03:54:19 +0200
parents a14e2e7f7d1f
children df90f4d6c609
line wrap: on
line diff
--- a/mercurial/obsutil.py	Tue Jun 27 02:45:09 2017 +0200
+++ b/mercurial/obsutil.py	Wed Jun 28 03:54:19 2017 +0200
@@ -7,6 +7,10 @@
 
 from __future__ import absolute_import
 
+from . import (
+    phases,
+)
+
 class marker(object):
     """Wrap obsolete marker raw data"""
 
@@ -285,6 +289,28 @@
             foreground = set(repo.set('%ln::', known))
     return set(c.node() for c in foreground)
 
+def getobsoleted(repo, tr):
+    """return the set of pre-existing revisions obsoleted by a transaction"""
+    torev = repo.unfiltered().changelog.nodemap.get
+    phase = repo._phasecache.phase
+    succsmarkers = repo.obsstore.successors.get
+    public = phases.public
+    addedmarkers = tr.changes.get('obsmarkers')
+    addedrevs = tr.changes.get('revs')
+    seenrevs = set(addedrevs)
+    obsoleted = set()
+    for mark in addedmarkers:
+        node = mark[0]
+        rev = torev(node)
+        if rev is None or rev in seenrevs:
+            continue
+        seenrevs.add(rev)
+        if phase(repo, rev) == public:
+            continue
+        if set(succsmarkers(node)).issubset(addedmarkers):
+            obsoleted.add(rev)
+    return obsoleted
+
 def successorssets(repo, initialnode, cache=None):
     """Return set of all latest successors of initial nodes