mercurial-plugin-1.0 doesn't work with mercurial-2.9

240 views
Skip to first unread message

Takumi IINO

unread,
Feb 6, 2014, 1:12:46 AM2/6/14
to trac...@googlegroups.com
Hi. I tried mercurial-plugin-1.0 with mercurial-2.9, and get following error.

    AttributeError: 'localrepository' object has no attribute 'branchtags'

Because branchtags method deleated in mercurial-2.9.

Same problem will also occur in 0.12 branch.

This is a monky patch.

# HG changeset patch
# User Takumi IINO <trot.t...@gmail.com>
# Date 1391665445 -32400
#      Thu Feb 06 14:44:05 2014 +0900
# Branch 1.0
# Node ID be9d923c8817ef46685d224e933cf8d476fcd505
# Parent  8df754d9b36a8bd5c7385f8ebebbf0069d2088d6
add helper method that deleted in mercurial-2.9

diff -r 8df754d9b36a -r be9d923c8817 tracext/hg/backend.py
--- a/tracext/hg/backend.py     Wed Oct 17 20:31:01 2012 +0200
+++ 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.
+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():

Christian Boos

unread,
Feb 6, 2014, 5:17:24 PM2/6/14
to trac...@googlegroups.com
Hello Takumi,

On 2014-02-06 7:12 AM, Takumi IINO wrote:
> Hi. I tried mercurial-plugin-1.0 with mercurial-2.9, and get following
> error.
>
> AttributeError: 'localrepository' object has no attribute 'branchtags'
>
> Because branchtags method deleated in mercurial-2.9.
> see http://selenic.com/hg/rev/4274eda143cb.
>

Thanks! But we (try to) support older Mercurial versions as well, and
changectx.closesbranches() was only introduced in 2.3.
So I needed to add a follow-up [1] which should make it work with any
supported version.

> Same problem will also occur in 0.12 branch.
>

Combined changes were backported to the 0.12 branch in [2].

Thanks again!

-- Christian

[1] - http://trac.edgewall.org/changeset/28/mercurial-plugin
[2] - http://trac.edgewall.org/changeset/29/mercurial-plugin
Reply all
Reply to author
Forward
0 new messages