changeset 31732:6be6e4becaaf

hgweb: prefix line id by ctx shortnode in filelog when patches are shown When "patch" query parameter is present in requests to filelog view, line ids in patches diff are no longer unique in the page since several patches are shown on the same page. We now prefix line id by changeset shortnode when several patches are displayed in the same page to have unique line ids overall.
author Denis Laxalde <denis@laxalde.org>
date Thu, 30 Mar 2017 21:40:10 +0200
parents bdb72dd3957e
children 35eb8f112c88
files mercurial/hgweb/webcommands.py mercurial/hgweb/webutil.py tests/test-hgweb-filelog.t
diffstat 3 files changed, 56 insertions(+), 54 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/webcommands.py	Wed Mar 29 12:14:20 2017 -0700
+++ b/mercurial/hgweb/webcommands.py	Thu Mar 30 21:40:10 2017 +0200
@@ -998,7 +998,8 @@
         basectx = ctx.p1()
         path = fctx.path()
         return webutil.diffs(web, tmpl, ctx, basectx, [path], diffstyle,
-                             linerange=linerange)
+                             linerange=linerange,
+                             lineidprefix='%s-' % ctx.hex()[:12])
 
     linerange = None
     if lrange is not None:
--- a/mercurial/hgweb/webutil.py	Wed Mar 29 12:14:20 2017 -0700
+++ b/mercurial/hgweb/webutil.py	Thu Mar 30 21:40:10 2017 +0200
@@ -434,7 +434,8 @@
     if len(files) > max:
         yield tmpl('fileellipses')
 
-def diffs(web, tmpl, ctx, basectx, files, style, linerange=None):
+def diffs(web, tmpl, ctx, basectx, files, style, linerange=None,
+          lineidprefix=''):
 
     def prettyprintlines(lines, blockno):
         for lineno, l in enumerate(lines, 1):
@@ -450,7 +451,7 @@
             yield tmpl(ltype,
                        line=l,
                        lineno=lineno,
-                       lineid="l%s" % difflineno,
+                       lineid=lineidprefix + "l%s" % difflineno,
                        linenumber="% 8s" % difflineno)
 
     repo = web.repo
--- a/tests/test-hgweb-filelog.t	Wed Mar 29 12:14:20 2017 -0700
+++ b/tests/test-hgweb-filelog.t	Thu Mar 30 21:40:10 2017 +0200
@@ -1124,10 +1124,10 @@
     </td>
    </tr>
    <tr><td colspan="3"><div class="bottomline inc-lineno"><pre class="sourcelines wrap">
-  <span id="l1.1" class="minusline">--- /dev/null	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.1"></a>
-  <span id="l1.2" class="plusline">+++ b/a	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.2"></a>
-  <span id="l1.3" class="atline">@@ -0,0 +1,1 @@</span><a href="#l1.3"></a>
-  <span id="l1.4" class="plusline">+b</span><a href="#l1.4"></a></pre></div></td></tr>
+  <span id="3f41bc784e7e-l1.1" class="minusline">--- /dev/null	Thu Jan 01 00:00:00 1970 +0000</span><a href="#3f41bc784e7e-l1.1"></a>
+  <span id="3f41bc784e7e-l1.2" class="plusline">+++ b/a	Thu Jan 01 00:00:00 1970 +0000</span><a href="#3f41bc784e7e-l1.2"></a>
+  <span id="3f41bc784e7e-l1.3" class="atline">@@ -0,0 +1,1 @@</span><a href="#3f41bc784e7e-l1.3"></a>
+  <span id="3f41bc784e7e-l1.4" class="plusline">+b</span><a href="#3f41bc784e7e-l1.4"></a></pre></div></td></tr>
    <tr>
     <td class="age">Thu, 01 Jan 1970 00:00:00 +0000</td>
     <td class="author">test</td>
@@ -1137,10 +1137,10 @@
     </td>
    </tr>
    <tr><td colspan="3"><div class="bottomline inc-lineno"><pre class="sourcelines wrap">
-  <span id="l1.1" class="minusline">--- /dev/null	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.1"></a>
-  <span id="l1.2" class="plusline">+++ b/a	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.2"></a>
-  <span id="l1.3" class="atline">@@ -0,0 +1,1 @@</span><a href="#l1.3"></a>
-  <span id="l1.4" class="plusline">+a</span><a href="#l1.4"></a></pre></div></td></tr>
+  <span id="5ed941583260-l1.1" class="minusline">--- /dev/null	Thu Jan 01 00:00:00 1970 +0000</span><a href="#5ed941583260-l1.1"></a>
+  <span id="5ed941583260-l1.2" class="plusline">+++ b/a	Thu Jan 01 00:00:00 1970 +0000</span><a href="#5ed941583260-l1.2"></a>
+  <span id="5ed941583260-l1.3" class="atline">@@ -0,0 +1,1 @@</span><a href="#5ed941583260-l1.3"></a>
+  <span id="5ed941583260-l1.4" class="plusline">+a</span><a href="#5ed941583260-l1.4"></a></pre></div></td></tr>
   
   </tbody>
   </table>
@@ -1404,16 +1404,16 @@
     </td>
    </tr>
    <tr><td colspan="3"><div class="bottomline inc-lineno"><pre class="sourcelines wrap">
-  <span id="l1.1" class="minusline">--- a/c	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.1"></a>
-  <span id="l1.2" class="plusline">+++ b/c	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.2"></a>
-  <span id="l1.3" class="atline">@@ -1,6 +1,6 @@</span><a href="#l1.3"></a>
-  <span id="l1.4"> 0</span><a href="#l1.4"></a>
-  <span id="l1.5"> 0</span><a href="#l1.5"></a>
-  <span id="l1.6" class="minusline">-b</span><a href="#l1.6"></a>
-  <span id="l1.7" class="plusline">+b-</span><a href="#l1.7"></a>
-  <span id="l1.8"> c++</span><a href="#l1.8"></a>
-  <span id="l1.9"> </span><a href="#l1.9"></a>
-  <span id="l1.10"> a</span><a href="#l1.10"></a></pre></div></td></tr>
+  <span id="fb9bc322513a-l1.1" class="minusline">--- a/c	Thu Jan 01 00:00:00 1970 +0000</span><a href="#fb9bc322513a-l1.1"></a>
+  <span id="fb9bc322513a-l1.2" class="plusline">+++ b/c	Thu Jan 01 00:00:00 1970 +0000</span><a href="#fb9bc322513a-l1.2"></a>
+  <span id="fb9bc322513a-l1.3" class="atline">@@ -1,6 +1,6 @@</span><a href="#fb9bc322513a-l1.3"></a>
+  <span id="fb9bc322513a-l1.4"> 0</span><a href="#fb9bc322513a-l1.4"></a>
+  <span id="fb9bc322513a-l1.5"> 0</span><a href="#fb9bc322513a-l1.5"></a>
+  <span id="fb9bc322513a-l1.6" class="minusline">-b</span><a href="#fb9bc322513a-l1.6"></a>
+  <span id="fb9bc322513a-l1.7" class="plusline">+b-</span><a href="#fb9bc322513a-l1.7"></a>
+  <span id="fb9bc322513a-l1.8"> c++</span><a href="#fb9bc322513a-l1.8"></a>
+  <span id="fb9bc322513a-l1.9"> </span><a href="#fb9bc322513a-l1.9"></a>
+  <span id="fb9bc322513a-l1.10"> a</span><a href="#fb9bc322513a-l1.10"></a></pre></div></td></tr>
    <tr>
     <td class="age">Thu, 01 Jan 1970 00:00:00 +0000</td>
     <td class="author">test</td>
@@ -1423,17 +1423,17 @@
     </td>
    </tr>
    <tr><td colspan="3"><div class="bottomline inc-lineno"><pre class="sourcelines wrap">
-  <span id="l1.1" class="minusline">--- a/c	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.1"></a>
-  <span id="l1.2" class="plusline">+++ b/c	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.2"></a>
-  <span id="l1.3" class="atline">@@ -1,7 +1,7 @@</span><a href="#l1.3"></a>
-  <span id="l1.4"> 0</span><a href="#l1.4"></a>
-  <span id="l1.5"> 0</span><a href="#l1.5"></a>
-  <span id="l1.6"> b</span><a href="#l1.6"></a>
-  <span id="l1.7" class="minusline">-c+</span><a href="#l1.7"></a>
-  <span id="l1.8" class="plusline">+c++</span><a href="#l1.8"></a>
-  <span id="l1.9"> </span><a href="#l1.9"></a>
-  <span id="l1.10"> a</span><a href="#l1.10"></a>
-  <span id="l1.11"> a</span><a href="#l1.11"></a></pre></div></td></tr>
+  <span id="e95928d60479-l1.1" class="minusline">--- a/c	Thu Jan 01 00:00:00 1970 +0000</span><a href="#e95928d60479-l1.1"></a>
+  <span id="e95928d60479-l1.2" class="plusline">+++ b/c	Thu Jan 01 00:00:00 1970 +0000</span><a href="#e95928d60479-l1.2"></a>
+  <span id="e95928d60479-l1.3" class="atline">@@ -1,7 +1,7 @@</span><a href="#e95928d60479-l1.3"></a>
+  <span id="e95928d60479-l1.4"> 0</span><a href="#e95928d60479-l1.4"></a>
+  <span id="e95928d60479-l1.5"> 0</span><a href="#e95928d60479-l1.5"></a>
+  <span id="e95928d60479-l1.6"> b</span><a href="#e95928d60479-l1.6"></a>
+  <span id="e95928d60479-l1.7" class="minusline">-c+</span><a href="#e95928d60479-l1.7"></a>
+  <span id="e95928d60479-l1.8" class="plusline">+c++</span><a href="#e95928d60479-l1.8"></a>
+  <span id="e95928d60479-l1.9"> </span><a href="#e95928d60479-l1.9"></a>
+  <span id="e95928d60479-l1.10"> a</span><a href="#e95928d60479-l1.10"></a>
+  <span id="e95928d60479-l1.11"> a</span><a href="#e95928d60479-l1.11"></a></pre></div></td></tr>
    <tr>
     <td class="age">Thu, 01 Jan 1970 00:00:00 +0000</td>
     <td class="author">test</td>
@@ -1443,21 +1443,21 @@
     </td>
    </tr>
    <tr><td colspan="3"><div class="bottomline inc-lineno"><pre class="sourcelines wrap">
-  <span id="l1.1" class="minusline">--- a/c	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.1"></a>
-  <span id="l1.2" class="plusline">+++ b/c	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.2"></a>
-  <span id="l1.3" class="atline">@@ -1,2 +1,11 @@</span><a href="#l1.3"></a>
-  <span id="l1.4" class="plusline">+0</span><a href="#l1.4"></a>
-  <span id="l1.5" class="plusline">+0</span><a href="#l1.5"></a>
-  <span id="l1.6"> b</span><a href="#l1.6"></a>
-  <span id="l1.7" class="minusline">-c</span><a href="#l1.7"></a>
-  <span id="l1.8" class="plusline">+c+</span><a href="#l1.8"></a>
-  <span id="l1.9" class="plusline">+</span><a href="#l1.9"></a>
-  <span id="l1.10" class="plusline">+a</span><a href="#l1.10"></a>
-  <span id="l1.11" class="plusline">+a</span><a href="#l1.11"></a>
-  <span id="l1.12" class="plusline">+</span><a href="#l1.12"></a>
-  <span id="l1.13" class="plusline">+d</span><a href="#l1.13"></a>
-  <span id="l1.14" class="plusline">+e</span><a href="#l1.14"></a>
-  <span id="l1.15" class="plusline">+f</span><a href="#l1.15"></a></pre></div></td></tr>
+  <span id="5c6574614c37-l1.1" class="minusline">--- a/c	Thu Jan 01 00:00:00 1970 +0000</span><a href="#5c6574614c37-l1.1"></a>
+  <span id="5c6574614c37-l1.2" class="plusline">+++ b/c	Thu Jan 01 00:00:00 1970 +0000</span><a href="#5c6574614c37-l1.2"></a>
+  <span id="5c6574614c37-l1.3" class="atline">@@ -1,2 +1,11 @@</span><a href="#5c6574614c37-l1.3"></a>
+  <span id="5c6574614c37-l1.4" class="plusline">+0</span><a href="#5c6574614c37-l1.4"></a>
+  <span id="5c6574614c37-l1.5" class="plusline">+0</span><a href="#5c6574614c37-l1.5"></a>
+  <span id="5c6574614c37-l1.6"> b</span><a href="#5c6574614c37-l1.6"></a>
+  <span id="5c6574614c37-l1.7" class="minusline">-c</span><a href="#5c6574614c37-l1.7"></a>
+  <span id="5c6574614c37-l1.8" class="plusline">+c+</span><a href="#5c6574614c37-l1.8"></a>
+  <span id="5c6574614c37-l1.9" class="plusline">+</span><a href="#5c6574614c37-l1.9"></a>
+  <span id="5c6574614c37-l1.10" class="plusline">+a</span><a href="#5c6574614c37-l1.10"></a>
+  <span id="5c6574614c37-l1.11" class="plusline">+a</span><a href="#5c6574614c37-l1.11"></a>
+  <span id="5c6574614c37-l1.12" class="plusline">+</span><a href="#5c6574614c37-l1.12"></a>
+  <span id="5c6574614c37-l1.13" class="plusline">+d</span><a href="#5c6574614c37-l1.13"></a>
+  <span id="5c6574614c37-l1.14" class="plusline">+e</span><a href="#5c6574614c37-l1.14"></a>
+  <span id="5c6574614c37-l1.15" class="plusline">+f</span><a href="#5c6574614c37-l1.15"></a></pre></div></td></tr>
    <tr>
     <td class="age">Thu, 01 Jan 1970 00:00:00 +0000</td>
     <td class="author">test</td>
