2014-09-08 09:25:50 -04:00
|
|
|
module Gitlab
|
|
|
|
module Diff
|
|
|
|
class File
|
2016-01-14 16:38:37 -05:00
|
|
|
attr_reader :diff, :new_ref, :old_ref
|
2014-09-08 09:25:50 -04:00
|
|
|
|
|
|
|
delegate :new_file, :deleted_file, :renamed_file,
|
|
|
|
:old_path, :new_path, to: :diff, prefix: false
|
|
|
|
|
2016-01-14 16:38:37 -05:00
|
|
|
def initialize(diff, diff_refs)
|
2014-09-08 09:25:50 -04:00
|
|
|
@diff = diff
|
2016-01-07 22:37:01 -05:00
|
|
|
@old_ref, @new_ref = diff_refs
|
2014-09-08 09:25:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
# Array of Gitlab::DIff::Line objects
|
|
|
|
def diff_lines
|
2014-09-08 14:54:52 -04:00
|
|
|
@lines ||= parser.parse(raw_diff.lines)
|
2014-09-08 09:25:50 -04:00
|
|
|
end
|
|
|
|
|
2015-12-30 00:52:50 -05:00
|
|
|
def highlighted_diff_lines
|
2016-01-14 16:28:07 -05:00
|
|
|
Gitlab::Diff::Highlight.new(self).highlight
|
2015-12-30 00:52:50 -05:00
|
|
|
end
|
|
|
|
|
2016-01-20 08:51:56 -05:00
|
|
|
def parallel_diff_lines
|
|
|
|
Gitlab::Diff::ParallelDiff.new(self).parallelize
|
|
|
|
end
|
|
|
|
|
2014-09-08 09:25:50 -04:00
|
|
|
def mode_changed?
|
2014-09-08 13:42:12 -04:00
|
|
|
!!(diff.a_mode && diff.b_mode && diff.a_mode != diff.b_mode)
|
2014-09-08 09:25:50 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def parser
|
|
|
|
Gitlab::Diff::Parser.new
|
|
|
|
end
|
|
|
|
|
2014-09-08 14:54:52 -04:00
|
|
|
def raw_diff
|
2014-09-24 06:26:53 -04:00
|
|
|
diff.diff.to_s
|
2014-09-08 14:54:52 -04:00
|
|
|
end
|
|
|
|
|
2014-09-08 09:25:50 -04:00
|
|
|
def next_line(index)
|
|
|
|
diff_lines[index + 1]
|
|
|
|
end
|
|
|
|
|
|
|
|
def prev_line(index)
|
|
|
|
if index > 0
|
|
|
|
diff_lines[index - 1]
|
|
|
|
end
|
|
|
|
end
|
2014-09-08 14:54:52 -04:00
|
|
|
|
|
|
|
def file_path
|
|
|
|
if diff.new_path.present?
|
|
|
|
diff.new_path
|
|
|
|
elsif diff.old_path.present?
|
|
|
|
diff.old_path
|
|
|
|
end
|
|
|
|
end
|
2015-10-01 07:52:08 -04:00
|
|
|
|
|
|
|
def added_lines
|
2015-12-14 21:53:52 -05:00
|
|
|
diff_lines.count(&:added?)
|
2015-10-01 07:52:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def removed_lines
|
2015-12-14 21:53:52 -05:00
|
|
|
diff_lines.count(&:removed?)
|
2015-10-01 07:52:08 -04:00
|
|
|
end
|
2014-09-08 09:25:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|