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

login
register
mail settings
Submitter Alexander Plavin
Date Aug. 9, 2013, 6:56 p.m.
Message ID <5928db37c6f57f046902.1376074571@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/2107/
State Superseded
Headers show

Comments

Alexander Plavin - Aug. 9, 2013, 6:56 p.m.
# HG changeset patch
# User Alexander Plavin <alexander@plav.in>
# Date 1376016843 -14400
#      Fri Aug 09 06:54:03 2013 +0400
# Node ID 5928db37c6f57f046902fef6f98ba640294f7fe8
# Parent  c982398539da5f6c32b98c9d68a339f527a8335a
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 c982398539da -r 5928db37c6f5 mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py	Sat Jul 20 21:29:17 2013 +0400
+++ b/mercurial/hgweb/webcommands.py	Fri Aug 09 06:54:03 2013 +0400
@@ -231,6 +231,14 @@ 
                 # no revset syntax used or blacklisted functions in the query
                 modename = 'kw'
 
+    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']
@@ -239,7 +247,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 c982398539da -r 5928db37c6f5 mercurial/templates/paper/search.tmpl
--- a/mercurial/templates/paper/search.tmpl	Sat Jul 20 21:29:17 2013 +0400
+++ b/mercurial/templates/paper/search.tmpl	Fri Aug 09 06:54:03 2013 +0400
@@ -24,6 +24,10 @@ 
 <h3>searching for '{query|escape}'</h3>
 
 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.')}
 
 <form class="search" action="{url|urlescape}log">
 {sessionvars%hiddenformentry}
diff -r c982398539da -r 5928db37c6f5 tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t	Sat Jul 20 21:29:17 2013 +0400
+++ b/tests/test-hgweb-commands.t	Fri Aug 09 06:54:03 2013 +0400
@@ -495,6 +495,8 @@ 
   
   Assuming literal keyword.
   
+  
+  
   <form class="search" action="/log">
   
   <p><input name="rev" id="search1" type="text" size="30" value="base"></p>