# HG changeset patch # User Pierre-Yves David # Date 1457982212 0 # Node ID 95874e8fc5f2a491fbc3c303829ac6c85c33f295 # Parent 5e9ce63107209754da23a87142ad2b9de99be9df stack: add basic formatter and label support This still is not great, especially I would like '-T' to be able to control how we display the changeset, but this is useful progress. diff -r 5e9ce6310720 -r 95874e8fc5f2 hgext3rd/topic/__init__.py --- a/hgext3rd/topic/__init__.py Mon Mar 14 18:43:23 2016 +0000 +++ b/hgext3rd/topic/__init__.py Mon Mar 14 19:03:32 2016 +0000 @@ -54,7 +54,6 @@ topicrev = re.compile(r'^t\d+$') - def _namemap(repo, name): if topicrev.match(name): idx = int(name[1:]) @@ -189,13 +188,13 @@ ('', 'clear', False, 'clear active topic if any'), ('', 'change', '', 'revset of existing revisions to change topic'), ('l', 'list', False, 'show the stack of changeset in the topic'), -]) -def topics(ui, repo, topic='', clear=False, change=None, list=False): + ] + commands.formatteropts) +def topics(ui, repo, topic='', clear=False, change=None, list=False, **opts): """View current topic, set current topic, or see all topics.""" if list: if clear or change: raise error.Abort(_("cannot use --clear or --change with --list")) - return stack.showstack(ui, repo, topic) + return stack.showstack(ui, repo, topic, opts) if change: if not obsolete.isenabled(repo, obsolete.createmarkersopt): diff -r 5e9ce6310720 -r 95874e8fc5f2 hgext3rd/topic/stack.py --- a/hgext3rd/topic/stack.py Mon Mar 14 18:43:23 2016 +0000 +++ b/hgext3rd/topic/stack.py Mon Mar 14 19:03:32 2016 +0000 @@ -13,11 +13,12 @@ trevs = repo.revs("topic(%s) - obsolete()", topic) return _orderrevs(repo, trevs) -def showstack(ui, repo, topic): +def showstack(ui, repo, topic, opts): if not topic: topic = repo.currenttopic if not topic: raise error.Abort(_('no active topic to list')) + fm = ui.formatter('topicstack', opts) for idx, r in enumerate(getstack(repo, topic)): # super crude initial version symbol = ':' @@ -28,14 +29,18 @@ if repo.revs('%d and unstable()', r): symbol = '$' state = 'unstable' - if state == 'clean': - l = "t%d%s %s\n" % (idx, symbol, - repo[r].description().splitlines()[0]) - else: - l = "t%d%s %s (%s)\n" % (idx, symbol, - repo[r].description().splitlines()[0], - state) - ui.write(l) + fm.startitem() + fm.write('topic.stack.index', 't%d', idx, + label='topic.stack.index topic.stack.index.%s' % state) + fm.write('topic.stack.state.symbol', '%s', symbol, + label='topic.stack.state topic.stack.state.%s' % state) + fm.plain(' ') + fm.write('topic.stack.desc', '%s', repo[r].description().splitlines()[0], + label='topic.stack.desc topic.stack.desc.%s' % state) + fm.condwrite(state != 'clean', 'topic.stack.state', ' (%s)', state, + label='topic.stack.state topic.stack.state.%s' % state) + fm.plain('\n') + fm.end() # Copied from evolve 081605c2e9b6