hgext/inhibit.py
author Pierre-Yves David <pierre-yves.david@fb.com>
Thu, 14 May 2015 15:59:06 -0700
changeset 1338 77cbf9121e8a
parent 1334 b8f880d4171d
child 1339 0e2eb196923a
permissions -rw-r--r--
inhibit: handle inhibit marker on stripped revision If a revision disappear from the repo, we should not crash.
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
1334
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    29
from mercurial import branchmap
1232
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
    30
from mercurial import revset
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
    31
from mercurial import error
1233
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
    32
from mercurial import commands
1297
51ec3610968c inhibit: fix devel warning
Laurent Charignon <lcharignon@fb.com>
parents: 1293
diff changeset
    33
from mercurial import lock as lockmod
1234
c15d4677f2ba inhibit: ensure that no obsolete changesets are visible after a bookmark change
Laurent Charignon <lcharignon@fb.com>
parents: 1233
diff changeset
    34
from mercurial import bookmarks
1303
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
    35
from mercurial import lock as lockmod
1241
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
    36
from mercurial.i18n import _
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    37
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    38
cmdtable = {}
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    39
command = cmdutil.command(cmdtable)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    40
1334
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    41
# List of commands where no warning is shown for direct access
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    42
directaccesslevel = [
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    43
    # warning or not, extension (None if core), command name
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    44
    (False, None, 'update'), 
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    45
    (False, None, 'export'),
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    46
    (True,  'rebase', 'rebase'),
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    47
    (False,  'evolve', 'prune'),
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    48
]
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    49
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    50
def reposetup(ui, repo):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    51
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    52
    class obsinhibitedrepo(repo.__class__):
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
        @localrepo.storecache('obsinhibit')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    55
        def _obsinhibit(self):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    56
            # 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
    57
            obsinhibit = set()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    58
            raw = self.sopener.tryread('obsinhibit')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    59
            for i in xrange(0, len(raw), 20):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    60
                obsinhibit.add(raw[i:i+20])
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    61
            return obsinhibit
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    62
1292
62229e7451f7 inhibit: wrap repo.commit to inhibit nodes
Durham Goode <durham@fb.com>
parents: 1247
diff changeset
    63
        def commit(self, *args, **kwargs):
62229e7451f7 inhibit: wrap repo.commit to inhibit nodes
Durham Goode <durham@fb.com>
parents: 1247
diff changeset
    64
            newnode = super(obsinhibitedrepo, self).commit(*args, **kwargs)
62229e7451f7 inhibit: wrap repo.commit to inhibit nodes
Durham Goode <durham@fb.com>
parents: 1247
diff changeset
    65
            _inhibitmarkers(repo, [newnode])
62229e7451f7 inhibit: wrap repo.commit to inhibit nodes
Durham Goode <durham@fb.com>
parents: 1247
diff changeset
    66
            return newnode
62229e7451f7 inhibit: wrap repo.commit to inhibit nodes
Durham Goode <durham@fb.com>
parents: 1247
diff changeset
    67
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    68
    repo.__class__ = obsinhibitedrepo
1232
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
    69
    repo._explicitaccess = set()
1332
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
    70
    if not ui.configbool('inhibit', 'onlydirectaccess', False):
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
    71
        # Wrapping this to inhibit obsolete revs resulting from a transaction
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
    72
        extensions.wrapfunction(localrepo.localrepository,
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
    73
                                'transaction', transactioncallback)
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
    74
1334
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    75
def _computehidden(repo):
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    76
    hidden = repoview.computehidden(repo)
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    77
    cl = repo.changelog
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    78
    dynamic = hidden & repo._explicitaccess
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    79
    if dynamic:
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    80
        blocked = cl.ancestors(dynamic, inclusive=True)
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    81
        hidden = frozenset(r for r in hidden if r not in blocked)
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    82
    return hidden
1233
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
    83
1334
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    84
def setupdirectaccess():
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    85
    """ Add two new filtername that behave like visible to provide direct access
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    86
    and direct access with warning. Wraps the commands to setup direct access """
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    87
    repoview.filtertable.update({'visible-directaccess-nowarn': _computehidden})
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    88
    repoview.filtertable.update({'visible-directaccess-warn': _computehidden})
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    89
    branchmap.subsettable['visible-directaccess-nowarn'] = 'visible'
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    90
    branchmap.subsettable['visible-directaccess-warn'] = 'visible'
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    91
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    92
    for warn, ext, cmd in directaccesslevel:
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    93
        cmdtable = extensions.find(ext).cmdtable if ext else commands.table
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    94
        wrapper = wrapwithwarning if warn else wrapwithoutwarning
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    95
        try:
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    96
            extensions.wrapcommand(cmdtable, cmd, wrapper)
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    97
        except error.UnknownCommand:
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
    98
            pass
