summaryrefslogtreecommitdiff
path: root/lib/gitlab/word_diff/segments/diff_hunk.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
commitf64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch)
treea2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /lib/gitlab/word_diff/segments/diff_hunk.rb
parentbfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff)
downloadgitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'lib/gitlab/word_diff/segments/diff_hunk.rb')
-rw-r--r--lib/gitlab/word_diff/segments/diff_hunk.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/gitlab/word_diff/segments/diff_hunk.rb b/lib/gitlab/word_diff/segments/diff_hunk.rb
new file mode 100644
index 00000000000..88b6817676f
--- /dev/null
+++ b/lib/gitlab/word_diff/segments/diff_hunk.rb
@@ -0,0 +1,40 @@
+# frozen_string_literal: true
+
+# Diff hunk is line that starts with @@
+# It contains information about start line numbers
+#
+# Example:
+# @@ -1,4 +1,5 @@
+#
+# See more: https://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html
+module Gitlab
+ module WordDiff
+ module Segments
+ class DiffHunk
+ def initialize(line)
+ @line = line
+ end
+
+ def pos_old
+ line.match(/\-[0-9]*/)[0].to_i.abs rescue 0
+ end
+
+ def pos_new
+ line.match(/\+[0-9]*/)[0].to_i.abs rescue 0
+ end
+
+ def first_line?
+ pos_old <= 1 && pos_new <= 1
+ end
+
+ def to_s
+ line
+ end
+
+ private
+
+ attr_reader :line
+ end
+ end
+ end
+end