# HG changeset patch # User Mads Kiilerich # Date 2015-01-05 23:54:36 # Node ID 1cd9bdf1362d7f7bf8d243963a496ebbf7ff9cc3 # Parent 7967d89fbe90ef07bd6549ccd47b04772b0930f3 hg: reimplement branch listings more efficiently Gives a 10 x speedup - which is noticable on big slow repos where the old implementation took several seconds. diff --git a/kallithea/lib/vcs/backends/hg/repository.py b/kallithea/lib/vcs/backends/hg/repository.py --- a/kallithea/lib/vcs/backends/hg/repository.py +++ b/kallithea/lib/vcs/backends/hg/repository.py @@ -121,34 +121,16 @@ class MercurialRepository(BaseRepository if self._empty: return {} - def _branchtags(localrepo): - """ - Patched version of mercurial branchtags to not return the closed - branches - - :param localrepo: locarepository instance - """ + bt = OrderedDict() + for bn, _heads, tip, isclosed in sorted(self._repo.branchmap().iterbranches()): + if isclosed: + if closed: + bt[safe_unicode(bn)] = hex(tip) + else: + if normal: + bt[safe_unicode(bn)] = hex(tip) - bt = {} - bt_closed = {} - for bn, heads in localrepo.branchmap().iteritems(): - tip = heads[-1] - if 'close' in localrepo.changelog.read(tip)[5]: - bt_closed[bn] = tip - else: - bt[bn] = tip - - if not normal: - return bt_closed - if closed: - bt.update(bt_closed) - return bt - - sortkey = lambda ctx: ctx[0] # sort by name - _branches = [(safe_unicode(n), hex(h),) for n, h in - _branchtags(self._repo).items()] - - return OrderedDict(sorted(_branches, key=sortkey, reverse=False)) + return bt @LazyProperty def tags(self):