Merge lp:~jelmer/bzr-search/support-new-log into lp:bzr-search

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 89
Merged at revision: 87
Proposed branch: lp:~jelmer/bzr-search/support-new-log
Merge into: lp:bzr-search
Diff against target: 146 lines (+38/-13)
3 files modified
NEWS (+3/-0)
index.py (+24/-7)
tests/test_index.py (+11/-6)
To merge this branch: bzr merge lp:~jelmer/bzr-search/support-new-log
Reviewer Review Type Date Requested Status
Robert Collins Pending
Review via email: mp+74601@code.launchpad.net

Description of the change

Fix compatibility with newer versions of bzr which provide a
match dictionary rather than just a plain string during "bzr log".

This at least fixes immediate breakage in "bzr log -m" as well as the
testsuite.

It disables bzr-search if the user tries to search on specific properties,
as bzr-search does not support that yet. More work is needed in that area.

To post a comment you must log in.
88. By Jelmer Vernooij

Cope with empty searches.

89. By Jelmer Vernooij

Fix support for bzr < 2.5.

Revision history for this message
Robert Collins (lifeless) wrote :

cool. doit.

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

On 09/09/2011 09:52 AM, Robert Collins wrote:
> cool. doit.
>
Thanks! You're still the owner of lp:bzr-search though, would you
consider making it owned by ~bzr?

Cheers,

