hgweb: fix search {entries} to not return results of template expansion
authorYuya Nishihara <yuya@tcha.org>
Sun, 18 Mar 2018 20:51:39 +0900
changeset 37400 47aea60d114d
parent 37399 0b64416224d9
child 37401 7d94fe3ea0ac
hgweb: fix search {entries} to not return results of template expansion "{entries%changelogentry}" in raw/search.tmpl was utterly wrong because "{entries}" here was a generator yielding results of template expansion. That's why we have a weird hack in runmap(), which I'm going to get rid of. https://www.mercurial-scm.org/repo/hg/file/4.5.2/mercurial/templater.py#l469 We have two choices: a) drop "%changelogentry" from raw/search.tmpl b) fix "{entries}" to yield mappings I take (b) because that's what the other log-like "{entries}" do. The "entries" keyword is wrapped by mappinggenerator so "{entries}" without "%searchentry" still works.
mercurial/hgweb/webcommands.py
mercurial/templates/gitweb/map
mercurial/templates/gitweb/search.tmpl
mercurial/templates/json/map
mercurial/templates/monoblue/map
mercurial/templates/monoblue/search.tmpl
mercurial/templates/paper/map
mercurial/templates/paper/search.tmpl
mercurial/templates/raw/map
mercurial/templates/spartan/map
mercurial/templates/spartan/search.tmpl
--- a/mercurial/hgweb/webcommands.py	Sat Mar 17 22:47:02 2018 +0900
+++ b/mercurial/hgweb/webcommands.py	Sun Mar 18 20:51:39 2018 +0900
@@ -36,6 +36,7 @@
     scmutil,
     smartset,
     templater,
+    templateutil,
 )
 
 from ..utils import (
@@ -287,7 +288,7 @@
                 LookupError):
             return MODE_KEYWORD, query
 
-    def changelist(**map):
+    def changelist(context):
         count = 0
 
         for ctx in searchfunc[0](funcarg):
@@ -303,7 +304,7 @@
                 'changelogtag': showtags,
                 'files': files,
             })
-            yield web.tmpl.generate('searchentry', lm)
+            yield lm
 
             if count >= revcount:
                 break
@@ -349,7 +350,7 @@
         query=query,
         node=tip.hex(),
         symrev='tip',
-        entries=changelist,
+        entries=templateutil.mappinggenerator(changelist, name='searchentry'),
         archives=web.archivelist('tip'),
         morevars=morevars,
         lessvars=lessvars,
--- a/mercurial/templates/gitweb/map	Sat Mar 17 22:47:02 2018 +0900
+++ b/mercurial/templates/gitweb/map	Sun Mar 18 20:51:39 2018 +0900
@@ -57,7 +57,6 @@
 
 fileellipses = '...'
 changelogentry = changelogentry.tmpl
-searchentry = changelogentry.tmpl
 changeset = changeset.tmpl
 manifest = manifest.tmpl
 direntry = '
--- a/mercurial/templates/gitweb/search.tmpl	Sat Mar 17 22:47:02 2018 +0900
+++ b/mercurial/templates/gitweb/search.tmpl	Sun Mar 18 20:51:39 2018 +0900
@@ -30,6 +30,6 @@
 
 <div class="title">searching for {query|escape}</div>
 
-{entries}
+{entries%changelogentry}
 
 {footer}
--- a/mercurial/templates/json/map	Sat Mar 17 22:47:02 2018 +0900
+++ b/mercurial/templates/json/map	Sun Mar 18 20:51:39 2018 +0900
@@ -18,9 +18,8 @@
 search = '\{
   "node": {node|json},
   "query": {query|json},
-  "entries": [{join(entries%searchentry, ", ")}]
+  "entries": [{join(entries%changelistentry, ", ")}]
   }'
-searchentry = '{changelistentry}'
 # changelog and shortlog are the same web API but with different
 # number of entries.
 changelog = changelist.tmpl
--- a/mercurial/templates/monoblue/map	Sat Mar 17 22:47:02 2018 +0900
+++ b/mercurial/templates/monoblue/map	Sun Mar 18 20:51:39 2018 +0900
@@ -57,7 +57,6 @@
 
 fileellipses = '...'
 changelogentry = changelogentry.tmpl
-searchentry = changelogentry.tmpl
 changeset = changeset.tmpl
 manifest = manifest.tmpl
 direntry = '
--- a/mercurial/templates/monoblue/search.tmpl	Sat Mar 17 22:47:02 2018 +0900
+++ b/mercurial/templates/monoblue/search.tmpl	Sun Mar 18 20:51:39 2018 +0900
@@ -26,6 +26,6 @@
     </div>
 
     <h2 class="no-link no-border">searching for {query|escape}</h2>
-    {entries}
+    {entries%changelogentry}
 
 {footer}
--- a/mercurial/templates/paper/map	Sat Mar 17 22:47:02 2018 +0900
+++ b/mercurial/templates/paper/map	Sun Mar 18 20:51:39 2018 +0900
@@ -33,7 +33,6 @@
 diffstatlink = diffstat.tmpl
 diffstatnolink = diffstat.tmpl
 changelogentry = shortlogentry.tmpl
-searchentry = shortlogentry.tmpl
 changeset = changeset.tmpl
 manifest = manifest.tmpl
 
--- a/mercurial/templates/paper/search.tmpl	Sat Mar 17 22:47:02 2018 +0900
+++ b/mercurial/templates/paper/search.tmpl	Sun Mar 18 20:51:39 2018 +0900
@@ -49,7 +49,7 @@
  </tr>
 </thead>
 <tbody class="stripes2">
-{entries}
+{entries%changelogentry}
 </tbody>
 </table>
 
--- a/mercurial/templates/raw/map	Sat Mar 17 22:47:02 2018 +0900
+++ b/mercurial/templates/raw/map	Sun Mar 18 20:51:39 2018 +0900
@@ -3,7 +3,6 @@
 changelog = changelog.tmpl
 changelogentry = logentry.tmpl
 search = search.tmpl
-searchentry = logentry.tmpl
 mimetype = 'text/plain; charset={encoding}'
 header = ''
 footer = ''
--- a/mercurial/templates/spartan/map	Sat Mar 17 22:47:02 2018 +0900
+++ b/mercurial/templates/spartan/map	Sun Mar 18 20:51:39 2018 +0900
@@ -17,7 +17,6 @@
 filenolink = '{file|escape} '
 fileellipses = '...'
 changelogentry = changelogentry.tmpl
-searchentry = changelogentry.tmpl
 changeset = changeset.tmpl
 manifest = manifest.tmpl
 
--- a/mercurial/templates/spartan/search.tmpl	Sat Mar 17 22:47:02 2018 +0900
+++ b/mercurial/templates/spartan/search.tmpl	Sun Mar 18 20:51:39 2018 +0900
@@ -24,7 +24,7 @@
 </p>
 </form>
 
-{entries}
+{entries%changelogentry}
 
 <form>
 {sessionvars%hiddenformentry}