Rev 16: Show the first line of commit messages on revision hits. in http://people.ubuntu.com/~robertc/baz2.0/plugins/search/trunk

Robert Collins robertc at robertcollins.net
Mon Jun 9 13:34:14 BST 2008


At http://people.ubuntu.com/~robertc/baz2.0/plugins/search/trunk

------------------------------------------------------------
revno: 16
revision-id: robertc at robertcollins.net-20080609123411-f1c05y8yp00k6y5d
parent: robertc at robertcollins.net-20080609101716-jic7t43fvbeewazh
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Mon 2008-06-09 22:34:11 +1000
message:
  Show the first line of commit messages on revision hits.
added:
  BUGS                           bugs-20080609101902-m23i5z2ojdgkeyof-1
modified:
  commands.py                    commands.py-20080608052041-z5bahsl8kwl0uf4x-5
  index.py                       index.py-20080608055509-hnimeek7q8tctkqf-2
  tests/test_blackbox.py         test_blackbox.py-20080608052041-z5bahsl8kwl0uf4x-9
  tests/test_index.py            test_index.py-20080608055509-hnimeek7q8tctkqf-4
=== added file 'BUGS'
--- a/BUGS	1970-01-01 00:00:00 +0000
+++ b/BUGS	2008-06-09 12:34:11 +0000
@@ -0,0 +1,8 @@
+For current bugs and to file bugs, please see launchpad:
+https://launchpad.net/bzr-search.
+
+Some key caveats though (not bugs per se):
+
+ - scaling: The current disk format will fail when a single term has more than
+   2000 (or so) references, because the bzr index bisection logic will not 
+   find the end of the row. 

=== modified file 'commands.py'
--- a/commands.py	2008-06-08 23:42:17 +0000
+++ b/commands.py	2008-06-09 12:34:11 +0000
@@ -54,7 +54,8 @@
         # XXX: Have a query translator etc.
         seen_count = 0
         for result in index.search(query_list):
-            self.outf.write(result.document_name() + '\n')
+            self.outf.write(result.document_name())
+            self.outf.write(" Summary: '%s'\n" % result.summary())
             seen_count += 1
         if seen_count == 0:
             raise errors.NoMatch(query_list)

=== modified file 'index.py'
--- a/index.py	2008-06-09 10:17:16 +0000
+++ b/index.py	2008-06-09 12:34:11 +0000
@@ -110,7 +110,7 @@
         branch = _mod_branch.Branch.open(url)
     except NotBranchError:
         raise errors.NoSearchIndex(url)
-    return Index(branch.bzrdir.transport.clone('bzr-search'))
+    return Index(branch.bzrdir.transport.clone('bzr-search'), branch)
 
 
 # XXX: This wants to be a PackCollection subclass with RepositoryPackCollection
@@ -118,10 +118,11 @@
 class Index(object):
     """A bzr content index."""
 
-    def __init__(self, index_transport):
+    def __init__(self, index_transport, branch):
         """Create an index stored at index_transport.
 
         :param index_transport: The path where the index data should be stored.
+        :param branch: The branch this Index is indexing.
         """
         self._transport = index_transport
         try:
@@ -142,6 +143,7 @@
         # because terms may occur in many component indices, we don't use a 
         # CombinedGraphIndex for grouping the term indices or doc indices.
         self._lock = LockDir(index_transport, 'names-lock')
+        self._branch = branch
 
     def _add_terms(self, index, terms):
         """Add a set of term posting lists to a in progress index.
@@ -358,7 +360,7 @@
             for doc_key in self._document_ids_to_keys(found_documents):
                 if doc_key[0] == 'r':
                     # revision
-                    yield RevisionHit(doc_key[2:3])
+                    yield RevisionHit(self._branch.repository, doc_key[2:3])
                 else:
                     raise Exception("unknown doc type")
 
@@ -395,11 +397,13 @@
 class RevisionHit(object):
     """A match found during a search in a revision object."""
 
-    def __init__(self, revision_key):
+    def __init__(self, repository, revision_key):
         """Create a RevisionHit.
 
