changeset 32070:a298f5c61b34 stable

hgweb: do not show "descending" link in followlines UI for filelog heads When on a filelog head, we are certain that there will be no descendant so the target of the "descending" link will lead to an empty log result. Do not display the link in this case.
author Denis Laxalde <denis.laxalde@logilab.fr>
date Mon, 24 Apr 2017 10:32:15 +0200
parents a457da5296a5
children 1cf0b651fa70
files mercurial/hgweb/webcommands.py mercurial/templates/gitweb/filerevision.tmpl mercurial/templates/paper/filerevision.tmpl mercurial/templates/static/followlines.js tests/test-hgweb-commands.t tests/test-highlight.t
diffstat 6 files changed, 21 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/webcommands.py	Mon Apr 24 18:33:23 2017 +0200
+++ b/mercurial/hgweb/webcommands.py	Mon Apr 24 10:32:15 2017 +0200
@@ -131,6 +131,7 @@
     f = fctx.path()
     text = fctx.data()
     parity = paritygen(web.stripecount)
+    ishead = fctx.filerev() in fctx.filelog().headrevs()
 
     if util.binary(text):
         mt = mimetypes.guess_type(f)[0] or 'application/octet-stream'
@@ -150,6 +151,7 @@
                 symrev=webutil.symrevorshortnode(req, fctx),
                 rename=webutil.renamelink(fctx),
                 permissions=fctx.manifest().flags(f),
+                ishead=int(ishead),
                 **webutil.commonentry(web.repo, fctx))
 
 @webcommand('file')
--- a/mercurial/templates/gitweb/filerevision.tmpl	Mon Apr 24 18:33:23 2017 +0200
+++ b/mercurial/templates/gitweb/filerevision.tmpl	Mon Apr 24 10:32:15 2017 +0200
@@ -64,7 +64,7 @@
 </div>
 
 <div class="page_body">
-<pre class="sourcelines stripes" data-logurl="{url|urlescape}log/{symrev}/{file|urlescape}">{text%fileline}</pre>
+<pre class="sourcelines stripes" data-logurl="{url|urlescape}log/{symrev}/{file|urlescape}" data-ishead="{ishead}">{text%fileline}</pre>
 </div>
 
 <script type="text/javascript" src="{staticurl|urlescape}followlines.js"></script>
--- a/mercurial/templates/paper/filerevision.tmpl	Mon Apr 24 18:33:23 2017 +0200
+++ b/mercurial/templates/paper/filerevision.tmpl	Mon Apr 24 10:32:15 2017 +0200
@@ -71,7 +71,7 @@
 <div class="overflow">
 <div class="sourcefirst linewraptoggle">line wrap: <a class="linewraplink" href="javascript:toggleLinewrap()">on</a></div>
 <div class="sourcefirst"> line source</div>
-<pre class="sourcelines stripes4 wrap bottomline" data-logurl="{url|urlescape}log/{symrev}/{file|urlescape}">{text%fileline}</pre>
+<pre class="sourcelines stripes4 wrap bottomline" data-logurl="{url|urlescape}log/{symrev}/{file|urlescape}" data-ishead="{ishead}">{text%fileline}</pre>
 </div>
 
 <script type="text/javascript" src="{staticurl|urlescape}followlines.js"></script>
--- a/mercurial/templates/static/followlines.js	Mon Apr 24 18:33:23 2017 +0200
+++ b/mercurial/templates/static/followlines.js	Mon Apr 24 10:32:15 2017 +0200
@@ -17,6 +17,8 @@
         return;
     }
 
+    var isHead = parseInt(sourcelines.dataset.ishead || "0");
+
     // tooltip to invite on lines selection
     var tooltip = document.createElement('div');
     tooltip.id = 'followlines-tooltip';
@@ -153,7 +155,7 @@
 
             // append the <div id="followlines"> element to last line of the
             // selection block
