Rev 2479: Rename push/pull back to 'run_hooks' (jameinel) in http://sourcefrog.net/bzr/run-hooks
Martin Pool
mbp at sourcefrog.net
Fri May 4 09:49:57 BST 2007
At http://sourcefrog.net/bzr/run-hooks
------------------------------------------------------------
revno: 2479
revision-id: mbp at sourcefrog.net-20070504084639-8v8mzetmr1y74xer
parent: mbp at sourcefrog.net-20070503080000-joirold1vv0dndgs
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: run-hooks
timestamp: Fri 2007-05-04 18:46:39 +1000
message:
Rename push/pull back to 'run_hooks' (jameinel)
Reorganize Branch.push into some template methods: public push,
_push_with_bound_branches, and _basic_push. This fixes the case
where the destination of push is bound, but the source branch
format doesn't support binding.
Run push and pull hook tests with a local branch that does support binding,
rather than skipping if the branch can't be bound to another of the same
format.
(broken) because the hooks are given the wrong parameters when
pushing into something bound to a remote branch.
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/tests/branch_implementations/test_pull.py test_pull.py-20060410103942-83c35b26657414fc
bzrlib/tests/branch_implementations/test_push.py test_push.py-20070130153159-fhfap8uoifevg30j-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2007-04-24 19:43:09 +0000
+++ b/bzrlib/branch.py 2007-05-04 08:46:39 +0000
@@ -1000,7 +1000,7 @@
# (push_result)
# containing the members
# (source, local, master, old_revno, old_revid, new_revno, new_revid)
- # where local is the local branch or None, master is the target
+ # where local is the local target branch or None, master is the target
# master branch, and the rest should be self explanatory. The source
# is read locked and the target branches write locked. Source will
# be the local low-latency branch.
@@ -1476,13 +1476,14 @@
@needs_write_lock
def pull(self, source, overwrite=False, stop_revision=None,
- _hook_master=None, _run_hooks=True):
+ _hook_master=None, run_hooks=True):
"""See Branch.pull.
:param _hook_master: Private parameter - set the branch to
be supplied as the master to push hooks.
- :param _run_hooks: Private parameter - allow disabling of
- hooks, used when pushing to a master branch.
+ :param run_hooks: Private parameter - if false, this branch
+ is being called because it's the master of the primary branch,
+ so it should not run its hooks.
"""
result = PullResult()
result.source_branch = source
@@ -1507,7 +1508,7 @@
else:
result.master_branch = self
result.local_branch = None
- if _run_hooks:
+ if run_hooks:
for hook in Branch.hooks['post_pull']:
hook(result)
finally:
@@ -1525,14 +1526,50 @@
@needs_read_lock
def push(self, target, overwrite=False, stop_revision=None,
- _hook_master=None, _run_hooks=True):
+ _hook_master=None, run_hooks=True):
"""See Branch.push.
+
+ This is the basic concrete implementation of push()
:param _hook_master: Private parameter - set the branch to
be supplied as the master to push hooks.
- :param _run_hooks: Private parameter - allow disabling of
- hooks, used when pushing to a master branch.
- """
+ :param run_hooks: Private parameter - if false, this branch
+ is being called because it's the master of the primary branch,
+ so it should not run its hooks.
+ """
+ return self._push_with_bound_branches(target, overwrite,
+ stop_revision, _hook_master, run_hooks)
+
+ def _push_with_bound_branches(self, target, overwrite,
+ stop_revision, _hook_master, run_hooks):
+ """Updates branch.push to be bound branch aware
+
+ This is on the base BzrBranch class even though it doesn't support
+ bound branches because the *target* might be bound.
+ """
+ bound_location = target.get_bound_location()
+ master_branch = None
+ if bound_location and target.base != bound_location:
+ # not pushing to master, so we need to update master.
+ master_branch = target.get_master_branch()
+ master_branch.lock_write()
+ try:
+ if master_branch:
+ # push into the master from this branch.
+ self._basic_push(master_branch, overwrite, stop_revision,
+ stop_revision, run_hooks=False)
+ # and push into the target branch from this. Note that we push from
+ # this branch again, because its considered the highest bandwidth
+ # repository.
+ return self._basic_push(target, overwrite, stop_revision,
+ _hook_master=master_branch, run_hooks=run_hooks)
+ finally:
+ if master_branch:
+ master_branch.unlock()
+
+ def _basic_push(self, target, overwrite, stop_revision, _hook_master,
+ run_hooks):
+ """Basic implementation of push without considering bound branches."""
result = PushResult()
result.source_branch = self
result.target_branch = target
@@ -1554,7 +1591,7 @@
else:
result.master_branch = target
result.local_branch = None
- if _run_hooks:
+ if run_hooks:
for hook in Branch.hooks['post_push']:
hook(result)
finally:
@@ -1634,11 +1671,12 @@
@needs_write_lock
def pull(self, source, overwrite=False, stop_revision=None,
- _run_hooks=True):
+ run_hooks=True):
"""Extends branch.pull to be bound branch aware.
- :param _run_hooks: Private parameter used to force hook running
- off during bound branch double-pushing.
+ :param run_hooks: Private parameter - if false, this branch
+ is being called because it's the master of the primary branch,
+ so it should not run its hooks.
"""
bound_location = self.get_bound_location()
master_branch = None
@@ -1650,33 +1688,10 @@
if master_branch:
# pull from source into master.
master_branch.pull(source, overwrite, stop_revision,
- _run_hooks=False)
+ run_hooks=False)
return super(BzrBranch5, self).pull(source, overwrite,
stop_revision, _hook_master=master_branch,
- _run_hooks=_run_hooks)
- finally:
- if master_branch:
- master_branch.unlock()
-
- @needs_read_lock
- def push(self, target, overwrite=False, stop_revision=None):
- """Updates branch.push to be bound branch aware."""
- bound_location = target.get_bound_location()
- master_branch = None
- if bound_location and target.base != bound_location:
- # not pushing to master, so we need to update master.
- master_branch = target.get_master_branch()
- master_branch.lock_write()
- try:
- if master_branch:
- # push into the master from this branch.
- super(BzrBranch5, self).push(master_branch, overwrite,
- stop_revision, _run_hooks=False)
- # and push into the target branch from this. Note that we push from
- # this branch again, because its considered the highest bandwidth
- # repository.
- return super(BzrBranch5, self).push(target, overwrite,
- stop_revision, _hook_master=master_branch)
+ run_hooks=run_hooks)
finally:
if master_branch:
master_branch.unlock()
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py 2007-05-03 08:00:00 +0000
+++ b/bzrlib/remote.py 2007-05-04 08:46:39 +0000
@@ -996,13 +996,19 @@
return self._real_branch.append_revision(*revision_ids)
@needs_write_lock
- def pull(self, source, overwrite=False, stop_revision=None):
+ def pull(self, source, overwrite=False, stop_revision=None,
+ **kwargs):
+ # FIXME: This lets the real branch run the hooks, so they'll be called
+ # with the wrong branch parameters -- mbp 20070405
self._ensure_real()
self._real_branch.pull(
- source, overwrite=overwrite, stop_revision=stop_revision)
+ source, overwrite=overwrite, stop_revision=stop_revision,
+ **kwargs)
@needs_read_lock
def push(self, target, overwrite=False, stop_revision=None):
+ # FIXME: This lets the real branch run the hooks, so they'll be called
+ # with the wrong branch parameters -- mbp 20070405
self._ensure_real()
return self._real_branch.push(
target, overwrite=overwrite, stop_revision=stop_revision)
=== modified file 'bzrlib/tests/branch_implementations/test_pull.py'
--- a/bzrlib/tests/branch_implementations/test_pull.py 2007-03-01 07:15:55 +0000
+++ b/bzrlib/tests/branch_implementations/test_pull.py 2007-05-04 08:46:39 +0000
@@ -18,10 +18,12 @@
import os
-from bzrlib.branch import Branch
+from bzrlib.branch import Branch, BzrBranchFormat5
+from bzrlib.bzrdir import BzrDir
from bzrlib import errors
from bzrlib.memorytree import MemoryTree
from bzrlib.revision import NULL_REVISION
+from bzrlib.tests import TestSkipped
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
@@ -142,8 +144,13 @@
try:
local.bind(target)
except errors.UpgradeRequired:
- # cant bind this format, the test is irrelevant.
- return
+ # We can't bind this format to itself- typically it is the local
+ # branch that doesn't support binding. As of May 2007
+ # 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)
source = self.make_branch('source')
Branch.hooks.install_hook('post_pull', self.capture_post_pull_hook)
local.pull(source)
=== modified file 'bzrlib/tests/branch_implementations/test_push.py'
--- a/bzrlib/tests/branch_implementations/test_push.py 2007-03-29 07:39:49 +0000
+++ b/bzrlib/tests/branch_implementations/test_push.py 2007-05-04 08:46:39 +0000
@@ -17,12 +17,14 @@
"""Tests for branch.push behaviour."""
import os
-
+
from bzrlib import bzrdir, errors
from bzrlib.branch import Branch
+from bzrlib.bzrdir import BzrDir
from bzrlib.memorytree import MemoryTree
from bzrlib.remote import RemoteBranch
from bzrlib.revision import NULL_REVISION
+from bzrlib.tests import TestSkipped
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
from bzrlib.transport.local import LocalURLServer
@@ -207,8 +209,15 @@
try:
local.bind(target)
except errors.UpgradeRequired:
- # cant bind this format, the test is irrelevant.
- return
+ # We can't bind this format to itself- typically it is the local
+ # branch that doesn't support binding. As of May 2007
+ # 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))
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