Patchwork [5,of,6] hgweb: file diff and changesets views behave like file source view

login
register
mail settings
Submitter Alexander Plavin
Date July 12, 2013, 9:07 p.m.
Message ID <0f5a867a0f2ce6396b70.1373663262@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/1850/
State Superseded, archived
Headers show

Comments

Alexander Plavin - July 12, 2013, 9:07 p.m.
# HG changeset patch
# User Alexander Plavin <me@aplavin.ru>
# Date 1373662630 -14400
#      Sat Jul 13 00:57:10 2013 +0400
# Node ID 0f5a867a0f2ce6396b709ed9831f7f64f9e578cd
# Parent  5f28ecff8fd41834918308628462e0b1a97772b2
hgweb: file diff and changesets views behave like file source view

This gives all the benefits introduced before for file source view, namely
code selection without line numbers and correct indents, highlighting line
which is linked to, long lines wrapping.

Implementation strategy is also the same as for file source view: all the
lines are put in a sigle pre tag with span's for each line. Correct line
numbering is achieved with nested CSS counters.

Patch

diff -r 5f28ecff8fd4 -r 0f5a867a0f2c mercurial/templates/paper/changeset.tmpl
--- a/mercurial/templates/paper/changeset.tmpl	Fri Jul 12 23:50:51 2013 +0400
+++ b/mercurial/templates/paper/changeset.tmpl	Sat Jul 13 00:57:10 2013 +0400
@@ -77,10 +77,11 @@ 
 </table>
 
 <div class="overflow">
-<div class="sourcefirst">   line diff</div>
-
+<div class="sourcefirst"> line diff</div>
+<div class="stripes2 reset-lineno">
 {diff}
 </div>
+</div>
 
 </div>
 </div>
diff -r 5f28ecff8fd4 -r 0f5a867a0f2c mercurial/templates/paper/filediff.tmpl
--- a/mercurial/templates/paper/filediff.tmpl	Fri Jul 12 23:50:51 2013 +0400
+++ b/mercurial/templates/paper/filediff.tmpl	Sat Jul 13 00:57:10 2013 +0400
@@ -68,11 +68,12 @@ 
 </table>
 
 <div class="overflow">
-<div class="sourcefirst">   line diff</div>
-
+<div class="sourcefirst"> line diff</div>
+<div class="stripes2 reset-lineno">
 {diff}
 </div>
 </div>
 </div>
+</div>
 
 {footer}
diff -r 5f28ecff8fd4 -r 0f5a867a0f2c mercurial/templates/paper/map
--- a/mercurial/templates/paper/map	Fri Jul 12 23:50:51 2013 +0400
+++ b/mercurial/templates/paper/map	Sat Jul 13 00:57:10 2013 +0400
@@ -84,11 +84,15 @@ 
     <td class="source"><a href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}</td>
   </tr>'
 
-diffblock = '<div class="source bottomline parity{parity}"><pre>{lines}</pre></div>'
-difflineplus = '<a href="#{lineid}" id="{lineid}">{linenumber}</a> <span class="plusline">{line|escape}</span>'
-difflineminus = '<a href="#{lineid}" id="{lineid}">{linenumber}</a> <span class="minusline">{line|escape}</span>'
-difflineat = '<a href="#{lineid}" id="{lineid}">{linenumber}</a> <span class="atline">{line|escape}</span>'
-diffline = '<a href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}'
+diffblock = '<div class="bottomline inc-lineno"><pre class="sourcelines wrap">{lines}</pre></div>'
+difflineplus = '
+  <span id="{lineid}" class="plusline">{strip(line|escape, '\r\n')}</span><a href="#{lineid}"></a>'
+difflineminus = '
+  <span id="{lineid}" class="minusline">{strip(line|escape, '\r\n')}</span><a href="#{lineid}"></a>'
+difflineat = '
+  <span id="{lineid}" class="atline">{strip(line|escape, '\r\n')}</span><a href="#{lineid}"></a>'
+diffline = '
+  <span id="{lineid}">{strip(line|escape, '\r\n')}</span><a href="#{lineid}"></a>'
 
 comparisonblock ='
   <tbody class="block">
