Rev 3429: switch find_unmerged to use the new function in http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/missing
John Arbash Meinel
john at arbash-meinel.com
Mon May 19 22:36:03 BST 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.6-dev/missing
------------------------------------------------------------
revno: 3429
revision-id: john at arbash-meinel.com-20080519213552-8jc1yc4w8rqhgzri
parent: john at arbash-meinel.com-20080519203537-6dqmxtn6fxlk1ter
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: missing
timestamp: Mon 2008-05-19 16:35:52 -0500
message:
switch find_unmerged to use the new function
The api is very compatible, so we don't really need to expose a new function.
So make it hidden, and leave find_unmerged to take out the write lock and call it.
modified:
bzrlib/missing.py missing.py-20050812153334-097f7097e2a8bcd1
bzrlib/tests/test_missing.py test_missing.py-20051212000028-694fa4f658a81f48
-------------- next part --------------
=== modified file 'bzrlib/missing.py'
--- a/bzrlib/missing.py 2008-05-19 20:35:37 +0000
+++ b/bzrlib/missing.py 2008-05-19 21:35:52 +0000
@@ -16,7 +16,6 @@
"""Display what revisions are missing in 'other' from 'this' and vice versa."""
-from bzrlib import ui
from bzrlib.log import (
LogRevision,
)
@@ -43,47 +42,17 @@
yield LogRevision(rev, revno, delta=delta)
-def find_unmerged(local_branch, remote_branch):
- progress = ui.ui_factory.nested_progress_bar()
+def find_unmerged(local_branch, remote_branch, restrict='all'):
local_branch.lock_read()
try:
remote_branch.lock_read()
try:
- # check for special case: both branches are equivalent
- if (local_branch.last_revision_info() ==
- remote_branch.last_revision_info()):
- return [], []
- local_rev_history, local_rev_history_map = \
- _get_history(local_branch, progress, "local", 0)
- remote_rev_history, remote_rev_history_map = \
- _get_history(remote_branch, progress, "remote", 1)
- result = _shortcut(local_rev_history, remote_rev_history)
- if result is not None:
- local_extra, remote_extra = result
- local_extra = sorted_revisions(local_extra,
- local_rev_history_map)
- remote_extra = sorted_revisions(remote_extra,
- remote_rev_history_map)
- return local_extra, remote_extra
-
- local_ancestry = _get_ancestry(local_branch.repository, progress,
- "local", 2, local_rev_history)
- remote_ancestry = _get_ancestry(remote_branch.repository, progress,
- "remote", 3, remote_rev_history)
- progress.update('pondering', 4, 5)
- extras = local_ancestry.symmetric_difference(remote_ancestry)
- local_extra = extras.intersection(set(local_rev_history))
- remote_extra = extras.intersection(set(remote_rev_history))
- local_extra = sorted_revisions(local_extra, local_rev_history_map)
- remote_extra = sorted_revisions(remote_extra,
- remote_rev_history_map)
-
+ return _find_unmerged(local_branch,
+ remote_branch, restrict=restrict)
finally:
remote_branch.unlock()
finally:
local_branch.unlock()
- progress.finished()
- return (local_extra, remote_extra)
def _enumerate_mainline(ancestry, graph, tip_revno, tip):
@@ -101,7 +70,7 @@
if not ancestry: #Empty ancestry, no need to do any work
return []
- # Optionally we could make 1 call to graph.get_parent_map with all
+ # Optionally, we could make 1 call to graph.get_parent_map with all
# ancestors. However that will often check many more parents than we
# actually need, and the Graph is likely to already have the parents cached
# anyway.
@@ -110,16 +79,17 @@
cur_revno = tip_revno
while cur in ancestry:
parent_map = graph.get_parent_map([cur])
- if cur not in parent_map:
+ parents = parent_map.get(cur)
+ if not parents:
break # Ghost, we are done
mainline.append((cur_revno, cur))
- cur = parent_map[cur]
+ cur = parents[0]
cur_revno -= 1
mainline.reverse()
return mainline
-def find_unmerged_mainline_revisions(local_branch, remote_branch, restrict):
+def _find_unmerged(local_branch, remote_branch, restrict):
"""Find revisions from each side that have not been merged.
Both branches should already be locked.
@@ -165,41 +135,6 @@
return local_mainline, remote_mainline
-def _shortcut(local_rev_history, remote_rev_history):
- local_history = set(local_rev_history)
- remote_history = set(remote_rev_history)
- if len(local_rev_history) == 0:
- return set(), remote_history
- elif len(remote_rev_history) == 0:
- return local_history, set()
- elif local_rev_history[-1] in remote_history:
- return set(), _after(remote_rev_history, local_rev_history)
- elif remote_rev_history[-1] in local_history:
- return _after(local_rev_history, remote_rev_history), set()
- else:
- return None
-
-def _after(larger_history, smaller_history):
- return set(larger_history[larger_history.index(smaller_history[-1])+1:])
-
-def _get_history(branch, progress, label, step):
- progress.update('%s history' % label, step, 5)
- rev_history = branch.revision_history()
- rev_history_map = dict(
- [(rev, rev_history.index(rev) + 1)
- for rev in rev_history])
- return rev_history, rev_history_map
-
-def _get_ancestry(repository, progress, label, step, rev_history):
- progress.update('%s ancestry' % label, step, 5)
- if len(rev_history) > 0:
- ancestry = set(repository.get_ancestry(rev_history[-1],
- topo_sorted=False))
- else:
- ancestry = set()
- return ancestry
-
-
def sorted_revisions(revisions, history_map):
revisions = [(history_map[r],r) for r in revisions]
revisions.sort()
=== modified file 'bzrlib/tests/test_missing.py'
--- a/bzrlib/tests/test_missing.py 2008-05-19 20:35:37 +0000
+++ b/bzrlib/tests/test_missing.py 2008-05-19 21:35:52 +0000
@@ -22,7 +22,6 @@
tests,
)
from bzrlib.missing import (
- find_unmerged,
iter_log_revisions,
)
from bzrlib.tests import TestCaseWithTransport
@@ -31,6 +30,10 @@
class TestMissing(TestCaseWithTransport):
+ def assertUnmerged(self, expected, source, target, restrict='all'):
+ unmerged = missing.find_unmerged(source, target, restrict=restrict)
+ self.assertEqual(expected, unmerged)
+
def test_find_unmerged(self):
original_tree = self.make_branch_and_tree('original')
original = original_tree.branch
@@ -38,26 +41,26 @@
puller = puller_tree.branch
merger_tree = self.make_branch_and_tree('merger')
merger = merger_tree.branch
- self.assertEqual(find_unmerged(original, puller), ([], []))
+ self.assertUnmerged(([], []), original, puller)
original_tree.commit('a', rev_id='a')
- self.assertEqual(find_unmerged(original, puller), ([(1, u'a')], []))
+ self.assertUnmerged(([(1, 'a')], []), original, puller)
puller_tree.pull(original)
- self.assertEqual(find_unmerged(original, puller), ([], []))
+ self.assertUnmerged(([], []), original, puller)
merger_tree.pull(original)
original_tree.commit('b', rev_id='b')
original_tree.commit('c', rev_id='c')
- self.assertEqual(find_unmerged(original, puller), ([(2, u'b'),
- (3, u'c')], []))
+ self.assertUnmerged(([(2, 'b'), (3, 'c')], []),
+ original, puller)
puller_tree.pull(original)
- self.assertEqual(find_unmerged(original, puller), ([], []))
- self.assertEqual(find_unmerged(original, merger), ([(2, u'b'),
- (3, u'c')], []))
+ self.assertUnmerged(([], []), original, puller)
+ self.assertUnmerged(([(2, 'b'), (3, 'c')], []),
+ original, merger)
merger_tree.merge_from_branch(original)
- self.assertEqual(find_unmerged(original, merger), ([(2, u'b'),
- (3, u'c')], []))
+ self.assertUnmerged(([(2, 'b'), (3, 'c')], []),
+ original, merger)
merger_tree.commit('d', rev_id='d')
- self.assertEqual(find_unmerged(original, merger), ([], [(2, 'd')]))
+ self.assertUnmerged(([], [(2, 'd')]), original, merger)
def test_iter_log_revisions(self):
base_tree = self.make_branch_and_tree('base')
@@ -80,8 +83,8 @@
child_tree.rename_one('b', 'c')
child_tree.commit('rename b=>c', rev_id='c-5')
- base_extra, child_extra = find_unmerged(base_tree.branch,
- child_tree.branch)
+ base_extra, child_extra = missing.find_unmerged(base_tree.branch,
+ child_tree.branch)
results = list(iter_log_revisions(base_extra,
base_tree.branch.repository,
verbose=True))
@@ -129,12 +132,12 @@
self.assertEqual([], delta3.modified)
-class TestFindUnmergedMainlineRevisions(tests.TestCaseWithTransport):
+class TestFindUnmerged(tests.TestCaseWithTransport):
def assertUnmerged(self, local, remote, local_branch, remote_branch,
restrict):
"""Check the output of find_unmerged_mainline_revisions"""
- local_extra, remote_extra = missing.find_unmerged_mainline_revisions(
+ local_extra, remote_extra = missing.find_unmerged(
local_branch, remote_branch, restrict)
self.assertEqual(local, local_extra)
self.assertEqual(remote, remote_extra)
@@ -172,3 +175,18 @@
self.assertUnmerged(None, [(2, rev2)], tree.branch, tree2.branch,
'remote')
+ def test_merged(self):
+ tree = self.make_branch_and_tree('tree')
+ rev1 = tree.commit('one')
+ tree2 = tree.bzrdir.sprout('tree2').open_workingtree()
+ rev2 = tree2.commit('two')
+ rev3 = tree2.commit('three')
+ tree.merge_from_branch(tree2.branch)
+ rev4 = tree.commit('four')
+
+ tree.lock_read()
+ self.addCleanup(tree.unlock)
+ tree2.lock_read()
+ self.addCleanup(tree2.unlock)
+
+ self.assertUnmerged([(2, rev4)], [], tree.branch, tree2.branch, 'all')
More information about the bazaar-commits
mailing list