diff options
author | Oswaldo Ferreira <oswaldo@gitlab.com> | 2018-06-04 19:20:58 -0300 |
---|---|---|
committer | Oswaldo Ferreira <oswaldo@gitlab.com> | 2018-06-05 01:02:30 -0300 |
commit | f46739191a71d881501bb3fc4740b953824a9fb3 (patch) | |
tree | b6fca3e62fd627b0914441f135ffd1f878edb08b /lib/gitlab | |
parent | 9c2961947826442e780285cb551583b09cf6dae9 (diff) | |
download | gitlab-ce-f46739191a71d881501bb3fc4740b953824a9fb3.tar.gz |
Adjust insufficient diff hunks being persisted on NoteDiffFileosw-ignore-diff-header-when-persisting-diff-hunk
This currently causes 500's errors when loading the MR page
(Discussion) in a few scenarios.
We were not considering detailed diff headers such as
"--- a/doc/update/mysql_to_postgresql.md\n+++ b/doc/update/mysql_to_postgresql.md"
to crop the diff. In order to address it, we're now using
Gitlab::Diff::Parser, clean the diffs and builds Gitlab::Diff::Line objects
we can iterate and filter on.
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/diff/file.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/diff/line.rb | 4 |
2 files changed, 10 insertions, 3 deletions
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index 765fb0289a8..2820293ad5c 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -78,9 +78,12 @@ module Gitlab # Returns the raw diff content up to the given line index def diff_hunk(diff_line) - # Adding 2 because of the @@ diff header and Enum#take should consider - # an extra line, because we're passing an index. - raw_diff.each_line.take(diff_line.index + 2).join + diff_line_index = diff_line.index + # @@ (match) header is not kept if it's found in the top of the file, + # therefore we should keep an extra line on this scenario. + diff_line_index += 1 unless diff_lines.first.match? + + diff_lines.select { |line| line.index <= diff_line_index }.map(&:text).join("\n") end def old_sha diff --git a/lib/gitlab/diff/line.rb b/lib/gitlab/diff/line.rb index 0603141e441..a1e904cfef4 100644 --- a/lib/gitlab/diff/line.rb +++ b/lib/gitlab/diff/line.rb @@ -53,6 +53,10 @@ module Gitlab %w[match new-nonewline old-nonewline].include?(type) end + def match? + type == :match + end + def discussable? !meta? end |