2011-10-08 23:36:38 +02:00
|
|
|
module CommitsHelper
|
2012-06-24 00:14:45 +02:00
|
|
|
def identification_type(line)
|
2012-01-25 20:10:09 +01:00
|
|
|
if line[0] == "+"
|
|
|
|
"new"
|
|
|
|
elsif line[0] == "-"
|
|
|
|
"old"
|
2012-01-11 23:26:01 +01:00
|
|
|
else
|
2012-01-25 20:10:09 +01:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-24 00:14:45 +02:00
|
|
|
def build_line_anchor(index, line_new, line_old)
|
2012-01-25 20:10:09 +01:00
|
|
|
"#{index}_#{line_old}_#{line_new}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def each_diff_line(diff_arr, index)
|
|
|
|
line_old = 1
|
|
|
|
line_new = 1
|
|
|
|
type = nil
|
2012-10-09 02:10:04 +02:00
|
|
|
|
2012-07-02 22:34:25 +02:00
|
|
|
lines_arr = ::Gitlab::InlineDiff.processing diff_arr
|
2012-01-25 20:10:09 +01:00
|
|
|
lines_arr.each do |line|
|
2012-02-14 19:00:25 +01:00
|
|
|
next if line.match(/^\-\-\- \/dev\/null/)
|
|
|
|
next if line.match(/^\+\+\+ \/dev\/null/)
|
|
|
|
next if line.match(/^\-\-\- a/)
|
|
|
|
next if line.match(/^\+\+\+ b/)
|
|
|
|
|
2012-05-30 05:56:48 +02:00
|
|
|
full_line = html_escape(line.gsub(/\n/, ''))
|
2012-07-02 22:34:25 +02:00
|
|
|
full_line = ::Gitlab::InlineDiff.replace_markers full_line
|
2012-07-02 22:08:07 +02:00
|
|
|
|
2012-01-25 20:10:09 +01:00
|
|
|
if line.match(/^@@ -/)
|
|
|
|
type = "match"
|
|
|
|
|
|
|
|
line_old = line.match(/\-[0-9]*/)[0].to_i.abs rescue 0
|
|
|
|
line_new = line.match(/\+[0-9]*/)[0].to_i.abs rescue 0
|
2012-05-30 05:56:48 +02:00
|
|
|
|
2012-06-24 00:14:45 +02:00
|
|
|
next if line_old == 1 && line_new == 1 #top of file
|
2012-04-03 18:43:07 +02:00
|
|
|
yield(full_line, type, nil, nil, nil)
|
2012-01-25 20:10:09 +01:00
|
|
|
next
|
|
|
|
else
|
2012-06-24 00:14:45 +02:00
|
|
|
type = identification_type(line)
|
|
|
|
line_code = build_line_anchor(index, line_new, line_old)
|
2012-01-25 20:10:09 +01:00
|
|
|
yield(full_line, type, line_code, line_new, line_old)
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if line[0] == "+"
|
|
|
|
line_new += 1
|
|
|
|
elsif line[0] == "-"
|
|
|
|
line_old += 1
|
|
|
|
else
|
|
|
|
line_new += 1
|
|
|
|
line_old += 1
|
|
|
|
end
|
2012-01-11 23:26:01 +01:00
|
|
|
end
|
|
|
|
end
|
2012-05-30 20:02:30 +02:00
|
|
|
|
|
|
|
def image_diff_class(diff)
|
|
|
|
if diff.deleted_file
|
2012-11-18 17:41:41 +01:00
|
|
|
"diff_removed"
|
2012-05-30 20:02:30 +02:00
|
|
|
elsif diff.new_file
|
2012-11-18 17:41:41 +01:00
|
|
|
"diff_added"
|
2012-05-30 20:02:30 +02:00
|
|
|
else
|
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
2012-07-02 22:08:07 +02:00
|
|
|
|
2012-10-31 13:29:42 +01:00
|
|
|
def commit_to_html commit
|
|
|
|
if commit.model
|
|
|
|
escape_javascript(render 'commits/commit', commit: commit)
|
|
|
|
end
|
|
|
|
end
|
2012-12-25 04:14:05 +01:00
|
|
|
|
|
|
|
def diff_line_content(line)
|
|
|
|
if line.blank?
|
|
|
|
" "
|
|
|
|
else
|
|
|
|
line
|
|
|
|
end
|
|
|
|
end
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|