diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-09-08 21:54:52 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-09-08 21:54:52 +0300 |
commit | 218219abbdfdc3bc0bc1a9c95cfc0e0ddb5861dd (patch) | |
tree | 42cbccd75357e44ad9895b59de76e9a56c03be4a /lib | |
parent | bde3f25d262b13d0139276786fe9d9cba29269b8 (diff) | |
download | gitlab-ce-218219abbdfdc3bc0bc1a9c95cfc0e0ddb5861dd.tar.gz |
Refactoring inside refactoring. We need to go deeper
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/diff/file.rb | 23 | ||||
-rw-r--r-- | lib/gitlab/diff/line.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/diff/line_code.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/diff/parser.rb | 9 |
4 files changed, 29 insertions, 18 deletions
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index 62c0d38884a..19a1198c68c 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -1,23 +1,18 @@ module Gitlab module Diff class File - attr_reader :diff, :blob + attr_reader :diff delegate :new_file, :deleted_file, :renamed_file, :old_path, :new_path, to: :diff, prefix: false - def initialize(project, commit, diff) + def initialize(diff) @diff = diff - @blob = project.repository.blob_for_diff(commit, diff) end # Array of Gitlab::DIff::Line objects def diff_lines - @lines ||= parser.parse(diff.diff.lines, old_path, new_path) - end - - def blob_exists? - !@blob.nil? + @lines ||= parser.parse(raw_diff.lines) end def mode_changed? @@ -28,6 +23,10 @@ module Gitlab Gitlab::Diff::Parser.new end + def raw_diff + diff.diff + end + def next_line(index) diff_lines[index + 1] end @@ -37,6 +36,14 @@ module Gitlab diff_lines[index - 1] end end + + def file_path + if diff.new_path.present? + diff.new_path + elsif diff.old_path.present? + diff.old_path + end + end end end end diff --git a/lib/gitlab/diff/line.rb b/lib/gitlab/diff/line.rb index e8b9c980a1a..8ac1b15e88a 100644 --- a/lib/gitlab/diff/line.rb +++ b/lib/gitlab/diff/line.rb @@ -1,10 +1,10 @@ module Gitlab module Diff class Line - attr_reader :type, :text, :index, :code, :old_pos, :new_pos + attr_reader :type, :text, :index, :old_pos, :new_pos - def initialize(text, type, index, old_pos, new_pos, code = nil) - @text, @type, @index, @code = text, type, index, code + def initialize(text, type, index, old_pos, new_pos) + @text, @type, @index = text, type, index @old_pos, @new_pos = old_pos, new_pos end end diff --git a/lib/gitlab/diff/line_code.rb b/lib/gitlab/diff/line_code.rb new file mode 100644 index 00000000000..f3578ab3d35 --- /dev/null +++ b/lib/gitlab/diff/line_code.rb @@ -0,0 +1,9 @@ +module Gitlab + module Diff + class LineCode + def self.generate(file_path, new_line_position, old_line_position) + "#{Digest::SHA1.hexdigest(file_path)}_#{old_line_position}_#{new_line_position}" + end + end + end +end diff --git a/lib/gitlab/diff/parser.rb b/lib/gitlab/diff/parser.rb index 0fd11c69a59..9d6309954a4 100644 --- a/lib/gitlab/diff/parser.rb +++ b/lib/gitlab/diff/parser.rb @@ -3,7 +3,7 @@ module Gitlab class Parser include Enumerable - def parse(lines, old_path, new_path) + def parse(lines) @lines = lines, lines_obj = [] line_obj_index = 0 @@ -33,8 +33,7 @@ module Gitlab next else type = identification_type(line) - line_code = generate_line_code(new_path, line_new, line_old) - lines_obj << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new, line_code) + lines_obj << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new) line_obj_index += 1 end @@ -73,10 +72,6 @@ module Gitlab end end - def generate_line_code(path, line_new, line_old) - "#{Digest::SHA1.hexdigest(path)}_#{line_old}_#{line_new}" - end - def html_escape str replacements = { '&' => '&', '>' => '>', '<' => '<', '"' => '"', "'" => ''' } str.gsub(/[&"'><]/, replacements) |