hgmo: refactor loop iterating over revs (bug 1303904); r?glob draft
authorGregory Szorc <gps@mozilla.com>
Thu, 08 Jun 2017 13:31:53 -0700
changeset 11236 6504363eb1aaf7d66a163e6df855fbd7735bcdc2
parent 11235 5cc88b2d2b8cf33d341780678114240df8331397
child 11237 bb140762d07e7164199f302892a6ca058f4da014
push id1708
push usergszorc@mozilla.com
push dateMon, 19 Jun 2017 18:36:36 +0000
reviewersglob
bugs1303904
hgmo: refactor loop iterating over revs (bug 1303904); r?glob We'll soon introduce a second consumer of this result. So we save the revset result to a variable to avoid redundant execution. We also buffer the result in a list because we know we'll be iterating twice and this will be more efficient than iterating a revset result type. MozReview-Commit-ID: IjAK6qMV8eA
hgext/hgmo/__init__.py
--- a/hgext/hgmo/__init__.py
+++ b/hgext/hgmo/__init__.py
@@ -437,17 +437,20 @@ def automationrelevancewebcommand(web, r
         'tags',
     ])
 
     csets = []
     # Query an unfiltered repo because sometimes automation wants to run against
     # changesets that have since become hidden. The response exposes whether the
     # requested node is visible, so consumers can make intelligent decisions
     # about what to do if the changeset isn't visible.
-    for ctx in repo.unfiltered().set('automationrelevant(%r)', req.form['node'][0]):
+    urepo = repo.unfiltered()
+    revs = list(urepo.revs('automationrelevant(%r)', req.form['node'][0]))
+    for rev in revs:
+        ctx = urepo[rev]
         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())