Rev 1: Starting a plugin for testing James Westby's dotted function. in http://bzr.arbash-meinel.com/plugins/test_dotted
John Arbash Meinel
john at arbash-meinel.com
Wed Mar 12 22:02:10 GMT 2008
At http://bzr.arbash-meinel.com/plugins/test_dotted
------------------------------------------------------------
revno: 1
revision-id:john at arbash-meinel.com-20080312220101-296ommcwi5h5w6xa
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: test_dotted
timestamp: Wed 2008-03-12 17:01:01 -0500
message:
Starting a plugin for testing James Westby's dotted function.
added:
__init__.py __init__.py-20080312220049-80ql6i9qz3ljobc6-1
dotted.py dotted.py-20080312220049-80ql6i9qz3ljobc6-2
-------------- next part --------------
=== added file '__init__.py'
--- a/__init__.py 1970-01-01 00:00:00 +0000
+++ b/__init__.py 2008-03-12 22:01:01 +0000
@@ -0,0 +1,14 @@
+"""A simple wrapper plugin around James Westby's dotted.py implementation.
+"""
+
+
+from bzrlib import commands
+
+
+class cmd_test_dotted(commands.Command):
+
+ def run(self):
+ pass
+
+
+commands.register_command(cmd_test_dotted)
=== added file 'dotted.py'
--- a/dotted.py 1970-01-01 00:00:00 +0000
+++ b/dotted.py 2008-03-12 22:01:01 +0000
@@ -0,0 +1,113 @@
+
+def get_dotted_revision_number(parents_map, mainline_revision,
+ mainline_revision_number, other_revision):
+
+ revision_numbers = {}
+ mainline = []
+
+ # first number the mainline
+ current_mainline_node = mainline_revision
+ parents = parents_map[current_mainline_node]
+ current_revno = mainline_revision_number
+ # this holds a stack of the revisions that we need to consider
+ # as they may form a line of development that affects our
+ # outcome
+ revisions_to_consider = []
+ while parents:
+ revision_numbers[current_mainline_node] = current_revno
+ mainline.insert(0, current_mainline_node)
+ if len(parents) > 1:
+ revisions_to_consider.insert(0, (current_mainline_node, parents))
+ current_mainline_node = parents[0]
+ parents = parents_map[current_mainline_node]
+ current_revno -= 1
+
+ # now follow the other_revision's left hand parents
+ # back to the mainline
+ current_other_node = other_revision
+ while current_other_node not in mainline:
+ current_other_node = parents_map[current_other_node][0]
+
+ # pivot_node is that at which the other_revision's
+ # left hand history meets the mainline, and as such
+ # it is crucial to everything that happens later
+ pivot_node = current_other_node
+ pivot_index = mainline.index(pivot_node)
+ pivot_revno = pivot_index + 1
+ before_pivot = mainline[:pivot_index]
+
+ # quick check that we weren't asked to number a mainline
+ # revision
+ if current_other_node == other_revision:
+ return revision_numbers[other_revision]
+
+ # now we have to prune the revisions_to_consider
+ # to remove those that come earlier than the pivot_node
+ # we also remove the pivot_node, as any parents of it
+ # can't affect the revision number we are calculating
+ for rev in before_pivot + [pivot_node]:
+ if revisions_to_consider[0][0] == rev:
+ revisions_to_consider.pop(0)
+
+ # Now we have to start spidering out the revisions
+ # from the mainline to find in which branch the
+ # other_revision lives, and what order its branch
+ # was merged back in.
+ # This means that whenever we pop off the stack
+ # we chase the left-hand-ancestory back and
+ # keep a record of the right hand parents again.
+ # Then when we hit the mainline one of three things
+ # happen.
+ # 1. We hit earlier than the pivot revision - This
+ # means that this line, and all of the right
+ # hand ancestories can have no impact on the
+ # revision number we are after. Therefore
+ # we drop what we are doing and just move on
+ # to the next one.
+ # 2. We hit the pivot revision. This means we
+ # can now number a new branch in the race
+ # to merge back to the mainline, as we must
+ # have already numbered those that were
+ # merged in before this. The right hand
+ # parents can still affect the result, so we
+ # have to follow them back as well.
+ # 3. We hit later the pivot revision. This line
+ # cannot influence the revision number, but
+ # it is possible that the right hand parents
+ # can, so we have to start chasing them
+ # back as well.
+ def find_mainline_intersection(start_rev):
+ parents_stack = []
+ revisions_list = []
+ current_rev = start_rev
+ while current_rev not in mainline:
+ revisions_list.insert(0, current_rev)
+ parents = parents_map[current_rev]
+ current_rev = parents[0]
+ if len(parents) > 1:
+ parents_stack.insert(0, (current_rev, parents[1:]))
+ return (current_rev, parents_stack, revisions_list)
+
+ current_branch_number = 1
+
+ def do_numbering(revs_to_consider):
+ for (rev, parents) in revs_to_consider:
+ for parent in parents:
+ intersection, other_revs, revisions_list = find_mainline_intersection(parent)
+ if intersection in before_pivot:
+ # Case 1. Drop everthing and move to the next node
+ pass
+ elif intersection == pivot_node:
+ # Case 2.
+ revno_base = "%d.%d." % (pivot_revno, current_branch_number)
+ for index, number_rev in enumerate(revisions_list):
+ revision_numbers[number_rev] = revno_base + "%d" % (index + 1)
+ current_branch_number += 1
+ else:
+ # Case 3.
+ # TODO: could actually number some things here.
+ do_numbering(revs_to_consider)
+
+ return revision_numbers[other_revision]
+
+
More information about the bazaar-commits
mailing list