+        :param repository: A repository to extract revisions from.
         :param revision_key: The revision_key that was hit.
         """
+        self.repository = repository
         self.revision_key = revision_key
 
     def document_name(self):
@@ -407,6 +411,12 @@
         # Perhaps need to utf_decode this?
         return "Revision id '%s'." % self.revision_key[0]
 
+    def summary(self):
+        """Get a summary of the revision."""
+        # Currently, just the commit first line.
+        revision = self.repository.get_revision(self.revision_key[-1])
+        return revision.message.splitlines()[0]
+
 
 class ComponentIndex(object):
     """A single component in the aggregate search index.

=== modified file 'tests/test_blackbox.py'
--- a/tests/test_blackbox.py	2008-06-08 23:42:17 +0000
+++ b/tests/test_blackbox.py	2008-06-09 12:34:11 +0000
@@ -46,7 +46,17 @@
         index = open_index_url(self.get_url('.'))
         out, err = self.run_bzr(['search', 'post'])
         self.assertEqual('', err)
-        self.assertEqual("Revision id '%s'.\n" % rev_id1, out)
+        self.assertEqual("Revision id '%s'. Summary: 'first post'\n" % rev_id1, out)
+
+    def test_summary_first_line(self):
+        tree = self.make_branch_and_tree('.')
+        init_index(tree.branch)
+        rev_id1 = tree.commit('this message\nhas two lines')
+        index_url(self.get_url('.'))
+        index = open_index_url(self.get_url('.'))
+        out, err = self.run_bzr(['search', 'two'])
+        self.assertEqual('', err)
+        self.assertEqual("Revision id '%s'. Summary: 'this message'\n" % rev_id1, out)
 
 
 class TestIndex(TestCaseWithTransport):

=== modified file 'tests/test_index.py'
--- a/tests/test_index.py	2008-06-09 10:17:16 +0000
+++ b/tests/test_index.py	2008-06-09 12:34:11 +0000
@@ -58,13 +58,13 @@
         search_index = index.init_index(branch)
         transport = self.get_transport('foo/.bzr/bzr-search')
         transport.put_bytes('format', 'garbage\n')
-        self.assertRaises(UnknownFormatError, index.Index, transport)
+        self.assertRaises(UnknownFormatError, index.Index, transport, branch)
 
     def test_open_index_missing_format_raises_NoSearchIndex(self):
         branch = self.make_branch('foo', format='pack-0.92')
         transport = self.get_transport('foo/.bzr/bzr-search')
         transport.mkdir('.')
-        self.assertRaises(errors.NoSearchIndex, index.Index, transport)
+        self.assertRaises(errors.NoSearchIndex, index.Index, transport, branch)
 
     def test_index_url_not_branch(self):
         self.assertRaises(NotBranchError, index.index_url,
@@ -134,10 +134,15 @@
 class TestResults(TestCaseWithTransport):
 
     def test_RevisionHit(self):
-        result = index.RevisionHit(('foo',))
-        self.assertEqualDiff(u"Revision id 'foo'.",
+        tree = self.make_branch_and_tree('tree')
+        rev_id1 = tree.commit('a multi\nline message')
+        result = index.RevisionHit(tree.branch.repository, (rev_id1,))
+        tree.lock_read()
+        self.addCleanup(tree.unlock)
+        self.assertEqualDiff(u"Revision id '%s'." % rev_id1,
             result.document_name())
-        self.assertEqual(('foo',), result.revision_key)
+        self.assertEqual((rev_id1,), result.revision_key)
+        self.assertEqual('a multi', result.summary())
 
 
 class TestComponentIndexBuilder(TestCaseWithTransport):




More information about the bazaar-commits mailing list