diff mercurial/cmdutil.py @ 31807:e6eb86b154c5

templater: provide loop counter as "index" keyword This was originally written for JSON templating where we would have to be careful to not add extra comma, but seems generally useful. Inner loop started by % operator has its own counter.
author Yuya Nishihara <yuya@tcha.org>
date Fri, 22 Apr 2016 21:46:33 +0900
parents 9b3577796291
children 2406dbba49bd
line wrap: on
line diff
--- a/mercurial/cmdutil.py	Fri Apr 22 21:45:06 2016 +0900
+++ b/mercurial/cmdutil.py	Fri Apr 22 21:46:33 2016 +0900
@@ -8,6 +8,7 @@
 from __future__ import absolute_import
 
 import errno
+import itertools
 import os
 import re
 import tempfile
@@ -1452,6 +1453,7 @@
             self.t = formatter.maketemplater(ui, 'changeset', tmpl,
                                              cache=defaulttempl)
 
+        self._counter = itertools.count()
         self.cache = {}
 
         # find correct templates for current mode
@@ -1490,6 +1492,7 @@
         props['ctx'] = ctx
         props['repo'] = self.repo
         props['ui'] = self.repo.ui
+        props['index'] = next(self._counter)
         props['revcache'] = {'copies': copies}
         props['cache'] = self.cache