Rev 3039: (robertc) Change commit on pack repositories to use the per-file in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Nov 28 00:59:39 GMT 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 3039
revision-id:pqm at pqm.ubuntu.com-20071128005930-4wb5pl12fyq8ek13
parent: pqm at pqm.ubuntu.com-20071127221818-jsklce3rngimazga
parent: robertc at robertcollins.net-20071127225128-s5dr0ry09hj78kdl
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2007-11-28 00:59:30 +0000
message:
  (robertc) Change commit on pack repositories to use the per-file
  	graph for heads() calculations. (Robert Collins, 165306)
modified:
  bzrlib/graph.py                graph_walker.py-20070525030359-y852guab65d4wtn0-1
  bzrlib/index.py                index.py-20070712131115-lolkarso50vjr64s-1
  bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
    ------------------------------------------------------------
    revno: 2979.2.5
    revision-id:robertc at robertcollins.net-20071127225128-s5dr0ry09hj78kdl
    parent: robertc at robertcollins.net-20071127222643-86fymmfpn6xw88up
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: commit.merge-speed
    timestamp: Wed 2007-11-28 09:51:28 +1100
    message:
      Make CommitBuilder.heads be _heads as its internal to CommitBuilder only.
    modified:
      bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
    ------------------------------------------------------------
    revno: 2979.2.4
    revision-id:robertc at robertcollins.net-20071127222643-86fymmfpn6xw88up
    parent: robertc at robertcollins.net-20071114181956-osz2q0sa6v2wpb1b
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: commit.merge-speed
    timestamp: Wed 2007-11-28 09:26:43 +1100
    message:
      Docstring fixes from review.
    modified:
      bzrlib/index.py                index.py-20070712131115-lolkarso50vjr64s-1
    ------------------------------------------------------------
    revno: 2979.2.3
    revision-id:robertc at robertcollins.net-20071114181956-osz2q0sa6v2wpb1b
    parent: robertc at robertcollins.net-20071112225758-co7hf9fpdonhkzs8
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: commit.merge-speed
    timestamp: Thu 2007-11-15 05:19:56 +1100
    message:
      Tweaks from John.
    modified:
      bzrlib/index.py                index.py-20070712131115-lolkarso50vjr64s-1
    ------------------------------------------------------------
    revno: 2979.2.2
    revision-id:robertc at robertcollins.net-20071112225758-co7hf9fpdonhkzs8
    parent: robertc at robertcollins.net-20071112210301-da1gpusi4p68xhxj
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: commit.merge-speed
    timestamp: Tue 2007-11-13 09:57:58 +1100
    message:
      Per-file graph heads detection during commit for pack repositories.
    modified:
      bzrlib/graph.py                graph_walker.py-20070525030359-y852guab65d4wtn0-1
      bzrlib/index.py                index.py-20070712131115-lolkarso50vjr64s-1
      bzrlib/repofmt/pack_repo.py    pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
    ------------------------------------------------------------
    revno: 2979.2.1
    revision-id:robertc at robertcollins.net-20071112210301-da1gpusi4p68xhxj
    parent: pqm at pqm.ubuntu.com-20071112195430-0xgqswqpc1j2pk2m
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: commit.merge-speed
    timestamp: Tue 2007-11-13 08:03:01 +1100
    message:
      Make it possible for different commit builders to override heads().
    modified:
      bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
=== modified file 'bzrlib/graph.py'
--- a/bzrlib/graph.py	2007-11-27 20:35:02 +0000
+++ b/bzrlib/graph.py	2007-11-28 00:59:30 +0000
@@ -19,7 +19,6 @@
     tsort,
     )
 from bzrlib.deprecated_graph import (node_distances, select_farthest)
-from bzrlib.revision import NULL_REVISION
 
 # DIAGRAM of terminology
 #       A

=== modified file 'bzrlib/index.py'
--- a/bzrlib/index.py	2007-11-12 23:43:54 +0000
+++ b/bzrlib/index.py	2007-11-28 00:59:30 +0000
@@ -32,6 +32,7 @@
 lazy_import(globals(), """
 from bzrlib import trace
 from bzrlib.bisect_multi import bisect_multi_bytes
+from bzrlib.revision import NULL_REVISION
 from bzrlib.trace import mutter
 """)
 from bzrlib import debug, errors
@@ -994,6 +995,35 @@
                 self.__class__.__name__,
                 ', '.join(map(repr, self._indices)))
 
+    def get_parents(self, revision_ids):
+        """See StackedParentsProvider.get_parents.
+        
+        This implementation thunks the graph.Graph.get_parents api across to
+        GraphIndex.
+
+        :param revision_ids: An iterable of graph keys for this graph.
+        :return: A list of parent details for each key in revision_ids.
+            Each parent details will be one of:
+             * None when the key was missing
+             * (NULL_REVISION,) when the key has no parents.
+             * (parent_key, parent_key...) otherwise.
+        """
+        search_keys = set(revision_ids)
+        search_keys.discard(NULL_REVISION)
+        found_parents = {NULL_REVISION:[]}
+        for index, key, value, refs in self.iter_entries(search_keys):
+            parents = refs[0]
+            if not parents:
+                parents = (NULL_REVISION,)
+            found_parents[key] = parents
+        result = []
+        for key in revision_ids:
+            try:
+                result.append(found_parents[key])
+            except KeyError:
+                result.append(None)
+        return result
+
     def insert_index(self, pos, index):
         """Insert a new index in the list of indices to query.
 
@@ -1128,7 +1158,7 @@
         """Iterate over keys within the index.
 
         :param keys: An iterable providing the keys to be retrieved.
