Patchwork D6211: branch: return early if we find an open named branch apart from default

login
register
mail settings
Submitter phabricator
Date April 5, 2019, 1:32 p.m.
Message ID <differential-rev-PHID-DREV-dxcwm2nb5khlk7vwcdbq-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/39508/
State Superseded
Headers show

Comments

phabricator - April 5, 2019, 1:32 p.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The current code builds a list of all the open named branches except default and
  then bool that. This is mostly fine until you get a repo which has thousands of
  named branches.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6211

AFFECTED FILES
  mercurial/commands.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1125,11 +1125,11 @@ 
             ui.status(_('marked working directory as branch %s\n') % label)
 
             # find any open named branches aside from default
-            others = [n for n, h, t, c in repo.branchmap().iterbranches()
-                      if n != "default" and not c]
-            if not others:
-                ui.status(_('(branches are permanent and global, '
-                            'did you want a bookmark?)\n'))
+            for n, h, t, c in repo.branchmap().iterbranches():
+                if n != "default" and not c:
+                    return 0
+            ui.status(_('(branches are permanent and global, '
+                        'did you want a bookmark?)\n'))
 
 @command('branches',
     [('a', 'active', False,