diff -r 5f28ecff8fd4 -r 0f5a867a0f2c tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t	Fri Jul 12 23:50:51 2013 +0400
+++ b/tests/test-hgweb-commands.t	Sat Jul 13 00:57:10 2013 +0400
@@ -450,17 +450,18 @@ 
   </table>
   
   <div class="overflow">
-  <div class="sourcefirst">   line diff</div>
-  
-  <div class="source bottomline parity0"><pre><a href="#l1.1" id="l1.1">     1.1</a> <span class="minusline">--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-  </span><a href="#l1.2" id="l1.2">     1.2</a> <span class="plusline">+++ b/da/foo	Thu Jan 01 00:00:00 1970 +0000
-  </span><a href="#l1.3" id="l1.3">     1.3</a> <span class="atline">@@ -0,0 +1,1 @@
-  </span><a href="#l1.4" id="l1.4">     1.4</a> <span class="plusline">+foo
-  </span></pre></div><div class="source bottomline parity1"><pre><a href="#l2.1" id="l2.1">     2.1</a> <span class="minusline">--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-  </span><a href="#l2.2" id="l2.2">     2.2</a> <span class="plusline">+++ b/foo	Thu Jan 01 00:00:00 1970 +0000
-  </span><a href="#l2.3" id="l2.3">     2.3</a> <span class="atline">@@ -0,0 +1,1 @@
-  </span><a href="#l2.4" id="l2.4">     2.4</a> <span class="plusline">+foo
-  </span></pre></div>
+  <div class="sourcefirst"> line diff</div>
+  <div class="stripes2 reset-lineno">
+  <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/da/foo	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">+foo</span><a href="#l1.4"></a></pre></div><div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+  <span id="l2.1" class="minusline">--- /dev/null	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l2.1"></a>
+  <span id="l2.2" class="plusline">+++ b/foo	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l2.2"></a>
+  <span id="l2.3" class="atline">@@ -0,0 +1,1 @@</span><a href="#l2.3"></a>
+  <span id="l2.4" class="plusline">+foo</span><a href="#l2.4"></a></pre></div>
+  </div>
   </div>
   
   </div>
diff -r 5f28ecff8fd4 -r 0f5a867a0f2c tests/test-hgweb-diffs.t
--- a/tests/test-hgweb-diffs.t	Fri Jul 12 23:50:51 2013 +0400
+++ b/tests/test-hgweb-diffs.t	Sat Jul 13 00:57:10 2013 +0400
@@ -142,17 +142,18 @@ 
   </table>
   
   <div class="overflow">
-  <div class="sourcefirst">   line diff</div>
-  
-  <div class="source bottomline parity0"><pre><a href="#l1.1" id="l1.1">     1.1</a> <span class="minusline">--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-  </span><a href="#l1.2" id="l1.2">     1.2</a> <span class="plusline">+++ b/a	Thu Jan 01 00:00:00 1970 +0000
-  </span><a href="#l1.3" id="l1.3">     1.3</a> <span class="atline">@@ -0,0 +1,1 @@
-  </span><a href="#l1.4" id="l1.4">     1.4</a> <span class="plusline">+a
-  </span></pre></div><div class="source bottomline parity1"><pre><a href="#l2.1" id="l2.1">     2.1</a> <span class="minusline">--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
-  </span><a href="#l2.2" id="l2.2">     2.2</a> <span class="plusline">+++ b/b	Thu Jan 01 00:00:00 1970 +0000
-  </span><a href="#l2.3" id="l2.3">     2.3</a> <span class="atline">@@ -0,0 +1,1 @@
-  </span><a href="#l2.4" id="l2.4">     2.4</a> <span class="plusline">+b
-  </span></pre></div>
+  <div class="sourcefirst"> line diff</div>
+  <div class="stripes2 reset-lineno">
+  <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><div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+  <span id="l2.1" class="minusline">--- /dev/null	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l2.1"></a>
+  <span id="l2.2" class="plusline">+++ b/b	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l2.2"></a>
+  <span id="l2.3" class="atline">@@ -0,0 +1,1 @@</span><a href="#l2.3"></a>
+  <span id="l2.4" class="plusline">+b</span><a href="#l2.4"></a></pre></div>
+  </div>
   </div>
   
   </div>
