Rev 4: Arf, lpto is already well known as gdfo, s/lpto/gdfo/ :) in file:///v/home/vila/.bazaar/plugins/gdfo/

Vincent Ladeuil v.ladeuil+lp at free.fr
Wed Oct 1 15:33:40 BST 2008


At file:///v/home/vila/.bazaar/plugins/gdfo/

------------------------------------------------------------
revno: 4
revision-id: v.ladeuil+lp at free.fr-20081001143340-moxbdi023r6pqke9
parent: v.ladeuil+lp at free.fr-20080913074548-rifgaaycas49r7qn
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: gdfo
timestamp: Wed 2008-10-01 16:33:40 +0200
message:
  Arf, lpto is already well known as gdfo, s/lpto/gdfo/ :)
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2008-09-13 07:45:48 +0000
+++ b/__init__.py	2008-10-01 14:33:40 +0000
@@ -14,15 +14,14 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-"""Calculate Longest Path To Origin"""
+"""Calculate Greatest Distance From Origin."""
 
 from bzrlib import commands
 
-class cmd_lpto(commands.Command):
+class cmd_gdfo(commands.Command):
     """Calculate longest path to origin starting at a given revision.
 
     By default the current branch is used and starts at the tip.
-
     """
 
     takes_args = ['location?']
@@ -37,11 +36,11 @@
             br.unlock()
 
     def _run(self, br):
-        for lpto, revno, revid in calculate_lptos(br):
-            print '%r:%r:%r:%r:%r' % (lpto, revno, depth, revid)
-
-
-def calculate_lptos(br):
+        for gdfo, revno, depth, revid in calculate_gdfos(br):
+            print '%r:%r:%r:%r' % (gdfo, revno, depth, revid)
+
+
+def calculate_gdfos(br):
     from bzrlib import (
         graph,
         log,
@@ -56,34 +55,41 @@
 
     merge_sorted_revisions.reverse()
     revs = []
-    lptos = {'null:':0}
+    # Calculate the longest paths to origin, starting at the null revision and
+    # going forward in time.
+    gdfos = {'null:':0}
     previous = None
     for seq, revid, depth, revno, end_of_merge in merge_sorted_revisions:
         if previous is None:
-            lpto = 1
+            # First revision
+            gdfo = 1
         else:
+            # Any other revision will receive the highest gdfo among its
+            # parents plus one.
             parents = gr.get_parent_map([revid]).get(revid)
-            if not parents:
-                # Ghost, we are doomed
-                import pdb; pdb.set_trace()
-            else:
-                lpto = 0
+            if parents: # Ghosts have no parents but are recognized below
+                gdfo = 0
                 for p in parents:
                     try:
-                        parent_lpto = lptos[p]
-                        if  parent_lpto > lpto:
-                            lpto = parent_lpto + 1
+                        parent_gdfo = gdfos[p]
+                        if  parent_gdfo > gdfo:
+                            gdfo = parent_gdfo + 1
                     except KeyError:
-                        # merge_sort (reversed) guarantees that we see the
-                        # parents before the children, this should be ghost.
+                        # We didn't find a parent for a revision. Yet we
+                        # started with a list of revisions in merge sort order,
+                        # so all parents must appear before any of their
+                        # children. We have a ghost. Greatest path from origin
+                        # is therefore undefined. Since a ghost can only appear
+                        # in a merge, there is at least one parent whose gdfo
+                        # can be used (the mainline one).
                         pass
-        lptos[revid] = lpto
-        revs.append((lpto, revno, depth, revid))
+        gdfos[revid] = gdfo
+        revs.append((gdfo, revno, depth, revid))
         previous = revid
 
     return revs
 
-commands.register_command(cmd_lpto)
+commands.register_command(cmd_gdfo)
 
 
 def load_tests(basic_tests, module, loader):

=== modified file 'tests/__init__.py'
--- a/tests/__init__.py	2008-09-12 16:01:52 +0000
+++ b/tests/__init__.py	2008-10-01 14:33:40 +0000
@@ -20,7 +20,7 @@
     # unwanted tests and I think that's sufficient.
 
     testmod_names = [
-        'test_lpto',
+        'test_gdfo',
         ]
     basic_tests.addTest(loader.loadTestsFromModuleNames(
             ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))

=== renamed file 'tests/test_lpto.py' => 'tests/test_gdfo.py'
--- a/tests/test_lpto.py	2008-09-13 07:45:48 +0000
+++ b/tests/test_gdfo.py	2008-10-01 14:33:40 +0000
@@ -18,20 +18,20 @@
     tests,
     )
 
-from bzrlib.plugins import lpto
-
-class TestCalculateLptos(tests.TestCaseWithMemoryTransport):
-
-    def _get_lptos(self, br):
+from bzrlib.plugins import gdfo
+
+class TestCalculateGdfos(tests.TestCaseWithMemoryTransport):
+
+    def _get_gdfos(self, br):
         br.lock_read()
         try:
-            return lpto.calculate_lptos(br)
+            return gdfo.calculate_gdfos(br)
         finally:
             br.unlock()
 
     def test_empty_branch(self):
         builder = self.make_branch_builder('path')
-        self.assertEqual([], self._get_lptos(builder.get_branch()))
+        self.assertEqual([], self._get_gdfos(builder.get_branch()))
 
     def test_simple_mainline(self):
         builder = self.make_branch_builder('path')
@@ -39,12 +39,12 @@
                                [('add', ('', 'a-root-id', 'directory', None))])
         builder.build_snapshot('B-id', ['A-id'], [])
         builder.build_snapshot('C-id', ['B-id'], [])
-        # FIXME: Since we use not tree, the following fails, that's a bug.
+        # FIXME: Since we use no tree, the following fails, that's a bug.
         # builder.finish_series()
         self.assertEqual([(1, (1,), 0, 'A-id'),
                           (2, (2,), 0, 'B-id'),
                           (3, (3,), 0, 'C-id')],
-                         self._get_lptos(builder.get_branch()))
+                         self._get_gdfos(builder.get_branch()))
 
     def test_simple_merge(self):
         builder = self.make_branch_builder('path')
@@ -54,12 +54,14 @@
         builder.build_snapshot('C-id', ['B-id'], [])
         builder.build_snapshot('D-id', ['A-id'], [])
         builder.build_snapshot('E-id', ['C-id', 'D-id'], [])
-        # FIXME: Since we use no tree, the following fails, that's a bug.
-        # builder.finish_series()
+        # FIXME: Since we use no tree, the following fails, that's a bug in
+        # builder.finish_series() or at least a shortcoming
+        gdfos = self._get_gdfos(builder.get_branch())
         self.assertEqual([(1, (1,), 0, 'A-id'),
                           (2, (2,), 0, 'B-id'),
                           (3, (3,), 0, 'C-id'),
                           (2, (1, 1, 1), 1, 'D-id'),
                           (4, (4,), 0, 'E-id'),
                          ],
-                         self._get_lptos(builder.get_branch()))
+                         gdfos)
+        



More information about the bazaar-commits mailing list