Rev 4: Start working on a write-out-for-dot functionality to help debugging. in http://bzr.arbash-meinel.com/plugins/test_graph

John Arbash Meinel john at arbash-meinel.com
Tue Dec 11 22:22:02 GMT 2007


At http://bzr.arbash-meinel.com/plugins/test_graph

------------------------------------------------------------
revno: 4
revision-id:john at arbash-meinel.com-20071211222132-7tb52l03llgx3kay
parent: john at arbash-meinel.com-20071211013859-953i0nvxzf5fo5iy
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: test_graph
timestamp: Tue 2007-12-11 16:21:32 -0600
message:
  Start working on a write-out-for-dot functionality to help debugging.
modified:
  __init__.py                    __init__.py-20071210194758-1pwa1q7e3wnjf418-1
  graph_testing.py               graph_testing.py-20071210194758-1pwa1q7e3wnjf418-2
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2007-12-10 19:47:59 +0000
+++ b/__init__.py	2007-12-11 22:21:32 +0000
@@ -35,3 +35,20 @@
         test_all(location)
 
 commands.register_command(cmd_test_graph)
+
+
+class cmd_disp_graph(commands.Commands):
+    """Create a subset graph.
+
+    This uses the raw output from _find_border_ancestors to figure out why a
+    node is, or is not considered an ancestor.
+    """
+
+    takes_options = ['revision']
+    takes_args = ['location?']
+
+    def run(self, revision=None, location='.'):
+        from graph_testing import graph_borders
+        graph_borders(location, revision, self.outf)
+
+commands.register_command(cmd_test_graph)

=== modified file 'graph_testing.py'
--- a/graph_testing.py	2007-12-11 01:38:59 +0000
+++ b/graph_testing.py	2007-12-11 22:21:32 +0000
@@ -64,14 +64,32 @@
         # We go in reverse order, so that we will tend to find the ancestries in
         # the map
         pb = ui.ui_factory.nested_progress_bar()
+        inner_hit = 0
         cache_hit = 0
         cache_miss = 0
+        import pdb; pdb.set_trace()
         for idx, interesting_id in enumerate(reversed(self.interesting)):
             pb.update('finding ancestries', idx, len(self.interesting))
             needed_ids = list(self.rev_graph[interesting_id]) + [interesting_id]
             for revision_id in needed_ids:
                 if revision_id in ancestries:
                     continue
+                ## # Special case when the parent ancestries are already present
+                ## parent_ids = self.rev_graph[revision_id]
+                ## for parent_id in parent_ids:
+                ##     if parent_id not in ancestries:
+                ##         break
+                ## else: # All parents already present
+                ##     if parent_ids:
+                ##         ancestry = ancestries[parent_ids[0]].copy()
+                ##         for parent_id in parent_ids[1:]:
+                ##             ancestry.update(ancestries[parent_id])
+                ##         ancestry.add(revision_id)
+                ##     else:
+                ##         ancestry = set([revision_id])
+                ##     ancestries[revision_id] = ancestry.copy()
+                ##     inner_hit += 1
+                ##     continue
                 ancestry = set([revision_id])
                 needed = set([revision_id])
                 while needed:
@@ -85,10 +103,12 @@
                         else: # We need to probe in this direction
                             cache_miss += 1
                             needed.add(parent_id)
-                ancestries[revision_id] = ancestry
+                ancestries[revision_id] = tuple(ancestry)
         pb.finished()
-        pb.note('Cache hit: %d, miss: %d', cache_hit, cache_miss)
+        pb.note('Cache hit: %d, miss: %d, inner: %d, nodes: %d', cache_hit, cache_miss,
+                inner_hit, len(ancestries))
         self.ancestries = ancestries
+        pdb.set_trace()
 
     def time_functions(self, a_branch):
         if self.hold_graph:
@@ -156,8 +176,8 @@
             finally:
                 a_branch.unlock()
             self.find_difference_times[revision_id] = t_diff
-            left_ancestry = self.ancestries[parent_ids[0]]
-            right_ancestry = self.ancestries[parent_ids[1]]
+            left_ancestry = frozenset(self.ancestries[parent_ids[0]])
+            right_ancestry = frozenset(self.ancestries[parent_ids[1]])
             left_correct = left == (left_ancestry - right_ancestry)
             right_correct = right == (right_ancestry - left_ancestry)
             if not left_correct and not right_correct:
@@ -223,3 +243,25 @@
     pprint.pprint(tester.get_statistics(tester.find_difference_times))
     import pdb; pdb.set_trace()
     the_branch.unlock()
+
+
+def graph_borders(location, revisionspec, to_file):
+    """Use _find_border_ancestors, and build up a dot graph."""
+    if revisionspec is None or len(revisionspec) != 2:
+        raise errors.BzrCommandError('you must supply 2 revisions')
+    the_branch = branch.Branch.open(location)
+    the_branch.lock_read()
+    try:
+        left_revision_id = revisionspec[0].in_history(the_branch).rev_id
+        right_revision_id = revisionspec[1].in_history(the_branch).rev_id
+        graph = the_branch.repository.get_graph()
+        border, common, (left, right) = graph._find_border_ancestors(
+            [left_revision_id, right_revision_id])
+        left_anc = set(the_branch.repository.get_ancestry(left_revision_id,
+                       topo_sorted=False))
+        right_anc = set(the_branch.repository.get_ancestry(right_revision_id,
+                        topo_sorted=False))
+        left_diff = left_anc - right_anc
+        right_diff = right_anc - left_diff
+    finally:
+        the_branch.unlock()



More information about the bazaar-commits mailing list