1233
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
    99
def _update(orig, ui, repo, *args, **kwargs):
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
   100
    """
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
   101
    When moving to a commit we want to inhibit any obsolete commit affecting
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
   102
    the changeset we are updating to. In other words we don't want any visible
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
   103
    commit to be obsolete.
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
   104
    """
1303
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
   105
    wlock = None
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
   106
    try:
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
   107
        # Evolve is running a hook on lock release to display a warning message 
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
   108
        # if the workind dir's parent is obsolete.
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
   109
        # We take the lock here to make sure that we inhibit the parent before
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
   110
        # that hook get a chance to run.
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
   111
        wlock = repo.wlock()
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
   112
        res = orig(ui, repo, *args, **kwargs)
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
   113
        newhead = repo['.'].node()
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
   114
        _inhibitmarkers(repo, [newhead])
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
   115
        return res
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
   116
    finally:
508f9911b042 inhibit: updating to a obsolete commit prints warning message
Laurent Charignon <lcharignon@fb.com>
parents: 1297
diff changeset
   117
        lockmod.release(wlock)
1233
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
   118
1234
c15d4677f2ba inhibit: ensure that no obsolete changesets are visible after a bookmark change
Laurent Charignon <lcharignon@fb.com>
parents: 1233
diff changeset
   119
def _bookmarkchanged(orig, bkmstoreinst, *args, **kwargs):
c15d4677f2ba inhibit: ensure that no obsolete changesets are visible after a bookmark change
Laurent Charignon <lcharignon@fb.com>
parents: 1233
diff changeset
   120
    """ Add inhibition markers to every obsolete bookmarks """
c15d4677f2ba inhibit: ensure that no obsolete changesets are visible after a bookmark change
Laurent Charignon <lcharignon@fb.com>
parents: 1233
diff changeset
   121
    repo = bkmstoreinst._repo
c15d4677f2ba inhibit: ensure that no obsolete changesets are visible after a bookmark change
Laurent Charignon <lcharignon@fb.com>
parents: 1233
diff changeset
   122
    bkmstorenodes = [repo[v].node() for v in bkmstoreinst.values()]
c15d4677f2ba inhibit: ensure that no obsolete changesets are visible after a bookmark change
Laurent Charignon <lcharignon@fb.com>
parents: 1233
diff changeset
   123
    _inhibitmarkers(repo, bkmstorenodes)
c15d4677f2ba inhibit: ensure that no obsolete changesets are visible after a bookmark change
Laurent Charignon <lcharignon@fb.com>
parents: 1233
diff changeset
   124
    return orig(bkmstoreinst, *args, **kwargs)
1233
63ee05dd557a inhibit: ensure no visible changesets are obsolete after an update
Laurent Charignon <lcharignon@fb.com>
parents: 1232
diff changeset
   125
1241
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
   126
def _bookmark(orig, ui, repo, *bookmarks, **opts):
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
   127
    """ Add a -D option to the bookmark command, map it to prune -B """
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
   128
    haspruneopt = opts.get('prune', False)
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
   129
    if not haspruneopt:
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
   130
        return orig(ui, repo, *bookmarks, **opts)
1293
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
   131
1241
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
   132
    # Call prune -B
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
   133
    evolve = extensions.find('evolve')
1293
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
   134
    optsdict = {
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
   135
        'new': [],
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
   136
        'succ': [],
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
   137
        'rev': [],
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
   138
        'bookmark': bookmarks[0],
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
   139
        'keep': None,
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
   140
        'biject': False,
dc5528e04c06 inhibit: remove book -D dependency on cmdprune
Durham Goode <durham@fb.com>
parents: 1292
diff changeset
   141
    }
1241
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
   142
    evolve.cmdprune(ui, repo, **optsdict)
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
   143
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   144
# obsolescence inhibitor
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   145
########################
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   146
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   147
def _schedulewrite(tr, obsinhibit):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   148
    """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
   149
    def writer(fp):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   150
        """Serialize the inhibited list to disk.
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   151
        """
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   152
        raw = ''.join(obsinhibit)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   153
        fp.write(raw)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   154
    tr.addfilegenerator('obsinhibit', ('obsinhibit',), writer)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   155
    tr.hookargs['obs_inbihited'] = '1'
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   156
1225
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
   157
def _filterpublic(repo, nodes):
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
   158
    """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
   159
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
   160
    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
   161
    getrev = repo.changelog.nodemap.get
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
   162
    getphase = repo._phasecache.phase
1338
77cbf9121e8a inhibit: handle inhibit marker on stripped revision
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1334
diff changeset
   163
    return (n for n in repo._obsinhibit
77cbf9121e8a inhibit: handle inhibit marker on stripped revision
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1334
diff changeset
   164
            if getrev(n) is not None and getphase(repo, getrev(n)))
