From 9c1e5dd717bae94a5b3d0d3849e155d4f860f0f6 Mon Sep 17 00:00:00 2001 From: Patrick Mezard Date: Wed, 20 Jun 2012 17:23:51 +0200 Subject: [PATCH] remotebranches: add remotebranches template keyword Return names of all remote branches heads on a revision. --- README | 4 ++++ hg_remotebranches.py | 23 +++++++++++++++++++++++ tests/test-remotebranches.t | 5 +++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/README b/README index df5046141b..d2ec9b08f8 100644 --- a/README +++ b/README @@ -42,3 +42,7 @@ a repository whose path is listed in the ``upstream`` field of the ``remotebranches.upstream`` setting, it defaults to behaving identically to ``pushed()``. The ``remotebranches()`` revset simply returns all remote branches head changesets. + +When template keywords can be registered (Mercurial 1.5 and later), +remotebranches adds a ``remotebranches`` keyword returning a space +separated list of all names of remote branches heads on a changeset. \ No newline at end of file diff --git a/hg_remotebranches.py b/hg_remotebranches.py index bc1a52a062..3a18786b4b 100644 --- a/hg_remotebranches.py +++ b/hg_remotebranches.py @@ -15,6 +15,13 @@ try: except ImportError: revset = None +try: + from mercurial import templatekw + # force demandimport to load templatekw + templatekw.keywords +except ImportError: + templatekw = None + from hgext import schemes def reposetup(ui, repo): @@ -207,3 +214,19 @@ if revset is not None: revset.symbols.update({'upstream': upstream, 'pushed': pushed, 'remotebranches': remotebranchesrevset}) + +def remotebrancheskw(**args): + """:remotebranches: List of strings. Any remote branch associated + with the changeset. + """ + repo, ctx = args['repo'], args['ctx'] + remotenodes = {} + for name, node in repo._remotebranches.iteritems(): + remotenodes.setdefault(node, []).append(name) + if ctx.node() in remotenodes: + names = sorted(remotenodes[ctx.node()]) + return templatekw.showlist('remotebranch', names, + plural='remotebranches', **args) + +if templatekw is not None: + templatekw.keywords['remotebranches'] = remotebrancheskw diff --git a/tests/test-remotebranches.t b/tests/test-remotebranches.t index c53cae3883..47f1fef2e1 100644 --- a/tests/test-remotebranches.t +++ b/tests/test-remotebranches.t @@ -199,9 +199,10 @@ but configured, it'll do the expected thing: | | summary: add d | | -Test remotebranches revset +Test remotebranches revset and keyword - $ hg log -r 'remotebranches()' --template '{rev}:{node|short} {tags}\n' + $ hg log -r 'remotebranches()' \ + > --template '{rev}:{node|short} {remotebranches}\n' 1:7c3bad9141dc alpha/default 2:95cb4ab9fe1d alpha/stable 3:78f83396d79e beta/default