[PATCH 1 of 3] hgweb: sort bookmarks early

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


# HG changeset patch
# User Anton Shestakov <av6 at dwimlabs.net>
# Date 1459405407 -28800
#      Thu Mar 31 14:23:27 2016 +0800
# Node ID af5e1389f02fc7a40a82ac1259a8e0c5083e9e1f
# Parent  ff0d3b6b287f89594bd8d0308fe2810d2a18ea01
hgweb: sort bookmarks early

Let's do the same thing that /tags page does. It gets sorted tags and then if
it needs the latest only, it just slices the first item from the list. Since
it's a slice and not a min(), it doesn't throw an exception if the list is
empty. This fixes HTTP 500 error from issue5022.

diff --git a/mercurial/hgweb/webcommands.py b/mercurial/hgweb/webcommands.py
--- a/mercurial/hgweb/webcommands.py
+++ b/mercurial/hgweb/webcommands.py
@@ -606,13 +606,13 @@ 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)
     parity = paritygen(web.stripecount)
 
     def entries(latestonly, **map):
+        t = i
         if latestonly:
-            t = [min(i)]
-        else:
-            t = sorted(i)
+            t = i[:1]
         for k, n in t:
             yield {"parity": parity.next(),
                    "bookmark": k,
diff --git a/tests/test-hgweb-empty.t b/tests/test-hgweb-empty.t
--- a/tests/test-hgweb-empty.t
+++ b/tests/test-hgweb-empty.t
@@ -461,4 +461,20 @@ Some tests for hgweb in an empty reposit
   </html>
   
 
+  $ (get-with-headers.py localhost:$HGPORT 'atom-bookmarks')
+  200 Script output follows
+  
+  <?xml version="1.0" encoding="ascii"?>
+  <feed xmlns="http://www.w3.org/2005/Atom">
+   <id>http://neuro:$HGPORT/</id>
+   <link rel="self" href="http://neuro:$HGPORT/atom-bookmarks"/>
+   <link rel="alternate" href="http://neuro:$HGPORT/bookmarks"/>
+   <title>test: bookmarks</title>
+   <summary>test bookmark history</summary>
+   <author><name>Mercurial SCM</name></author>
+   
+  
+  
+  </feed>
+
   $ cd ..


More information about the Mercurial-devel mailing list