1225
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
   165
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   166
def _inhibitmarkers(repo, nodes):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   167
    """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
   168
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   169
    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
   170
    obsolete revision only are created.
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   171
    """
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   172
    newinhibit = repo.set('::%ln and obsolete()', nodes)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   173
    if newinhibit:
1297
51ec3610968c inhibit: fix devel warning
Laurent Charignon <lcharignon@fb.com>
parents: 1293
diff changeset
   174
        lock = tr = None
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   175
        try:
1297
51ec3610968c inhibit: fix devel warning
Laurent Charignon <lcharignon@fb.com>
parents: 1293
diff changeset
   176
            lock = repo.lock()
51ec3610968c inhibit: fix devel warning
Laurent Charignon <lcharignon@fb.com>
parents: 1293
diff changeset
   177
            tr = repo.transaction('obsinhibit')
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   178
            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
   179
            _schedulewrite(tr, _filterpublic(repo, repo._obsinhibit))
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   180
            repo.invalidatevolatilesets()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   181
            tr.close()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   182
        finally:
1297
51ec3610968c inhibit: fix devel warning
Laurent Charignon <lcharignon@fb.com>
parents: 1293
diff changeset
   183
            lockmod.release(tr, lock)
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   184
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   185
def _deinhibitmarkers(repo, nodes):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   186
    """lift obsolescence inhibition on a set of nodes
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   187
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   188
    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
   189
    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
   190
    """
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   191
    deinhibited = repo._obsinhibit & set(nodes)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   192
    if deinhibited:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   193
        tr = repo.transaction('obsinhibit')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   194
        try:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   195
            repo._obsinhibit -= deinhibited
1225
577f5340be6f inhibit: Add some inhibition clearing mechanism
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1224
diff changeset
   196
            _schedulewrite(tr, _filterpublic(repo, repo._obsinhibit))
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   197
            repo.invalidatevolatilesets()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   198
            tr.close()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   199
        finally:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   200
            tr.release()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   201
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   202
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
   203
    """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
   204
    # 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
   205
    tr = repo.transaction('add-obsolescence-marker')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   206
    try:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   207
        orig(repo, relations, flag, date, metadata)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   208
        precs = (r[0].node() for r in relations)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   209
        _deinhibitmarkers(repo, precs)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   210
        tr.close()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   211
    finally:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   212
        tr.release()
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   213
1240
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
   214
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
   215
def transactioncallback(orig, repo, *args, **kwargs):
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
   216
    """ Wrap localrepo.transaction to inhibit new obsolete changes """
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
   217
    def inhibitposttransaction(transaction):
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
   218
        # At the end of the transaction we catch all the new visible and
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
   219
        # obsolete commit to inhibit them
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
   220
        visibleobsolete = repo.revs('(not hidden()) and obsolete()')
1321
8fa74845eb1f inhibit: don't inhibit pinned commits during rebase
Durham Goode <durham@fb.com>
parents: 1303
diff changeset
   221
        ignoreset = set(getattr(repo, '_rebaseset', []))
8fa74845eb1f inhibit: don't inhibit pinned commits during rebase
Durham Goode <durham@fb.com>
parents: 1303
diff changeset
   222
        visibleobsolete = list(r for r in visibleobsolete if r not in ignoreset)
1240
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
   223
        if visibleobsolete:
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
   224
            _inhibitmarkers(repo, [repo[r].node() for r in visibleobsolete])
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
   225
    transaction = orig(repo, *args, **kwargs)
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
   226
    transaction.addpostclose('inhibitposttransaction', inhibitposttransaction)
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
   227
    return transaction
e1347ce2f954 inhibit: don't leave any obsolete commit visible after closing transaction
Laurent Charignon <lcharignon@fb.com>
parents: 1234
diff changeset
   228
1334
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   229
def wrapwithoutwarning(orig, ui, repo, *args, **kwargs):
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   230
    if repo and repo.filtername == 'visible':
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   231
        repo = repo.filtered("visible-directaccess-nowarn")
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   232
    return orig(ui, repo, *args, **kwargs)
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   233
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   234
def wrapwithwarning(orig, ui, repo, *args, **kwargs):
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   235
    if repo and repo.filtername == 'visible':
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   236
        repo = repo.filtered("visible-directaccess-warn")
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   237
    return orig(ui, repo, *args, **kwargs)
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   238
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   239
def extsetup(ui):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   240
    # lets wrap the computation of the obsolete set
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   241
    # We apply inhibition there
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   242
    obsfunc = obsolete.cachefuncs['obsolete']
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   243
    def _computeobsoleteset(repo):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   244
        """remove any inhibited nodes from the obsolete set
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   245
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   246
        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
   247
        obs = obsfunc(repo)
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   248
        getrev = repo.changelog.nodemap.get
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   249
        for n in repo._obsinhibit:
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   250
            obs.discard(getrev(n))
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   251
        return obs
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   252
    obsolete.cachefuncs['obsolete'] = _computeobsoleteset
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   253
    # 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
   254
    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
   255
    extensions.wrapfunction(revset, 'posttreebuilthook', _posttreebuilthook)
