Commit 42ba6d04f84b722bc1212378633cd8c05a2c6ded
1 parent
c2cfc52e
Exists in
master
and in
4 other branches
refactor each_line detect to detect all diff file
Showing
2 changed files
with
5 additions
and
3 deletions
Show diff stats
app/views/commits/_text_file.html.haml
1 | %table | 1 | %table |
2 | - line_old = 0 | 2 | - line_old = 0 |
3 | - line_new = 0 | 3 | - line_new = 0 |
4 | - - lines_arr = diff.diff.lines.to_a | 4 | + - diff_str = encode(diff.diff) |
5 | + - lines_arr = diff_str.lines.to_a | ||
5 | - lines_arr.each do |line| | 6 | - lines_arr.each do |line| |
6 | - - line = encode(line) | ||
7 | - next if line.match(/^--- \/dev\/null/) | 7 | - next if line.match(/^--- \/dev\/null/) |
8 | - next if line.match(/^--- a/) | 8 | - next if line.match(/^--- a/) |
9 | - next if line.match(/^\+\+\+ b/) | 9 | - next if line.match(/^\+\+\+ b/) |
@@ -18,7 +18,7 @@ | @@ -18,7 +18,7 @@ | ||
18 | = link_to raw(diff_line_class(line) == "new" ? " " : line_old), "#OLD#{index}-#{line_old}", :id => "OLD#{index}-#{line_old}" | 18 | = link_to raw(diff_line_class(line) == "new" ? " " : line_old), "#OLD#{index}-#{line_old}", :id => "OLD#{index}-#{line_old}" |
19 | %td.new_line | 19 | %td.new_line |
20 | = link_to raw(diff_line_class(line) == "old" ? " " : line_new) , "#NEW#{index}-#{line_new}", :id => "NEW#{index}-#{line_new}" | 20 | = link_to raw(diff_line_class(line) == "old" ? " " : line_new) , "#NEW#{index}-#{line_new}", :id => "NEW#{index}-#{line_new}" |
21 | - %td.line_content{:class => diff_line_class(full_line)}= raw "#{full_line} " | 21 | + %td.line_content{:class => diff_line_class(full_line)}= raw "#{full_line} " |
22 | - if line[0] == "+" | 22 | - if line[0] == "+" |
23 | - line_new += 1 | 23 | - line_new += 1 |
24 | - elsif line[0] == "-" | 24 | - elsif line[0] == "-" |
lib/utils.rb
@@ -23,6 +23,8 @@ module Utils | @@ -23,6 +23,8 @@ module Utils | ||
23 | string.force_encoding(cd.encoding) | 23 | string.force_encoding(cd.encoding) |
24 | end | 24 | end |
25 | string.encode("utf-8", :undef => :replace, :replace => "?", :invalid => :replace) | 25 | string.encode("utf-8", :undef => :replace, :replace => "?", :invalid => :replace) |
26 | + rescue | ||
27 | + "Invalid code encoding" | ||
26 | end | 28 | end |
27 | end | 29 | end |
28 | 30 |