Add {firstaurora} and {firstnightly} templates
authorGregory Szorc <gps@mozilla.com>
Thu, 07 Nov 2013 23:09:30 -0800
changeset 63 a10db377c453387b2460da08748d9b460cb5f6f5
parent 62 c679e3ef7e09724cd71544c96c9a108536206269
child 64 05f97a21b0c18ed99f48c3cee392d031aa73d6ae
push id44
push usergszorc@mozilla.com
push dateFri, 08 Nov 2013 07:09:34 +0000
Add {firstaurora} and {firstnightly} templates
__init__.py
--- a/__init__.py
+++ b/__init__.py
@@ -148,16 +148,24 @@ bugs
 firstrelease
    The version number of the first release channel release a changeset
    was present in.
 
 firstbeta
    The version number of the first beta channel release a changeset was
    present in.
 
+firstaurora
+   The version number of the first aurora channel release a changeset was
+   present in.
+
+firstnightly
+   The version number of the first nightly channel release a changeset was
+   present in.
+
 auroradate
    The date of the first Aurora a changeset was likely present in.
 
    This value may not be accurate. The value is currently obtained by
    querying the pushlog data to see when a changeset was pushed to this
    channel. The date of the next Aurora is then calculated from that
    (essentially looking for the next early morning Pacific time day).
    Aurora releases are not always consistent. A more robust method of
@@ -755,16 +763,43 @@ def template_firstrelease(repo, ctx, **a
 
 def template_firstbeta(repo, ctx, **args):
     """:firstbeta: String. The version of the first beta release with this
     changeset.
     """
     return _compute_first_version(repo, ctx, 'beta', args['cache'])
 
 
+def _calculate_push_milestone(repo, ctx, tree):
+    # This function appears to be slow. Consider caching results.
+    pushes = repo.changetracker.pushes_for_changeset(ctx.node())
+    pushes = [p for p in pushes if p[0] == tree]
+
+    if not pushes:
+        return None
+
+    push = pushes[0]
+
+    return repo._revision_milestone(str(push[4]))
+
+
+def template_firstaurora(repo, ctx, **args):
+    """:firstaurora: String. The version of the first aurora release with
+    this changeset.
+    """
+    return _calculate_push_milestone(repo, ctx, 'aurora')
+
+
+def template_firstnightly(repo, ctx, **args):
+    """:firstnightly: String. The version of the first nightly release
+    with this changeset.
+    """
+    return _calculate_push_milestone(repo, ctx, 'central')
+
+
 def _calculate_next_daily_release(repo, ctx, tree):
     pushes = repo.changetracker.pushes_for_changeset(ctx.node())
     pushes = [p for p in pushes if p[0] == tree]
 
     if not pushes:
         return None
 
     push = pushes[0]
@@ -841,16 +876,18 @@ def extsetup(ui):
     revset.symbols['bug'] = revset_bug
     revset.symbols['me'] = revset_me
     revset.symbols['tree'] = revset_tree
 
     templatekw.keywords['bug'] = template_bug
     templatekw.keywords['bugs'] = template_bugs
     templatekw.keywords['firstrelease'] = template_firstrelease
     templatekw.keywords['firstbeta'] = template_firstbeta
+    templatekw.keywords['firstaurora'] = template_firstaurora
+    templatekw.keywords['firstnightly'] = template_firstnightly
     templatekw.keywords['auroradate'] = template_auroradate
     templatekw.keywords['nightlydate'] = template_nightlydate
 
 
 def reposetup(ui, repo):
     """Custom repository implementation.
 
     Our custom repository class tracks remote tree references so users can
@@ -973,36 +1010,26 @@ def reposetup(ui, repo):
                     except KeyError:
                         pass
 
             self.remoterefs.write()
 
             if mb:
                 self._bookmarks.write()
 
-        def _milestone_changesets(self):
-            """Look up Gecko milestone changes.
-
-            Returns a mapping of changeset node to milestone text.
-            """
-            m = {}
-
-            for rev in self.file('config/milestone.txt'):
-                ctx = self.filectx('config/milestone.txt', fileid=rev)
+        def _revision_milestone(self, rev):
+            """Look up the Gecko milestone of a revision."""
+            fctx = self.filectx('config/milestone.txt', changeid=rev)
+            lines = fctx.data().splitlines()
+            lines = [l for l in lines if not l.startswith('#') and l.strip()]
 
-                lines = ctx.data().splitlines()
-                lines = [l for l in lines if not l.startswith('#') and
-                    l.strip()]
+            if not lines:
+                return None
 
-                if len(lines) != 1:
-                    continue
-
-                m[ctx.node()] = lines[0]
-
-            return m
+            return lines[0]
 
         def _beta_releases(self):
             """Obtain information for each beta release."""
             return self._release_versions('beta/')
 
         def _release_releases(self):
             return self._release_versions('release/')