Rev 3251: Accelerate Branch revision-history operations, looms (abentley) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Mar 5 13:13:59 GMT 2008
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3251
revision-id:pqm at pqm.ubuntu.com-20080305131343-toq33x607hecihie
parent: pqm at pqm.ubuntu.com-20080304113936-4wrordr8lrxhvfdl
parent: abentley at lappy-20080305100828-nj092v7gjok7h7mo
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2008-03-05 13:13:43 +0000
message:
Accelerate Branch revision-history operations, looms (abentley)
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/tests/branch_implementations/test_branch.py testbranch.py-20050711070244-121d632bc37d7253
bzrlib/tests/branch_implementations/test_revision_history.py test_revision_histor-20070326062311-v7co92liyuchb80w-1
------------------------------------------------------------
revno: 3240.1.7
revision-id:abentley at lappy-20080305100828-nj092v7gjok7h7mo
parent: aaron at aaronbentley.com-20080304231331-y8arw2a75cxcp5cb
committer: Aaron Bentley <abentley at lappy>
branch nick: faster_generate_history
timestamp: Wed 2008-03-05 10:08:28 +0000
message:
Update from review comments
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/tests/branch_implementations/test_revision_history.py test_revision_histor-20070326062311-v7co92liyuchb80w-1
------------------------------------------------------------
revno: 3240.1.6
revision-id:aaron at aaronbentley.com-20080304231331-y8arw2a75cxcp5cb
parent: aaron at aaronbentley.com-20080304230014-uv5qocaij4rvo5nw
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: faster_generate_history
timestamp: Tue 2008-03-04 23:13:31 +0000
message:
Update docs
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
------------------------------------------------------------
revno: 3240.1.5
revision-id:aaron at aaronbentley.com-20080304230014-uv5qocaij4rvo5nw
parent: aaron at aaronbentley.com-20080304222054-3vu14n6m8iml94x8
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: faster_generate_history
timestamp: Tue 2008-03-04 23:00:14 +0000
message:
Further clean-ups, move None conversion out into API functions
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
------------------------------------------------------------
revno: 3240.1.4
revision-id:aaron at aaronbentley.com-20080304222054-3vu14n6m8iml94x8
parent: aaron at aaronbentley.com-20080304215933-8tplic6pcdpd7tp7
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: faster_generate_history
timestamp: Tue 2008-03-04 22:20:54 +0000
message:
Simplify _lefthand_history code
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
------------------------------------------------------------
revno: 3240.1.3
revision-id:aaron at aaronbentley.com-20080304215933-8tplic6pcdpd7tp7
parent: aaron at aaronbentley.com-20080303115347-sdp9qnx1a6z80x43
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: faster_generate_history
timestamp: Tue 2008-03-04 21:59:33 +0000
message:
Use Graph to generate revision_history
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/tests/branch_implementations/test_branch.py testbranch.py-20050711070244-121d632bc37d7253
------------------------------------------------------------
revno: 3240.1.2
revision-id:aaron at aaronbentley.com-20080303115347-sdp9qnx1a6z80x43
parent: aaron at aaronbentley.com-20080303112452-iur8sj9mpi9fd0t5
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: faster_generate_history
timestamp: Mon 2008-03-03 11:53:47 +0000
message:
Add write lock
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
------------------------------------------------------------
revno: 3240.1.1
revision-id:aaron at aaronbentley.com-20080303112452-iur8sj9mpi9fd0t5
parent: pqm at pqm.ubuntu.com-20080227213154-a7egrkiapeuvmu3b
committer: Aaron Bentley <aaron at aaronbentley.com>
branch nick: faster_generate_history
timestamp: Mon 2008-03-03 11:24:52 +0000
message:
Avoid doing Branch._lefthand_history twice
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
=== modified file 'NEWS'
--- a/NEWS 2008-03-04 10:07:06 +0000
+++ b/NEWS 2008-03-05 13:13:43 +0000
@@ -38,6 +38,10 @@
IMPROVEMENTS:
+ * BzrBranch._lefthand_history is faster on pack repos. (Aaron Bentley)
+
+ * Branch6.generate_revision_history is faster. (Aaron Bentley)
+
BUGFIXES:
* Disable plink's interactive prompt for password.
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2008-02-26 23:45:35 +0000
+++ b/bzrlib/branch.py 2008-03-05 13:13:43 +0000
@@ -260,8 +260,7 @@
if last_revision is None:
pb.update('get source history')
last_revision = from_branch.last_revision()
- if last_revision is None:
- last_revision = _mod_revision.NULL_REVISION
+ last_revision = _mod_revision.ensure_null(last_revision)
return self.repository.fetch(from_branch.repository,
revision_id=last_revision,
pb=nested_pb)
@@ -1394,6 +1393,7 @@
configured to check constraints on history, in which case this may not
be permitted.
"""
+ revision_id = _mod_revision.ensure_null(revision_id)
history = self._lefthand_history(revision_id)
assert len(history) == revno, '%d != %d' % (len(history), revno)
self.set_revision_history(history)
@@ -1410,21 +1410,23 @@
if 'evil' in debug.debug_flags:
mutter_callsite(4, "_lefthand_history scales with history.")
# stop_revision must be a descendant of last_revision
- stop_graph = self.repository.get_revision_graph(revision_id)
- if (last_rev is not None and last_rev != _mod_revision.NULL_REVISION
- and last_rev not in stop_graph):
- # our previous tip is not merged into stop_revision
- raise errors.DivergedBranches(self, other_branch)
+ graph = self.repository.get_graph()
+ if last_rev is not None:
+ if not graph.is_ancestor(last_rev, revision_id):
+ # our previous tip is not merged into stop_revision
+ raise errors.DivergedBranches(self, other_branch)
# make a new revision history from the graph
+ parents_map = graph.get_parent_map([revision_id])
+ if revision_id not in parents_map:
+ raise errors.NoSuchRevision(self, revision_id)
current_rev_id = revision_id
new_history = []
- while current_rev_id not in (None, _mod_revision.NULL_REVISION):
+ # Do not include ghosts or graph origin in revision_history
+ while (current_rev_id in parents_map and
+ len(parents_map[current_rev_id]) > 0):
new_history.append(current_rev_id)
- current_rev_id_parents = stop_graph[current_rev_id]
- try:
- current_rev_id = current_rev_id_parents[0]
- except IndexError:
- current_rev_id = None
+ current_rev_id = parents_map[current_rev_id][0]
+ parents_map = graph.get_parent_map([current_rev_id])
new_history.reverse()
return new_history
@@ -1824,13 +1826,13 @@
Intended to be called by set_last_revision_info and
_write_revision_history.
"""
- if revision_id is None:
- revision_id = 'null:'
+ assert revision_id is not None, "Use NULL_REVISION, not None"
out_string = '%d %s\n' % (revno, revision_id)
self.control_files.put_bytes('last-revision', out_string)
@needs_write_lock
def set_last_revision_info(self, revno, revision_id):
+ revision_id = _mod_revision.ensure_null(revision_id)
if self._get_append_revisions_only():
self._check_history_violation(revision_id)
self._write_last_revision_info(revno, revision_id)
@@ -1959,6 +1961,14 @@
def _make_tags(self):
return BasicTags(self)
+ @needs_write_lock
+ def generate_revision_history(self, revision_id, last_rev=None,
+ other_branch=None):
+ """See BzrBranch5.generate_revision_history"""
+ history = self._lefthand_history(revision_id, last_rev, other_branch)
+ revno = len(history)
+ self.set_last_revision_info(revno, revision_id)
+
######################################################################
# results of operations
=== modified file 'bzrlib/tests/branch_implementations/test_branch.py'
--- a/bzrlib/tests/branch_implementations/test_branch.py 2007-12-11 14:26:18 +0000
+++ b/bzrlib/tests/branch_implementations/test_branch.py 2008-03-04 21:59:33 +0000
@@ -214,6 +214,8 @@
wt = self.make_branch_and_tree('.')
wt.set_parent_ids(['non:existent at rev--ision--0--2'],
allow_leftmost_as_ghost=True)
+ self.assertEqual(['non:existent at rev--ision--0--2'],
+ wt.get_parent_ids())
rev_id = wt.commit('commit against a ghost first parent.')
rev = wt.branch.repository.get_revision(rev_id)
self.assertEqual(rev.parent_ids, ['non:existent at rev--ision--0--2'])
=== modified file 'bzrlib/tests/branch_implementations/test_revision_history.py'
--- a/bzrlib/tests/branch_implementations/test_revision_history.py 2007-08-14 08:38:06 +0000
+++ b/bzrlib/tests/branch_implementations/test_revision_history.py 2008-03-05 10:08:28 +0000
@@ -19,6 +19,7 @@
from bzrlib import (
branch,
errors,
+ revision as _mod_revision,
)
from bzrlib.tests.branch_implementations.test_branch import TestCaseWithBranch
@@ -139,7 +140,7 @@
# Lock the branch, set the last revision info, then call
# last_revision_info.
a_branch.lock_write()
- a_branch.set_last_revision_info(0, None)
+ a_branch.set_last_revision_info(0, _mod_revision.NULL_REVISION)
del calls[:]
try:
a_branch.last_revision_info()
@@ -147,6 +148,19 @@
finally:
a_branch.unlock()
+ def test_set_last_revision_info_none(self):
+ """Passing None to revision_info to None sets it to NULL_REVISION."""
+ a_branch = self.get_branch()
+ # Lock the branch, set the last revision info, then call
+ # last_revision_info.
+ a_branch.lock_write()
+ self.addCleanup(a_branch.unlock)
+ self.callDeprecated(['NULL_REVISION should be used for the null'
+ ' revision instead of None, as of bzr 0.91.'],
+ a_branch.set_last_revision_info, 0, None)
+ self.assertEqual((0, _mod_revision.NULL_REVISION),
+ a_branch.last_revision_info())
+
def test_set_last_revision_info_uncaches_revision_history_for_format6(self):
"""On format 6 branches, set_last_revision_info invalidates the revision
history cache.
@@ -158,7 +172,7 @@
a_branch.lock_write()
a_branch.revision_history()
# Set the last revision info, clearing the cache.
- a_branch.set_last_revision_info(0, None)
+ a_branch.set_last_revision_info(0, _mod_revision.NULL_REVISION)
del calls[:]
try:
a_branch.revision_history()
More information about the bazaar-commits
mailing list