-        :return: An iterable of (index, key, reference_lists, value). There is no
+        :return: An iterable of (index, key, value, reference_lists). There is no
             defined order for the result iteration - it will be in the most
             efficient order for the index (keys iteration order in this case).
         """
@@ -1312,7 +1342,7 @@
         """Iterate over keys within the index.
 
         :param keys: An iterable providing the keys to be retrieved.
-        :return: An iterable of (key, reference_lists, value). There is no
+        :return: An iterable of (index, key, value, reference_lists). There is no
             defined order for the result iteration - it will be in the most
             efficient order for the index (keys iteration order in this case).
         """

=== modified file 'bzrlib/repofmt/pack_repo.py'
--- a/bzrlib/repofmt/pack_repo.py	2007-11-27 20:35:02 +0000
+++ b/bzrlib/repofmt/pack_repo.py	2007-11-28 00:59:30 +0000
@@ -26,6 +26,7 @@
         pack,
         ui,
         )
+from bzrlib.graph import Graph
 from bzrlib.index import (
     GraphIndex,
     GraphIndexBuilder,
@@ -73,11 +74,24 @@
     added text, reducing memory and object pressure.
     """
 
+    def __init__(self, repository, parents, config, timestamp=None,
+                 timezone=None, committer=None, revprops=None,
+                 revision_id=None):
+        CommitBuilder.__init__(self, repository, parents, config,
+            timestamp=timestamp, timezone=timezone, committer=committer,
+            revprops=revprops, revision_id=revision_id)
+        self._file_graph = Graph(
+            repository._pack_collection.text_index.combined_index)
+
     def _add_text_to_weave(self, file_id, new_lines, parents, nostore_sha):
         return self.repository._pack_collection._add_text_to_weave(file_id,
             self._new_revision_id, new_lines, parents, nostore_sha,
             self.random_revid)
 
+    def _heads(self, file_id, revision_ids):
+        keys = [(file_id, revision_id) for revision_id in revision_ids]
+        return set([key[1] for key in self._file_graph.heads(keys)])
+
 
 class PackRootCommitBuilder(RootCommitBuilder):
     """A subclass of RootCommitBuilder to add texts with pack semantics.
@@ -86,11 +100,24 @@
     added text, reducing memory and object pressure.
     """
 
+    def __init__(self, repository, parents, config, timestamp=None,
+                 timezone=None, committer=None, revprops=None,
+                 revision_id=None):
+        CommitBuilder.__init__(self, repository, parents, config,
+            timestamp=timestamp, timezone=timezone, committer=committer,
+            revprops=revprops, revision_id=revision_id)
+        self._file_graph = Graph(
+            repository._pack_collection.text_index.combined_index)
+
     def _add_text_to_weave(self, file_id, new_lines, parents, nostore_sha):
         return self.repository._pack_collection._add_text_to_weave(file_id,
             self._new_revision_id, new_lines, parents, nostore_sha,
             self.random_revid)
 
+    def _heads(self, file_id, revision_ids):
+        keys = [(file_id, revision_id) for revision_id in revision_ids]
+        return set([key[1] for key in self._file_graph.heads(keys)])
+
 
 class Pack(object):
     """An in memory proxy for a pack and its indices.

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2007-11-25 17:54:55 +0000
+++ b/bzrlib/repository.py	2007-11-28 00:59:30 +0000
@@ -76,8 +76,8 @@
     # the default CommitBuilder does not manage trees whose root is versioned.
     _versioned_root = False
 
-    def __init__(self, repository, parents, config, timestamp=None, 
-                 timezone=None, committer=None, revprops=None, 
+    def __init__(self, repository, parents, config, timestamp=None,
+                 timezone=None, committer=None, revprops=None,
                  revision_id=None):
         """Initiate a CommitBuilder.
 
@@ -118,7 +118,7 @@
             self._timezone = int(timezone)
 
         self._generate_revision_if_needed()
-        self._heads = graph.HeadsCache(repository.get_graph()).heads
+        self.__heads = graph.HeadsCache(repository.get_graph()).heads
 
     def commit(self, message):
         """Make the actual commit.
@@ -190,6 +190,14 @@
         else:
             self.random_revid = False
 
+    def _heads(self, file_id, revision_ids):
+        """Calculate the graph heads for revision_ids in the graph of file_id.
+
+        This can use either a per-file graph or a global revision graph as we
+        have an identity relationship between the two graphs.
+        """
+        return self.__heads(revision_ids)
+
     def _check_root(self, ie, parent_invs, tree):
         """Helper for record_entry_contents.
 
@@ -287,7 +295,7 @@
         # XXX: Friction: parent_candidates should return a list not a dict
         #      so that we don't have to walk the inventories again.
         parent_candiate_entries = ie.parent_candidates(parent_invs)
-        head_set = self._heads(parent_candiate_entries.keys())
+        head_set = self._heads(ie.file_id, parent_candiate_entries.keys())
         heads = []
         for inv in parent_invs:
             if ie.file_id in inv:




More information about the bazaar-commits mailing list