Rev 3823: Bring in the caching-basis logic for generic fetch. in http://bzr.arbash-meinel.com/branches/bzr/brisbane/generic_fetch_ordering
John Arbash Meinel
john at arbash-meinel.com
Wed Feb 18 17:13:56 GMT 2009
At http://bzr.arbash-meinel.com/branches/bzr/brisbane/generic_fetch_ordering
------------------------------------------------------------
revno: 3823
revision-id: john at arbash-meinel.com-20090218171343-4l9rgozo4hbj3l2h
parent: john at arbash-meinel.com-20090218163618-isb3yg01ygdx3m2n
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: generic_fetch_ordering
timestamp: Wed 2009-02-18 11:13:43 -0600
message:
Bring in the caching-basis logic for generic fetch.
-------------- next part --------------
=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py 2009-02-18 14:57:11 +0000
+++ b/bzrlib/repository.py 2009-02-18 17:13:43 +0000
@@ -3278,15 +3278,43 @@
return False
return True
- def _fetch_batch(self, revision_ids, basis_id, basis_tree):
+ def _get_delta_for_revision(self, basis_id, basis_tree, last_batch,
+ new_batch, tree, parent_ids):
+ """Get the best delta and base for this revision.
+
+ :return: (basis_id, basis_tree, delta)
+ """
+ possible_trees = []
+ for parent_id in parent_ids:
+ if parent_id == basis_id:
+ possible_trees.append((basis_id, basis_tree))
+ elif parent_id in new_batch:
+ possible_trees.append((parent_id, new_batch[parent_id]))
+ elif parent_id in last_batch:
+ possible_trees.append((parent_id, last_batch[parent_id]))
+ if len(possible_trees) == 0:
+ # There either aren't any parents, or the parents aren't in the
+ # caches, so just use the last converted tree
+ possible_trees.append((basis_id, basis_tree))
+ deltas = []
+ for basis_id, basis_tree in possible_trees:
+ delta = tree.inventory._make_delta(basis_tree.inventory)
+ deltas.append((len(delta), basis_id, basis_tree, delta))
+ deltas.sort()
+ return deltas[0][1:]
+
+ def _fetch_batch(self, revision_ids, basis_id, basis_tree, last_batch):
"""Fetch across a few revisions.
:param revision_ids: The revisions to copy
:param basis_id: The revision_id of basis_tree
:param basis_tree: A tree that is not in revision_ids which should
already exist in the target.
- :return: (basis_id, basis_tree) A new basis to use now that these trees
- have been copied.
+ :param last_batch: A dict of {revid: rev_tree}. Used as potential basis
+ trees for computing a new delta.
+ :return: (basis_id, basis_tree, new_batch) A new basis to use now that
+ these trees have been copied, new_batch is a dict that can be
+ passed back in via last_batch
"""
# Walk though all revisions; get inventory deltas, copy referenced
# texts that delta references, insert the delta, revision and
@@ -3294,15 +3322,20 @@
text_keys = set()
pending_deltas = []
pending_revisions = []
+ new_batch = {}
+ parent_map = self.source.get_parent_map(revision_ids)
for tree in self.source.revision_trees(revision_ids):
current_revision_id = tree.get_revision_id()
- delta = tree.inventory._make_delta(basis_tree.inventory)
+ new_batch[current_revision_id] = tree
+ parent_ids = parent_map.get(current_revision_id, ())
+ basis_id, basis_tree, delta = self._get_delta_for_revision(
+ basis_id, basis_tree, last_batch, new_batch, tree, parent_ids)
+ # Find text entries that need to be copied
for old_path, new_path, file_id, entry in delta:
if new_path is not None:
if not (new_path or self.target.supports_rich_root()):
- # We leave the inventory delta in, because that
- # will have the deserialised inventory root
- # pointer.
+ # We don't copy the text for the root node unless the
+ # target supports_rich_root.
continue
# TODO: Do we need:
# "if entry.revision == current_revision_id" ?
@@ -3333,7 +3366,7 @@
except errors.NoSuchRevision:
pass
self.target.add_revision(revision.revision_id, revision)
- return basis_id, basis_tree
+ return basis_id, basis_tree, new_batch
def _fetch_all_revisions(self, revision_ids, pb):
"""Fetch everything for the list of revisions.
@@ -3345,14 +3378,15 @@
"""
basis_id, basis_tree = self._get_basis(revision_ids[0])
batch_size = 100
+ last_batch = {}
for offset in range(0, len(revision_ids), batch_size):
self.target.start_write_group()
try:
pb.update('Transferring revisions', offset,
len(revision_ids))
batch = revision_ids[offset:offset+batch_size]
- basis_id, basis_tree = self._fetch_batch(batch,
- basis_id, basis_tree)
+ basis_id, basis_tree, last_batch = self._fetch_batch(batch,
+ basis_id, basis_tree, last_batch)
except:
self.target.abort_write_group()
raise
More information about the bazaar-commits
mailing list