# HG changeset patch # User Anton Shestakov # Date 1557566072 -28800 # Node ID fd4f422b0b5734daf35f0c9fe9c0cc964e10326f # Parent b72cd597a88780f430c7a464c6b41b2262e9b5e8 stack: leverage labelsgen() to produce all needed labels for fm.write() diff -r b72cd597a887 -r fd4f422b0b57 hgext3rd/topic/stack.py --- a/hgext3rd/topic/stack.py Wed May 08 16:00:34 2019 +0800 +++ b/hgext3rd/topic/stack.py Sat May 11 17:14:32 2019 +0800 @@ -215,11 +215,9 @@ branches = set([self._repo[None].branch()]) return branches -def labelsgen(prefix, labelssuffix): - """ Takes a label prefix and a list of suffixes. Returns a string of the prefix - formatted with each suffix separated with a space. - """ - return ' '.join(prefix % suffix.replace(' ', '-') for suffix in labelssuffix) +def labelsgen(prefix, parts): + fmt = prefix + '.%s' + return prefix + ' ' + ' '.join(fmt % p.replace(' ', '-') for p in parts) def showstack(ui, repo, branch=None, topic=None, opts=None): if opts is None: @@ -364,17 +362,17 @@ fm.plain(' ') else: fm.write('topic.stack.index', '%s%%d' % prefix, idx, - label='topic.stack.index ' + labelsgen('topic.stack.index.%s', states)) + label=labelsgen('topic.stack.index', states)) if ui.verbose: fm.write('topic.stack.shortnode', '(%s)', short(ctx.node()), - label='topic.stack.shortnode ' + labelsgen('topic.stack.shortnode.%s', states)) + label=labelsgen('topic.stack.shortnode', states)) fm.write('topic.stack.state.symbol', '%s', symbol, - label='topic.stack.state ' + labelsgen('topic.stack.state.%s', states)) + label=labelsgen('topic.stack.state', states)) fm.plain(' ') fm.write('topic.stack.desc', '%s', ctx.description().splitlines()[0], - label='topic.stack.desc ' + labelsgen('topic.stack.desc.%s', states)) + label=labelsgen('topic.stack.desc', states)) fm.condwrite(states != ['clean'] and idx is not None, 'topic.stack.state', ' (%s)', fm.formatlist(states, 'topic.stack.state'), - label='topic.stack.state ' + labelsgen('topic.stack.state.%s', states)) + label=labelsgen('topic.stack.state', states)) fm.plain('\n') fm.end()