-            var divAndButton = followlinesBox(targetUri, startId, endId);
+            var divAndButton = followlinesBox(targetUri, startId, endId, isHead);
             var div = divAndButton[0],
                 button = divAndButton[1];
             inviteElement.appendChild(div);
@@ -186,7 +188,7 @@
     sourcelines.addEventListener('click', lineSelectStart);
 
     //** return a <div id="followlines"> and inner cancel <button> elements */
-    function followlinesBox(targetUri, fromline, toline) {
+    function followlinesBox(targetUri, fromline, toline, isHead) {
         // <div id="followlines">
         var div = document.createElement('div');
         div.id = 'followlines';
@@ -213,13 +215,16 @@
         aAsc.setAttribute('href', url);
         aAsc.textContent = 'ascending';
         aDiv.appendChild(aAsc);
-        var sep = document.createTextNode(' / ');
-        aDiv.appendChild(sep);
-        //     link to "descending" followlines
-        var aDesc = document.createElement('a');
-        aDesc.setAttribute('href', url + '&descend=');
-        aDesc.textContent = 'descending';
-        aDiv.appendChild(aDesc);
+
+        if (!isHead) {
+            var sep = document.createTextNode(' / ');
+            aDiv.appendChild(sep);
+            //     link to "descending" followlines
+            var aDesc = document.createElement('a');
+            aDesc.setAttribute('href', url + '&descend=');
+            aDesc.textContent = 'descending';
+            aDiv.appendChild(aDesc);
+        }
 
         div.appendChild(aDiv);
 
--- a/tests/test-hgweb-commands.t	Mon Apr 24 18:33:23 2017 +0200
+++ b/tests/test-hgweb-commands.t	Mon Apr 24 10:32:15 2017 +0200
@@ -1343,7 +1343,7 @@
   <div class="overflow">
   <div class="sourcefirst linewraptoggle">line wrap: <a class="linewraplink" href="javascript:toggleLinewrap()">on</a></div>
   <div class="sourcefirst"> line source</div>
-  <pre class="sourcelines stripes4 wrap bottomline" data-logurl="/log/1/foo">
+  <pre class="sourcelines stripes4 wrap bottomline" data-logurl="/log/1/foo" data-ishead="0">
   <span id="l1">foo</span><a href="#l1"></a></pre>
   </div>
   
@@ -1471,7 +1471,7 @@
   <div class="overflow">
   <div class="sourcefirst linewraptoggle">line wrap: <a class="linewraplink" href="javascript:toggleLinewrap()">on</a></div>
   <div class="sourcefirst"> line source</div>
-  <pre class="sourcelines stripes4 wrap bottomline" data-logurl="/log/2/foo">
+  <pre class="sourcelines stripes4 wrap bottomline" data-logurl="/log/2/foo" data-ishead="1">
   <span id="l1">another</span><a href="#l1"></a></pre>
   </div>
   
--- a/tests/test-highlight.t	Mon Apr 24 18:33:23 2017 +0200
+++ b/tests/test-highlight.t	Mon Apr 24 10:32:15 2017 +0200
@@ -149,7 +149,7 @@
   <div class="overflow">
   <div class="sourcefirst linewraptoggle">line wrap: <a class="linewraplink" href="javascript:toggleLinewrap()">on</a></div>
   <div class="sourcefirst"> line source</div>
-  <pre class="sourcelines stripes4 wrap bottomline" data-logurl="/log/tip/primes.py">
+  <pre class="sourcelines stripes4 wrap bottomline" data-logurl="/log/tip/primes.py" data-ishead="1">
   <span id="l1"><span class="c">#!/usr/bin/env python</span></span><a href="#l1"></a>
   <span id="l2"></span><a href="#l2"></a>
   <span id="l3"><span class="sd">&quot;&quot;&quot;Fun with generators. Corresponding Haskell implementation:</span></span><a href="#l3"></a>