mercurial/templatekw.py
changeset 39616 87428152e820
parent 39615 a5da906306c9
child 39639 34ecc0a09c76
equal deleted inserted replaced
39615:a5da906306c9 39616:87428152e820
   299                                listunknown=listall)
   299                                listunknown=listall)
   300         revcache['filestatus'] = stat
   300         revcache['filestatus'] = stat
   301         revcache['filestatusall'] = listall
   301         revcache['filestatusall'] = listall
   302     return revcache['filestatus']
   302     return revcache['filestatus']
   303 
   303 
       
   304 def _getfilestatusmap(context, mapping, listall=False):
       
   305     revcache = context.resource(mapping, 'revcache')
       
   306     if 'filestatusmap' not in revcache or revcache['filestatusall'] < listall:
       
   307         stat = _getfilestatus(context, mapping, listall=listall)
       
   308         revcache['filestatusmap'] = statmap = {}
       
   309         for char, files in zip(pycompat.iterbytestr('MAR!?IC'), stat):
       
   310             statmap.update((f, char) for f in files)
       
   311     return revcache['filestatusmap']  # {path: statchar}
       
   312 
   304 def _showfilesbystat(context, mapping, name, index):
   313 def _showfilesbystat(context, mapping, name, index):
   305     stat = _getfilestatus(context, mapping)
   314     stat = _getfilestatus(context, mapping)
   306     files = stat[index]
   315     files = stat[index]
   307     return templateutil.compatfileslist(context, mapping, name, files)
   316     return templateutil.compatfileslist(context, mapping, name, files)
   308 
   317 
   593 def showsize(context, mapping):
   602 def showsize(context, mapping):
   594     """Integer. Size of the current file in bytes. (EXPERIMENTAL)"""
   603     """Integer. Size of the current file in bytes. (EXPERIMENTAL)"""
   595     fctx = context.resource(mapping, 'fctx')
   604     fctx = context.resource(mapping, 'fctx')
   596     return fctx.size()
   605     return fctx.size()
   597 
   606 
       
   607 # requires 'fctx' to denote {status} depends on (ctx, path) pair
       
   608 @templatekeyword('status', requires={'ctx', 'fctx', 'revcache'})
       
   609 def showstatus(context, mapping):
       
   610     """String. Status code of the current file. (EXPERIMENTAL)"""
       
   611     path = templateutil.runsymbol(context, mapping, 'path')
       
   612     path = templateutil.stringify(context, mapping, path)
       
   613     if not path:
       
   614         return
       
   615     statmap = _getfilestatusmap(context, mapping)
       
   616     if path not in statmap:
       
   617         statmap = _getfilestatusmap(context, mapping, listall=True)
       
   618     return statmap.get(path)
       
   619 
   598 @templatekeyword("successorssets", requires={'repo', 'ctx'})
   620 @templatekeyword("successorssets", requires={'repo', 'ctx'})
   599 def showsuccessorssets(context, mapping):
   621 def showsuccessorssets(context, mapping):
   600     """Returns a string of sets of successors for a changectx. Format used
   622     """Returns a string of sets of successors for a changectx. Format used
   601     is: [ctx1, ctx2], [ctx3] if ctx has been splitted into ctx1 and ctx2
   623     is: [ctx1, ctx2], [ctx3] if ctx has been splitted into ctx1 and ctx2
   602     while also diverged into ctx3. (EXPERIMENTAL)"""
   624     while also diverged into ctx3. (EXPERIMENTAL)"""