[PATCH 2 of 2] obsolete: reports the number of local changeset obsoleted when unbundling

Sean Farley sean at farley.io
Sat Jul 1 19:49:27 EDT 2017


Pierre-Yves David <pierre-yves.david at ens-lyon.org> writes:

> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at octobus.net>
> # Date 1498614859 -7200
> #      Wed Jun 28 03:54:19 2017 +0200
> # Node ID 56079875cf347a283833e89296310cdac78a211c
> # Parent  7f2c9fb4ce2aa427e01ccf02641d218966b580d4
> # EXP-Topic tr.changes
> # Available At https://www.mercurial-scm.org/repo/users/marmoute/mercurial/
> #              hg pull https://www.mercurial-scm.org/repo/users/marmoute/mercurial/ -r 56079875cf34
> 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.

Ah, cool! I can use this to improve our webhook system at Bitbucket :-)

Nits below.

> diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
> --- a/mercurial/bundle2.py
> +++ b/mercurial/bundle2.py
> @@ -161,6 +161,7 @@ from . import (
>      phases,
>      pushkey,
>      pycompat,
> +    scmutil,
>      tags,
>      url,
>      util,
> @@ -1810,6 +1811,7 @@ def handleobsmarker(op, inpart):
>      if new:
>          op.repo.ui.status(_('%i new obsolescence markers\n') % new)
>      op.records.add('obsmarkers', {'new': new})
> +    scmutil.registersummarycallback(op.repo, tr)
>      if op.reply is not None:
>          rpart = op.reply.newpart('reply:obsmarkers')
>          rpart.addparam('in-reply-to', str(inpart.id), mandatory=False)
> diff --git a/mercurial/obsutil.py b/mercurial/obsutil.py
> --- a/mercurial/obsutil.py
> +++ b/mercurial/obsutil.py
> @@ -7,6 +7,10 @@
>  
>  from __future__ import absolute_import
>  
> +from . import (
> +    phases,
> +)
> +
>  class marker(object):
>      """Wrap obsolete marker raw data"""
>  
> @@ -285,6 +289,28 @@ def foreground(repo, nodes):
>              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

Sometimes I really dislike Python.

> +    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
>  
> diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
> --- a/mercurial/scmutil.py
> +++ b/mercurial/scmutil.py
> @@ -13,6 +13,7 @@ import hashlib
>  import os
>  import re
>  import socket
> +import weakref
>  
>  from .i18n import _
>  from .node import (
> @@ -22,11 +23,13 @@ from .node import (
>      wdirrev,
>  )
>  
> +from .i18n import _
>  from . import (
>      encoding,
>      error,
>      match as matchmod,
>      obsolete,
> +    obsutil,
>      pathutil,
>      phases,
>      pycompat,
> @@ -1059,3 +1062,15 @@ class simplekeyvaluefile(object):
>              lines.append("%s=%s\n" % (k, v))
>          with self.vfs(self.path, mode='wb', atomictemp=True) as fp:
>              fp.write(''.join(lines))
> +
> +def registersummarycallback(repo, otr):
> +    """register a callback to issue a summary after the transaction is closed
> +    """
> +    reporef = weakref.ref(repo)

Is a weakref the best we can do here? I really dislike them but I don't
know anything else off the top of my head.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 800 bytes
Desc: not available
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20170701/43fde713/attachment.sig>


More information about the Mercurial-devel mailing list