summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-09-08 16:27:12 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2014-09-08 16:27:12 +0300
commit531f16beb0a860a94f732f9e697a447513abe363 (patch)
tree18c2715734fb078294d9db49e104de4528eb1a0d /lib
parente0eb48031dc3ed8079c637fa3b82556747f9f8e0 (diff)
downloadgitlab-ce-531f16beb0a860a94f732f9e697a447513abe363.tar.gz
Use new diff parsing logic
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/diff_parser.rb88
1 files changed, 0 insertions, 88 deletions
diff --git a/lib/gitlab/diff_parser.rb b/lib/gitlab/diff_parser.rb
deleted file mode 100644
index 3f402c4c238..00000000000
--- a/lib/gitlab/diff_parser.rb
+++ /dev/null
@@ -1,88 +0,0 @@
-module Gitlab
- class DiffParser
- include Enumerable
-
- attr_reader :lines, :new_path
-
- def initialize(lines, new_path = '')
- @lines = lines
- @new_path = new_path
- end
-
- def each
- line_old = 1
- line_new = 1
- type = nil
-
- lines_arr = ::Gitlab::InlineDiff.processing lines
-
- lines_arr.each_cons(2) do |line, next_line|
- raw_line = line.dup
-
- next if filename?(line)
-
- full_line = html_escape(line.gsub(/\n/, ''))
- full_line = ::Gitlab::InlineDiff.replace_markers full_line
-
- next_line = html_escape(next_line.gsub(/\n/, ''))
- next_line = ::Gitlab::InlineDiff.replace_markers next_line
-
- 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
-
- next if line_old == 1 && line_new == 1 #top of file
- yield(full_line, type, nil, line_new, line_old)
- next
- else
- type = identification_type(line)
- next_type = identification_type(next_line)
- line_code = generate_line_code(new_path, line_new, line_old)
- yield(full_line, type, line_code, line_new, line_old, raw_line, next_type, next_line)
- end
-
-
- if line[0] == "+"
- line_new += 1
- elsif line[0] == "-"
- line_old += 1
- else
- line_new += 1
- line_old += 1
- end
- end
- end
-
- def empty?
- @lines.empty?
- end
-
- private
-
- def filename?(line)
- line.start_with?('--- /dev/null', '+++ /dev/null', '--- a', '+++ b',
- '--- /tmp/diffy', '+++ /tmp/diffy')
- end
-
- def identification_type(line)
- if line[0] == "+"
- "new"
- elsif line[0] == "-"
- "old"
- else
- nil
- end
- end
-
- def generate_line_code(path, line_new, line_old)
- "#{Digest::SHA1.hexdigest(path)}_#{line_old}_#{line_new}"
- end
-
- def html_escape str
- replacements = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;', "'" => '&#39;' }
- str.gsub(/[&"'><]/, replacements)
- end
- end
-end