Mercurial > hg
comparison mercurial/hgweb.py @ 538:7140bc781655
Add multiple keyword search to hgweb
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Add multiple keyword search to hgweb
People kept pestering me about this one. Now it's done.
If you type a tag/id/rev in the search box, it takes you to that entry
in the changelog.
If you type some other random keywords, it does a case-insensitive
search through the history and returns the most recent N items.
It's not super-fast, but it's serviceable.
manifest hash: e8fa980dee92cf78c04051d3028da9b07a45f3de
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCxO6JywK+sNU5EO8RArAwAKCq+9qO/OL0mQxa1J7C77Z6AcZoWgCfbiDC
AZ5KllldwBtdRRREn7HH6go=
=sIy0
-----END PGP SIGNATURE-----
author | mpm@selenic.com |
---|---|
date | Thu, 30 Jun 2005 23:19:37 -0800 |
parents | c15b4bc0a11c |
children | 44b29b98254a |
comparison
equal
deleted
inserted
replaced
537:411e05b04ffa | 538:7140bc781655 |
---|---|
283 footer = self.footer(), | 283 footer = self.footer(), |
284 repo = self.reponame, | 284 repo = self.reponame, |
285 changenav = changenav, | 285 changenav = changenav, |
286 manifest = hex(mf), | 286 manifest = hex(mf), |
287 rev = pos, changesets = count, entries = changelist) | 287 rev = pos, changesets = count, entries = changelist) |
288 | |
289 def search(self, query): | |
290 | |
291 def changelist(): | |
292 cl = self.repo.changelog | |
293 count = 0 | |
294 qw = query.lower().split() | |
295 | |
296 def revgen(): | |
297 for i in range(cl.count() - 1, 0, -100): | |
298 l = [] | |
299 for j in range(max(0, i - 100), i): | |
300 n = cl.node(j) | |
301 changes = cl.read(n) | |
302 l.insert(0, (n, j, changes)) | |
303 for e in l: | |
304 yield e | |
305 | |
306 for n, i, changes in revgen(): | |
307 miss = 0 | |
308 for q in qw: | |
309 if not (q in changes[1].lower() or | |
310 q in changes[4].lower() or | |
311 q in " ".join(changes[3][:20]).lower()): | |
312 miss = 1 | |
313 break | |
314 if miss: continue | |
315 | |
316 count += 1 | |
317 hn = hex(n) | |
318 p1, p2 = cl.parents(n) | |
319 t = float(changes[2].split(' ')[0]) | |
320 | |
321 yield self.t( | |
322 'searchentry', | |
323 parity = count & 1, | |
324 author = changes[1], | |
325 parent1 = self.parent("changelogparent", | |
326 hex(p1), cl.rev(p1)), | |
327 parent2 = self.parent("changelogparent", | |
328 hex(p2), cl.rev(p2)), | |
329 p1 = hex(p1), p2 = hex(p2), | |
330 p1rev = cl.rev(p1), p2rev = cl.rev(p2), | |
331 manifest = hex(changes[0]), | |
332 desc = changes[4], | |
333 date = t, | |
334 files = self.listfilediffs(changes[3], n), | |
335 rev = i, | |
336 node = hn) | |
337 | |
338 if count >= self.maxchanges: break | |
339 | |
340 cl = self.repo.changelog | |
341 mf = cl.read(cl.tip())[0] | |
342 | |
343 yield self.t('search', | |
344 header = self.header(), | |
345 footer = self.footer(), | |
346 query = query, | |
347 repo = self.reponame, | |
348 manifest = hex(mf), | |
349 entries = changelist) | |
288 | 350 |
289 def changeset(self, nodeid): | 351 def changeset(self, nodeid): |
290 n = bin(nodeid) | 352 n = bin(nodeid) |
291 cl = self.repo.changelog | 353 cl = self.repo.changelog |
292 changes = cl.read(n) | 354 changes = cl.read(n) |
584 if os.path.isfile(p): m = p | 646 if os.path.isfile(p): m = p |
585 | 647 |
586 self.t = templater(m, self.filters) | 648 self.t = templater(m, self.filters) |
587 | 649 |
588 if not args.has_key('cmd') or args['cmd'][0] == 'changelog': | 650 if not args.has_key('cmd') or args['cmd'][0] == 'changelog': |
589 hi = self.repo.changelog.count() - 1 | 651 c = self.repo.changelog.count() - 1 |
652 hi = c | |
590 if args.has_key('rev'): | 653 if args.has_key('rev'): |
591 hi = args['rev'][0] | 654 hi = args['rev'][0] |
592 try: | 655 try: |
593 hi = self.repo.changelog.rev(self.repo.lookup(hi)) | 656 hi = self.repo.changelog.rev(self.repo.lookup(hi)) |
594 except KeyError: pass | 657 except KeyError: |
595 | 658 write(self.search(hi)) |
659 return | |
660 | |
596 write(self.changelog(hi)) | 661 write(self.changelog(hi)) |
597 | 662 |
598 elif args['cmd'][0] == 'changeset': | 663 elif args['cmd'][0] == 'changeset': |
599 write(self.changeset(args['node'][0])) | 664 write(self.changeset(args['node'][0])) |
600 | 665 |