hgmo: make automationrelevance API compatible with Mercurial 3.7 (bug 1228088); r=dminor draft
authorGregory Szorc <gps@mozilla.com>
Wed, 02 Mar 2016 12:08:57 -0800
changeset 7419 18982d7c7f4d8459d2aa5ed492088ca2c89b737a
parent 7418 a5788d4cafeeefc55729b98450300662c05afbfc
child 7420 3444079fd2e52b156aa3f1eedaea5c6ac52149e6
push id675
push usergszorc@mozilla.com
push dateWed, 02 Mar 2016 22:08:21 +0000
reviewersdminor
bugs1228088
hgmo: make automationrelevance API compatible with Mercurial 3.7 (bug 1228088); r=dminor parent changed from a generator to a lambda. A number of other keys were added. We filter them to keep test output the same. We should consider displaying them some day... MozReview-Commit-ID: GcNaBxTfKt5
hgext/hgmo/__init__.py
--- a/hgext/hgmo/__init__.py
+++ b/hgext/hgmo/__init__.py
@@ -366,31 +366,44 @@ def headdivergencewebcommand(web, req, t
                 filemerges=filemerges, filemergesignored=filemergesignored)
 
 
 def automationrelevancewebcommand(web, req, tmpl):
     if 'node' not in req.form:
         return tmpl('error', error={'error': "missing parameter 'node'"})
 
     repo = web.repo
+    deletefields = set([
+        'bookmarks',
+        'branch',
+        'branches',
+        'changelogtag',
+        'child',
+        'inbranch',
+        'phase',
+        'tags',
+    ])
 
     csets = []
     for ctx in repo.set('automationrelevant(%r)', req.form['node'][0]):
         entry = webutil.changelistentry(web, ctx, tmpl)
         # Some items in changelistentry are generators, which json.dumps()
         # can't handle. So we expand them.
         for k, v in entry.items():
             # "files" is a generator that attempts to call a template.
             # Don't even bother and just repopulate it.
             if k == 'files':
                 entry['files'] = sorted(ctx.files())
+            # "parent" is a generator in 3.6 and a lambda in 3.7+.
+            elif k == 'parent' and not isinstance(v, types.GeneratorType):
+                entry['parent'] = list(v())
             # These aren't interesting to us, so prune them. The
             # original impetus for this was because "changelogtag"
             # isn't part of the json template and adding it is non-trivial.
-            elif k in ('bookmarks', 'branches', 'changelogtag', 'child', 'inbranch', 'tags'):
+            elif k in deletefields:
                 del entry[k]
             elif isinstance(v, types.GeneratorType):
                 entry[k] = list(v)
 
         csets.append(entry)
 
     req.respond(HTTP_OK, 'application/json')
     return json.dumps({'changesets': csets}, indent=2, sort_keys=True)