sapling/hgext3rd/bundle2hooks.py
Jun Wu 3d461ae600 check-ext: make checks stricter
Summary:
Enhance check-ext script to be more strict:

 - Only one foreign extension is allowed: `remotenames`
 - Require explicit path for in-repo extensions to avoid wrong extensions
   being tested

This would make the test more predicatable since system extensions
will be less likely to be imported. Explicit path is better than
setting `PYTHONPATH` since `hgext/name.py` could override
`hgext3rd/name.py` regardless of `PYTHONPATH`.

Test Plan: arc unit

Reviewers: phillco, durham, ikostia, #mercurial, stash

Reviewed By: stash

Subscribers: medson, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D5271430

Signature: t1:5271430:1497861776:7dd35ec7c522cd9b26aa0871cb4306b4f1b8993a
2017-06-19 08:02:38 -07:00

52 lines
1.8 KiB
Python

# bundle2hooks.py - fix bundle2's support for hooks prior to lock acquisition.
#
# Copyright 2012 Facebook
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
'''Hooks arguments are typically stored on the transaction object. However, we
may want to add hooks arguments without starting a transaction. This allows us
to queue hook arguments on the bundle2 operation object.
'''
from __future__ import absolute_import
from mercurial import bundle2
from mercurial import error
from mercurial.i18n import _
from hgext3rd.extutil import replaceclass
def reposetup(ui, repo):
@replaceclass(bundle2, 'bundleoperation')
class bundleoperationhooked(bundle2.bundleoperation):
def __init__(self, repo, transactiongetter, *args, **kwargs):
def gettransaction():
transaction = transactiongetter()
if self.hookargs is not None:
# the ones added to the transaction supercede those added
# to the operation.
self.hookargs.update(transaction.hookargs)
transaction.hookargs = self.hookargs
# mark the hookargs as flushed. further attempts to add to
# hookargs will result in an abort.
self.hookargs = None
return transaction
super(bundleoperationhooked, self).__init__(repo, gettransaction,
*args, **kwargs)
self.hookargs = {}
def addhookargs(self, hookargs):
if self.hookargs is None:
raise error.Abort(
_('attempted to add hooks to operation after transaction '
'started'))
self.hookargs.update(hookargs)