Jelmer

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'NEWS'
--- NEWS 2011-04-23 23:14:07 +0000
+++ NEWS 2011-09-08 13:56:27 +0000
@@ -57,6 +57,9 @@
57 * Does not break when bzr-svn is present and incompatible with bzr.57 * Does not break when bzr-svn is present and incompatible with bzr.
58 (Gary van der Merwe)58 (Gary van der Merwe)
5959
60 * Fix compatibility with newer versions of bzr which support searching
61 on specific properties in `bzr log`. (Jelmer Vernooij, #844806)
62
60 * When a 0 revision pack is added and the existing repo is empty, do not63 * When a 0 revision pack is added and the existing repo is empty, do not
61 crash. This is probably a stacked branch situation but we don't actually64 crash. This is probably a stacked branch situation but we don't actually
62 know how to reproduce. (Martin Pool, #627202)65 know how to reproduce. (Martin Pool, #627202)
6366
=== modified file 'index.py'
--- index.py 2011-03-14 22:42:42 +0000
+++ index.py 2011-09-08 13:56:27 +0000
@@ -1472,7 +1472,24 @@
1472_original_make_search_filter = None1472_original_make_search_filter = None
14731473
14741474
1475def make_disable_search_filter(branch, generate_delta, search, log_rev_iterator):1475def query_from_match(match):
1476 """Create a query from a 'bzr log' match dictionary or string.
1477
1478 :param match: Dictionary mapping properties to user search strings
1479 :return: None or a bzr-search query
1480 """
1481 if match is None:
1482 return None
1483 if isinstance(match, basestring):
1484 # Older versions of bzr just provided match as a plain string
1485 return query_from_regex(match)
1486 if match.keys() == ['']:
1487 return query_from_regex(match[''])
1488 # FIXME: Support searching on other properties as well
1489 return None
1490
1491
1492def make_disable_search_filter(branch, generate_delta, match, log_rev_iterator):
1476 """Disable search filtering if bzr-search will be active.1493 """Disable search filtering if bzr-search will be active.
14771494
1478 This filter replaces the default search filter, using the original filter1495 This filter replaces the default search filter, using the original filter
@@ -1480,23 +1497,23 @@
14801497
1481 :param branch: The branch being logged.1498 :param branch: The branch being logged.
1482 :param generate_delta: Whether to generate a delta for each revision.1499 :param generate_delta: Whether to generate a delta for each revision.
1483 :param search: A user text search string.1500 :param match: Dictionary mapping property names to user search strings
1484 :param log_rev_iterator: An input iterator containing all revisions that1501 :param log_rev_iterator: An input iterator containing all revisions that
1485 could be displayed, in lists.1502 could be displayed, in lists.
1486 :return: An iterator over ((rev_id, revno, merge_depth), rev, delta).1503 :return: An iterator over ((rev_id, revno, merge_depth), rev, delta).
1487 """1504 """
1488 try:1505 try:
1489 open_index_branch(branch)1506 open_index_branch(branch)
1490 query = query_from_regex(search)1507 query = query_from_match(match)
1491 if query:1508 if query:
1492 return log_rev_iterator1509 return log_rev_iterator
1493 except errors.NoSearchIndex:1510 except errors.NoSearchIndex:
1494 pass1511 pass
1495 return _original_make_search_filter(branch, generate_delta, search,1512 return _original_make_search_filter(branch, generate_delta, match,
1496 log_rev_iterator)1513 log_rev_iterator)
14971514
14981515
1499def make_log_search_filter(branch, generate_delta, search, log_rev_iterator):1516def make_log_search_filter(branch, generate_delta, match, log_rev_iterator):
1500 """Filter revisions by using a search index.1517 """Filter revisions by using a search index.
15011518
1502 This filter looks up revids in the search index along with the search1519 This filter looks up revids in the search index along with the search
@@ -1505,13 +1522,13 @@
15051522
1506 :param branch: The branch being logged.1523 :param branch: The branch being logged.
1507 :param generate_delta: Whether to generate a delta for each revision.1524 :param generate_delta: Whether to generate a delta for each revision.
1508 :param search: A user text search string.1525 :param match: Dictionary mapping property names to user search strings
1509 :param log_rev_iterator: An input iterator containing all revisions that1526 :param log_rev_iterator: An input iterator containing all revisions that
1510 could be displayed, in lists.1527 could be displayed, in lists.
1511 :return: An iterator over ((rev_id, revno, merge_depth), rev, delta).1528 :return: An iterator over ((rev_id, revno, merge_depth), rev, delta).
1512 """1529 """
1513 # Can we possibly search on this regex?1530 # Can we possibly search on this regex?
1514 query = query_from_regex(search)1531 query = query_from_match(match)
1515 if not query:1532 if not query:
1516 return log_rev_iterator1533 return log_rev_iterator
1517 try:1534 try:
15181535
=== modified file 'tests/test_index.py'
--- tests/test_index.py 2010-05-14 14:57:37 +0000
+++ tests/test_index.py 2011-09-08 13:56:27 +0000
@@ -17,6 +17,7 @@
1717
18"""Tests for the index layer."""18"""Tests for the index layer."""
1919
20from bzrlib import version_info as bzrlib_version
20from bzrlib.errors import NotBranchError, UnknownFormatError21from bzrlib.errors import NotBranchError, UnknownFormatError
21from bzrlib.btree_index import BTreeGraphIndex, BTreeBuilder22from bzrlib.btree_index import BTreeGraphIndex, BTreeBuilder
22from bzrlib.index import InMemoryGraphIndex, GraphIndex23from bzrlib.index import InMemoryGraphIndex, GraphIndex
@@ -739,10 +740,10 @@
739 base_iterator = 'base'740 base_iterator = 'base'
740 # bzr-search won't kick in741 # bzr-search won't kick in
741 self.assertEqual(base_iterator, index.make_log_search_filter(742 self.assertEqual(base_iterator, index.make_log_search_filter(
742 tree.branch, False, "\\bword\\b", base_iterator))743 tree.branch, False, {'': "\\bword\\b"}, base_iterator))
743 # so the disabling wrapper must.744 # so the disabling wrapper must.
744 self.assertNotEqual(base_iterator, index.make_disable_search_filter(745 self.assertNotEqual(base_iterator, index.make_disable_search_filter(
745 tree.branch, False, "\\bword\\b", base_iterator))746 tree.branch, False, {'': "\\bword\\b"}, base_iterator))
746747
747 def test_get_filter_too_complex(self):748 def test_get_filter_too_complex(self):
748 """A too complex regex becomes a baseline search."""749 """A too complex regex becomes a baseline search."""
@@ -753,14 +754,18 @@
753 index.index_url(self.get_url('foo'))754 index.index_url(self.get_url('foo'))
754 rev = tree.branch.repository.get_revision(revid)755 rev = tree.branch.repository.get_revision(revid)
755 input_iterator = [[((revid, 1, 0), rev, None)]]756 input_iterator = [[((revid, 1, 0), rev, None)]]
757 if bzrlib_version >= (2, 5):
758 match = {'': "st po"}
759 else:
760 match = "st po"
756 rev_log_iterator = index.make_disable_search_filter(761 rev_log_iterator = index.make_disable_search_filter(
757 tree.branch, False, "st po", input_iterator)762 tree.branch, False, match, input_iterator)
758 self.assertNotEqual(input_iterator, rev_log_iterator)763 self.assertNotEqual(input_iterator, rev_log_iterator)
759 # everything matches764 # everything matches
760 self.assertEqual(input_iterator, list(rev_log_iterator))765 self.assertEqual(input_iterator, list(rev_log_iterator))
761 # bzr-search won't kick in766 # bzr-search won't kick in
762 self.assertEqual(input_iterator, index.make_log_search_filter(767 self.assertEqual(input_iterator, index.make_log_search_filter(
763 tree.branch, False, "st po", input_iterator))768 tree.branch, False, match, input_iterator))
764769
765 def test_get_filter_searchable_regex(self):770 def test_get_filter_searchable_regex(self):
766 """A parsable regex becomes a index search."""771 """A parsable regex becomes a index search."""
@@ -779,10 +784,10 @@
779 [((revid2, 2, 0), None, None), ((revid, 1, 0), None, None)]]784 [((revid2, 2, 0), None, None), ((revid, 1, 0), None, None)]]
780 # the disabled filter must not kick in785 # the disabled filter must not kick in
781 self.assertEqual(input_iterator, index.make_disable_search_filter(786 self.assertEqual(input_iterator, index.make_disable_search_filter(
782 tree.branch, False, "\\bfirst\\b", input_iterator))787 tree.branch, False, {'': "\\bfirst\\b"}, input_iterator))
783 # we must get a functional search from the log search filter.788 # we must get a functional search from the log search filter.
784 rev_log_iterator = index.make_log_search_filter(789 rev_log_iterator = index.make_log_search_filter(
785 tree.branch, False, "\\bfirst\\b", input_iterator)790 tree.branch, False, {'': "\\bfirst\\b"}, input_iterator)
786 self.assertNotEqual(input_iterator, rev_log_iterator)791 self.assertNotEqual(input_iterator, rev_log_iterator)
787 # rev id 2 should be filtered out.792 # rev id 2 should be filtered out.
788 expected_result = [[((revid, 1, 0), None, None)]]793 expected_result = [[((revid, 1, 0), None, None)]]

Subscribers

People subscribed via source and target branches

to all changes: