Rev 2257: (robertc) Merge new Branch.last_revision_info method. in http://people.ubuntu.com/~robertc/baz2.0/integration
Robert Collins
robertc at robertcollins.net
Fri Feb 2 09:18:21 GMT 2007
------------------------------------------------------------
revno: 2257
revision-id: robertc at robertcollins.net-20070202091723-xtak1zzhe2ylwksa
parent: pqm at pqm.ubuntu.com-20070202061004-5fdd6c2715ccaaa9
parent: larstiq at larstiq.dyndns.org-20070201144747-3szl1p7drs9v1hkh
committer: Robert Collins <robertc at robertcollins.net>
branch nick: integration
timestamp: Fri 2007-02-02 20:17:23 +1100
message:
(robertc) Merge new Branch.last_revision_info method.
added:
bzrlib/tests/branch_implementations/test_last_revision_info.py test_last_revision_i-20070201133317-51mzi40m8hv1i0i9-1
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/commit.py commit.py-20050511101309-79ec1a0168e0e825
bzrlib/info.py info.py-20050323235939-6bbfe7d9700b0b9b
bzrlib/log.py log.py-20050505065812-c40ce11702fe5fb1
bzrlib/revisionspec.py revisionspec.py-20050907152633-17567659fd5c0ddb
bzrlib/tests/branch_implementations/__init__.py __init__.py-20060123013057-b12a52c3f361daf4
bzrlib/workingtree.py workingtree.py-20050511021032-29b6ec0a681e02e3
------------------------------------------------------------
revno: 2249.4.2
merged: larstiq at larstiq.dyndns.org-20070201144747-3szl1p7drs9v1hkh
parent: larstiq at larstiq.dyndns.org-20070201133345-5hsm5hxzqbvmtklr
committer: Wouter van Heyst <larstiq at larstiq.dyndns.org>
branch nick: tip.info
timestamp: Thu 2007-02-01 15:47:47 +0100
message:
Convert callers of Branch.revision_history() to Branch.last_revision_info() where sensible.
(Wouter van Heyst, Robert Collins)
------------------------------------------------------------
revno: 2249.4.1
merged: larstiq at larstiq.dyndns.org-20070201133345-5hsm5hxzqbvmtklr
parent: pqm at pqm.ubuntu.com-20070131184047-424584b0fabcee96
committer: Wouter van Heyst <larstiq at larstiq.dyndns.org>
branch nick: tip.info
timestamp: Thu 2007-02-01 14:33:45 +0100
message:
New Branch.last_revision_info method, this is being done to allow
optimization of requests for both the number of revisions and the last
revision of a branch with smartservers and potentially future branch
formats. (Wouter van Heyst, Robert Collins)
=== added file 'bzrlib/tests/branch_implementations/test_last_revision_info.py'
--- a/bzrlib/tests/branch_implementations/test_last_revision_info.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/branch_implementations/test_last_revision_info.py 2007-02-01 13:33:45 +0000
@@ -0,0 +1,35 @@
+# Copyright (C) 2004, 2005, 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+"""Tests for branch.last_revision_info."""
+
+from bzrlib.revision import NULL_REVISION
+from bzrlib.tests import TestCaseWithTransport
+
+
+class TestLastRevisionInfo(TestCaseWithTransport):
+
+ def test_empty_branch(self):
+ # on an empty branch we want (0, NULL_REVISION)
+ branch = self.make_branch('branch')
+ self.assertEqual((0, NULL_REVISION), branch.last_revision_info())
+
+ def test_non_empty_branch(self):
+ # after the second commit we want (2, 'second-revid')
+ tree = self.make_branch_and_tree('branch')
+ tree.commit('1st post')
+ revid = tree.commit('2st post', allow_pointless=True)
+ self.assertEqual((2, revid), tree.branch.last_revision_info())
=== modified file 'NEWS'
--- a/NEWS 2007-02-01 21:29:19 +0000
+++ b/NEWS 2007-02-02 09:17:23 +0000
@@ -34,6 +34,11 @@
branch as it makes performance and policy decisions to match the UI
level command ``push``. (Robert Collins).
+ * New Branch.last_revision_info method, this is being done to allow
+ optimization of requests for both the number of revisions and the last
+ revision of a branch with smartservers and potentially future branch
+ formats. (Wouter van Heyst, Robert Collins)
+
BUGFIXES:
* ``bzr annotate`` now uses dotted revnos from the viewpoint of the
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2007-02-01 17:18:42 +0000
+++ b/bzrlib/branch.py 2007-02-02 09:17:23 +0000
@@ -225,12 +225,7 @@
try:
if last_revision is None:
pb.update('get source history')
- from_history = from_branch.revision_history()
- if from_history:
- last_revision = from_history[-1]
- else:
- # no history in the source branch
- last_revision = _mod_revision.NULL_REVISION
+ last_revision = from_branch.last_revision_info()[1]
return self.repository.fetch(from_branch.repository,
revision_id=last_revision,
pb=nested_pb)
@@ -324,6 +319,18 @@
else:
return None
+ def last_revision_info(self):
+ """Return information about the last revision.
+
+ :return: A tuple (revno, last_revision_id).
+ """
+ rh = self.revision_history()
+ revno = len(rh)
+ if revno:
+ return (revno, rh[-1])
+ else:
+ return (0, _mod_revision.NULL_REVISION)
+
def missing_revisions(self, other, stop_revision=None):
"""Return a list of new revisions that would perfectly fit.
@@ -1246,7 +1253,7 @@
"""See Branch.pull."""
source.lock_read()
try:
- old_count = len(self.revision_history())
+ old_count = self.last_revision_info()[0]
try:
self.update_revisions(source, stop_revision)
except DivergedBranches:
@@ -1254,7 +1261,7 @@
raise
if overwrite:
self.set_revision_history(source.revision_history())
- new_count = len(self.revision_history())
+ new_count = self.last_revision_info()[0]
return new_count - old_count
finally:
source.unlock()
=== modified file 'bzrlib/builtins.py'
--- a/bzrlib/builtins.py 2007-02-02 04:32:56 +0000
+++ b/bzrlib/builtins.py 2007-02-02 09:17:23 +0000
@@ -663,7 +663,7 @@
dir_to = br_from.bzrdir.clone(location_url,
revision_id=br_from.last_revision())
br_to = dir_to.open_branch()
- count = len(br_to.revision_history())
+ count = br_to.last_revision_info()[0]
# 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)
@@ -2231,9 +2231,6 @@
branch1 = Branch.open_containing(branch)[0]
branch2 = Branch.open_containing(other)[0]
- history_1 = branch1.revision_history()
- history_2 = branch2.revision_history()
-
last1 = branch1.last_revision()
last2 = branch2.last_revision()
=== modified file 'bzrlib/commit.py'
--- a/bzrlib/commit.py 2006-12-01 19:41:16 +0000
+++ b/bzrlib/commit.py 2007-02-01 14:47:47 +0000
@@ -428,9 +428,9 @@
# to local.
# Make sure the local branch is identical to the master
- master_rh = self.master_branch.revision_history()
- local_rh = self.branch.revision_history()
- if local_rh != master_rh:
+ master_info = self.master_branch.last_revision_info()
+ local_info = self.branch.last_revision_info()
+ if local_info != master_info:
raise errors.BoundBranchOutOfDate(self.branch,
self.master_branch)
=== modified file 'bzrlib/info.py'
--- a/bzrlib/info.py 2006-12-21 06:00:17 +0000
+++ b/bzrlib/info.py 2007-02-01 14:47:47 +0000
@@ -176,15 +176,15 @@
branch = working.branch
basis = working.basis_tree()
work_inv = working.inventory
- history = branch.revision_history()
+ branch_revno, branch_last_revision = branch.last_revision_info()
try:
tree_last_id = working.get_parent_ids()[0]
except IndexError:
tree_last_id = None
- if len(history) and tree_last_id != history[-1]:
+ if branch_revno and tree_last_id != branch_last_revision:
tree_last_revno = branch.revision_id_to_revno(tree_last_id)
- missing_count = len(history) - tree_last_revno
+ missing_count = branch_revno - tree_last_revno
print
print 'Working tree is out of date: missing %d revision%s.' % (
missing_count, plural(missing_count))
=== modified file 'bzrlib/log.py'
--- a/bzrlib/log.py 2006-10-16 09:14:47 +0000
+++ b/bzrlib/log.py 2007-02-01 14:47:47 +0000
@@ -296,8 +296,6 @@
elif direction != 'reverse':
raise ValueError('invalid direction %r' % direction)
- revision_history = branch.revision_history()
-
for sequence, rev_id, merge_depth, revno, end_of_merge in merge_sorted_revisions:
yield rev_id, '.'.join(map(str, revno)), merge_depth
=== modified file 'bzrlib/revisionspec.py'
--- a/bzrlib/revisionspec.py 2006-11-08 16:29:27 +0000
+++ b/bzrlib/revisionspec.py 2007-02-01 14:47:47 +0000
@@ -326,6 +326,8 @@
return RevisionInfo(branch, None, revisions[0][1])
else:
if revno < 0:
+ # if get_rev_id supported negative revnos, there would not be a
+ # need for this special case.
if (-revno) >= len(revs):
revno = 1
else:
=== modified file 'bzrlib/tests/branch_implementations/__init__.py'
--- a/bzrlib/tests/branch_implementations/__init__.py 2007-02-01 17:18:42 +0000
+++ b/bzrlib/tests/branch_implementations/__init__.py 2007-02-02 09:17:23 +0000
@@ -44,6 +44,7 @@
'bzrlib.tests.branch_implementations.test_break_lock',
'bzrlib.tests.branch_implementations.test_hooks',
'bzrlib.tests.branch_implementations.test_http',
+ 'bzrlib.tests.branch_implementations.test_last_revision_info',
'bzrlib.tests.branch_implementations.test_locking',
'bzrlib.tests.branch_implementations.test_parent',
'bzrlib.tests.branch_implementations.test_permissions',
=== modified file 'bzrlib/workingtree.py'
--- a/bzrlib/workingtree.py 2007-02-01 23:48:08 +0000
+++ b/bzrlib/workingtree.py 2007-02-02 09:17:23 +0000
@@ -1321,16 +1321,12 @@
try:
pp = ProgressPhase("Pull phase", 2, top_pb)
pp.next_phase()
- old_revision_history = self.branch.revision_history()
+ old_revision_info = self.branch.last_revision_info()
basis_tree = self.basis_tree()
count = self.branch.pull(source, overwrite, stop_revision)
- new_revision_history = self.branch.revision_history()
- if new_revision_history != old_revision_history:
+ new_revision_info = self.branch.last_revision_info()
+ if new_revision_info != old_revision_info:
pp.next_phase()
- if len(old_revision_history):
- other_revision = old_revision_history[-1]
- else:
- other_revision = None
repository = self.branch.repository
pb = bzrlib.ui.ui_factory.nested_progress_bar()
try:
More information about the bazaar-commits
mailing list