changeset 28711:06ae7a6daad0

hgweb: sort bookmarks in revlog order of their nodes Changes, branches and tags are already in revlog order on /summary, /branches and /tags, let's now make bookmarks be sorted by the same principle. It's more helpful to show more "recent" bookmarks on top. 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.
author Anton Shestakov <av6@dwimlabs.net>
date Thu, 31 Mar 2016 15:22:06 +0800
parents ca0c0ca30c62
children 80e922479891
files mercurial/hgweb/webcommands.py tests/test-hgweb-commands.t tests/test-hgweb-json.t
diffstat 3 files changed, 23 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/webcommands.py	Thu Mar 31 14:23:27 2016 +0800
+++ b/mercurial/hgweb/webcommands.py	Thu Mar 31 15:22:06 2016 +0800
@@ -606,7 +606,8 @@
     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 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(),
--- a/tests/test-hgweb-commands.t	Thu Mar 31 14:23:27 2016 +0800
+++ b/tests/test-hgweb-commands.t	Thu Mar 31 15:22:06 2016 +0800
@@ -1496,8 +1496,8 @@
   $ 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 @@
   
   <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 @@
   <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>
   
--- a/tests/test-hgweb-json.t	Thu Mar 31 14:23:27 2016 +0800
+++ b/tests/test-hgweb-json.t	Thu Mar 31 15:22:06 2016 +0800
@@ -680,20 +680,20 @@
   {
     "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"