Rev 2301: Push now returns a PushResult rather than just an integer. in http://sourcefrog.net/bzr/resultobj
Martin Pool
mbp at sourcefrog.net
Sun Feb 25 10:40:17 GMT 2007
At http://sourcefrog.net/bzr/resultobj
------------------------------------------------------------
revno: 2301
revision-id: mbp at sourcefrog.net-20070225104016-np1gvynr1nqkbnpo
parent: mbp at sourcefrog.net-20070223055544-ux2lcobwiudl3f53
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: resultobj
timestamp: Sun 2007-02-25 21:40:16 +1100
message:
Push now returns a PushResult rather than just an integer.
This result object is also passed to the push hooks.
pull ui slightly clearer about what has happened.
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
bzrlib/tests/branch_implementations/test_push.py test_push.py-20070130153159-fhfap8uoifevg30j-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2007-02-23 05:55:44 +0000
+++ b/bzrlib/branch.py 2007-02-25 10:40:16 +0000
@@ -1413,13 +1413,13 @@
if overwrite:
self.set_revision_history(source.revision_history())
result.new_revno, result.new_revid = self.last_revision_info()
+ if _hook_master:
+ result.master = _hook_master
+ result.local = self
+ else:
+ result.master = self
+ result.local = None
if _run_hooks:
- if _hook_master:
- result.master = _hook_master
- result.local = self
- else:
- result.master = self
- result.local = None
for hook in Branch.hooks['post_pull']:
hook(result)
finally:
@@ -1445,9 +1445,12 @@
:param _run_hooks: Private parameter - allow disabling of
hooks, used when pushing to a master branch.
"""
+ result = PushResult()
+ result.source = self
+ result.target = target
target.lock_write()
try:
- old_count, old_tip = target.last_revision_info()
+ result.old_revno, result.old_revid = target.last_revision_info()
try:
target.update_revisions(self, stop_revision)
except DivergedBranches:
@@ -1455,19 +1458,19 @@
raise
if overwrite:
target.set_revision_history(self.revision_history())
- new_count, new_tip = target.last_revision_info()
+ result.new_revno, result.new_revid = target.last_revision_info()
+ if _hook_master:
+ result.master = _hook_master
+ result.local = target
+ else:
+ result.master = target
+ result.local = None
if _run_hooks:
- if _hook_master:
- _hook_local = target
- else:
- _hook_master = target
- _hook_local = None
for hook in Branch.hooks['post_push']:
- hook(self, _hook_local, _hook_master, old_count, old_tip,
- new_count, new_tip)
- return new_count - old_count
+ hook(result)
finally:
target.unlock()
+ return result
def get_parent(self):
"""See Branch.get_parent."""
@@ -1924,7 +1927,14 @@
class PullResult(object):
def __int__(self):
- # somewhat deprecated: pull used to return the change in revno
+ # DEPRECATED: pull used to return the change in revno
+ return self.new_revno - self.old_revno
+
+
+class PushResult(object):
+
+ def __int__(self):
+ # DEPRECATED: push used to return the change in revno
return self.new_revno - self.old_revno
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2007-02-23 05:39:35 +0000
+++ b/bzrlib/builtins.py 2007-02-25 10:40:16 +0000
@@ -679,9 +679,6 @@
to_transport = transport.get_transport(location)
location_url = to_transport.base
- old_rh = []
- count = 0
-
br_to = repository_to = dir_to = None
try:
dir_to = bzrdir.BzrDir.open_from_transport(to_transport)
@@ -701,9 +698,10 @@
else:
# Found a branch, so we must have found a repository
repository_to = br_to.repository
-
+ push_result = None
old_rh = []
if dir_to is None:
+ # The destination doesn't exist; create it.
# XXX: Refactor the create_prefix/no_create_prefix code into a
# common helper function
try:
@@ -750,7 +748,8 @@
dir_to = br_from.bzrdir.clone(location_url,
revision_id=br_from.last_revision())
br_to = dir_to.open_branch()
- count = br_to.last_revision_info()[0]
+ # TODO: Some more useful message about what was copied
+ note('Created new branch.')
# We successfully created the target, remember it
if br_from.get_push_location() is None or remember:
br_from.set_push_location(br_to.base)
@@ -769,7 +768,7 @@
repository_to.fetch(br_from.repository,
revision_id=last_revision_id)
br_to = br_from.clone(dir_to, revision_id=last_revision_id)
- count = len(br_to.revision_history())
+ note('Created new branch.')
if br_from.get_push_location() is None or remember:
br_from.set_push_location(br_to.base)
else: # We have a valid to branch
@@ -784,28 +783,35 @@
except errors.NotLocalUrl:
warning('This transport does not update the working '
'tree of: %s' % (br_to.base,))
- count = br_from.push(br_to, overwrite)
+ push_result = br_from.push(br_to, overwrite)
except errors.NoWorkingTree:
- count = br_from.push(br_to, overwrite)
+ push_result = br_from.push(br_to, overwrite)
else:
tree_to.lock_write()
try:
- count = br_from.push(tree_to.branch, overwrite)
+ push_result = br_from.push(tree_to.branch, overwrite)
tree_to.update()
finally:
tree_to.unlock()
except errors.DivergedBranches:
raise errors.BzrCommandError('These branches have diverged.'
' Try using "merge" and then "push".')
- note('%d revision(s) pushed.' % (count,))
-
- if verbose:
+ if push_result is not None:
+ if push_result.old_revid == push_result.new_revid:
+ note('No new revisions to push.\n')
+ else:
+ note('Pushed up to revision %d.' % push_result.new_revno)
+ elif verbose:
new_rh = br_to.revision_history()
if old_rh != new_rh:
# Something changed
from bzrlib.log import show_changed_revisions
show_changed_revisions(br_to, old_rh, new_rh,
to_file=self.outf)
+ else:
+ # we probably did a clone rather than a push, so a message was
+ # emitted above
+ pass
class cmd_branch(Command):
=== modified file 'bzrlib/tests/blackbox/test_push.py'
--- a/bzrlib/tests/blackbox/test_push.py 2007-02-14 09:51:20 +0000
+++ b/bzrlib/tests/blackbox/test_push.py 2007-02-25 10:40:16 +0000
@@ -85,7 +85,7 @@
self.assertEquals(('Using saved location: %s\n'
% (local_path_from_url(path),)
, 'All changes applied successfully.\n'
- '1 revision(s) pushed.\n'), out)
+ 'Pushed up to revision 2.\n'), out)
self.assertEqual(path,
branch_b.bzrdir.root_transport.base)
# test explicit --remember
@@ -98,7 +98,7 @@
b = self.make_branch('.')
out, err = self.run_bzr('push', 'pushed-location')
self.assertEqual('', out)
- self.assertEqual('0 revision(s) pushed.\n', err)
+ self.assertEqual('Created new branch.\n', err)
b2 = Branch.open('pushed-location')
self.assertEndsWith(b2.base, 'pushed-location/')
@@ -114,7 +114,7 @@
out, err = self.run_bzr('push', 'pushed-to')
os.chdir('..')
self.assertEqual('', out)
- self.assertEqual('1 revision(s) pushed.\n', err)
+ self.assertEqual('Created new branch.\n', err)
def test_push_only_pushes_history(self):
# Knit branches should only push the history for the current revision.
=== modified file 'bzrlib/tests/branch_implementations/test_push.py'
--- a/bzrlib/tests/branch_implementations/test_push.py 2007-02-12 22:58:48 +0000
+++ b/bzrlib/tests/branch_implementations/test_push.py 2007-02-25 10:40:16 +0000
@@ -36,8 +36,13 @@
other.commit('my change', rev_id='M1', allow_pointless=True)
mine.merge_from_branch(other.branch)
mine.commit('merge my change', rev_id='P2')
- mine.branch.push(other.branch)
+ result = mine.branch.push(other.branch)
self.assertEqual(['P1', 'P2'], other.branch.revision_history())
+ # result object contains some structured data
+ self.assertEqual(result.old_revid, 'M1')
+ self.assertEqual(result.new_revid, 'P2')
+ # and it can be treated as an integer for compatibility
+ self.assertEqual(int(result), 0)
def test_push_merged_indirect(self):
# it should be possible to do a push from one branch into another
@@ -143,22 +148,22 @@
self.hook_calls = []
TestCaseWithBranch.setUp(self)
- def capture_post_push_hook(self, source, local, master, old_revno,
- old_revid, new_revno, new_revid):
+ def capture_post_push_hook(self, result):
"""Capture post push hook calls to self.hook_calls.
The call is logged, as is some state of the two branches.
"""
- if local:
- local_locked = local.is_locked()
- local_base = local.base
+ if result.local:
+ local_locked = result.local.is_locked()
+ local_base = result.local.base
else:
local_locked = None
local_base = None
self.hook_calls.append(
- ('post_push', source, local_base, master.base, old_revno, old_revid,
- new_revno, new_revid, source.is_locked(), local_locked,
- master.is_locked()))
+ ('post_push', result.source, local_base, result.master.base,
+ result.old_revno, result.old_revid,
+ result.new_revno, result.new_revid, result.source.is_locked(), local_locked,
+ result.master.is_locked()))
def test_post_push_empty_history(self):
target = self.make_branch('target')
More information about the bazaar-commits
mailing list