Patchwork [2,of,2,v2] commands: allow debugobsolete to delete arbitrary obsmarkers

login
register
mail settings
Submitter Kostia Balytskyi
Date April 1, 2016, 10:23 p.m.
Message ID <9e48077372c5bff9ff6f.1459549421@dev1902.lla1.facebook.com>
Download mbox | patch
Permalink /patch/14238/
State Superseded
Delegated to: Pierre-Yves David
Headers show

Comments

Kostia Balytskyi - April 1, 2016, 10:23 p.m.
# HG changeset patch
# User Kostia Balytskyi <ikostia@fb.com>
# Date 1459548770 25200
#      Fri Apr 01 15:12:50 2016 -0700
# Node ID 9e48077372c5bff9ff6f09fc7b6396cd63f38f5a
# Parent  ad2dcfb236925128183bfec0e1ea8cf105c83f10
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.
timeless - April 4, 2016, 10:54 p.m.
Kostia Balytskyi wrote:
> +        """Delete some obsmarkers from store and return the number of them

the number of them => how many were deleted

seems ok otherwise
Kostia Balytskyi - April 5, 2016, 12:06 a.m.
On 4/4/16, 11:54 PM, "timeless.bmo1@gmail.com on behalf of timeless" <timeless.bmo1@gmail.com on behalf of timeless@gmail.com> wrote:


>Kostia Balytskyi wrote:

>> +        """Delete some obsmarkers from store and return the number of them

>

>the number of them => how many were deleted

Can this be fixed in-place by whoever accepts the patch?

>

>seems ok otherwise

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3046,6 +3046,7 @@  def debuglocks(ui, repo, **opts):
           _('record parent information for the precursor')),
          ('r', 'rev', [], _('display markers relevant to REV')),
          ('', 'index', False, _('display index of the marker')),
+         ('', 'delete', [], _('delete markers specified by indices')),
         ] + commitopts2,
          _('[OBSOLETED [REPLACEMENT ...]]'))
 def debugobsolete(ui, repo, precursor=None, *successors, **opts):
@@ -3066,6 +3067,32 @@  def debugobsolete(ui, repo, precursor=No
             raise error.Abort('changeset references must be full hexadecimal '
                              'node identifiers')
 
+    if opts.get('delete'):
+        try:
+            indices = [int(v) for v in opts.get('delete')]
+        except ValueError:
+            raise error.Abort(_('invalid index value'),
+                              hint=_('use integers fro indices'))
+
+        if repo.currenttransaction():
+            raise error.Abort(_('Cannot delete obsmarkers in the middle '
+                                'of transaction.'))
+
+        w = repo.wlock()
+        l = repo.lock()
+        try:
+            tr = repo.transaction('debugobsolete')
+            try:
+                n = repo.obsstore.delete(indices)
+                ui.write(_('Deleted %i obsolescense markers\n') % n)
+                tr.close()
+            finally:
+                tr.release()
+        finally:
+            l.release()
+            w.release()
+        return
+
     if precursor is not None:
         if opts['rev']:
             raise error.Abort('cannot select revision when creating marker')
diff --git a/mercurial/obsolete.py b/mercurial/obsolete.py
--- a/mercurial/obsolete.py
+++ b/mercurial/obsolete.py
@@ -633,6 +633,30 @@  class obsstore(object):
         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
 
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -261,7 +261,7 @@  Show all commands + options
   debuglocks: force-lock, force-wlock
   debugmergestate: 
   debugnamecomplete: 
-  debugobsolete: flags, record-parents, rev, index, date, user
+  debugobsolete: flags, record-parents, rev, index, delete, date, user
   debugpathcomplete: full, normal, added, removed
   debugpushkey: 
   debugpvec: 
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -1083,4 +1083,17 @@  Test ability to pull changeset with loca
   |
   @  0:a78f55e5508c (draft) [ ] 0
   
+  $ cd ..
 
+Test the --delete option of debugobsolete command
+  $ hg init dorepo
+  $ cd dorepo
+  $ echo a > a && hg ci -Am a
+  adding a
+  $ hg ci --amend -m aa
+  $ hg debugobsolete
+  cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b f9bd49731b0b175e42992a3c8fa6c678b2bc11f1 0 (.*) {'user': 'test'} (re)
+  $ hg debugobsolete --delete 0
+  Deleted 1 obsolescense markers
+  $ hg debugobsolete
+  $ cd ..