pushlog: create pushes entry before adding node (bug 1286426); r=glandium
authorGregory Szorc <gps@mozilla.com>
Thu, 14 Jul 2016 10:54:15 -0700
changeset 8967 0bc74c039485df943b4650dc0bf2a858efcf5771
parent 8966 b03458db3e8a5fa53e9a51677a71445a9823ce09
child 8968 cc3360b720c65f901fa67070f57bdd6311415f0a
push id1034
push userbmo:gps@mozilla.com
push dateTue, 19 Jul 2016 18:10:24 +0000
reviewersglandium
bugs1286426
pushlog: create pushes entry before adding node (bug 1286426); r=glandium An upcoming commit will change behavior to discard filtered nodes but retain the push entry. To make the code simpler to read, create the pushes entry first. MozReview-Commit-ID: KaGHn862Pqg
hgext/pushlog-legacy/pushlog-feed.py
--- a/hgext/pushlog-legacy/pushlog-feed.py
+++ b/hgext/pushlog-legacy/pushlog-feed.py
@@ -467,34 +467,40 @@ def pushlogHTML(web, req, tmpl):
                 archives=web.archivelist("tip"))
 
 def pushes_worker(query, repo, full):
     """Given a PushlogQuery, return a data structure mapping push IDs
     to a map of data about the push."""
     pushes = {}
     for id, user, date, node in query.entries:
         id = str(id)
+
+        # Create the pushes entry first. It is OK to have empty
+        # pushes if nodes from the pushlog no longer exist.
+        if id not in pushes:
+            pushes[id] = {
+                'user': user,
+                'date': date,
+                'changesets': [],
+            }
+
         if full:
             ctx = repo[node]
             node = {
                 'node': ctx.hex(),
                 'author': ctx.user(),
                 'desc': ctx.description(),
                 'branch': ctx.branch(),
                 'parents': [c.hex() for c in ctx.parents()],
                 'tags': ctx.tags(),
                 'files': ctx.files()
             }
-        if id in pushes:
-            # we get the pushes in reverse order
-            pushes[id]['changesets'].insert(0, node)
-        else:
-            pushes[id] = {'user': user,
-                          'date': date,
-                          'changesets': [node]}
+
+        # we get the pushes in reverse order
+        pushes[id]['changesets'].insert(0, node)
 
     return {'pushes': pushes, 'lastpushid': query.lastpushid}
 
 def pushes(web, req, tmpl):
     """WebCommand to return a data structure containing pushes."""
     query = pushlogSetup(web.repo, req)
     data = pushes_worker(query, web.repo, 'full' in req.form)