2011-10-08 17:36:38 -04:00
|
|
|
module CommitsHelper
|
2011-11-30 18:51:04 -05:00
|
|
|
def old_line_number(line, i)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def new_line_number(line, i)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2011-10-08 17:36:38 -04:00
|
|
|
def more_commits_link
|
|
|
|
offset = params[:offset] || 0
|
|
|
|
limit = params[:limit] || 100
|
2011-12-26 18:39:42 -05:00
|
|
|
link_to "More", project_commits_path(@project, :offset => offset.to_i + limit.to_i, :limit => limit),
|
2011-10-08 17:36:38 -04:00
|
|
|
:remote => true, :class => "lite_button vm", :style => "text-align:center; width:930px; ", :id => "more-commits-link"
|
|
|
|
end
|
2011-12-26 15:35:25 -05:00
|
|
|
|
2011-12-26 17:22:15 -05:00
|
|
|
def commit_msg_with_link_to_issues(project, message)
|
|
|
|
return '' unless message
|
|
|
|
out = ''
|
|
|
|
message.split(/(#[0-9]+)/m).each do |m|
|
2011-12-26 15:35:25 -05:00
|
|
|
if m =~ /(#([0-9]+))/m
|
|
|
|
begin
|
2011-12-27 18:06:55 -05:00
|
|
|
issue = project.issues.find($2)
|
2011-12-26 17:22:15 -05:00
|
|
|
out += link_to($1, project_issue_path(project, $2))
|
2011-12-26 15:35:25 -05:00
|
|
|
rescue
|
2011-12-26 17:22:15 -05:00
|
|
|
out += $1
|
2011-12-26 15:35:25 -05:00
|
|
|
end
|
|
|
|
else
|
2011-12-26 17:22:15 -05:00
|
|
|
out += m
|
2011-12-26 15:35:25 -05:00
|
|
|
end
|
|
|
|
end
|
2011-12-26 17:22:15 -05:00
|
|
|
preserve out
|
2011-12-26 15:35:25 -05:00
|
|
|
end
|
|
|
|
|
2012-01-25 14:10:09 -05:00
|
|
|
def diff_line_class(line)
|
|
|
|
if line[0] == "+"
|
|
|
|
"new"
|
|
|
|
elsif line[0] == "-"
|
|
|
|
"old"
|
2012-01-11 17:26:01 -05:00
|
|
|
else
|
2012-01-25 14:10:09 -05:00
|
|
|
nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def build_line_code(line, index, line_new, line_old)
|
|
|
|
"#{index}_#{line_old}_#{line_new}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def each_diff_line(diff_arr, index)
|
|
|
|
line_old = 1
|
|
|
|
line_new = 1
|
|
|
|
type = nil
|
|
|
|
|
|
|
|
lines_arr = diff_arr
|
|
|
|
lines_arr.each do |line|
|
2012-02-14 13:00:25 -05:00
|
|
|
next if line.match(/^\-\-\- \/dev\/null/)
|
|
|
|
next if line.match(/^\+\+\+ \/dev\/null/)
|
|
|
|
next if line.match(/^\-\-\- a/)
|
|
|
|
next if line.match(/^\+\+\+ b/)
|
|
|
|
|
2012-02-14 17:41:36 -05:00
|
|
|
full_line = html_escape(line.gsub(/\n/, '')).force_encoding("UTF-8")
|
2012-01-25 14:10:09 -05: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-02-22 10:04:41 -05:00
|
|
|
|
|
|
|
next if line_old == 1 && line_new == 1
|
2012-04-03 12:43:07 -04:00
|
|
|
yield(full_line, type, nil, nil, nil)
|
2012-01-25 14:10:09 -05:00
|
|
|
next
|
|
|
|
else
|
|
|
|
type = diff_line_class(line)
|
|
|
|
line_code = build_line_code(line, index, line_new, line_old)
|
|
|
|
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 17:26:01 -05:00
|
|
|
end
|
|
|
|
end
|
2011-10-08 17:36:38 -04:00
|
|
|
end
|