# HG changeset patch # User Anton Shestakov # Date 1459408926 -28800 # Node ID 06ae7a6daad0d6e313d6121284869049b95607ee # Parent ca0c0ca30c62400fb1c33092d736a52e540e72e3 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. diff -r ca0c0ca30c62 -r 06ae7a6daad0 mercurial/hgweb/webcommands.py --- 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(), diff -r ca0c0ca30c62 -r 06ae7a6daad0 tests/test-hgweb-commands.t --- 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 @@ Thu, 01 Jan 1970 00:00:00 +0000 + something + + changeset | + changelog | + files + + + + Thu, 01 Jan 1970 00:00:00 +0000 anotherthing changeset | @@ -1638,15 +1647,6 @@ files - - Thu, 01 Jan 1970 00:00:00 +0000 - something - - changeset | - changelog | - files - - ... diff -r ca0c0ca30c62 -r 06ae7a6daad0 tests/test-hgweb-json.t --- 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"