diff mercurial/obsolete.py @ 28795:f456834b2f7e

commands: allow debugobsolete to delete arbitrary obsmarkers Sample usage is: '$ hg debugobsolete --delete 0 5' This is a debug feature that will help people working on evolution and obsolescense.
author Kostia Balytskyi <ikostia@fb.com>
date Fri, 01 Apr 2016 15:12:50 -0700
parents e60e13a86529
children ffcc649a4e8f
line wrap: on
line diff
--- a/mercurial/obsolete.py	Fri Apr 01 15:20:31 2016 -0700
+++ b/mercurial/obsolete.py	Fri Apr 01 15:12:50 2016 -0700
@@ -628,6 +628,30 @@
         transaction.hookargs['new_obsmarkers'] = str(previous + len(new))
         return len(new)
 
+    def delete(self, indices):
+        """Delete some obsmarkers from store and return the number of them
+
+        Indices is a list of ints which are the indices
+        of the markers to be deleted."""
+        if not indices:
+            # we don't want to rewrite the obsstore with the same content
+            return
+
+        left = []
+        current = self._all
+        n = 0
+        for i, m in enumerate(current):
+            if i in indices:
+                n += 1
+                continue
+            left.append(m)
+
+        newobsstore = self.svfs('obsstore', 'w', atomictemp=True)
+        for bytes in encodemarkers(left, True, self._version):
+            newobsstore.write(bytes)
+        newobsstore.close()
+        return n
+
     def mergemarkers(self, transaction, data):
         """merge a binary stream of markers inside the obsstore