Commits

Yuya Nishihara committed 3d8163b

repofilter: show current working branch first (closes #2042)

If you go feature-branch development, there are many short-term branches,
which bursts branch combo box. In that case, the current branch will be
accessed more often, let's give higher priority to it.

  • Participants
  • Parent commits a32bf09
  • Branches stable

Comments (0)

Files changed (2)

File tests/widget/repofilterbar_branch_test.py

             hg.branch(name)
             hg.commit('-m', 'create %s branch' % name)
         hg.commit('--close-branch', '-m', 'close baz branch')
+        hg.update('foo')  # current branch will be listed first
         cls.repo = thgrepo.repository(path=hg.path)
 
     @classmethod
 
     def test_open_branches(self):
         self.assertEqual([self.widget._allBranchesLabel,
-                          'default', 'bar', 'foo'],
+                          'foo', 'default', 'bar'],
                          _listitems(self.widget._branchCombo))
         self.assertTrue(self.widget._branchCombo.isEnabled())
         self.assertFalse(self.branchchanged.called)
         self.widget._abranchAction.setChecked(False)
         self.widget._abranchAction.trigger()  # checked
         self.assertEqual([self.widget._allBranchesLabel,
-                          'bar', 'foo'],
+                          'foo', 'bar'],
                          _listitems(self.widget._branchCombo))
         self.assertTrue(self.widget._branchCombo.isEnabled())
         self.assertFalse(self.branchchanged.called)
         self.widget._cbranchAction.setChecked(False)
         self.widget._cbranchAction.trigger()  # checked
         self.assertEqual([self.widget._allBranchesLabel,
-                          'default', 'bar', 'baz', 'foo'],
+                         'foo',  'default', 'bar', 'baz'],
                          _listitems(self.widget._branchCombo))
         self.assertTrue(self.widget._branchCombo.isEnabled())
         self.assertFalse(self.branchchanged.called)

File tortoisehg/hgqt/repofilter.py

         else:
             branches = self._repo.namedbranches
 
-        # show the 'default' branch on top, if there is one
-        if 'default' in branches:
-            branches = ['default'] + \
-                [branch for branch in branches if branch != 'default']
+        # easy access to common branches (Python sorted() is stable)
+        priomap = {self._repo.dirstate.branch(): -2, 'default': -1}
+        branches = sorted(branches, key=lambda e: priomap.get(e, 0))
+
         self._branchReloading = True
         self._branchCombo.clear()
         self._branchCombo.addItem(self._allBranchesLabel)