Patchwork [4,of,4,V2] hgweb: add link to force literal keyword search

login
register
mail settings
Submitter Alexander Plavin
Date Aug. 16, 2013, 8:06 p.m.
Message ID <0eefb2daf844d832d177.1376683591@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/2192/
State Superseded
Headers show

Comments

Alexander Plavin - Aug. 16, 2013, 8:06 p.m.
# HG changeset patch
# User Alexander Plavin <alexander@plav.in>
# Date 1376680910 -14400
#      Fri Aug 16 23:21:50 2013 +0400
# Node ID 0eefb2daf844d832d177a37a001113e8ae368982
# Parent  71ff24dc3d8d4723ffebc68d5ae7ed8f4ac26208
hgweb: add link to force literal keyword search

This makes it possible to make keyword search in case the search query also
specifies an exact revision (like '1234' or 'abcdef'), or a revset expression.

Patch

diff -r 71ff24dc3d8d -r 0eefb2daf844 mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py	Fri Aug 16 23:16:15 2013 +0400
+++ b/mercurial/hgweb/webcommands.py	Fri Aug 16 23:21:50 2013 +0400
@@ -240,7 +240,17 @@ 
     morevars['rev'] = query
 
     revdef = 'reverse(%s)' % query
-    searchfunc = searchfuncs[getsearchmode()]
+    modename = getsearchmode()
+
+    if 'forcekw' in req.form:
+        showforcekw = ''
+        showunforcekw = searchfuncs[modename][1]
+        modename = 'kw'
+    else:
+        showforcekw = modename != 'kw' and searchfuncs['kw'][1] or ''
+        showunforcekw = ''
+
+    searchfunc = searchfuncs[modename]
 
     tip = web.repo['tip']
     parity = paritygen(web.stripecount)
@@ -248,7 +258,8 @@ 
     return tmpl('search', query=query, node=tip.hex(),
                 entries=changelist, archives=web.archivelist("tip"),
                 morevars=morevars, lessvars=lessvars,
-                modedesc=searchfunc[1])
+                modedesc=searchfunc[1],
+                showforcekw=showforcekw, showunforcekw=showunforcekw)
 
 def changelog(web, req, tmpl, shortlog=False):
 
diff -r 71ff24dc3d8d -r 0eefb2daf844 mercurial/templates/paper/search.tmpl
--- a/mercurial/templates/paper/search.tmpl	Fri Aug 16 23:16:15 2013 +0400
+++ b/mercurial/templates/paper/search.tmpl	Fri Aug 16 23:21:50 2013 +0400
@@ -25,6 +25,10 @@ 
 
 <p>
 Assuming {modedesc}.
+{if(showforcekw, '<a href="{url|urlescape}log?rev={query|urlescape}&forcekw=1">
+Use {showforcekw}</a> instead.')}
+{if(showunforcekw, '<a href="{url|urlescape}log?rev={query|urlescape}">
+Use {showunforcekw}</a> instead.')}
 </p>
 
 <form class="search" action="{url|urlescape}log">
diff -r 71ff24dc3d8d -r 0eefb2daf844 tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t	Fri Aug 16 23:16:15 2013 +0400
+++ b/tests/test-hgweb-commands.t	Fri Aug 16 23:21:50 2013 +0400
@@ -495,6 +495,8 @@ 
   
   <p>
   Assuming literal keyword.
+  
+  
   </p>
   
   <form class="search" action="/log">