2014-09-08 09:25:50 -04:00
|
|
|
module Gitlab
|
|
|
|
module Diff
|
|
|
|
class File
|
2014-09-08 14:54:52 -04:00
|
|
|
attr_reader :diff
|
2014-09-08 09:25:50 -04:00
|
|
|
|
|
|
|
delegate :new_file, :deleted_file, :renamed_file,
|
|
|
|
:old_path, :new_path, to: :diff, prefix: false
|
|
|
|
|
2014-09-08 14:54:52 -04:00
|
|
|
def initialize(diff)
|
2014-09-08 09:25:50 -04:00
|
|
|
@diff = diff
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
2014-09-08 09:25:50 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|