paper: make different blocks of annotated lines have different colors
authorAnton Shestakov <av6@dwimlabs.net>
Sat, 16 Jul 2016 14:49:07 +0800
changeset 29572 d86b54d9bb0c
parent 29571 d1a7d9c279bb
child 29573 2b42fa1810c4
paper: make different blocks of annotated lines have different colors
mercurial/hgweb/webcommands.py
mercurial/templates/paper/map
tests/test-highlight.t
--- a/mercurial/hgweb/webcommands.py	Fri May 20 09:47:35 2016 +0900
+++ b/mercurial/hgweb/webcommands.py	Sat Jul 16 14:49:07 2016 +0800
@@ -880,9 +880,14 @@
             lines = fctx.annotate(follow=True, linenumber=True,
                                   diffopts=diffopts)
         previousrev = None
+        blockparitygen = paritygen(1)
         for lineno, ((f, targetline), l) in enumerate(lines):
             rev = f.rev()
-            blockhead = rev != previousrev or None
+            if rev != previousrev:
+                blockhead = True
+                blockparity = next(blockparitygen)
+            else:
+                blockhead = None
             previousrev = rev
             yield {"parity": next(parity),
                    "node": f.hex(),
@@ -893,6 +898,7 @@
                    "extra": f.extra(),
                    "file": f.path(),
                    "blockhead": blockhead,
+                   "blockparity": blockparity,
                    "targetline": targetline,
                    "line": l,
                    "lineno": lineno + 1,
--- a/mercurial/templates/paper/map	Fri May 20 09:47:35 2016 +0900
+++ b/mercurial/templates/paper/map	Sat Jul 16 14:49:07 2016 +0800
@@ -77,7 +77,7 @@
 
 annotateline = '
   <tr id="{lineid}"{ifeq(node, originalnode, ' class="thisrev"')}>
-    <td class="annotate">
+    <td class="annotate parity{blockparity}">
       {if(blockhead,
           '<a href="{url|urlescape}annotate/{node|short}/{file|urlescape}{sessionvars%urlparameter}#l{targetline}">
              {rev}
--- a/tests/test-highlight.t	Fri May 20 09:47:35 2016 +0900
+++ b/tests/test-highlight.t	Sat Jul 16 14:49:07 2016 +0800
@@ -289,7 +289,7 @@
   <tbody class="stripes2">
     
   <tr id="l1" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   <a href="/annotate/06824edf55d0/primes.py#l1">
   0
   </a>
@@ -308,7 +308,7 @@
   <td class="source"><a href="#l1">     1</a> <span class="c">#!/usr/bin/env python</span></td>
   </tr>
   <tr id="l2" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -325,7 +325,7 @@
   <td class="source"><a href="#l2">     2</a> </td>
   </tr>
   <tr id="l3" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -342,7 +342,7 @@
   <td class="source"><a href="#l3">     3</a> <span class="sd">&quot;&quot;&quot;Fun with generators. Corresponding Haskell implementation:</span></td>
   </tr>
   <tr id="l4" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -359,7 +359,7 @@
   <td class="source"><a href="#l4">     4</a> </td>
   </tr>
   <tr id="l5" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -376,7 +376,7 @@
   <td class="source"><a href="#l5">     5</a> <span class="sd">primes = 2 : sieve [3, 5..]</span></td>
   </tr>
   <tr id="l6" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -393,7 +393,7 @@
   <td class="source"><a href="#l6">     6</a> <span class="sd">    where sieve (p:ns) = p : sieve [n | n &lt;- ns, mod n p /= 0]</span></td>
   </tr>
   <tr id="l7" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -410,7 +410,7 @@
   <td class="source"><a href="#l7">     7</a> <span class="sd">&quot;&quot;&quot;</span></td>
   </tr>
   <tr id="l8" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -427,7 +427,7 @@
   <td class="source"><a href="#l8">     8</a> </td>
   </tr>
   <tr id="l9" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -444,7 +444,7 @@
   <td class="source"><a href="#l9">     9</a> <span class="kn">from</span> <span class="nn">itertools</span> <span class="kn">import</span> <span class="n">dropwhile</span><span class="p">,</span> <span class="n">ifilter</span><span class="p">,</span> <span class="n">islice</span><span class="p">,</span> <span class="n">count</span><span class="p">,</span> <span class="n">chain</span></td>
   </tr>
   <tr id="l10" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -461,7 +461,7 @@
   <td class="source"><a href="#l10">    10</a> </td>
   </tr>
   <tr id="l11" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -478,7 +478,7 @@
   <td class="source"><a href="#l11">    11</a> <span class="kn">def</span> <span class="nf">primes</span><span class="p">():</span></td>
   </tr>
   <tr id="l12" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -495,7 +495,7 @@
   <td class="source"><a href="#l12">    12</a>     <span class="sd">&quot;&quot;&quot;Generate all primes.&quot;&quot;&quot;</span></td>
   </tr>
   <tr id="l13" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -512,7 +512,7 @@
   <td class="source"><a href="#l13">    13</a>     <span class="kn">def</span> <span class="nf">sieve</span><span class="p">(</span><span class="n">ns</span><span class="p">):</span></td>
   </tr>
   <tr id="l14" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -529,7 +529,7 @@
   <td class="source"><a href="#l14">    14</a>         <span class="n">p</span> <span class="o">=</span> <span class="n">ns</span><span class="o">.</span><span class="n">next</span><span class="p">()</span></td>
   </tr>
   <tr id="l15" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -546,7 +546,7 @@
   <td class="source"><a href="#l15">    15</a>         <span class="c"># It is important to yield *here* in order to stop the</span></td>
   </tr>
   <tr id="l16" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -563,7 +563,7 @@
   <td class="source"><a href="#l16">    16</a>         <span class="c"># infinite recursion.</span></td>
   </tr>
   <tr id="l17" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -580,7 +580,7 @@
   <td class="source"><a href="#l17">    17</a>         <span class="kn">yield</span> <span class="n">p</span></td>
   </tr>
   <tr id="l18" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -597,7 +597,7 @@
   <td class="source"><a href="#l18">    18</a>         <span class="n">ns</span> <span class="o">=</span> <span class="n">ifilter</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span> <span class="o">%</span> <span class="n">p</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">,</span> <span class="n">ns</span><span class="p">)</span></td>
   </tr>
   <tr id="l19" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -614,7 +614,7 @@
   <td class="source"><a href="#l19">    19</a>         <span class="kn">for</span> <span class="n">n</span> <span class="ow">in</span> <span class="n">sieve</span><span class="p">(</span><span class="n">ns</span><span class="p">):</span></td>
   </tr>
   <tr id="l20" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -631,7 +631,7 @@
   <td class="source"><a href="#l20">    20</a>             <span class="kn">yield</span> <span class="n">n</span></td>
   </tr>
   <tr id="l21" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -648,7 +648,7 @@
   <td class="source"><a href="#l21">    21</a> </td>
   </tr>
   <tr id="l22" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -665,7 +665,7 @@
   <td class="source"><a href="#l22">    22</a>     <span class="n">odds</span> <span class="o">=</span> <span class="n">ifilter</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">i</span><span class="p">:</span> <span class="n">i</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">1</span><span class="p">,</span> <span class="n">count</span><span class="p">())</span></td>
   </tr>
   <tr id="l23" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -682,7 +682,7 @@
   <td class="source"><a href="#l23">    23</a>     <span class="kn">return</span> <span class="n">chain</span><span class="p">([</span><span class="mi">2</span><span class="p">],</span> <span class="n">sieve</span><span class="p">(</span><span class="n">dropwhile</span><span class="p">(</span><span class="kn">lambda</span> <span class="n">n</span><span class="p">:</span> <span class="n">n</span> <span class="o">&lt;</span> <span class="mi">3</span><span class="p">,</span> <span class="n">odds</span><span class="p">)))</span></td>
   </tr>
   <tr id="l24" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -699,7 +699,7 @@
   <td class="source"><a href="#l24">    24</a> </td>
   </tr>
   <tr id="l25" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -716,7 +716,7 @@
   <td class="source"><a href="#l25">    25</a> <span class="kn">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="s">&quot;__main__&quot;</span><span class="p">:</span></td>
   </tr>
   <tr id="l26" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -733,7 +733,7 @@
   <td class="source"><a href="#l26">    26</a>     <span class="kn">import</span> <span class="nn">sys</span></td>
   </tr>
   <tr id="l27" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -750,7 +750,7 @@
   <td class="source"><a href="#l27">    27</a>     <span class="kn">try</span><span class="p">:</span></td>
   </tr>
   <tr id="l28" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -767,7 +767,7 @@
   <td class="source"><a href="#l28">    28</a>         <span class="n">n</span> <span class="o">=</span> <span class="nb">int</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span></td>
   </tr>
   <tr id="l29" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -784,7 +784,7 @@
   <td class="source"><a href="#l29">    29</a>     <span class="kn">except</span> <span class="p">(</span><span class="ne">ValueError</span><span class="p">,</span> <span class="ne">IndexError</span><span class="p">):</span></td>
   </tr>
   <tr id="l30" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -801,7 +801,7 @@
   <td class="source"><a href="#l30">    30</a>         <span class="n">n</span> <span class="o">=</span> <span class="mi">10</span></td>
   </tr>
   <tr id="l31" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -818,7 +818,7 @@
   <td class="source"><a href="#l31">    31</a>     <span class="n">p</span> <span class="o">=</span> <span class="n">primes</span><span class="p">()</span></td>
   </tr>
   <tr id="l32" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>
@@ -835,7 +835,7 @@
   <td class="source"><a href="#l32">    32</a>     <span class="kn">print</span> <span class="s">&quot;The first </span><span class="si">%d</span><span class="s"> primes: </span><span class="si">%s</span><span class="s">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">n</span><span class="p">,</span> <span class="nb">list</span><span class="p">(</span><span class="n">islice</span><span class="p">(</span><span class="n">p</span><span class="p">,</span> <span class="n">n</span><span class="p">)))</span></td>
   </tr>
   <tr id="l33" class="thisrev">
-  <td class="annotate">
+  <td class="annotate parity0">
   
   <div class="annotate-info">
   <div>