[PATCH 2 of 2 v4] commands: allow debugobsolete to delete arbitrary obsmarkers
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Mon Apr 11 01:35:38 EDT 2016
On 04/04/2016 03:27 AM, Kostia Balytskyi wrote:
> # HG changeset patch
> # User Kostia Balytskyi <ikostia at fb.com>
> # Date 1459765540 25200
> # Mon Apr 04 03:25:40 2016 -0700
> # Node ID 94b4d90b65f9d8d46adcf7dac409bb36adf34e8d
> # Parent 64295f5fe12dab428a69cfcf7a27a66735f17d7a
> commands: allow debugobsolete to delete arbitrary obsmarkers
I've a couple of feedback on this patch 2. My apologies for the delay.
> Sample usage is:
> '$ hg debugobsolete --delete 0 --delete 5'
>
> This is a debug feature that will help people working on evolution and
> obsolescense.
>
> 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')),
We can use a list, (so, `hg debugobsolete --delete 1 --delete 3 `) but
as the command will never be doing multiple things at the same time,
maybe we want a boolean flag (so, `hg debugobsolete --delete 1 3`) What
would you think about it?
> ] + commitopts2,
> _('[OBSOLETED [REPLACEMENT ...]]'))
> def debugobsolete(ui, repo, precursor=None, *successors, **opts):
> @@ -3066,6 +3067,22 @@ 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 for indices'))
You want to mention the bad value in your error message. so that the
user know where to look at.
> +
> + if repo.currenttransaction():
> + err = _('cannot delete obsmarkers in the middle of transaction.')
> + raise error.Abort(err)
We'll want this check at a lower level to make sure it catch actual
programming error.
cf: https://selenic.com/hg/file/c5565fc8848d/mercurial/repair.py#l156
> +
> + with repo.lock():
> + n = repo.obsstore._deletemarkers(indices)
> + ui.write(_('deleted %i obsolescense markers\n') % n)
> + 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 _deletemarkers(self, indices):
I think we should really have this function in mercurial/repair.py, the
place where all horribles stripping sins happen.
Can you also elaborate on how the repo.obsstore object content get
replaced after this command is called ?
> + """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
> @@ -1097,5 +1097,17 @@ only a subset of those are displayed (be
> $ hg debugobsolete --index --rev "3+7"
> 1 6fdef60fcbabbd3d50e9b9cbc2a240724b91a5e1 d27fb9b066076fd921277a4b9e8b9cb48c95bc6a 0 \(.*\) {'user': 'test'} (re)
> 3 4715cf767440ed891755448016c2b8cf70760c30 7ae79c5d60f049c7b0dd02f5f25b9d60aaf7b36d 0 \(.*\) {'user': 'test'} (re)
> +
> +Test the --delete option of debugobsolete command
> + $ hg debugobsolete --index
> + 0 cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b f9bd49731b0b175e42992a3c8fa6c678b2bc11f1 0 (Mon Apr 04 10:22:18 2016 +0000) {'user': 'test'}
> + 1 6fdef60fcbabbd3d50e9b9cbc2a240724b91a5e1 d27fb9b066076fd921277a4b9e8b9cb48c95bc6a 0 (Mon Apr 04 10:22:19 2016 +0000) {'user': 'test'}
> + 2 1ab51af8f9b41ef8c7f6f3312d4706d870b1fb74 29346082e4a9e27042b62d2da0e2de211c027621 0 (Mon Apr 04 10:22:19 2016 +0000) {'user': 'test'}
> + 3 4715cf767440ed891755448016c2b8cf70760c30 7ae79c5d60f049c7b0dd02f5f25b9d60aaf7b36d 0 (Mon Apr 04 10:22:19 2016 +0000) {'user': 'test'}
> + $ hg debugobsolete --delete 1 --delete 3
> + deleted 2 obsolescense markers
> + $ hg debugobsolete
> + cb9a9f314b8b07ba71012fcdbc544b5a4d82ff5b f9bd49731b0b175e42992a3c8fa6c678b2bc11f1 0 (Mon Apr 04 10:22:18 2016 +0000) {'user': 'test'}
> + 1ab51af8f9b41ef8c7f6f3312d4706d870b1fb74 29346082e4a9e27042b62d2da0e2de211c027621 0 (Mon Apr 04 10:22:19 2016 +0000) {'user': 'test'}
> $ cd ..
>
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list