diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-03-14 13:16:26 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-03-14 13:16:26 +0000 |
commit | 181c2582fbba4cdb276709b3f4920fab18e1e962 (patch) | |
tree | a28adb1cbb2c65f32274c9a187aa7227483b20f6 /lib | |
parent | 270e15f1538fe2b325dbb9bdcf58b622c2a4e86d (diff) | |
parent | 985af1a6707af531a242051e46a54c16dc31b9bc (diff) | |
download | gitlab-ce-181c2582fbba4cdb276709b3f4920fab18e1e962.tar.gz |
Merge branch 'nonewline-parser' into 'master'
Take nonewline context into account in diff parser
Closes #28128 and #22636
See merge request !9705
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/diff/line.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/diff/parser.rb | 6 |
2 files changed, 8 insertions, 4 deletions
diff --git a/lib/gitlab/diff/line.rb b/lib/gitlab/diff/line.rb index 80a146b4a5a..114656958e3 100644 --- a/lib/gitlab/diff/line.rb +++ b/lib/gitlab/diff/line.rb @@ -38,11 +38,11 @@ module Gitlab end def added? - type == 'new' + type == 'new' || type == 'new-nonewline' end def removed? - type == 'old' + type == 'old' || type == 'old-nonewline' end def rich_text @@ -52,7 +52,7 @@ module Gitlab end def meta? - type == 'match' || type == 'nonewline' + type == 'match' end def as_json(opts = nil) diff --git a/lib/gitlab/diff/parser.rb b/lib/gitlab/diff/parser.rb index 8f844224a7a..742f989c50b 100644 --- a/lib/gitlab/diff/parser.rb +++ b/lib/gitlab/diff/parser.rb @@ -11,6 +11,7 @@ module Gitlab line_old = 1 line_new = 1 type = nil + context = nil # By returning an Enumerator we make it possible to search for a single line (with #find) # without having to instantiate all the others that come after it. @@ -31,7 +32,8 @@ module Gitlab line_obj_index += 1 next elsif line[0] == '\\' - type = 'nonewline' + type = "#{context}-nonewline" + yielder << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new) line_obj_index += 1 else @@ -43,8 +45,10 @@ module Gitlab case line[0] when "+" line_new += 1 + context = :new when "-" line_old += 1 + context = :old when "\\" # rubocop:disable Lint/EmptyWhen # No increment else |