hgext3rd/evolve/safeguard.py
branchstable
changeset 5277 9ed5f9c5d8ae
parent 4814 48b30ff742cb
child 5288 5cfec61b872b
equal deleted inserted replaced
5275:1a81bbc94d45 5277:9ed5f9c5d8ae
    17 
    17 
    18 from . import exthelper
    18 from . import exthelper
    19 
    19 
    20 eh = exthelper.exthelper()
    20 eh = exthelper.exthelper()
    21 
    21 
    22 # hg <= 4.8
    22 # hg <= 4.8 (33d30fb1e4ae)
    23 if b'auto-publish' not in configitems.coreitems.get(b'experimental', {}):
    23 if b'auto-publish' not in configitems.coreitems.get(b'experimental', {}):
    24 
    24 
    25     eh.configitem(b'experimental', b'auto-publish', b'publish')
    25     eh.configitem(b'experimental', b'auto-publish', b'publish')
       
    26 
       
    27     def _checkpublish(pushop):
       
    28         repo = pushop.repo
       
    29         ui = repo.ui
       
    30         behavior = ui.config(b'experimental', b'auto-publish')
       
    31         nocheck = behavior not in (b'warn', b'abort')
       
    32         if nocheck or getattr(pushop, 'publish', False):
       
    33             return
       
    34         remotephases = pushop.remote.listkeys(b'phases')
       
    35         publishing = remotephases.get(b'publishing', False)
       
    36         if publishing:
       
    37             if pushop.revs is None:
       
    38                 published = repo.filtered(b'served').revs(b"not public()")
       
    39             else:
       
    40                 published = repo.revs(b"::%ln - public()", pushop.revs)
       
    41             if published:
       
    42                 if behavior == b'warn':
       
    43                     ui.warn(_(b'%i changesets about to be published\n')
       
    44                             % len(published))
       
    45                 elif behavior == b'abort':
       
    46                     msg = _(b'push would publish 1 changesets')
       
    47                     hint = _(b"behavior controlled by "
       
    48                              b"'experimental.auto-publish' config")
       
    49                     raise error.Abort(msg, hint=hint)
    26 
    50 
    27     @eh.reposetup
    51     @eh.reposetup
    28     def setuppublishprevention(ui, repo):
    52     def setuppublishprevention(ui, repo):
    29 
    53 
    30         class noautopublishrepo(repo.__class__):
    54         class noautopublishrepo(repo.__class__):
    31 
    55 
    32             def checkpush(self, pushop):
    56             def checkpush(self, pushop):
    33                 super(noautopublishrepo, self).checkpush(pushop)
    57                 super(noautopublishrepo, self).checkpush(pushop)
    34                 behavior = self.ui.config(b'experimental', b'auto-publish')
    58                 _checkpublish(pushop)
    35                 nocheck = behavior not in (b'warn', b'abort')
       
    36                 if nocheck or getattr(pushop, 'publish', False):
       
    37                     return
       
    38                 remotephases = pushop.remote.listkeys(b'phases')
       
    39                 publishing = remotephases.get(b'publishing', False)
       
    40                 if publishing:
       
    41                     if pushop.revs is None:
       
    42                         published = self.filtered(b'served').revs(b"not public()")
       
    43                     else:
       
    44                         published = self.revs(b"::%ln - public()", pushop.revs)
       
    45                     if published:
       
    46                         if behavior == b'warn':
       
    47                             self.ui.warn(_(b'%i changesets about to be published\n')
       
    48                                          % len(published))
       
    49                         elif behavior == b'abort':
       
    50                             msg = _(b'push would publish 1 changesets')
       
    51                             hint = _(b"behavior controlled by "
       
    52                                      b"'experimental.auto-publish' config")
       
    53                             raise error.Abort(msg, hint=hint)
       
    54 
    59 
    55         repo.__class__ = noautopublishrepo
    60         repo.__class__ = noautopublishrepo