summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2019-02-18 23:19:39 +0000
committerGo MAEDA <maeda@farend.jp>2019-02-18 23:19:39 +0000
commit7b20e4c0348b9c7c59b13ee38a47a3d591f29db2 (patch)
treec290e5a02ba03680042f0888074377474220b9ee /lib
parentb68dcfc930399bffdeef154f666d5e516c7680ae (diff)
downloadredmine-7b20e4c0348b9c7c59b13ee38a47a3d591f29db2.tar.gz
redmine-7b20e4c0348b9c7c59b13ee38a47a3d591f29db2.zip
Refactor GitAdapter#default_branch not to unnecessarily iterate through all elements (#30828).
Patch by Pavel Rosický. git-svn-id: http://svn.redmine.org/redmine/trunk@17883 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib')
-rw-r--r--lib/redmine/scm/adapters/git_adapter.rb10
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/redmine/scm/adapters/git_adapter.rb b/lib/redmine/scm/adapters/git_adapter.rb
index fcc77f393..93d48a64d 100644
--- a/lib/redmine/scm/adapters/git_adapter.rb
+++ b/lib/redmine/scm/adapters/git_adapter.rb
@@ -108,11 +108,11 @@ module Redmine
def default_branch
bras = self.branches
- return nil if bras.nil?
- default_bras = bras.select{|x| x.is_default == true}
- return default_bras.first.to_s if ! default_bras.empty?
- master_bras = bras.select{|x| x.to_s == 'master'}
- master_bras.empty? ? bras.first.to_s : 'master'
+ return unless bras
+ default_bras = bras.detect{|x| x.is_default == true}
+ return default_bras.to_s if default_bras
+ master_bras = bras.detect{|x| x.to_s == 'master'}
+ master_bras ? 'master' : bras.first.to_s
end
def entry(path=nil, identifier=nil)