# HG changeset patch # User Brodie Rao # Date 1379318909 25200 # Node ID 38fad5e76ee856a3f2bfa31174af58a8b2e0e9f9 # Parent cbe2bcc927cd0f106d8bc78bc9575cacc3ef3225 branches: simplify with repo.branchmap().iterbranches() Running hg branches on the PyPy repo (with 996) over a busy NFS server, before this change: $ time hg --profile branches > /dev/null CallCount Recursive Total(s) Inline(s) module:lineno(function) 1069 0 1.2955 1.2955 1063 0 0.5576 0.5576 4122 0 0.1993 0.0449 mercurial.repoview:161(changelog) 8240 0 0.0771 0.0299 mercurial.changelog:133(tip) 4122 0 0.0422 0.0204 mercurial.localrepo:26(__get__) 8240 0 0.0252 0.0131 4122 0 0.0060 0.0037 mercurial.repoview:112(filterrevs) 8240 0 0.0028 0.0028 3029 0 0.2139 0.0390 mercurial.context:202(__init__) 3029 0 0.1402 0.0339 mercurial.repoview:161(changelog) 3029 0 0.0240 0.0087 mercurial.changelog:183(rev) 9087 0 0.0067 0.0067 1096 0 0.0025 0.0025 4125 0 0.0015 0.0015 4229 0 0.0344 0.0344 mercurial.revlog:296(rev) 1061 0 0.0343 0.0343 1063 0 0.0339 0.0339 40476 16488 0.0479 0.0311 16488 0 0.0216 0.0168 mercurial.revlog:262(__len__) 8240 0 0.0771 0.0299 mercurial.changelog:133(tip) 8240 0 0.0281 0.0203 mercurial.changelog:190(node) 8240 0 0.0191 0.0095 1342 0 0.0278 0.0278 1074 0 2.2143 0.0266 mercurial.changelog:270(read) 1074 0 2.1328 0.0230 mercurial.revlog:907(revision) 1073 0 0.0208 0.0108 mercurial.changelog:28(decodeextra) 2148 0 0.0072 0.0072 2148 0 0.0211 0.0038 mercurial.encoding:61(tolocal) 1074 0 0.0028 0.0028 1061 0 1.9811 0.0237 mercurial.revlog:817(_loadchunk) real 0m2.742s user 0m0.811s sys 0m0.188s After this change: $ time hg --profile branches > /dev/null CallCount Recursive Total(s) Inline(s) module:lineno(function) 2092 0 0.1444 0.0292 mercurial.context:202(__init__) 2092 0 0.0908 0.0216 mercurial.repoview:161(changelog) 2092 0 0.0164 0.0057 mercurial.changelog:183(rev) 6276 0 0.0045 0.0045 1096 0 0.0024 0.0024 3188 0 0.0013 0.0013 2218 0 0.0230 0.0230 mercurial.revlog:296(rev) 2111 0 0.1028 0.0218 mercurial.repoview:161(changelog) 4218 0 0.0387 0.0146 mercurial.changelog:133(tip) 2111 0 0.0238 0.0104 mercurial.localrepo:26(__get__) 4218 0 0.0122 0.0062 2111 0 0.0038 0.0021 mercurial.repoview:112(filterrevs) 4218 0 0.0014 0.0014 20240 8444 0.0233 0.0149 8444 0 0.0110 0.0084 mercurial.revlog:262(__len__) 4218 0 0.0387 0.0146 mercurial.changelog:133(tip) 4218 0 0.0144 0.0103 mercurial.changelog:190(node) 4218 0 0.0097 0.0048 2398 1 0.0271 0.0115 mercurial.localrepo:26(__get__) 2398 1 0.0146 0.0046 mercurial.scmutil:939(__get__) 2124 0 0.0009 0.0009 mercurial.localrepo:330(unfiltered) 274 0 0.0002 0.0002 mercurial.repoview:192(unfiltered) 4 0 0.1409 0.0112 mercurial.branchmap:19(read) 1096 0 0.1113 0.0028 mercurial.localrepo:407(__contains__) 1098 0 0.0020 0.0020 1097 0 0.0019 0.0019 1096 0 0.0093 0.0018 mercurial.encoding:61(tolocal) 1096 0 0.0010 0.0010 4349 0 0.0150 0.0105 mercurial.changelog:190(node) 4349 0 0.0045 0.0045 mercurial.revlog:317(node) real 0m0.362s user 0m0.329s sys 0m0.024s diff -r cbe2bcc927cd -r 38fad5e76ee8 mercurial/commands.py --- a/mercurial/commands.py Mon Sep 16 01:08:29 2013 -0700 +++ b/mercurial/commands.py Mon Sep 16 01:08:29 2013 -0700 @@ -1015,17 +1015,9 @@ allheads = set(repo.heads()) branches = [] - for tag, heads in repo.branchmap().iteritems(): - for h in reversed(heads): - ctx = repo[h] - isopen = not ctx.closesbranch() - if isopen: - tip = ctx - break - else: - tip = repo[heads[-1]] - isactive = isopen and bool(set(heads) & allheads) - branches.append((tag, tip, isactive, isopen)) + for tag, heads, tip, isclosed in repo.branchmap().iterbranches(): + isactive = not isclosed and bool(set(heads) & allheads) + branches.append((tag, repo[tip], isactive, not isclosed)) branches.sort(key=lambda i: (i[2], i[1].rev(), i[0], i[3]), reverse=True)