Mon Jan 9 05:24:26 UTC 2006 Alberto Bertogli * Implement a search box. This implements a small search box that appears on the right top besides the logo (which will be changed to a small version in a following patch). diff -rN -u old-darcsweb/config.py.sample new-darcsweb/config.py.sample --- old-darcsweb/config.py.sample 2015-04-18 08:11:54.000000000 +0000 +++ new-darcsweb/config.py.sample 2015-04-18 08:11:54.000000000 +0000 @@ -40,6 +40,12 @@ # otherwise the directory is assumed to exist and be writeable. #cachedir = '/tmp/darcsweb-cache' + # By default, darcsweb's search looks in the last 100 commits; you can + # change that number by specifying it here. + # Note that search are not cached, so if you have tons of commits and + # set the limit to a very high number, they will take time. + #searchlimit = 100 + # # From now on, every class is a repo configuration, with the same format diff -rN -u old-darcsweb/darcsweb.cgi new-darcsweb/darcsweb.cgi --- old-darcsweb/darcsweb.cgi 2015-04-18 08:11:54.000000000 +0000 +++ new-darcsweb/darcsweb.cgi 2015-04-18 08:11:54.000000000 +0000 @@ -163,6 +163,22 @@ pos = s.find("\t") return s +def highlight(s, l): + "Highlights appearences of s in l" + import re + # build the regexp by leaving "(s)", replacing '(' and ') first + s = s.replace('\\', '\\\\') + s = s.replace('(', '\\(') + s = s.replace(')', '\\)') + s = '(' + escape(s) + ')' + try: + pat = re.compile(s, re.I) + repl = '\\1' + l = re.sub(pat, repl, l) + except: + pass + return l + def fperms(fname): m = os.stat(fname)[stat.ST_MODE] m = m & 0777 @@ -242,21 +258,31 @@ """ % { 'reponame': config.reponame, 'css': config.cssfile, 'url': config.myurl + '/' + config.myreponame, 'fav': config.darcsfav, 'logo': config.darcslogo, + 'myname': config.myname, + 'myreponame': config.myreponame, + 'action': action } - print 'repos /' % config.myname - print '%s' % (config.myreponame, - config.reponame), - print '/ ' + action - print "" def print_footer(put_rss = 1): @@ -546,6 +572,27 @@ f = run_darcs(params) return f.readlines() + def matches(self, s): + "Defines if the patch matches a given string" + if s.lower() in self.comment.lower(): + return self.comment + elif s.lower() in self.name.lower(): + return self.name + elif s.lower() in self.author.lower(): + return self.author + elif s == self.hash: + return self.hash + + s = s.lower() + for l in (self.adds, self.removes, self.modifies, + self.diradds, self.dirremoves, + self.replaces.keys(), self.moves.keys(), + self.moves.keys() ): + for i in l: + if s in i.lower(): + return i + return '' + # patch parsing, we get them through "darcs changes --xml-output" class BuildPatchList(xml.sax.handler.ContentHandler): @@ -1893,6 +1940,55 @@ print '' +def do_search(s): + print_header() + print_navbar() + ps = get_last_patches(config.searchlimit) + + print '
Search last %d commits for "%s"
' \ + % (config.searchlimit, escape(s)) + print '' + + alt = False + for p in ps: + match = p.matches(s) + if not match: + continue + + if alt: + print '' + else: + print '' + alt = not alt + + print """ + + + + + """ % { + 'age': how_old(p.local_date), + 'author': shorten_str(p.shortauthor, 26), + 'myrname': config.myreponame, + 'hash': p.hash, + 'name': escape(shorten_str(p.name)), + 'fullname': escape(p.name), + 'match': highlight(s, shorten_str(match)), + } + print "" + + print '
%(age)s%(author)s + + %(name)s +
+ %(match)s +
' + print_footer() + + def do_die(): print_header() print "

Error! Malformed query

" @@ -2095,6 +2191,11 @@ else: config.cachedir = None + if "searchlimit" in dir(base): + config.searchlimit = base.searchlimit + else: + config.searchlimit = 100 + if name and "footer" in dir(c): config.footer = c.footer elif "footer" in dir(base): @@ -2269,6 +2370,15 @@ elif action == 'atom': do_atom() +elif action == 'search': + if form.has_key('s'): + s = form["s"].value + else: + s = '' + do_search(s) + if config.cachedir: + cache.cancel() + else: action = "invalid query" do_die() diff -rN -u old-darcsweb/style.css new-darcsweb/style.css --- old-darcsweb/style.css 2015-04-18 08:11:54.000000000 +0000 +++ new-darcsweb/style.css 2015-04-18 08:11:54.000000000 +0000 @@ -69,6 +69,22 @@ padding:8px; } +div.search_box { + float:right; + text-align:right; +} + +input.search_text { + font-size:xx-small; + background-color: #edece6; + vertical-align: top; +} + +input.search_button { + font-size:xx-small; + vertical-align: top; +} + div.title, a.title { display:block; padding:6px 8px; font-weight:bold; @@ -136,7 +152,7 @@ } table { - clear:both; + /*clear:both;*/ padding:8px 4px; } @@ -239,3 +255,10 @@ background-color:#ee5500; } +img.logo { + border-width:0px; + vertical-align:top; + margin-left:12pt; + margin-right:5pt; +} +