Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templatekw.py @ 39616:87428152e820
templatekw: add experimental {status} keyword
This is another example of fctx-based keywords. I think this is somewhat
useful in log templates.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 29 Jul 2018 22:04:01 +0900 |
parents | a5da906306c9 |
children | 34ecc0a09c76 |
line wrap: on
line diff
--- a/mercurial/templatekw.py Sun Jul 29 21:52:01 2018 +0900 +++ b/mercurial/templatekw.py Sun Jul 29 22:04:01 2018 +0900 @@ -301,6 +301,15 @@ revcache['filestatusall'] = listall return revcache['filestatus'] +def _getfilestatusmap(context, mapping, listall=False): + revcache = context.resource(mapping, 'revcache') + if 'filestatusmap' not in revcache or revcache['filestatusall'] < listall: + stat = _getfilestatus(context, mapping, listall=listall) + revcache['filestatusmap'] = statmap = {} + for char, files in zip(pycompat.iterbytestr('MAR!?IC'), stat): + statmap.update((f, char) for f in files) + return revcache['filestatusmap'] # {path: statchar} + def _showfilesbystat(context, mapping, name, index): stat = _getfilestatus(context, mapping) files = stat[index] @@ -595,6 +604,19 @@ fctx = context.resource(mapping, 'fctx') return fctx.size() +# requires 'fctx' to denote {status} depends on (ctx, path) pair +@templatekeyword('status', requires={'ctx', 'fctx', 'revcache'}) +def showstatus(context, mapping): + """String. Status code of the current file. (EXPERIMENTAL)""" + path = templateutil.runsymbol(context, mapping, 'path') + path = templateutil.stringify(context, mapping, path) + if not path: + return + statmap = _getfilestatusmap(context, mapping) + if path not in statmap: + statmap = _getfilestatusmap(context, mapping, listall=True) + return statmap.get(path) + @templatekeyword("successorssets", requires={'repo', 'ctx'}) def showsuccessorssets(context, mapping): """Returns a string of sets of successors for a changectx. Format used