Commit 228d2a4c authored by Douwe Maan's avatar Douwe Maan

Add some more code comments.

parent d9c75aec
...@@ -31,6 +31,7 @@ module NoteOnDiff ...@@ -31,6 +31,7 @@ module NoteOnDiff
false false
end end
# Returns an array of at most 16 highlighted lines above a diff note
def truncated_diff_lines def truncated_diff_lines
prev_match_line = nil prev_match_line = nil
prev_lines = [] prev_lines = []
......
...@@ -186,8 +186,9 @@ class MergeRequest < ActiveRecord::Base ...@@ -186,8 +186,9 @@ class MergeRequest < ActiveRecord::Base
# This will not be the actual base commit if the target branch was merged into # This will not be the actual base commit if the target branch was merged into
# the source branch after the merge request was created, but it is good enough # the source branch after the merge request was created, but it is good enough
# for the specific purpose of linking to a commit. # for the specific purpose of linking to a commit.
# It is not good enough for use in Gitlab::Git::DiffRefs, which need the # It is not good enough for use in `Gitlab::Git::DiffRefs`, which needs the
# true base commit. # true base commit, so we can't simply have `#diff_base_commit` fall back on
# this method.
def likely_diff_base_commit def likely_diff_base_commit
first_commit.parent || first_commit first_commit.parent || first_commit
end end
......
...@@ -18,6 +18,16 @@ module Gitlab ...@@ -18,6 +18,16 @@ module Gitlab
head_sha == other.head_sha head_sha == other.head_sha
end end
# There is only one case in which we will have `start_sha` and `head_sha`,
# but not `base_sha`, which is when a diff is generated between an
# orphaned branch and another branch, which means there _is_ no base, but
# we're still able to highlight it, and to create diff notes, which are
# the primary things `DiffRefs` are used for.
# `DiffRefs` are "complete" when they have `start_sha` and `head_sha`,
# because `base_sha` can always be derived from this, to return an actual
# sha, or `nil`.
# We have `base_sha` directly available on `DiffRefs` because it's faster#
# than having to look it up in the repo every time.
def complete? def complete?
start_sha && head_sha start_sha && head_sha
end end
......
...@@ -26,7 +26,7 @@ module Gitlab ...@@ -26,7 +26,7 @@ module Gitlab
@diff_lines ||= @diff_file.diff_lines @diff_lines ||= @diff_file.diff_lines
end end
# Find old line number based on new line number. # Find old/new line number based on its old/new counterpart line number.
def map_line_number(from_line, from:, to:) def map_line_number(from_line, from:, to:)
# If no diff file could be found, the file wasn't changed, and the # If no diff file could be found, the file wasn't changed, and the
# mapped line number is the same as the specified line number. # mapped line number is the same as the specified line number.
......
...@@ -28,6 +28,11 @@ module Gitlab ...@@ -28,6 +28,11 @@ module Gitlab
end end
end end
# `Gitlab::Diff::Position` objects are stored as serialized attributes in
# `DiffNote`, which use YAML to encode and decode objects.
# `#init_with` and `#encode_with` can be used to customize the en/decoding
# behavior. In this case, we override these to prevent memoized instance
# variables like `@diff_file` and `@diff_line` from being serialized.
def init_with(coder) def init_with(coder)
initialize(coder['attributes']) initialize(coder['attributes'])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment