Patchwork hgweb: prefix line id by ctx shortnode in filelog when patches are shown

login
register
mail settings
Submitter Denis Laxalde
Date March 31, 2017, 8:55 a.m.
Message ID <7ae1cc7ae6c50a037525.1490950557@sh77.tls.logilab.fr>
Download mbox | patch
Permalink /patch/19863/
State Accepted
Headers show

Comments

Denis Laxalde - March 31, 2017, 8:55 a.m.
# HG changeset patch
# User Denis Laxalde <denis@laxalde.org>
# Date 1490902810 -7200
#      Thu Mar 30 21:40:10 2017 +0200
# Node ID 7ae1cc7ae6c50a037525f27e203a2ce75fc3004f
# Parent  dea2a17cbfd00bf08ee87b3e44b1c71499189f89
# Available At http://hg.logilab.org/users/dlaxalde/hg
#              hg pull http://hg.logilab.org/users/dlaxalde/hg -r 7ae1cc7ae6c5
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.
Yuya Nishihara - March 31, 2017, 2:51 p.m.
On Fri, 31 Mar 2017 10:55:57 +0200, Denis Laxalde wrote:
> # HG changeset patch
> # User Denis Laxalde <denis@laxalde.org>
> # Date 1490902810 -7200
> #      Thu Mar 30 21:40:10 2017 +0200
> # Node ID 7ae1cc7ae6c50a037525f27e203a2ce75fc3004f
> # Parent  dea2a17cbfd00bf08ee87b3e44b1c71499189f89
> # Available At http://hg.logilab.org/users/dlaxalde/hg
> #              hg pull http://hg.logilab.org/users/dlaxalde/hg -r 7ae1cc7ae6c5
> hgweb: prefix line id by ctx shortnode in filelog when patches are shown

Nice, queued, thanks.
via Mercurial-devel - April 3, 2017, 7:42 p.m.
On Fri, Mar 31, 2017 at 1:55 AM, Denis Laxalde <denis@laxalde.org> wrote:
> # HG changeset patch
> # User Denis Laxalde <denis@laxalde.org>
> # Date 1490902810 -7200
> #      Thu Mar 30 21:40:10 2017 +0200
> # Node ID 7ae1cc7ae6c50a037525f27e203a2ce75fc3004f
> # Parent  dea2a17cbfd00bf08ee87b3e44b1c71499189f89
> # Available At http://hg.logilab.org/users/dlaxalde/hg
> #              hg pull http://hg.logilab.org/users/dlaxalde/hg -r 7ae1cc7ae6c5
> 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.
>
> diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
> --- a/mercurial/hgweb/webcommands.py
> +++ b/mercurial/hgweb/webcommands.py
> @@ -998,7 +998,8 @@ def filelog(web, req, tmpl):
>          basectx = ctx.p1()
>          path = fctx.path()
>          return webutil.diffs(web, tmpl, ctx, basectx, [path], diffstyle,
> -                             linerange=linerange)
> +                             linerange=linerange,
> +                             lineidprefix='%s-' % ctx.hex()[:12])

Nit: would "lineidprefix=short(ctx.node())" be better? That returns
bytes. I don't know if that's what you want on py3.
Yuya Nishihara - April 4, 2017, 3:48 p.m.
On Mon, 3 Apr 2017 12:42:01 -0700, Martin von Zweigbergk via Mercurial-devel wrote:
> On Fri, Mar 31, 2017 at 1:55 AM, Denis Laxalde <denis@laxalde.org> wrote:
> > # HG changeset patch
> > # User Denis Laxalde <denis@laxalde.org>
> > # Date 1490902810 -7200
> > #      Thu Mar 30 21:40:10 2017 +0200
> > # Node ID 7ae1cc7ae6c50a037525f27e203a2ce75fc3004f
> > # Parent  dea2a17cbfd00bf08ee87b3e44b1c71499189f89
> > # Available At http://hg.logilab.org/users/dlaxalde/hg
> > #              hg pull http://hg.logilab.org/users/dlaxalde/hg -r 7ae1cc7ae6c5
> > 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.
> >
> > diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
> > --- a/mercurial/hgweb/webcommands.py
> > +++ b/mercurial/hgweb/webcommands.py
> > @@ -998,7 +998,8 @@ def filelog(web, req, tmpl):
> >          basectx = ctx.p1()
> >          path = fctx.path()
> >          return webutil.diffs(web, tmpl, ctx, basectx, [path], diffstyle,
> > -                             linerange=linerange)
> > +                             linerange=linerange,
> > +                             lineidprefix='%s-' % ctx.hex()[:12])
> 
> Nit: would "lineidprefix=short(ctx.node())" be better? That returns
> bytes. I don't know if that's what you want on py3.

Could be. I don't care much about that because [:12] is seen at several places
in templater code.

Patch

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -998,7 +998,8 @@  def filelog(web, req, tmpl):
         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:
diff --git a/mercurial/hgweb/webutil.py b/mercurial/hgweb/webutil.py
--- a/mercurial/hgweb/webutil.py
+++ b/mercurial/hgweb/webutil.py
@@ -434,7 +434,8 @@  def listfilediffs(tmpl, files, node, max
     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 @@  def diffs(web, tmpl, ctx, basectx, files
             yield tmpl(ltype,
                        line=l,
                        lineno=lineno,
-                       lineid="l%s" % difflineno,
+                       lineid=lineidprefix + "l%s" % difflineno,
                        linenumber="% 8s" % difflineno)
 
     repo = web.repo
diff --git a/tests/test-hgweb-filelog.t b/tests/test-hgweb-filelog.t
--- a/tests/test-hgweb-filelog.t
+++ b/tests/test-hgweb-filelog.t
@@ -1124,10 +1124,10 @@  filelog with patch
     </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 @@  filelog with patch
     </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 @@  filelog with 'linerange' and 'patch'
     </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 @@  filelog with 'linerange' and 'patch'
     </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 @@  filelog with 'linerange' and 'patch'
     </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 @@  filelog with 'linerange' and 'patch'
     </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 @@  filelog with 'linerange' and 'patch'
     </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>