@@ -1467,11 +1467,11 @@
     </td>
    </tr>
    <tr><td colspan="3"><div class="bottomline inc-lineno"><pre class="sourcelines wrap">
-  <span id="l1.1" class="minusline">--- a/c	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.1"></a>
-  <span id="l1.2" class="plusline">+++ b/c	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.2"></a>
-  <span id="l1.3" class="atline">@@ -1,1 +1,2 @@</span><a href="#l1.3"></a>
-  <span id="l1.4"> b</span><a href="#l1.4"></a>
-  <span id="l1.5" class="plusline">+c</span><a href="#l1.5"></a></pre></div></td></tr>
+  <span id="46c1a66bd8fc-l1.1" class="minusline">--- a/c	Thu Jan 01 00:00:00 1970 +0000</span><a href="#46c1a66bd8fc-l1.1"></a>
+  <span id="46c1a66bd8fc-l1.2" class="plusline">+++ b/c	Thu Jan 01 00:00:00 1970 +0000</span><a href="#46c1a66bd8fc-l1.2"></a>
+  <span id="46c1a66bd8fc-l1.3" class="atline">@@ -1,1 +1,2 @@</span><a href="#46c1a66bd8fc-l1.3"></a>
+  <span id="46c1a66bd8fc-l1.4"> b</span><a href="#46c1a66bd8fc-l1.4"></a>
+  <span id="46c1a66bd8fc-l1.5" class="plusline">+c</span><a href="#46c1a66bd8fc-l1.5"></a></pre></div></td></tr>
    <tr>
     <td class="age">Thu, 01 Jan 1970 00:00:00 +0000</td>
     <td class="author">test</td>
@@ -1481,8 +1481,8 @@
     </td>
    </tr>
    <tr><td colspan="3"><div class="bottomline inc-lineno"><pre class="sourcelines wrap">
-  <span id="l1.1" class="minusline">--- /dev/null	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.1"></a>
-  <span id="l1.2" class="plusline">+++ b/b	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.2"></a></pre></div></td></tr>
+  <span id="6563da9dcf87-l1.1" class="minusline">--- /dev/null	Thu Jan 01 00:00:00 1970 +0000</span><a href="#6563da9dcf87-l1.1"></a>
+  <span id="6563da9dcf87-l1.2" class="plusline">+++ b/b	Thu Jan 01 00:00:00 1970 +0000</span><a href="#6563da9dcf87-l1.2"></a></pre></div></td></tr>
   
   </tbody>
   </table>