Rev 2482: More cleanups of Branch.push to get the right behaviour with RemoteBranches in http://sourcefrog.net/bzr/run-hooks
Martin Pool
mbp at sourcefrog.net
Fri May 4 11:01:18 BST 2007
At http://sourcefrog.net/bzr/run-hooks
------------------------------------------------------------
revno: 2482
revision-id: mbp at sourcefrog.net-20070504100117-p3bksdrvjjnoz6qi
parent: mbp at sourcefrog.net-20070504095119-sxlhgb1tmxjflj09
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: run-hooks
timestamp: Fri 2007-05-04 20:01:17 +1000
message:
More cleanups of Branch.push to get the right behaviour with RemoteBranches
Pass in an _override_hook_source_branch
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/tests/branch_implementations/test_push.py test_push.py-20070130153159-fhfap8uoifevg30j-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2007-05-04 09:31:12 +0000
+++ b/bzrlib/branch.py 2007-05-04 10:01:17 +0000
@@ -1526,28 +1526,26 @@
@needs_read_lock
def push(self, target, overwrite=False, stop_revision=None,
- run_hooks=True):
+ run_hooks=True,
+ _override_hook_source_branch=None):
"""See Branch.push.
This is the basic concrete implementation of push()
"""
# TODO: Public option to disable running hooks - should be trivial but
# needs tests.
- def _run_hooks(result):
- for hook in Branch.hooks['post_push']:
- hook(result)
-
target.lock_write()
try:
result = self._push_with_bound_branches(target, overwrite,
stop_revision,
- run_hooks_cb=_run_hooks)
+ _override_hook_source_branch=_override_hook_source_branch)
return result
finally:
target.unlock()
def _push_with_bound_branches(self, target, overwrite,
- stop_revision, run_hooks_cb):
+ stop_revision,
+ _override_hook_source_branch=None):
"""Updates branch.push to be bound branch aware
This is on the base BzrBranch class even though it doesn't support
@@ -1558,6 +1556,12 @@
first. May be a do-nothing function to disable running hooks.
Called with all branches locked, including the master if any.
"""
+ def _run_hooks():
+ if _override_hook_source_branch:
+ result.source_branch = _override_hook_source_branch
+ for hook in Branch.hooks['post_push']:
+ hook(result)
+
bound_location = target.get_bound_location()
if bound_location and target.base != bound_location:
# there is a master branch and we're not pushing to it, so we need
@@ -1576,18 +1580,19 @@
result = self._basic_push(target, overwrite, stop_revision)
result.master_branch = master_branch
result.local_branch = target
- run_hooks_cb(result)
+ _run_hooks()
return result
finally:
master_branch.unlock()
else:
# no master branch
result = self._basic_push(target, overwrite, stop_revision)
- # TODO: Why set these if there's no binding? Maybe cleaner to
- # just leave them unset? -- mbp 20070504
+ # TODO: Why set master_branch and local_branch if there's no
+ # binding? Maybe cleaner to just leave them unset? -- mbp
+ # 20070504
result.master_branch = target
result.local_branch = None
- run_hooks_cb(result)
+ _run_hooks()
return result
def _basic_push(self, target, overwrite, stop_revision):
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2007-05-04 08:46:39 +0000
+++ b/bzrlib/remote.py 2007-05-04 10:01:17 +0000
@@ -20,7 +20,7 @@
from cStringIO import StringIO
from bzrlib import branch, errors, lockdir, repository
-from bzrlib.branch import BranchReferenceFormat
+from bzrlib.branch import Branch, BranchReferenceFormat
from bzrlib.bzrdir import BzrDir, RemoteBzrDirFormat
from bzrlib.config import BranchConfig, TreeConfig
from bzrlib.decorators import needs_read_lock, needs_write_lock
@@ -1011,7 +1011,8 @@
# with the wrong branch parameters -- mbp 20070405
self._ensure_real()
return self._real_branch.push(
- target, overwrite=overwrite, stop_revision=stop_revision)
+ target, overwrite=overwrite, stop_revision=stop_revision,
+ _override_hook_source_branch=self)
def is_locked(self):
return self._lock_count >= 1
=== modified file 'bzrlib/tests/branch_implementations/test_push.py'
--- a/bzrlib/tests/branch_implementations/test_push.py 2007-05-04 08:46:39 +0000
+++ b/bzrlib/tests/branch_implementations/test_push.py 2007-05-04 10:01:17 +0000
@@ -187,12 +187,6 @@
source.push(target)
# with nothing there we should still get a notification, and
# have both branches locked at the notification time.
- if isinstance(source, RemoteBranch):
- # XXX: at the moment, push on remote branches is just delegated to
- # the file-level branch object, so we adjust the expected result
- # accordingly. In the future, when RemoteBranch implements push
- # directly, this should be unnecessary.
- source = source._real_branch
self.assertEqual([
('post_push', source, None, target.base, 0, NULL_REVISION,
0, NULL_REVISION, True, None, True)
@@ -214,10 +208,12 @@
# remotebranches can't be bound. Let's instead make a new local
# branch of the default type, which does allow binding.
# See https://bugs.launchpad.net/bzr/+bug/112020
- local = BzrDir.create_branch_convenience('local2')
- local.bind(target)
- #raise TestSkipped("Can't bind %s to %s" %
- # (local, target))
+ if 1:
+ local = BzrDir.create_branch_convenience('local2')
+ local.bind(target)
+ else:
+ raise TestSkipped("Can't bind %s to %s" %
+ (local, target))
source = self.make_branch('source')
Branch.hooks.install_hook('post_push', self.capture_post_push_hook)
source.push(local)
More information about the bazaar-commits
mailing list