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
1=== modified file 'NEWS'
2--- NEWS 2011-04-23 23:14:07 +0000
3+++ NEWS 2011-09-08 13:56:27 +0000
4@@ -57,6 +57,9 @@
5 * Does not break when bzr-svn is present and incompatible with bzr.
6 (Gary van der Merwe)
7
8+ * Fix compatibility with newer versions of bzr which support searching
9+ on specific properties in `bzr log`. (Jelmer Vernooij, #844806)
10+
11 * When a 0 revision pack is added and the existing repo is empty, do not
12 crash. This is probably a stacked branch situation but we don't actually
13 know how to reproduce. (Martin Pool, #627202)
14
15=== modified file 'index.py'
16--- index.py 2011-03-14 22:42:42 +0000
17+++ index.py 2011-09-08 13:56:27 +0000
18@@ -1472,7 +1472,24 @@
19 _original_make_search_filter = None
20
21
22-def make_disable_search_filter(branch, generate_delta, search, log_rev_iterator):
23+def query_from_match(match):
24+ """Create a query from a 'bzr log' match dictionary or string.
25+
26+ :param match: Dictionary mapping properties to user search strings
27+ :return: None or a bzr-search query
28+ """
29+ if match is None:
30+ return None
31+ if isinstance(match, basestring):
32+ # Older versions of bzr just provided match as a plain string
33+ return query_from_regex(match)
34+ if match.keys() == ['']:
35+ return query_from_regex(match[''])
36+ # FIXME: Support searching on other properties as well
37+ return None
38+
39+
40+def make_disable_search_filter(branch, generate_delta, match, log_rev_iterator):
41 """Disable search filtering if bzr-search will be active.
42
43 This filter replaces the default search filter, using the original filter
44@@ -1480,23 +1497,23 @@
45
46 :param branch: The branch being logged.
47 :param generate_delta: Whether to generate a delta for each revision.
48- :param search: A user text search string.
49+ :param match: Dictionary mapping property names to user search strings
50 :param log_rev_iterator: An input iterator containing all revisions that
51 could be displayed, in lists.
52 :return: An iterator over ((rev_id, revno, merge_depth), rev, delta).
53 """
54 try:
55 open_index_branch(branch)
56- query = query_from_regex(search)
57+ query = query_from_match(match)
58 if query:
59 return log_rev_iterator
60 except errors.NoSearchIndex:
61 pass
62- return _original_make_search_filter(branch, generate_delta, search,
63+ return _original_make_search_filter(branch, generate_delta, match,
64 log_rev_iterator)
65
66
67-def make_log_search_filter(branch, generate_delta, search, log_rev_iterator):
68+def make_log_search_filter(branch, generate_delta, match, log_rev_iterator):
69 """Filter revisions by using a search index.
70
71 This filter looks up revids in the search index along with the search
72@@ -1505,13 +1522,13 @@
73
74 :param branch: The branch being logged.
75 :param generate_delta: Whether to generate a delta for each revision.
76- :param search: A user text search string.
77+ :param match: Dictionary mapping property names to user search strings
78 :param log_rev_iterator: An input iterator containing all revisions that
79 could be displayed, in lists.
80 :return: An iterator over ((rev_id, revno, merge_depth), rev, delta).
81 """
82 # Can we possibly search on this regex?
83- query = query_from_regex(search)
84+ query = query_from_match(match)
85 if not query:
86 return log_rev_iterator
87 try:
88
89=== modified file 'tests/test_index.py'
90--- tests/test_index.py 2010-05-14 14:57:37 +0000
91+++ tests/test_index.py 2011-09-08 13:56:27 +0000
92@@ -17,6 +17,7 @@
93
94 """Tests for the index layer."""
95
96+from bzrlib import version_info as bzrlib_version
97 from bzrlib.errors import NotBranchError, UnknownFormatError
98 from bzrlib.btree_index import BTreeGraphIndex, BTreeBuilder
99 from bzrlib.index import InMemoryGraphIndex, GraphIndex
100@@ -739,10 +740,10 @@
101 base_iterator = 'base'
102 # bzr-search won't kick in
103 self.assertEqual(base_iterator, index.make_log_search_filter(
104- tree.branch, False, "\\bword\\b", base_iterator))
105+ tree.branch, False, {'': "\\bword\\b"}, base_iterator))
106 # so the disabling wrapper must.
107 self.assertNotEqual(base_iterator, index.make_disable_search_filter(
108- tree.branch, False, "\\bword\\b", base_iterator))
109+ tree.branch, False, {'': "\\bword\\b"}, base_iterator))
110
111 def test_get_filter_too_complex(self):
112 """A too complex regex becomes a baseline search."""
113@@ -753,14 +754,18 @@
114 index.index_url(self.get_url('foo'))
115 rev = tree.branch.repository.get_revision(revid)
116 input_iterator = [[((revid, 1, 0), rev, None)]]
117+ if bzrlib_version >= (2, 5):
118+ match = {'': "st po"}
119+ else:
120+ match = "st po"
121 rev_log_iterator = index.make_disable_search_filter(
122- tree.branch, False, "st po", input_iterator)
123+ tree.branch, False, match, input_iterator)
124 self.assertNotEqual(input_iterator, rev_log_iterator)
125 # everything matches
126 self.assertEqual(input_iterator, list(rev_log_iterator))
127 # bzr-search won't kick in
128 self.assertEqual(input_iterator, index.make_log_search_filter(
129- tree.branch, False, "st po", input_iterator))
130+ tree.branch, False, match, input_iterator))
131
132 def test_get_filter_searchable_regex(self):
133 """A parsable regex becomes a index search."""
134@@ -779,10 +784,10 @@
135 [((revid2, 2, 0), None, None), ((revid, 1, 0), None, None)]]
136 # the disabled filter must not kick in
137 self.assertEqual(input_iterator, index.make_disable_search_filter(
138- tree.branch, False, "\\bfirst\\b", input_iterator))
139+ tree.branch, False, {'': "\\bfirst\\b"}, input_iterator))
140 # we must get a functional search from the log search filter.
141 rev_log_iterator = index.make_log_search_filter(
142- tree.branch, False, "\\bfirst\\b", input_iterator)
143+ tree.branch, False, {'': "\\bfirst\\b"}, input_iterator)
144 self.assertNotEqual(input_iterator, rev_log_iterator)
145 # rev id 2 should be filtered out.
146 expected_result = [[((revid, 1, 0), None, None)]]

Subscribers

People subscribed via source and target branches

to all changes: