Rev 2: It *is* simpler. Basically, merge_sort ensures that the last mainline revision *is* the one that merged it. in http://bzr.arbash-meinel.com/plugins/find_mainline_rev
John Arbash Meinel
john at arbash-meinel.com
Thu Nov 1 19:37:33 GMT 2007
At http://bzr.arbash-meinel.com/plugins/find_mainline_rev
------------------------------------------------------------
revno: 2
revision-id:john at arbash-meinel.com-20071101193731-9k12asz8pye6b21l
parent: john at arbash-meinel.com-20071101191856-nq75rlbq0nwzm1tr
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: find_mainline_rev
timestamp: Thu 2007-11-01 14:37:31 -0500
message:
It *is* simpler. Basically, merge_sort ensures that the last mainline revision *is* the one that merged it.
modified:
__init__.py __init__.py-20071101191826-bpibqad1s9oeqw1d-1
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py 2007-11-01 19:18:56 +0000
+++ b/__init__.py 2007-11-01 19:37:31 +0000
@@ -35,63 +35,13 @@
[(node, parents) for node, parents in rev_graph.iteritems()],
tip_revision_id, generate_revno=True)
- node_offset = {}
- nodes = []
- target_node_offset = None
-
- # We've checked these nodes already
- # not_in_ancestry_of = set()
-
- def _check_in_ancestry(mainline_rev_id):
- found = False
- nodes_to_check = [mainline_rev_id]
- checked_nodes = set()
-
- while nodes_to_check:
- node = nodes_to_check.pop()
- checked_nodes.add(node)
- for parent in rev_graph[node]:
- # if parent in not_in_ancestry_of:
- # # We've checked this one in the past
- # continue
- if (parent not in node_offset
- or node_offset[parent] > target_node_offset):
- # This parent is too old
- continue
- if parent == revision_id:
- # Found it
- return True
- nodes_to_check.append(parent)
- # if we have gotten this far, then the node is not in the ancestry of
- # any of the nodes we checked
- # not_in_ancestry_of.update(checked_nodes)
- return False
-
- # topo_sorted starts from the tip and works backwards
- # this will be the list of all mainline revisions that happen after the
- # merged revision.
- mainline_revs = []
+ last_mainline = None
for num, rev_id, depth, dotted_revno, eo_merge in topo_sorted:
- node_offset[rev_id] = num
+ if depth == 0:
+ last_mainline = (dotted_revno, rev_id)
if rev_id == revision_id:
- target_node_offset = num
- print 'found node at %d' % (num,)
- if depth == 0:
- return revision_id
- break
- elif depth == 0:
- mainline_revs.append(rev_id)
-
- for main_rev_id in reversed(mainline_revs):
- # We have a mainline node, check if the desired node is in the
- # ancestry.
- if _check_in_ancestry(main_rev_id):
- return main_rev_id
- assert 'it should have been the last one'
- trace.warning("somehow we didn't find it in the ancestry,"
- " even though get_revision_graph said it was.")
- import pdb; pdb.set_trace()
- return None
+ return last_mainline
+ assert False, 'we should never get here'
class cmd_find_mainline_rev(commands.Command):
@@ -106,14 +56,16 @@
a_branch.lock_read()
try:
revision_id = revision[0].in_history(a_branch).rev_id
- mainline_revision_id = _find_mainline_rev(a_branch, revision_id)
+ mainline_info = _find_mainline_rev(a_branch, revision_id)
finally:
a_branch.unlock()
- if mainline_revision_id is None:
+ if mainline_info is None:
trace.note('Revision not present in ancestry')
return 1
else:
- self.outf.write(mainline_revision_id + '\n')
+ split_revno, mainline_revision_id = mainline_info
+ assert len(split_revno) == 1
+ self.outf.write('%d %s\n' % (split_revno[0], mainline_revision_id))
commands.register_command(cmd_find_mainline_rev)
More information about the bazaar-commits
mailing list