summaryrefslogtreecommitdiff
path: root/lib/gitlab/conflict
diff options
context:
space:
mode:
authorMaxim Rydkin <maks.rydkin@gmail.com>2017-09-12 17:02:11 +0000
committerRobert Speicher <robert@gitlab.com>2017-09-12 17:02:11 +0000
commit4db6b8f0bb35fabf48c2d795ef3151810bb8251c (patch)
treefcf5371b245851b331fe7bc09b802fdf0e8293ac /lib/gitlab/conflict
parenta1a2ce4af4abddea64f909997c4a214dd2c04aa3 (diff)
downloadgitlab-ce-4db6b8f0bb35fabf48c2d795ef3151810bb8251c.tar.gz
Decrease Cyclomatic Complexity threshold to 13
Diffstat (limited to 'lib/gitlab/conflict')
-rw-r--r--lib/gitlab/conflict/parser.rb28
1 files changed, 19 insertions, 9 deletions
diff --git a/lib/gitlab/conflict/parser.rb b/lib/gitlab/conflict/parser.rb
index 84f9ecd3d23..e3678c914db 100644
--- a/lib/gitlab/conflict/parser.rb
+++ b/lib/gitlab/conflict/parser.rb
@@ -12,12 +12,7 @@ module Gitlab
MissingEndDelimiter = Class.new(ParserError)
def parse(text, our_path:, their_path:, parent_file: nil)
- raise UnmergeableFile if text.blank? # Typically a binary file
- raise UnmergeableFile if text.length > 200.kilobytes
-
- text.force_encoding('UTF-8')
-
- raise UnsupportedEncoding unless text.valid_encoding?
+ validate_text!(text)
line_obj_index = 0
line_old = 1
@@ -32,15 +27,15 @@ module Gitlab
full_line = line.delete("\n")
if full_line == conflict_start
- raise UnexpectedDelimiter unless type.nil?
+ validate_delimiter!(type.nil?)
type = 'new'
elsif full_line == conflict_middle
- raise UnexpectedDelimiter unless type == 'new'
+ validate_delimiter!(type == 'new')
type = 'old'
elsif full_line == conflict_end
- raise UnexpectedDelimiter unless type == 'old'
+ validate_delimiter!(type == 'old')
type = nil
elsif line[0] == '\\'
@@ -59,6 +54,21 @@ module Gitlab
lines
end
+
+ private
+
+ def validate_text!(text)
+ raise UnmergeableFile if text.blank? # Typically a binary file
+ raise UnmergeableFile if text.length > 200.kilobytes
+
+ text.force_encoding('UTF-8')
+
+ raise UnsupportedEncoding unless text.valid_encoding?
+ end
+
+ def validate_delimiter!(condition)
+ raise UnexpectedDelimiter unless condition
+ end
end
end
end