debian-mirror-gitlab/lib/gitlab/diff/file.rb

75 lines
1.4 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
module Gitlab
module Diff
class File
2016-01-29 22:53:50 +05:30
attr_reader :diff, :diff_refs
2015-04-26 12:48:37 +05:30
delegate :new_file, :deleted_file, :renamed_file,
:old_path, :new_path, to: :diff, prefix: false
2016-01-29 22:53:50 +05:30
def initialize(diff, diff_refs)
2015-04-26 12:48:37 +05:30
@diff = diff
2016-01-29 22:53:50 +05:30
@diff_refs = diff_refs
end
def old_ref
diff_refs[0] if diff_refs
end
def new_ref
diff_refs[1] if diff_refs
2015-04-26 12:48:37 +05:30
end
# Array of Gitlab::DIff::Line objects
def diff_lines
@lines ||= parser.parse(raw_diff.lines)
end
2016-01-29 22:53:50 +05:30
def highlighted_diff_lines
Gitlab::Diff::Highlight.new(self).highlight
end
def parallel_diff_lines
Gitlab::Diff::ParallelDiff.new(self).parallelize
end
2015-04-26 12:48:37 +05:30
def mode_changed?
!!(diff.a_mode && diff.b_mode && diff.a_mode != diff.b_mode)
end
def parser
Gitlab::Diff::Parser.new
end
def raw_diff
diff.diff.to_s
end
def next_line(index)
diff_lines[index + 1]
end
def prev_line(index)
if index > 0
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
2015-10-24 18:46:33 +05:30
def added_lines
2015-12-23 02:04:40 +05:30
diff_lines.count(&:added?)
2015-10-24 18:46:33 +05:30
end
def removed_lines
2015-12-23 02:04:40 +05:30
diff_lines.count(&:removed?)
2015-10-24 18:46:33 +05:30
end
2015-04-26 12:48:37 +05:30
end
end
end