Rev 3304: Reduce code duplication as per review. in http://people.ubuntu.com/~robertc/baz2.0/versioned_files

Robert Collins robertc at robertcollins.net
Fri Mar 28 03:54:55 GMT 2008


At http://people.ubuntu.com/~robertc/baz2.0/versioned_files

------------------------------------------------------------
revno: 3304
revision-id: robertc at robertcollins.net-20080328035440-4cflvryqujresn2g
parent: robertc at robertcollins.net-20080327045412-rju4uoh3glidd2px
committer: Robert Collins <robertc at robertcollins.net>
branch nick: versionedfile.apicleanup
timestamp: Fri 2008-03-28 14:54:40 +1100
message:
  Reduce code duplication as per review.
modified:
  bzrlib/branch.py               branch.py-20050309040759-e4baf4e0d046576e
  bzrlib/log.py                  log.py-20050505065812-c40ce11702fe5fb1
  bzrlib/repository.py           rev_storage.py-20051111201905-119e9401e46257e3
  bzrlib/smart/repository.py     repository.py-20061128022038-vr5wy5bubyb8xttk-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py	2008-03-26 21:42:35 +0000
+++ b/bzrlib/branch.py	2008-03-28 03:54:40 +0000
@@ -25,6 +25,7 @@
         errors,
         lockdir,
         lockable_files,
+        repository,
         revision as _mod_revision,
         transport,
         tsort,
@@ -192,17 +193,8 @@
         :return: A dictionary mapping revision_id => dotted revno.
         """
         last_revision = self.last_revision()
-        graph = self.repository.get_graph()
-        search = graph._make_breadth_first_searcher([last_revision])
-        transitive_ids = set()
-        map(transitive_ids.update, list(search))
-        revision_graph = graph.get_parent_map(transitive_ids)
-        # Filter ghosts, and null:
-        if _mod_revision.NULL_REVISION in revision_graph:
-            del revision_graph[_mod_revision.NULL_REVISION]
-        for key, parents in revision_graph.items():
-            revision_graph[key] = tuple(parent for parent in parents if parent
-                in revision_graph)
+        revision_graph = repository._old_get_graph(self.repository,
+            last_revision)
         merge_sorted_revisions = tsort.merge_sort(
             revision_graph,
             last_revision,

=== modified file 'bzrlib/log.py'
--- a/bzrlib/log.py	2008-03-26 21:42:35 +0000
+++ b/bzrlib/log.py	2008-03-28 03:54:40 +0000
@@ -72,6 +72,7 @@
     get_terminal_encoding,
     terminal_width,
     )
+from bzrlib.repository import _strip_NULL_ghosts
 from bzrlib.revision import (
     NULL_REVISION,
     )
@@ -463,10 +464,8 @@
     # This asks for all mainline revisions, which means we only have to spider
     # sideways, rather than depth history. That said, its still size-of-history
     # and should be addressed.
-    search = graph._make_breadth_first_searcher(mainline_revisions)
-    transitive_ids = set()
-    map(transitive_ids.update, list(search))
-    parent_map = graph.get_parent_map(transitive_ids)
+    parent_map = dict(((key, value) for key, value in
+        graph.iter_ancestry(mainline_revisions) if value is not None))
     sorted_rev_list = topo_sort(parent_map.items())
     ancestry = {}
     for rev in sorted_rev_list:
@@ -516,18 +515,10 @@
     # This asks for all mainline revisions, which means we only have to spider
     # sideways, rather than depth history. That said, its still size-of-history
     # and should be addressed.
-    search = graph._make_breadth_first_searcher(mainline_revs)
-    transitive_ids = set()
-    map(transitive_ids.update, list(search))
-    parent_map = graph.get_parent_map(transitive_ids)
+    parent_map = dict(((key, value) for key, value in
+        graph.iter_ancestry(mainline_revs) if value is not None))
     # filter out ghosts; merge_sort errors on ghosts.
-    rev_graph = {}
-    # Filter ghosts, and null:
-    if NULL_REVISION in parent_map:
-        del parent_map[NULL_REVISION]
-    for key, parents in parent_map.iteritems():
-        rev_graph[key] = tuple(parent for parent in parents if parent in
-            parent_map)
+    rev_graph = _strip_NULL_ghosts(parent_map)
     merge_sorted_revisions = merge_sort(
         rev_graph,
         mainline_revs[-1],

=== modified file 'bzrlib/repository.py'
--- a/bzrlib/repository.py	2008-03-26 21:53:32 +0000
+++ b/bzrlib/repository.py	2008-03-28 03:54:40 +0000
@@ -3140,3 +3140,22 @@
                 if correct_parents != knit_parents:
                     wrong_parents[revision_id] = (knit_parents, correct_parents)
         return wrong_parents, unused_versions
+
+
+def _old_get_graph(repository, revision_id):
+    """DO NOT USE. That is all. I'm serious."""
+    graph = repository.get_graph()
+    revision_graph = dict(((key, value) for key, value in
+        graph.iter_ancestry([revision_id]) if value is not None))
+    return _strip_NULL_ghosts(revision_graph)
+
+
+def _strip_NULL_ghosts(revision_graph):
+    """Also don't use this. more compatibility code for unmigrated clients."""
+    # Filter ghosts, and null:
+    if _mod_revision.NULL_REVISION in revision_graph:
+        del revision_graph[_mod_revision.NULL_REVISION]
+    for key, parents in revision_graph.items():
+        revision_graph[key] = tuple(parent for parent in parents if parent
+            in revision_graph)
+    return revision_graph

=== modified file 'bzrlib/smart/repository.py'
--- a/bzrlib/smart/repository.py	2008-03-26 21:42:35 +0000
+++ b/bzrlib/smart/repository.py	2008-03-28 03:54:40 +0000
@@ -31,6 +31,7 @@
     SmartServerRequest,
     SuccessfulSmartServerResponse,
     )
+from bzrlib.repository import _strip_NULL_ghosts
 from bzrlib import revision as _mod_revision
 
 
@@ -210,12 +211,7 @@
         transitive_ids = set()
         map(transitive_ids.update, list(search))
         parent_map = graph.get_parent_map(transitive_ids)
-        revision_graph = {}
-        if _mod_revision.NULL_REVISION in parent_map:
-            del parent_map[_mod_revision.NULL_REVISION]
-        for key, parents in parent_map.iteritems():
-            revision_graph[key] = tuple(parent for parent in parents if
-                parent in parent_map)
+        revision_graph = _strip_NULL_ghosts(parent_map)
         if revision_id and revision_id not in revision_graph:
             # Note that we return an empty body, rather than omitting the body.
             # This way the client knows that it can always expect to find a body




More information about the bazaar-commits mailing list