Rev 3976: add stop-rule to iter_merge_sorted_revisions() (Ian Clatworthy) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Sat Jan 31 23:19:36 GMT 2009
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3976
revision-id: pqm at pqm.ubuntu.com-20090131231933-8o4phfvmuuizyyn6
parent: pqm at pqm.ubuntu.com-20090130185542-dbj7mapm1fvtwm3y
parent: ian.clatworthy at canonical.com-20090131223819-uufv50vychm3mnki
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sat 2009-01-31 23:19:33 +0000
message:
add stop-rule to iter_merge_sorted_revisions() (Ian Clatworthy)
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/tests/branch_implementations/test_iter_merge_sorted_revisions.py test_merge_sorted_re-20090121004847-to3gvjwigstu93eh-1
------------------------------------------------------------
revno: 3975.1.1
revision-id: ian.clatworthy at canonical.com-20090131223819-uufv50vychm3mnki
parent: pqm at pqm.ubuntu.com-20090130185542-dbj7mapm1fvtwm3y
parent: ian.clatworthy at canonical.com-20090129091435-s719ii56so4q826r
committer: Ian Clatworthy <ian.clatworthy at canonical.com>
branch nick: ianc-integration
timestamp: Sun 2009-02-01 08:38:19 +1000
message:
add stop-rule to iter_merge_sorted_revisions()
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/tests/branch_implementations/test_iter_merge_sorted_revisions.py test_merge_sorted_re-20090121004847-to3gvjwigstu93eh-1
------------------------------------------------------------
revno: 3960.3.4
revision-id: ian.clatworthy at canonical.com-20090129091435-s719ii56so4q826r
parent: ian.clatworthy at canonical.com-20090127043046-0x22acyb7jbanlfl
committer: Ian Clatworthy <ian.clatworthy at canonical.com>
branch nick: bzr.merge_sorted_revisions
timestamp: Thu 2009-01-29 19:14:35 +1000
message:
implement with-merges by checking for left-hand parent, not depth
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
------------------------------------------------------------
revno: 3960.3.3
revision-id: ian.clatworthy at canonical.com-20090127043046-0x22acyb7jbanlfl
parent: ian.clatworthy at canonical.com-20090127042757-slszc22d2p34ualk
committer: Ian Clatworthy <ian.clatworthy at canonical.com>
branch nick: bzr.merge_sorted_revisions
timestamp: Tue 2009-01-27 14:30:46 +1000
message:
apply fix for single revision case
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
------------------------------------------------------------
revno: 3960.3.2
revision-id: ian.clatworthy at canonical.com-20090127042757-slszc22d2p34ualk
parent: ian.clatworthy at canonical.com-20090127001039-ill4gah3eqx7w7gz
committer: Ian Clatworthy <ian.clatworthy at canonical.com>
branch nick: bzr.merge_sorted_revisions
timestamp: Tue 2009-01-27 14:27:57 +1000
message:
add single revision tests
modified:
bzrlib/tests/branch_implementations/test_iter_merge_sorted_revisions.py test_merge_sorted_re-20090121004847-to3gvjwigstu93eh-1
------------------------------------------------------------
revno: 3960.3.1
revision-id: ian.clatworthy at canonical.com-20090127001039-ill4gah3eqx7w7gz
parent: pqm at pqm.ubuntu.com-20090126181248-yl5ctbxc3y6nu9m4
committer: Ian Clatworthy <ian.clatworthy at canonical.com>
branch nick: bzr.merge_sorted_revisions
timestamp: Tue 2009-01-27 10:10:39 +1000
message:
add stop_rule to Branch.iter_merge_sorted_revisions()
modified:
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/tests/branch_implementations/test_iter_merge_sorted_revisions.py test_merge_sorted_re-20090121004847-to3gvjwigstu93eh-1
=== modified file 'bzrlib/branch.py'
--- a/bzrlib/branch.py 2009-01-24 04:03:08 +0000
+++ b/bzrlib/branch.py 2009-01-29 09:14:35 +0000
@@ -291,7 +291,7 @@
@needs_read_lock
def iter_merge_sorted_revisions(self, start_revision_id=None,
- stop_revision_id=None, direction='reverse'):
+ stop_revision_id=None, stop_rule='exclude', direction='reverse'):
"""Walk the revisions for a branch in merge sorted order.
Merge sorted order is the output from a merge-aware,
@@ -301,8 +301,13 @@
:param start_revision_id: the revision_id to begin walking from.
If None, the branch tip is used.
:param stop_revision_id: the revision_id to terminate the walk
- after (i.e. the range is inclusive). If None, the rest of
- history is included.
+ after. If None, the rest of history is included.
+ :param stop_rule: if stop_revision_id is not None, the precise rule
+ to use for termination:
+ * 'exclude' - leave the stop revision out of the result (default)
+ * 'include' - the stop revision is the last item in the result
+ * 'with-merges' - include the stop revision and all of its
+ merged revisions in the result
:param direction: either 'reverse' or 'forward':
* reverse means return the start_revision_id first, i.e.
start at the most recent revision and go backwards in history
@@ -341,7 +346,7 @@
filtered = self._filter_merge_sorted_revisions(
self._merge_sorted_revisions_cache, start_revision_id,
- stop_revision_id)
+ stop_revision_id, stop_rule)
if direction == 'reverse':
return filtered
if direction == 'forward':
@@ -350,7 +355,7 @@
raise ValueError('invalid direction %r' % direction)
def _filter_merge_sorted_revisions(self, merge_sorted_revisions,
- start_revision_id, stop_revision_id):
+ start_revision_id, stop_revision_id, stop_rule):
"""Iterate over an inclusive range of sorted revisions."""
rev_iter = iter(merge_sorted_revisions)
if start_revision_id is not None:
@@ -358,12 +363,37 @@
if rev_id != start_revision_id:
continue
else:
- yield rev_id, depth, revno, end_of_merge
+ # The decision to include the start or not
+ # depends on the stop_rule if a stop is provided
+ rev_iter = chain(
+ iter([(rev_id, depth, revno, end_of_merge)]),
+ rev_iter)
break
- for rev_id, depth, revno, end_of_merge in rev_iter:
- yield rev_id, depth, revno, end_of_merge
- if stop_revision_id is not None and rev_id == stop_revision_id:
- return
+ if stop_revision_id is None:
+ for rev_id, depth, revno, end_of_merge in rev_iter:
+ yield rev_id, depth, revno, end_of_merge
+ elif stop_rule == 'exclude':
+ for rev_id, depth, revno, end_of_merge in rev_iter:
+ if rev_id == stop_revision_id:
+ return
+ yield rev_id, depth, revno, end_of_merge
+ elif stop_rule == 'include':
+ for rev_id, depth, revno, end_of_merge in rev_iter:
+ yield rev_id, depth, revno, end_of_merge
+ if rev_id == stop_revision_id:
+ return
+ elif stop_rule == 'with-merges':
+ stop_rev = self.repository.get_revision(stop_revision_id)
+ if stop_rev.parent_ids:
+ left_parent = stop_rev.parent_ids[0]
+ else:
+ left_parent = _mod_revision.NULL_REVISION
+ for rev_id, depth, revno, end_of_merge in rev_iter:
+ if rev_id == left_parent:
+ return
+ yield rev_id, depth, revno, end_of_merge
+ else:
+ raise ValueError('invalid stop_rule %r' % stop_rule)
def leave_lock_in_place(self):
"""Tell this branch object not to release the physical lock when this
=== modified file 'bzrlib/tests/branch_implementations/test_iter_merge_sorted_revisions.py'
--- a/bzrlib/tests/branch_implementations/test_iter_merge_sorted_revisions.py 2009-01-23 21:19:24 +0000
+++ b/bzrlib/tests/branch_implementations/test_iter_merge_sorted_revisions.py 2009-01-27 04:27:57 +0000
@@ -43,7 +43,7 @@
('rev-1.1.1', 1, (1,1,1), True),
('rev-2', 0, (2,), False),
], list(the_branch.iter_merge_sorted_revisions(
- start_revision_id='rev-1.1.1', stop_revision_id='rev-2')))
+ start_revision_id='rev-1.1.1', stop_revision_id='rev-1')))
def test_merge_sorted_range_start_only(self):
tree = self.create_tree_with_merge()
@@ -55,15 +55,61 @@
], list(the_branch.iter_merge_sorted_revisions(
start_revision_id='rev-1.1.1')))
- def test_merge_sorted_range_stop_only(self):
- tree = self.create_tree_with_merge()
- the_branch = tree.bzrdir.open_branch()
- self.assertEqual([
- ('rev-3', 0, (3,), False),
- ('rev-1.1.1', 1, (1,1,1), True),
- ('rev-2', 0, (2,), False),
- ], list(the_branch.iter_merge_sorted_revisions(
- stop_revision_id='rev-2')))
+ def test_merge_sorted_range_stop_exclude(self):
+ tree = self.create_tree_with_merge()
+ the_branch = tree.bzrdir.open_branch()
+ self.assertEqual([
+ ('rev-3', 0, (3,), False),
+ ('rev-1.1.1', 1, (1,1,1), True),
+ ('rev-2', 0, (2,), False),
+ ], list(the_branch.iter_merge_sorted_revisions(
+ stop_revision_id='rev-1')))
+
+ def test_merge_sorted_range_stop_include(self):
+ tree = self.create_tree_with_merge()
+ the_branch = tree.bzrdir.open_branch()
+ self.assertEqual([
+ ('rev-3', 0, (3,), False),
+ ('rev-1.1.1', 1, (1,1,1), True),
+ ('rev-2', 0, (2,), False),
+ ], list(the_branch.iter_merge_sorted_revisions(
+ stop_revision_id='rev-2', stop_rule='include')))
+
+ def test_merge_sorted_range_stop_with_merges(self):
+ tree = self.create_tree_with_merge()
+ the_branch = tree.bzrdir.open_branch()
+ self.assertEqual([
+ ('rev-3', 0, (3,), False),
+ ('rev-1.1.1', 1, (1,1,1), True),
+ ], list(the_branch.iter_merge_sorted_revisions(
+ stop_revision_id='rev-3', stop_rule='with-merges')))
+
+ def test_merge_sorted_single_stop_exclude(self):
+ # from X..X exclusive is an empty result
+ tree = self.create_tree_with_merge()
+ the_branch = tree.bzrdir.open_branch()
+ self.assertEqual([], list(the_branch.iter_merge_sorted_revisions(
+ start_revision_id='rev-3', stop_revision_id='rev-3')))
+
+ def test_merge_sorted_single_stop_include(self):
+ # from X..X inclusive is [X]
+ tree = self.create_tree_with_merge()
+ the_branch = tree.bzrdir.open_branch()
+ self.assertEqual([
+ ('rev-3', 0, (3,), False),
+ ], list(the_branch.iter_merge_sorted_revisions(
+ start_revision_id='rev-3', stop_revision_id='rev-3',
+ stop_rule='include')))
+
+ def test_merge_sorted_single_stop_with_merges(self):
+ tree = self.create_tree_with_merge()
+ the_branch = tree.bzrdir.open_branch()
+ self.assertEqual([
+ ('rev-3', 0, (3,), False),
+ ('rev-1.1.1', 1, (1,1,1), True),
+ ], list(the_branch.iter_merge_sorted_revisions(
+ start_revision_id='rev-3', stop_revision_id='rev-3',
+ stop_rule='with-merges')))
def test_merge_sorted_forward(self):
tree = self.create_tree_with_merge()
@@ -83,7 +129,7 @@
('rev-2', 0, (2,), False),
('rev-1.1.1', 1, (1,1,1), True),
], list(the_branch.iter_merge_sorted_revisions(
- start_revision_id='rev-1.1.1', stop_revision_id='rev-2',
+ start_revision_id='rev-1.1.1', stop_revision_id='rev-1',
direction='forward')))
def test_merge_sorted_range_start_only_forward(self):
@@ -96,12 +142,33 @@
], list(the_branch.iter_merge_sorted_revisions(
start_revision_id='rev-1.1.1', direction='forward')))
- def test_merge_sorted_range_stop_only_forward(self):
- tree = self.create_tree_with_merge()
- the_branch = tree.bzrdir.open_branch()
- self.assertEqual([
- ('rev-2', 0, (2,), False),
- ('rev-1.1.1', 1, (1,1,1), True),
- ('rev-3', 0, (3,), False),
- ], list(the_branch.iter_merge_sorted_revisions(
- stop_revision_id='rev-2', direction='forward')))
+ def test_merge_sorted_range_stop_exclude_forward(self):
+ tree = self.create_tree_with_merge()
+ the_branch = tree.bzrdir.open_branch()
+ self.assertEqual([
+ ('rev-2', 0, (2,), False),
+ ('rev-1.1.1', 1, (1,1,1), True),
+ ('rev-3', 0, (3,), False),
+ ], list(the_branch.iter_merge_sorted_revisions(
+ stop_revision_id='rev-1', direction='forward')))
+
+ def test_merge_sorted_range_stop_include_forward(self):
+ tree = self.create_tree_with_merge()
+ the_branch = tree.bzrdir.open_branch()
+ self.assertEqual([
+ ('rev-2', 0, (2,), False),
+ ('rev-1.1.1', 1, (1,1,1), True),
+ ('rev-3', 0, (3,), False),
+ ], list(the_branch.iter_merge_sorted_revisions(
+ stop_revision_id='rev-2', stop_rule='include',
+ direction='forward')))
+
+ def test_merge_sorted_range_stop_with_merges_forward(self):
+ tree = self.create_tree_with_merge()
+ the_branch = tree.bzrdir.open_branch()
+ self.assertEqual([
+ ('rev-1.1.1', 1, (1,1,1), True),
+ ('rev-3', 0, (3,), False),
+ ], list(the_branch.iter_merge_sorted_revisions(
+ stop_revision_id='rev-3', stop_rule='with-merges',
+ direction='forward')))
More information about the bazaar-commits
mailing list