changeset 27:7aaccb9f649a 1.0

add helper method that deleted in mercurial-2.9
author Takumi IINO <trot.thunder@gmail.com>
date Thu, 06 Feb 2014 14:44:05 +0900
parents 546d3f11ac7a
children 46ae3c486ed6
files tracext/hg/backend.py
diffstat 1 files changed, 22 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/tracext/hg/backend.py	Thu Feb 06 19:56:06 2014 +0100
+++ b/tracext/hg/backend.py	Thu Feb 06 14:44:05 2014 +0900
@@ -155,6 +155,26 @@
             return get_bookmarks(ctx)
     return ()
 
+# Note: localrepository.branchtags deleated 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 the tipmost branch head in heads'''
+        tip = heads[-1]
+        for h in reversed(heads):
+            if not repo[h].closesbranch():
+              tip = h
+              break
+        return tip
+
+    bt = {}
+    for bn, heads in repo.branchmap().iteritems():
+        bt[bn] = branchtip(repo, heads)
+    return bt
+
 class trac_ui(ui):
     # Note: will be dropped in 0.13, see MercurialConnector._setup_ui
     def __init__(self, *args, **kwargs):
@@ -453,7 +473,7 @@
                 repos = rm.get_repository(reponame)
             if repos:
                 if ns == 'branch':
-                    for b, n in repos.repo.branchtags().items():
+                    for b, n in get_branchtags(repos.repo).items():
                         if repos.to_u(b) == rev:
                             rev = repos.repo.changelog.rev(n)
                             break
@@ -616,7 +636,7 @@
         # map ctx to (unicode) branch
         branches = {}
         closed_branches = {}
-        for b, n in self.repo.branchtags().items():
+        for b, n in get_branchtags(self.repo).items():
             b = self.to_u(b)
             ctx = self.repo[n]
             if 'close' in ctx.extra():