[PATCH 4 of 4 V3] hgweb: add link to force literal keyword search

Alexander Plavin alexander at plav.in
Thu Aug 22 10:12:24 CDT 2013


# HG changeset patch
# User Alexander Plavin <alexander at plav.in>
# Date 1376680910 -14400
#      Fri Aug 16 23:21:50 2013 +0400
# Node ID b495249eb9ea62a43259c05bde1560989be4fba7
# Parent  db2d5658d6dc5322aea42a72e1aeb60dcb44dd13
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.

diff -r db2d5658d6dc -r b495249eb9ea 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
@@ -241,6 +241,15 @@
     morevars['rev'] = query
 
     mode, funcarg = getsearchmode(query)
+
+    if 'forcekw' in req.form:
+        showforcekw = ''
+        showunforcekw = searchfuncs[mode][1]
+        mode = 'kw'
+    else:
+        showforcekw = mode != 'kw' and searchfuncs['kw'][1] or ''
+        showunforcekw = ''
+
     searchfunc = searchfuncs[mode]
 
     tip = web.repo['tip']
@@ -249,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 db2d5658d6dc -r b495249eb9ea 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 db2d5658d6dc -r b495249eb9ea 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">


More information about the Mercurial-devel mailing list