Mercurial > hg > trac > jungle > src > mercurial-plugin
changeset 28:46ae3c486ed6 1.0
Fix for hg 2.9 branchtags() doesn't break with older hg versions.
author | Christian Boos <cboos@edgewall.org> |
---|---|
date | Thu, 06 Feb 2014 20:55:32 +0100 |
parents | 7aaccb9f649a |
children | 21bb3cc19977 |
files | tracext/hg/backend.py |
diffstat | 1 files changed, 13 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/tracext/hg/backend.py Thu Feb 06 14:44:05 2014 +0900 +++ b/tracext/hg/backend.py Thu Feb 06 20:55:32 2014 +0100 @@ -21,6 +21,7 @@ import posixpath import re import sys +import types import pkg_resources @@ -155,13 +156,13 @@ return get_bookmarks(ctx) return () -# Note: localrepository.branchtags deleated in mercurial-2.9. -# see http://selenic.com/hg/rev/4274eda143cb +# Note: localrepository.branchtags was removed in mercurial-2.9 +# see http://selenic.com/hg/rev/4274eda143cb def get_branchtags(repo): - '''return a dict where branch names map to the tipmost head of - the branch, open heads come before closed''' - - def branchtip(repo, heads): + """return a dict where branch names map to the tipmost head of + the branch, open heads come before closed_branches + """ + def branchtip(heads): '''return the tipmost branch head in heads''' tip = heads[-1] for h in reversed(heads): @@ -172,7 +173,7 @@ bt = {} for bn, heads in repo.branchmap().iteritems(): - bt[bn] = branchtip(repo, heads) + bt[bn] = branchtip(heads) return bt class trac_ui(ui): @@ -473,7 +474,7 @@ repos = rm.get_repository(reponame) if repos: if ns == 'branch': - for b, n in get_branchtags(repos.repo).items(): + for b, n in repos.repo.branchtags().items(): if repos.to_u(b) == rev: rev = repos.repo.changelog.rev(n) break @@ -566,6 +567,9 @@ " repository (Mercurial %(version)s says " "%(error)s)", path=path, version=version, error=error)) + # restore branchtags() if needed (see StackOverflow:972) + if not getattr(self.repo, 'branchtags', None): + self.repo.branchtags = types.MethodType(get_branchtags, self.repo) Repository.__init__(self, 'hg:%s' % path, params, log) def from_hg_time(self, timeinfo): @@ -636,7 +640,7 @@ # map ctx to (unicode) branch branches = {} closed_branches = {} - for b, n in get_branchtags(self.repo).items(): + for b, n in self.repo.branchtags().items(): b = self.to_u(b) ctx = self.repo[n] if 'close' in ctx.extra():