comparison 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
comparison
equal deleted inserted replaced
31806:8f203b491bb5 31807:e6eb86b154c5
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from __future__ import absolute_import 8 from __future__ import absolute_import
9 9
10 import errno 10 import errno
11 import itertools
11 import os 12 import os
12 import re 13 import re
13 import tempfile 14 import tempfile
14 15
15 from .i18n import _ 16 from .i18n import _
1450 cache=defaulttempl) 1451 cache=defaulttempl)
1451 else: 1452 else:
1452 self.t = formatter.maketemplater(ui, 'changeset', tmpl, 1453 self.t = formatter.maketemplater(ui, 'changeset', tmpl,
1453 cache=defaulttempl) 1454 cache=defaulttempl)
1454 1455
1456 self._counter = itertools.count()
1455 self.cache = {} 1457 self.cache = {}
1456 1458
1457 # find correct templates for current mode 1459 # find correct templates for current mode
1458 tmplmodes = [ 1460 tmplmodes = [
1459 (True, None), 1461 (True, None),
1488 props.update(templatekw.keywords) 1490 props.update(templatekw.keywords)
1489 props['templ'] = self.t 1491 props['templ'] = self.t
1490 props['ctx'] = ctx 1492 props['ctx'] = ctx
1491 props['repo'] = self.repo 1493 props['repo'] = self.repo
1492 props['ui'] = self.repo.ui 1494 props['ui'] = self.repo.ui
1495 props['index'] = next(self._counter)
1493 props['revcache'] = {'copies': copies} 1496 props['revcache'] = {'copies': copies}
1494 props['cache'] = self.cache 1497 props['cache'] = self.cache
1495 1498
1496 # write header 1499 # write header
1497 if self._parts['header']: 1500 if self._parts['header']: