From fc98fed6e5e7a5d48e6940c70f4281347d3eae6b Mon Sep 17 00:00:00 2001 From: MAEDA Go Date: Sun, 28 Aug 2022 14:01:29 +0900 Subject: [PATCH 5/5] Use the safe navigation operator instead of checking if an object is nil --- app/models/repository/git.rb | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/app/models/repository/git.rb b/app/models/repository/git.rb index b5927ad79..85a3b3baa 100644 --- a/app/models/repository/git.rb +++ b/app/models/repository/git.rb @@ -40,9 +40,7 @@ class Repository::Git < Repository end def report_last_commit - return false if extra_info.nil? - - v = extra_info["extra_report_last_commit"] + v = extra_info&.fetch('extra_report_last_commit', nil) return false if v.nil? v.to_s != '0' @@ -133,11 +131,9 @@ class Repository::Git < Repository scm_brs = branches return if scm_brs.blank? - h1 = extra_info || {} - h = h1.dup + h = extra_info&.dup || {} repo_heads = scm_brs.map(&:scmid) - h["heads"] ||= [] - prev_db_heads = h["heads"].dup + prev_db_heads = h["heads"]&.dup || [] prev_db_heads += heads_from_branches_hash if prev_db_heads.empty? return if prev_db_heads.sort == repo_heads.sort @@ -232,8 +228,7 @@ class Repository::Git < Repository private :save_revision def heads_from_branches_hash - h1 = extra_info || {} - h = h1.dup + h = extra_info&.dup || {} h["branches"] ||= {} h['branches'].map{|br, hs| hs['last_scmid']} end -- 2.34.1