1334
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   256
    setupdirectaccess()
1332
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
   257
    if not ui.configbool('inhibit', 'onlydirectaccess', False):
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
   258
        # drop divergence computation since it is incompatible with "light revive"
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
   259
        obsolete.cachefuncs['divergent'] = lambda repo: set()
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
   260
        # drop bumped computation since it is incompatible with "light revive"
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
   261
        obsolete.cachefuncs['bumped'] = lambda repo: set()
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
   262
        # wrap update to make sure that no obsolete commit is visible after an
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
   263
        # update
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
   264
        extensions.wrapcommand(commands.table, 'update', _update)
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
   265
        # There are two ways to save bookmark changes during a transation, we
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
   266
        # wrap both to add inhibition markers.
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
   267
        extensions.wrapfunction(bookmarks.bmstore, 'recordchange', _bookmarkchanged)
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
   268
        extensions.wrapfunction(bookmarks.bmstore, 'write', _bookmarkchanged)
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
   269
        # Add bookmark -D option
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
   270
        entry = extensions.wrapcommand(commands.table, 'bookmark', _bookmark)
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
   271
        entry[1].append(('D','prune',None,
1ed337c7f061 inhibit: config to enable only direct access
Laurent Charignon <lcharignon@fb.com>
parents: 1321
diff changeset
   272
                        _('delete the bookmark and prune the commits underneath')))
1241
3625d006e81b inhibit: Add -D option to the bookmark command
Laurent Charignon <lcharignon@fb.com>
parents: 1240
diff changeset
   273
1234
c15d4677f2ba inhibit: ensure that no obsolete changesets are visible after a bookmark change
Laurent Charignon <lcharignon@fb.com>
parents: 1233
diff changeset
   274
1232
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   275
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   276
def gethashsymbols(tree):
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   277
    # 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
   278
    # 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
   279
    if not tree:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   280
        return []
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   281
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   282
    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
   283
        try:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   284
            int(tree[1])
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   285
            return []
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   286
        except ValueError as e:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   287
            return [tree[1]]
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   288
    elif len(tree) == 3:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   289
        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
   290
    else:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   291
        return []
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   292
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   293
def _posttreebuilthook(orig, tree, repo):
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   294
    # 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
   295
    # 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
   296
    # explicitaccess set
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   297
    orig(tree, repo)
1334
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   298
    filternm = ""
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   299
    if repo is not None:
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   300
        filternm = repo.filtername
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   301
    if filternm is not None and filternm.startswith('visible-directaccess'):
1232
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   302
        prelength = len(repo._explicitaccess)
1334
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   303
        accessbefore = set(repo._explicitaccess)
1232
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   304
        repo.symbols = gethashsymbols(tree)
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   305
        cl = repo.unfiltered().changelog
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   306
        for node in repo.symbols:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   307
            try:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   308
                node = cl._partialmatch(node)
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   309
            except error.LookupError:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   310
                node = None
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   311
            if node is not None:
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   312
                rev = cl.rev(node)
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   313
                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
   314
                    repo._explicitaccess.add(rev)
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   315
        if prelength != len(repo._explicitaccess):
1334
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   316
            if repo.filtername != 'visible-directaccess-nowarn':
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   317
                unhiddencommits = repo._explicitaccess - accessbefore
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   318
                repo.ui.warn( _("Warning: accessing hidden changesets %s " 
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   319
                                "for write operation\n") % 
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   320
                                (",".join([str(repo.unfiltered()[l]) 
b8f880d4171d inhibit: direct access with and without warning on a per command basis
Laurent Charignon <lcharignon@fb.com>
parents: 1332
diff changeset
   321
                                    for l in unhiddencommits])))
1232
37c00aeb4762 inhibit: enable direct access from parsing the revset tree
Laurent Charignon <lcharignon@fb.com>
parents: 1225
diff changeset
   322
            repo.invalidatevolatilesets()
1224
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   323
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   324
@command('debugobsinhibit', [], '')
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   325
def cmddebugobsinhibit(ui, repo, *revs):
859a854cedc3 add a 'inhibit' extension
Pierre-Yves David <pierre-yves.david@fb.com>
parents:
diff changeset
   326
    """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
   327
    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
   328
    _inhibitmarkers(repo, nodes)