hgext/inhibit.py
author Laurent Charignon <lcharignon@fb.com>
Fri, 27 Mar 2015 10:58:04 -0700
changeset 1232 37c00aeb4762
parent 1225 577f5340be6f
child 1233 63ee05dd557a
permissions -rw-r--r--
inhibit: enable direct access from parsing the revset tree To enable direct access we: - detect explicit hexadical reference to node in the revset tree - add these hashes to the static blockers to make them and their parent visible for the command to run
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.
1232
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
    16
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
    17
The second feature is called direct access. It is the ability to refer and
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
    18
access hidden sha in commands provided that you know their value.
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
    19
For example hg log -r XXX where XXX is a commit has should work whether XXX is
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
    20
hidden or not as we assume that the user knows what he is doing when referring
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
    21
to XXX.
1224
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
from mercurial import localrepo
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    24
from mercurial import obsolete
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    25
from mercurial import extensions
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    26
from mercurial import cmdutil
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    27
from mercurial import scmutil
1232
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
    28
from mercurial import repoview
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
    29
from mercurial import revset
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
    30
from mercurial import error
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    31
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    32
cmdtable = {}
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    33
command = cmdutil.command(cmdtable)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    34
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    35
def reposetup(ui, repo):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    36
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    37
    class obsinhibitedrepo(repo.__class__):
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
        @localrepo.storecache('obsinhibit')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    40
        def _obsinhibit(self):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    41
            # 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
    42
            obsinhibit = set()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    43
            raw = self.sopener.tryread('obsinhibit')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    44
            for i in xrange(0, len(raw), 20):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    45
                obsinhibit.add(raw[i:i+20])
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    46
            return obsinhibit
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    47
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    48
    repo.__class__ = obsinhibitedrepo
1232
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
    49
    repo._explicitaccess = set()
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    50
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    51
# obsolescence inhibitor
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    52
########################
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    53
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    54
def _schedulewrite(tr, obsinhibit):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    55
    """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
    56
    def writer(fp):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    57
        """Serialize the inhibited list to disk.
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    58
        """
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    59
        raw = ''.join(obsinhibit)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    60
        fp.write(raw)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    61
    tr.addfilegenerator('obsinhibit', ('obsinhibit',), writer)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    62
    tr.hookargs['obs_inbihited'] = '1'
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    63
1225
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
    64
def _filterpublic(repo, nodes):
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
    65
    """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
    66
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
    67
    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
    68
    getrev = repo.changelog.nodemap.get
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
    69
    getphase = repo._phasecache.phase
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
    70
    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
    71
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    72
def _inhibitmarkers(repo, nodes):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    73
    """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
    74
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    75
    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
    76
    obsolete revision only are created.
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    77
    """
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    78
    newinhibit = repo.set('::%ln and obsolete()', nodes)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    79
    if newinhibit:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    80
        tr = repo.transaction('obsinhibit')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    81
        try:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    82
            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
    83
            _schedulewrite(tr, _filterpublic(repo, repo._obsinhibit))
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    84
            repo.invalidatevolatilesets()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    85
            tr.close()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    86
        finally:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    87
            tr.release()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    88
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    89
def _deinhibitmarkers(repo, nodes):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    90
    """lift obsolescence inhibition on a set of nodes
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    91
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    92
    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
    93
    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
    94
    """
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    95
    deinhibited = repo._obsinhibit & set(nodes)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    96
    if deinhibited:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    97
        tr = repo.transaction('obsinhibit')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    98
        try:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    99
            repo._obsinhibit -= deinhibited
1225
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
   100
            _schedulewrite(tr, _filterpublic(repo, repo._obsinhibit))
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   101
            repo.invalidatevolatilesets()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   102
            tr.close()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   103
        finally:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   104
            tr.release()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   105
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   106
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
   107
    """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
   108
    # 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
   109
    tr = repo.transaction('add-obsolescence-marker')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   110
    try:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   111
        orig(repo, relations, flag, date, metadata)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   112
        precs = (r[0].node() for r in relations)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   113
        _deinhibitmarkers(repo, precs)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   114
        tr.close()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   115
    finally:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   116
        tr.release()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   117
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   118
def extsetup(ui):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   119
    # lets wrap the computation of the obsolete set
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   120
    # We apply inhibition there
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   121
    obsfunc = obsolete.cachefuncs['obsolete']
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   122
    def _computeobsoleteset(repo):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   123
        """remove any inhibited nodes from the obsolete set
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   124
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   125
        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
   126
        obs = obsfunc(repo)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   127
        getrev = repo.changelog.nodemap.get
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   128
        for n in repo._obsinhibit:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   129
            obs.discard(getrev(n))
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   130
        return obs
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   131
    obsolete.cachefuncs['obsolete'] = _computeobsoleteset
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   132
    # 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
   133
    obsolete.cachefuncs['divergent'] = lambda repo: set()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   134
    # 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
   135
    obsolete.cachefuncs['bumped'] = lambda repo: set()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   136
    # 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
   137
    extensions.wrapfunction(obsolete, 'createmarkers', _createmarkers)
1232
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   138
    extensions.wrapfunction(repoview, '_getdynamicblockers', _accessvisible)
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   139
    extensions.wrapfunction(revset, 'posttreebuilthook', _posttreebuilthook)
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   140
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   141
def gethashsymbols(tree):
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   142
    # Returns the list of symbols of the tree that look like hashes
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   143
    # for example for the revset 3::abe3ff it will return ('abe3ff')
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   144
    if not tree:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   145
        return []
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   146
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   147
    if len(tree) == 2 and tree[0] == "symbol":
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   148
        try:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   149
            int(tree[1])
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   150
            return []
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   151
        except ValueError as e:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   152
            return [tree[1]]
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   153
    elif len(tree) == 3:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   154
        return gethashsymbols(tree[1]) + gethashsymbols(tree[2])
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   155
    else:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   156
        return []
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   157
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   158
def _posttreebuilthook(orig, tree, repo):
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   159
    # This is use to enabled direct hash access
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   160
    # We extract the symbols that look like hashes and add them to the
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   161
    # explicitaccess set
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   162
    orig(tree, repo)
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   163
    if repo and repo.filtername == 'visible':
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   164
        prelength = len(repo._explicitaccess)
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   165
        repo.symbols = gethashsymbols(tree)
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   166
        cl = repo.unfiltered().changelog
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   167
        for node in repo.symbols:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   168
            try:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   169
                node = cl._partialmatch(node)
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   170
            except error.LookupError:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   171
                node = None
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   172
            if node is not None:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   173
                rev = cl.rev(node)
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   174
                if rev not in repo.changelog:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   175
                    repo._explicitaccess.add(rev)
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   176
        if prelength != len(repo._explicitaccess):
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   177
            repo.invalidatevolatilesets()
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   178
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   179
@command('debugobsinhibit', [], '')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   180
def cmddebugobsinhibit(ui, repo, *revs):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   181
    """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
   182
    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
   183
    _inhibitmarkers(repo, nodes)
1232
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   184
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   185
# ensure revision accessed by hash are visible
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   186
###############################################
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   187
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   188
def _accessvisible(orig, repo):
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   189
    """ensure accessed revs stay visible"""
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   190
    blockers = orig(repo)
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   191
    blockers.update(getattr(repo, '_explicitaccess', ()))
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   192
    return blockers