[PATCH 1 of 2 STABLE] hgweb: do not show "descending" link in followlines UI for filelog heads

Denis Laxalde denis at laxalde.org
Mon Apr 24 07:37:33 EDT 2017


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1493022735 -7200
#      Mon Apr 24 10:32:15 2017 +0200
# Branch stable
# Node ID 713eaf91eb7e80d954de1b3a8b3963e5367e1a9b
# Parent  40cf693fc07d846502f9c15a1602880ca99d7b56
# Available At http://hg.logilab.org/users/dlaxalde/hg
#              hg pull http://hg.logilab.org/users/dlaxalde/hg -r 713eaf91eb7e
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.

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -131,6 +131,7 @@ def _filerevision(web, req, tmpl, fctx):
     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 @@ def _filerevision(web, req, tmpl, fctx):
                 symrev=webutil.symrevorshortnode(req, fctx),
                 rename=webutil.renamelink(fctx),
                 permissions=fctx.manifest().flags(f),
+                ishead=int(ishead),
                 **webutil.commonentry(web.repo, fctx))
 
 @webcommand('file')
diff --git a/mercurial/templates/gitweb/filerevision.tmpl b/mercurial/templates/gitweb/filerevision.tmpl
--- a/mercurial/templates/gitweb/filerevision.tmpl
+++ b/mercurial/templates/gitweb/filerevision.tmpl
@@ -64,7 +64,7 @@ file |
 </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>
diff --git a/mercurial/templates/paper/filerevision.tmpl b/mercurial/templates/paper/filerevision.tmpl
--- a/mercurial/templates/paper/filerevision.tmpl
+++ b/mercurial/templates/paper/filerevision.tmpl
@@ -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>
diff --git a/mercurial/templates/static/followlines.js b/mercurial/templates/static/followlines.js
--- a/mercurial/templates/static/followlines.js
+++ b/mercurial/templates/static/followlines.js
@@ -17,6 +17,8 @@ document.addEventListener('DOMContentLoa
         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 @@ document.addEventListener('DOMContentLoa
 
             // 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 @@ document.addEventListener('DOMContentLoa
     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 @@ document.addEventListener('DOMContentLoa
         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);
 
diff --git a/tests/test-hgweb-commands.t b/tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t
+++ b/tests/test-hgweb-commands.t
@@ -1343,7 +1343,7 @@ File-related
   <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 @@ File-related
   <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>
   


More information about the Mercurial-devel mailing list