diff rhodecode/controllers/branches.py @ 1440:b074dfa51292 beta

implements #195 added closed branches to detailed branches view
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 06 Aug 2011 23:13:23 +0300
parents 37625d304a16
children bf263968da47 87ec80c280bb
line wrap: on
line diff
--- a/rhodecode/controllers/branches.py	Fri Aug 05 21:21:51 2011 +0300
+++ b/rhodecode/controllers/branches.py	Sat Aug 06 23:13:23 2011 +0300
@@ -26,11 +26,12 @@
 import logging
 
 from pylons import tmpl_context as c
+import binascii
 
 from rhodecode.lib.auth import LoginRequired, HasRepoPermissionAnyDecorator
 from rhodecode.lib.base import BaseRepoController, render
 from rhodecode.lib.odict import OrderedDict
-
+from rhodecode.lib import safe_unicode
 log = logging.getLogger(__name__)
 
 
@@ -44,8 +45,34 @@
 
     def index(self):
 
-        c.repo_branches = OrderedDict()
-        for name, hash_ in c.rhodecode_repo.branches.items():
-            c.repo_branches[name] = c.rhodecode_repo.get_changeset(hash_)
+        def _branchtags(localrepo):
+
+            bt = {}
+            bt_closed = {}
+
+            for bn, heads in localrepo.branchmap().iteritems():
+                tip = heads[-1]
+                if 'close' not in localrepo.changelog.read(tip)[5]:
+                    bt[bn] = tip
+                else:
+                    bt_closed[bn] = tip
+            return bt, bt_closed
+
+
+        bt, bt_closed = _branchtags(c.rhodecode_repo._repo)
+        cs_g = c.rhodecode_repo.get_changeset
+        _branches = [(safe_unicode(n), cs_g(binascii.hexlify(h)),) for n, h in
+                     bt.items()]
+
+        _closed_branches = [(safe_unicode(n), cs_g(binascii.hexlify(h)),) for n, h in
+                     bt_closed.items()]
+
+        c.repo_branches = OrderedDict(sorted(_branches,
+                                             key=lambda ctx: ctx[0],
+                                             reverse=False))
+        c.repo_closed_branches = OrderedDict(sorted(_closed_branches,
+                                                    key=lambda ctx: ctx[0],
+                                                    reverse=False))
+
 
         return render('branches/branches.html')