Mercurial > hg
comparison mercurial/formatter.py @ 29882:307b20e5e505
formatter: add context manager interface for convenience
And port "hg files" to test it.
As you can see, extra indent is necessary to port to this API. I don't think
we should switch every fm.formatter() call to "with" statement.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Mon, 29 Aug 2016 00:00:05 +0900 |
parents | 5b886289a1ca |
children | e7cacb45c4be |
comparison
equal
deleted
inserted
replaced
29881:12f8bef59bfa | 29882:307b20e5e505 |
---|---|
50 self._template = opts.get("template") | 50 self._template = opts.get("template") |
51 self._converter = converter | 51 self._converter = converter |
52 self._item = None | 52 self._item = None |
53 # function to convert node to string suitable for this output | 53 # function to convert node to string suitable for this output |
54 self.hexfunc = hex | 54 self.hexfunc = hex |
55 def __enter__(self): | |
56 return self | |
57 def __exit__(self, exctype, excvalue, traceback): | |
58 if exctype is None: | |
59 self.end() | |
55 def __nonzero__(self): | 60 def __nonzero__(self): |
56 '''return False if we're not doing real templating so we can | 61 '''return False if we're not doing real templating so we can |
57 skip extra work''' | 62 skip extra work''' |
58 return True | 63 return True |
59 def _showitem(self): | 64 def _showitem(self): |