@@ -271,13 +272,14 @@ 
   </table>
   
   <div class="overflow">
-  <div class="sourcefirst">   line diff</div>
-  
-  <div class="source bottomline parity0"><pre><a href="#l1.1" id="l1.1">     1.1</a> <span class="minusline">--- a/b	Thu Jan 01 00:00:00 1970 +0000
-  </span><a href="#l1.2" id="l1.2">     1.2</a> <span class="plusline">+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
-  </span><a href="#l1.3" id="l1.3">     1.3</a> <span class="atline">@@ -1,1 +0,0 @@
-  </span><a href="#l1.4" id="l1.4">     1.4</a> <span class="minusline">-b
-  </span></pre></div>
+  <div class="sourcefirst"> line diff</div>
+  <div class="stripes2 reset-lineno">
+  <div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+  <span id="l1.1" class="minusline">--- a/b	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.1"></a>
+  <span id="l1.2" class="plusline">+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.2"></a>
+  <span id="l1.3" class="atline">@@ -1,1 +0,0 @@</span><a href="#l1.3"></a>
+  <span id="l1.4" class="minusline">-b</span><a href="#l1.4"></a></pre></div>
+  </div>
   </div>
   </div>
   </div>
@@ -403,19 +405,20 @@ 
   </table>
   
   <div class="overflow">
-  <div class="sourcefirst">   line diff</div>
-  
-  <div class="source bottomline parity0"><pre><a href="#l1.1" id="l1.1">     1.1</a> new file mode 100644
-  <a href="#l1.2" id="l1.2">     1.2</a> <span class="minusline">--- /dev/null
-  </span><a href="#l1.3" id="l1.3">     1.3</a> <span class="plusline">+++ b/a
-  </span><a href="#l1.4" id="l1.4">     1.4</a> <span class="atline">@@ -0,0 +1,1 @@
-  </span><a href="#l1.5" id="l1.5">     1.5</a> <span class="plusline">+a
-  </span></pre></div><div class="source bottomline parity1"><pre><a href="#l2.1" id="l2.1">     2.1</a> new file mode 100644
-  <a href="#l2.2" id="l2.2">     2.2</a> <span class="minusline">--- /dev/null
-  </span><a href="#l2.3" id="l2.3">     2.3</a> <span class="plusline">+++ b/b
-  </span><a href="#l2.4" id="l2.4">     2.4</a> <span class="atline">@@ -0,0 +1,1 @@
-  </span><a href="#l2.5" id="l2.5">     2.5</a> <span class="plusline">+b
-  </span></pre></div>
+  <div class="sourcefirst"> line diff</div>
+  <div class="stripes2 reset-lineno">
+  <div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+  <span id="l1.1">new file mode 100644</span><a href="#l1.1"></a>
+  <span id="l1.2" class="minusline">--- /dev/null</span><a href="#l1.2"></a>
+  <span id="l1.3" class="plusline">+++ b/a</span><a href="#l1.3"></a>
+  <span id="l1.4" class="atline">@@ -0,0 +1,1 @@</span><a href="#l1.4"></a>
+  <span id="l1.5" class="plusline">+a</span><a href="#l1.5"></a></pre></div><div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+  <span id="l2.1">new file mode 100644</span><a href="#l2.1"></a>
+  <span id="l2.2" class="minusline">--- /dev/null</span><a href="#l2.2"></a>
+  <span id="l2.3" class="plusline">+++ b/b</span><a href="#l2.3"></a>
+  <span id="l2.4" class="atline">@@ -0,0 +1,1 @@</span><a href="#l2.4"></a>
+  <span id="l2.5" class="plusline">+b</span><a href="#l2.5"></a></pre></div>
+  </div>
   </div>
   
   </div>
@@ -536,11 +539,12 @@ 
   </table>
   
   <div class="overflow">
-  <div class="sourcefirst">   line diff</div>
-  
-  <div class="source bottomline parity0"><pre><a href="#l1.1" id="l1.1">     1.1</a> old mode 100644
-  <a href="#l1.2" id="l1.2">     1.2</a> new mode 100755
-  </pre></div>
+  <div class="sourcefirst"> line diff</div>
+  <div class="stripes2 reset-lineno">
+  <div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+  <span id="l1.1">old mode 100644</span><a href="#l1.1"></a>
+  <span id="l1.2">new mode 100755</span><a href="#l1.2"></a></pre></div>
+  </div>
   </div>
   </div>
   </div>
diff -r 5f28ecff8fd4 -r 0f5a867a0f2c tests/test-hgweb-removed.t
--- a/tests/test-hgweb-removed.t	Fri Jul 12 23:50:51 2013 +0400
+++ b/tests/test-hgweb-removed.t	Sat Jul 13 00:57:10 2013 +0400
@@ -115,13 +115,14 @@ 
   </table>
   
   <div class="overflow">
-  <div class="sourcefirst">   line diff</div>
-  
-  <div class="source bottomline parity0"><pre><a href="#l1.1" id="l1.1">     1.1</a> <span class="minusline">--- a/a	Thu Jan 01 00:00:00 1970 +0000
-  </span><a href="#l1.2" id="l1.2">     1.2</a> <span class="plusline">+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
-  </span><a href="#l1.3" id="l1.3">     1.3</a> <span class="atline">@@ -1,1 +0,0 @@
-  </span><a href="#l1.4" id="l1.4">     1.4</a> <span class="minusline">-a
-  </span></pre></div>
+  <div class="sourcefirst"> line diff</div>
+  <div class="stripes2 reset-lineno">
+  <div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+  <span id="l1.1" class="minusline">--- a/a	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.1"></a>
+  <span id="l1.2" class="plusline">+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.2"></a>
+  <span id="l1.3" class="atline">@@ -1,1 +0,0 @@</span><a href="#l1.3"></a>
+  <span id="l1.4" class="minusline">-a</span><a href="#l1.4"></a></pre></div>
+  </div>
   </div>
   
   </div>
@@ -215,13 +216,14 @@ 
   </table>
   
   <div class="overflow">
-  <div class="sourcefirst">   line diff</div>
-  
-  <div class="source bottomline parity0"><pre><a href="#l1.1" id="l1.1">     1.1</a> <span class="minusline">--- a/a	Thu Jan 01 00:00:00 1970 +0000
-  </span><a href="#l1.2" id="l1.2">     1.2</a> <span class="plusline">+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
-  </span><a href="#l1.3" id="l1.3">     1.3</a> <span class="atline">@@ -1,1 +0,0 @@
-  </span><a href="#l1.4" id="l1.4">     1.4</a> <span class="minusline">-a
-  </span></pre></div>
+  <div class="sourcefirst"> line diff</div>
+  <div class="stripes2 reset-lineno">
+  <div class="bottomline inc-lineno"><pre class="sourcelines wrap">
+  <span id="l1.1" class="minusline">--- a/a	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.1"></a>
+  <span id="l1.2" class="plusline">+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000</span><a href="#l1.2"></a>
+  <span id="l1.3" class="atline">@@ -1,1 +0,0 @@</span><a href="#l1.3"></a>
+  <span id="l1.4" class="minusline">-a</span><a href="#l1.4"></a></pre></div>
+  </div>
   </div>
   </div>
   </div>