[PATCH 2 of 3] hgweb: sort bookmarks in revlog order of their nodes

Anton Shestakov av6 at dwimlabs.net
Thu Mar 31 04:12:20 EDT 2016


# HG changeset patch
# User Anton Shestakov <av6 at dwimlabs.net>
# Date 1459408926 -28800
#      Thu Mar 31 15:22:06 2016 +0800
# Node ID 2cc26be32b21a913de45f77d3125b335e60beead
# Parent  af5e1389f02fc7a40a82ac1259a8e0c5083e9e1f
hgweb: sort bookmarks in revlog order of their nodes

Changes, branches and tags are already sorted on /summary, /branches and /tags,
let's now make bookmarks do the same. This will affect /bookmarks page in all
styles, including atom, rss and raw, and also /summary page.

Bookmarks are sorted using a (revision number, bookmark name) tuple.

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -606,7 +606,8 @@ def bookmarks(web, req, tmpl):
     The ``bookmarks`` template is rendered.
     """
     i = [b for b in web.repo._bookmarks.items() if b[1] in web.repo]
-    i = sorted(i)
+    sortkey = lambda b: (web.repo[b[1]].rev(), b[0])
+    i = sorted(i, key=sortkey, reverse=True)
     parity = paritygen(web.stripecount)
 
     def entries(latestonly, **map):
@@ -678,7 +679,9 @@ def summary(web, req, tmpl):
     def bookmarks(**map):
         parity = paritygen(web.stripecount)
         marks = [b for b in web.repo._bookmarks.items() if b[1] in web.repo]
-        for k, n in sorted(marks)[:10]:  # limit to 10 bookmarks
+        sortkey = lambda b: (web.repo[b[1]].rev(), b[0])
+        marks = sorted(marks, key=sortkey, reverse=True)
+        for k, n in marks[:10]:  # limit to 10 bookmarks
             yield {'parity': parity.next(),
                    'bookmark': k,
                    'date': web.repo[n].date(),
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
@@ -1496,8 +1496,8 @@ Overviews
   $ get-with-headers.py 127.0.0.1:$HGPORT 'raw-bookmarks'
   200 Script output follows
   
+  something	cad8025a2e87f88c06259790adfa15acb4080123
   anotherthing	2ef0ac749a14e4f57a5a822464a0902c6f7f448f
-  something	cad8025a2e87f88c06259790adfa15acb4080123
   $ get-with-headers.py 127.0.0.1:$HGPORT 'summary/?style=gitweb'
   200 Script output follows
   
@@ -1631,6 +1631,15 @@ Overviews
   
   <tr class="parity0">
   <td class="age"><i class="age">Thu, 01 Jan 1970 00:00:00 +0000</i></td>
+  <td><a class="list" href="/rev/something?style=gitweb"><b>something</b></a></td>
+  <td class="link">
+  <a href="/rev/cad8025a2e87?style=gitweb">changeset</a> |
+  <a href="/log/cad8025a2e87?style=gitweb">changelog</a> |
+  <a href="/file/cad8025a2e87?style=gitweb">files</a>
+  </td>
+  </tr>
+  <tr class="parity1">
+  <td class="age"><i class="age">Thu, 01 Jan 1970 00:00:00 +0000</i></td>
   <td><a class="list" href="/rev/anotherthing?style=gitweb"><b>anotherthing</b></a></td>
   <td class="link">
   <a href="/rev/2ef0ac749a14?style=gitweb">changeset</a> |
@@ -1638,15 +1647,6 @@ Overviews
   <a href="/file/2ef0ac749a14?style=gitweb">files</a>
   </td>
   </tr>
-  <tr class="parity1">
-  <td class="age"><i class="age">Thu, 01 Jan 1970 00:00:00 +0000</i></td>
-  <td><a class="list" href="/rev/something?style=gitweb"><b>something</b></a></td>
-  <td class="link">
-  <a href="/rev/cad8025a2e87?style=gitweb">changeset</a> |
-  <a href="/log/cad8025a2e87?style=gitweb">changelog</a> |
-  <a href="/file/cad8025a2e87?style=gitweb">files</a>
-  </td>
-  </tr>
   <tr class="light"><td colspan="3"><a class="list" href="/bookmarks?style=gitweb">...</a></td></tr>
   </table>
   
diff --git a/tests/test-hgweb-json.t b/tests/test-hgweb-json.t
--- a/tests/test-hgweb-json.t
+++ b/tests/test-hgweb-json.t
@@ -618,20 +618,20 @@ bookmarks/ shows bookmarks info
   {
     "bookmarks": [
       {
+        "bookmark": "bookmark2",
+        "date": [
+          0.0,
+          0
+        ],
+        "node": "ceed296fe500c3fac9541e31dad860cb49c89e45"
+      },
+      {
         "bookmark": "bookmark1",
         "date": [
           0.0,
           0
         ],
         "node": "8d7c456572acf3557e8ed8a07286b10c408bcec5"
-      },
-      {
-        "bookmark": "bookmark2",
-        "date": [
-          0.0,
-          0
-        ],
-        "node": "ceed296fe500c3fac9541e31dad860cb49c89e45"
       }
     ],
     "node": "cc725e08502a79dd1eda913760fbe06ed7a9abc7"


More information about the Mercurial-devel mailing list