Rev 2298: Pull now returns a PullResult rather than just an integer. in http://sourcefrog.net/bzr/resultobj
Martin Pool
mbp at sourcefrog.net
Fri Feb 23 05:39:36 GMT 2007
At http://sourcefrog.net/bzr/resultobj
------------------------------------------------------------
revno: 2298
revision-id: mbp at sourcefrog.net-20070223053935-r601f8e1xwwljm21
parent: pqm at pqm.ubuntu.com-20070221200818-3edf47a2bd3f472b
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: resultobj
timestamp: Fri 2007-02-23 16:39:35 +1100
message:
Pull now returns a PullResult rather than just an integer.
Remove old Branch.is_control_file function.
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/tests/blackbox/test_merge.py test_merge.py-20060323225809-9bc0459c19917f41
bzrlib/tests/blackbox/test_pull.py test_pull.py-20051201144907-64959364f629947f
bzrlib/tests/branch_implementations/test_pull.py test_pull.py-20060410103942-83c35b26657414fc
=== modified file 'NEWS'
--- a/NEWS 2007-02-17 02:36:32 +0000
+++ b/NEWS 2007-02-23 05:39:35 +0000
@@ -101,6 +101,10 @@
you pass a Unicode string rather than an 8-bit string. Callers need
to be updated to encode first. (John Arbash Meinel)
+ * Branch.push, pull, merge now return Result objects with information
+ about what happened, rather than a scattering of various methods. These
+ are also passed to the post hooks. (Martin Pool)
+
BUGFIXES:
* ``bzr annotate`` now uses dotted revnos from the viewpoint of the
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2007-02-17 02:33:45 +0000
+++ b/bzrlib/branch.py 2007-02-23 05:39:35 +0000
@@ -399,6 +399,8 @@
"""Mirror source into this branch.
This branch is considered to be 'local', having low latency.
+
+ :returns: PullResult instance
"""
raise NotImplementedError(self.pull)
@@ -1398,9 +1400,11 @@
:param _run_hooks: Private parameter - allow disabling of
hooks, used when pushing to a master branch.
"""
+ result = PullResult()
+ result.source = source
source.lock_read()
try:
- old_count, old_tip = self.last_revision_info()
+ result.old_revno, result.old_revid = self.last_revision_info()
try:
self.update_revisions(source, stop_revision)
except DivergedBranches:
@@ -1408,19 +1412,19 @@
raise
if overwrite:
self.set_revision_history(source.revision_history())
- new_count, new_tip = self.last_revision_info()
+ result.new_revno, result.new_revid = self.last_revision_info()
if _run_hooks:
if _hook_master:
- _hook_local = self
+ result.master = _hook_master
+ result.local = self
else:
- _hook_master = self
- _hook_local = None
+ result.master = self
+ result.local = None
for hook in Branch.hooks['post_pull']:
- hook(source, _hook_local, _hook_master, old_count, old_tip,
- new_count, new_tip)
- return new_count - old_count
+ hook(result)
finally:
source.unlock()
+ return result
def _get_parent_location(self):
_locs = ['parent', 'pull', 'x-pull']
@@ -1914,6 +1918,14 @@
return result
+######################################################################
+# results of operations
+
+class PullResult(object):
+
+ pass
+
+
class BranchCheckResult(object):
"""Results of checking branch consistency.
@@ -1934,17 +1946,6 @@
self.branch._format)
-######################################################################
-# predicates
-
-
- at deprecated_function(zero_eight)
-def is_control_file(*args, **kwargs):
- """See bzrlib.workingtree.is_control_file."""
- from bzrlib import workingtree
- return workingtree.is_control_file(*args, **kwargs)
-
-
class Converter5to6(object):
"""Perform an in-place upgrade of format 5 to format 6"""
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2007-02-15 18:01:21 +0000
+++ b/bzrlib/builtins.py 2007-02-23 05:39:35 +0000
@@ -597,19 +597,19 @@
old_rh = branch_to.revision_history()
if tree_to is not None:
- count = tree_to.pull(branch_from, overwrite, rev_id,
+ result = tree_to.pull(branch_from, overwrite, rev_id,
delta.ChangeReporter(tree_to.inventory))
else:
- count = branch_to.pull(branch_from, overwrite, rev_id)
- note('%d revision(s) pulled.' % (count,))
+ result = branch_to.pull(branch_from, overwrite, rev_id)
- if verbose:
+ if result.old_revid == result.new_revid:
+ note('No revisions to pull.')
+ elif verbose:
+ from bzrlib.log import show_changed_revisions
new_rh = branch_to.revision_history()
- if old_rh != new_rh:
- # Something changed
- from bzrlib.log import show_changed_revisions
- show_changed_revisions(branch_to, old_rh, new_rh,
- to_file=self.outf)
+ show_changed_revisions(branch_to, old_rh, new_rh, to_file=self.outf)
+ else:
+ note('Now on revision %d.' % result.new_revno)
class cmd_push(Command):
@@ -3228,9 +3228,13 @@
return 0
if file_list is None:
if pull and merger.base_rev_id == merger.this_rev_id:
- count = merger.this_tree.pull(merger.this_branch,
+ # FIXME: deduplicate with pull
+ result = merger.this_tree.pull(merger.this_branch,
False, merger.other_rev_id)
- note('%d revision(s) pulled.' % (count,))
+ if result.old_revid == result.new_revid:
+ note('No revisions to pull.')
+ else:
+ note('Now on revision %d.' % result.new_revno)
return 0
merger.backup_files = backup_files
merger.merge_type = merge_type
=== modified file 'bzrlib/tests/blackbox/test_merge.py'
--- a/bzrlib/tests/blackbox/test_merge.py 2007-02-14 21:57:40 +0000
+++ b/bzrlib/tests/blackbox/test_merge.py 2007-02-23 05:39:35 +0000
@@ -267,7 +267,7 @@
self.pullable_branch()
os.chdir('a')
(out, err) = self.run_bzr('merge', '--pull', '../b')
- self.assertContainsRe(err, '1 revision\\(s\\) pulled')
+ self.assertContainsRe(err, 'Now on revision 2\\.')
tree_a = WorkingTree.open('.')
self.assertEqual([self.id2], tree_a.get_parent_ids())
=== modified file 'bzrlib/tests/blackbox/test_pull.py'
--- a/bzrlib/tests/blackbox/test_pull.py 2007-02-14 21:57:40 +0000
+++ b/bzrlib/tests/blackbox/test_pull.py 2007-02-23 05:39:35 +0000
@@ -300,7 +300,8 @@
output = self.run_bzr('pull', '../bundle')
self.assertEqual('', output[0])
self.assertEqual(' M a\nAll changes applied successfully.\n'
- '1 revision(s) pulled.\n', output[1])
+ 'Now on revision 2.\n',
+ output[1])
self.assertEqualDiff(tree_a.branch.revision_history(),
tree_b.branch.revision_history())
@@ -315,4 +316,4 @@
# it is legal to attempt to pull an already-merged bundle
output = self.run_bzr('pull', '../bundle')
self.assertEqual('', output[0])
- self.assertEqual('0 revision(s) pulled.\n', output[1])
+ self.assertEqual('No revisions to pull.\n', output[1])
=== modified file 'bzrlib/tests/branch_implementations/test_pull.py'
--- a/bzrlib/tests/branch_implementations/test_pull.py 2007-02-06 02:33:42 +0000
+++ b/bzrlib/tests/branch_implementations/test_pull.py 2007-02-23 05:39:35 +0000
@@ -87,22 +87,22 @@
self.hook_calls = []
TestCaseWithBranch.setUp(self)
- def capture_post_pull_hook(self, source, local, master, old_revno,
- old_revid, new_revno, new_revid):
+ def capture_post_pull_hook(self, result):
"""Capture post pull 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_pull', source, local_base, master.base, old_revno, old_revid,
- new_revno, new_revid, source.is_locked(), local_locked,
- master.is_locked()))
+ ('post_pull', 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_pull_empty_history(self):
target = self.make_branch('target')
More information about the bazaar-commits
mailing list