hgext/inhibit.py
author Pierre-Yves David <pierre-yves.david@fb.com>
Sat, 07 Mar 2015 02:32:43 -0800
changeset 1225 577f5340be6f
parent 1224 859a854cedc3
child 1232 37c00aeb4762
permissions -rw-r--r--
inhibit: Add some inhibition clearing mechanism We do not want to keep inhibition marker around for ever. So we are removing the one applying on public changeset.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     1
"""Reduce the changesets evolution feature scope for early and noob friendly UI
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     2
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     3
The full scale changeset evolution have some massive bleeding edge and it is
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     4
very easy for people not very intimate with the concept to end up in intricate
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     5
situation. In order to get some of the benefit sooner, this extension is
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     6
disabling some of the less polished aspect of evolution. It should gradually
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     7
get thinner and thinner as changeset evolution will get more polished. This
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     8
extension is only recommended for large scale organisations. Individual user
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
     9
should probably stick on using Evolution in its current state, understand its
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    10
concept and provide feedback
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    11
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    12
The first feature provided by this extension is the ability to "inhibit"
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    13
obsolescence markers. Obsolete revision can be cheaply brought back to life
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    14
that way. However as the inhibitor are not fitting in an append only model,
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    15
this is incompatible with sharing mutable history.
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    16
"""
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    17
from mercurial import localrepo
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    18
from mercurial import obsolete
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    19
from mercurial import extensions
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    20
from mercurial import cmdutil
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    21
from mercurial import scmutil
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    22
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    23
cmdtable = {}
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    24
command = cmdutil.command(cmdtable)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    25
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    26
def reposetup(ui, repo):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    27
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    28
    class obsinhibitedrepo(repo.__class__):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    29
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    30
        @localrepo.storecache('obsinhibit')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    31
        def _obsinhibit(self):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    32
            # XXX we should make sure it is invalidated by transaction failure
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    33
            obsinhibit = set()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    34
            raw = self.sopener.tryread('obsinhibit')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    35
            for i in xrange(0, len(raw), 20):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    36
                obsinhibit.add(raw[i:i+20])
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    37
            return obsinhibit
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    38
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    39
    repo.__class__ = obsinhibitedrepo
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    40
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    41
# obsolescence inhibitor
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    42
########################
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    43
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    44
def _schedulewrite(tr, obsinhibit):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    45
    """Make sure on disk content will be updated on transaction commit"""
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    46
    def writer(fp):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    47
        """Serialize the inhibited list to disk.
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    48
        """
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    49
        raw = ''.join(obsinhibit)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    50
        fp.write(raw)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    51
    tr.addfilegenerator('obsinhibit', ('obsinhibit',), writer)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    52
    tr.hookargs['obs_inbihited'] = '1'
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    53
1225
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
    54
def _filterpublic(repo, nodes):
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
    55
    """filter out inhibitor on public changeset
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
    56
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
    57
    Public changesets are already immune to obsolescence"""
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
    58
    getrev = repo.changelog.nodemap.get
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
    59
    getphase = repo._phasecache.phase
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
    60
    return (n for n in repo._obsinhibit if getphase(repo, getrev(n)))
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
    61
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    62
def _inhibitmarkers(repo, nodes):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    63
    """add marker inhibitor for all obsolete revision under <nodes>
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    64
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    65
    Content of <nodes> and all mutable ancestors are considered. Marker for
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    66
    obsolete revision only are created.
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    67
    """
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    68
    newinhibit = repo.set('::%ln and obsolete()', nodes)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    69
    if newinhibit:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    70
        tr = repo.transaction('obsinhibit')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    71
        try:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    72
            repo._obsinhibit.update(c.node() for c in newinhibit)
1225
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
    73
            _schedulewrite(tr, _filterpublic(repo, repo._obsinhibit))
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    74
            repo.invalidatevolatilesets()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    75
            tr.close()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    76
        finally:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    77
            tr.release()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    78
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    79
def _deinhibitmarkers(repo, nodes):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    80
    """lift obsolescence inhibition on a set of nodes
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    81
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    82
    This will be triggered when inhibited nodes received new obsolescence
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    83
    markers. Otherwise the new obsolescence markers would also be inhibited.
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    84
    """
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    85
    deinhibited = repo._obsinhibit & set(nodes)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    86
    if deinhibited:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    87
        tr = repo.transaction('obsinhibit')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    88
        try:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    89
            repo._obsinhibit -= deinhibited
1225
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
    90
            _schedulewrite(tr, _filterpublic(repo, repo._obsinhibit))
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    91
            repo.invalidatevolatilesets()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    92
            tr.close()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    93
        finally:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    94
            tr.release()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    95
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    96
def _createmarkers(orig, repo, relations, flag=0, date=None, metadata=None):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    97
    """wrap markers create to make sure we de-inhibit target nodes"""
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    98
    # wrapping transactio to unify the one in each function
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    99
    tr = repo.transaction('add-obsolescence-marker')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   100
    try:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   101
        orig(repo, relations, flag, date, metadata)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   102
        precs = (r[0].node() for r in relations)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   103
        _deinhibitmarkers(repo, precs)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   104
        tr.close()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   105
    finally:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   106
        tr.release()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   107
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   108
def extsetup(ui):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   109
    # lets wrap the computation of the obsolete set
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   110
    # We apply inhibition there
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   111
    obsfunc = obsolete.cachefuncs['obsolete']
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   112
    def _computeobsoleteset(repo):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   113
        """remove any inhibited nodes from the obsolete set
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   114
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   115
        This will trickle down to other part of mercurial (hidden, log, etc)"""
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   116
        obs = obsfunc(repo)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   117
        getrev = repo.changelog.nodemap.get
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   118
        for n in repo._obsinhibit:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   119
            obs.discard(getrev(n))
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   120
        return obs
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   121
    obsolete.cachefuncs['obsolete'] = _computeobsoleteset
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   122
    # drop divergence computation since it is incompatible with "light revive"
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   123
    obsolete.cachefuncs['divergent'] = lambda repo: set()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   124
    # drop bumped computation since it is incompatible with "light revive"
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   125
    obsolete.cachefuncs['bumped'] = lambda repo: set()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   126
    # wrap create marker to make it able to lift the inhibition
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   127
    extensions.wrapfunction(obsolete, 'createmarkers', _createmarkers)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   128
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   129
@command('debugobsinhibit', [], '')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   130
def cmddebugobsinhibit(ui, repo, *revs):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   131
    """inhibit obsolescence markers effect on a set of revs"""
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   132
    nodes = (repo[r].node() for r in scmutil.revrange(repo, revs))
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   133
    _inhibitmarkers(repo, nodes)