hgext/inhibit.py
changeset 1551 40e496bc7b54
parent 1542 333e056b3034
child 1560 59d47a9f633d
equal deleted inserted replaced
1550:e47dda53a5c2 1551:40e496bc7b54
     7 get thinner and thinner as changeset evolution will get more polished. this
     7 get thinner and thinner as changeset evolution will get more polished. this
     8 extension is only recommended for large scale organisations. individual user
     8 extension is only recommended for large scale organisations. individual user
     9 should probably stick on using evolution in its current state, understand its
     9 should probably stick on using evolution in its current state, understand its
    10 concept and provide feedback
    10 concept and provide feedback
    11 
    11 
    12 This extension provides the ability to "inhibit" obsolescence markers. obsolete 
    12 This extension provides the ability to "inhibit" obsolescence markers. obsolete
    13 revision can be cheaply brought back to life that way. 
    13 revision can be cheaply brought back to life that way.
    14 However as the inhibitor are not fitting in an append only model, this is 
    14 However as the inhibitor are not fitting in an append only model, this is
    15 incompatible with sharing mutable history.
    15 incompatible with sharing mutable history.
    16 """
    16 """
    17 from mercurial import localrepo
    17 from mercurial import localrepo
    18 from mercurial import obsolete
    18 from mercurial import obsolete
    19 from mercurial import extensions
    19 from mercurial import extensions
    20 from mercurial import cmdutil
    20 from mercurial import cmdutil
       
    21 from mercurial import error
    21 from mercurial import scmutil
    22 from mercurial import scmutil
    22 from mercurial import commands
    23 from mercurial import commands
    23 from mercurial import lock as lockmod
    24 from mercurial import lock as lockmod
    24 from mercurial import util
    25 from mercurial import util
    25 from mercurial.i18n import _
    26 from mercurial.i18n import _
    38         def _obsinhibit(self):
    39         def _obsinhibit(self):
    39             # XXX we should make sure it is invalidated by transaction failure
    40             # XXX we should make sure it is invalidated by transaction failure
    40             obsinhibit = set()
    41             obsinhibit = set()
    41             raw = self.svfs.tryread('obsinhibit')
    42             raw = self.svfs.tryread('obsinhibit')
    42             for i in xrange(0, len(raw), 20):
    43             for i in xrange(0, len(raw), 20):
    43                 obsinhibit.add(raw[i:i+20])
    44                 obsinhibit.add(raw[i:i + 20])
    44             return obsinhibit
    45             return obsinhibit
    45 
    46 
    46         def commit(self, *args, **kwargs):
    47         def commit(self, *args, **kwargs):
    47             newnode = super(obsinhibitedrepo, self).commit(*args, **kwargs)
    48             newnode = super(obsinhibitedrepo, self).commit(*args, **kwargs)
    48             if newnode is not None:
    49             if newnode is not None:
    57     the changeset we are updating to. In other words we don't want any visible
    58     the changeset we are updating to. In other words we don't want any visible
    58     commit to be obsolete.
    59     commit to be obsolete.
    59     """
    60     """
    60     wlock = None
    61     wlock = None
    61     try:
    62     try:
    62         # Evolve is running a hook on lock release to display a warning message 
    63         # Evolve is running a hook on lock release to display a warning message
    63         # if the workind dir's parent is obsolete.
    64         # if the workind dir's parent is obsolete.
    64         # We take the lock here to make sure that we inhibit the parent before
    65         # We take the lock here to make sure that we inhibit the parent before
    65         # that hook get a chance to run.
    66         # that hook get a chance to run.
    66         wlock = repo.wlock()
    67         wlock = repo.wlock()
    67         res = orig(ui, repo, *args, **kwargs)
    68         res = orig(ui, repo, *args, **kwargs)
    75     """ Add a -D option to the bookmark command, map it to prune -B """
    76     """ Add a -D option to the bookmark command, map it to prune -B """
    76     haspruneopt = opts.get('prune', False)
    77     haspruneopt = opts.get('prune', False)
    77     if not haspruneopt:
    78     if not haspruneopt:
    78         return orig(ui, repo, *bookmarks, **opts)
    79         return orig(ui, repo, *bookmarks, **opts)
    79     elif opts.get('rename'):
    80     elif opts.get('rename'):
    80         raise util.Abort('Cannot use both -m and -D')
    81         raise error.Abort('Cannot use both -m and -D')
    81     elif len(bookmarks) == 0:
    82     elif len(bookmarks) == 0:
    82         hint = _('make sure to put a space between -D and your bookmark name')
    83         hint = _('make sure to put a space between -D and your bookmark name')
    83         raise util.Abort(_('Error, please check your command'), hint=hint)
    84         raise error.Abort(_('Error, please check your command'), hint=hint)
    84 
    85 
    85     # Call prune -B
    86     # Call prune -B
    86     evolve = extensions.find('evolve')
    87     evolve = extensions.find('evolve')
    87     optsdict = {
    88     optsdict = {
    88         'new': [],
    89         'new': [],
   182         lockmod.release(tr, lock)
   183         lockmod.release(tr, lock)
   183 
   184 
   184 def _computeobsoletenotrebasedwrap(orig, repo, rebasesetrevs, dest):
   185 def _computeobsoletenotrebasedwrap(orig, repo, rebasesetrevs, dest):
   185     repo._notinhibited = rebasesetrevs
   186     repo._notinhibited = rebasesetrevs
   186     try:
   187     try:
   187        repo.invalidatevolatilesets()
   188         repo.invalidatevolatilesets()
   188        r = orig(repo, rebasesetrevs, dest)
   189         r = orig(repo, rebasesetrevs, dest)
   189     finally:
   190     finally:
   190        del repo._notinhibited
   191         del repo._notinhibited
   191        repo.invalidatevolatilesets()
   192         repo.invalidatevolatilesets()
   192     return r
   193     return r
   193 
   194 
   194 def transactioncallback(orig, repo, desc, *args, **kwargs):
   195 def transactioncallback(orig, repo, desc, *args, **kwargs):
   195     """ Wrap localrepo.transaction to inhibit new obsolete changes """
   196     """ Wrap localrepo.transaction to inhibit new obsolete changes """
   196     def inhibitposttransaction(transaction):
   197     def inhibitposttransaction(transaction):
   201         visibleobsolete = list(r for r in visibleobsolete if r not in ignoreset)
   202         visibleobsolete = list(r for r in visibleobsolete if r not in ignoreset)
   202         if visibleobsolete:
   203         if visibleobsolete:
   203             _inhibitmarkers(repo, [repo[r].node() for r in visibleobsolete])
   204             _inhibitmarkers(repo, [repo[r].node() for r in visibleobsolete])
   204     transaction = orig(repo, desc, *args, **kwargs)
   205     transaction = orig(repo, desc, *args, **kwargs)
   205     if desc != 'strip' and _inhibitenabled(repo):
   206     if desc != 'strip' and _inhibitenabled(repo):
   206         transaction.addpostclose('inhibitposttransaction', inhibitposttransaction)
   207         transaction.addpostclose('inhibitposttransaction',
       
   208                                  inhibitposttransaction)
   207     return transaction
   209     return transaction
   208 
   210 
   209 def extsetup(ui):
   211 def extsetup(ui):
   210     # lets wrap the computation of the obsolete set
   212     # lets wrap the computation of the obsolete set
   211     # We apply inhibition there
   213     # We apply inhibition there