Commit d74d7c7c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Update app code to use Gitlab::Git::Diff

parent 6a4a17f3
......@@ -68,8 +68,8 @@ class Note < ActiveRecord::Base
def diff
if noteable.diffs.present?
noteable.diffs.select do |d|
if d.b_path
Digest::SHA1.hexdigest(d.b_path) == diff_file_index
if d.new_path
Digest::SHA1.hexdigest(d.new_path) == diff_file_index
end
end.first
end
......@@ -80,7 +80,7 @@ class Note < ActiveRecord::Base
end
def diff_file_name
diff.b_path
diff.new_path
end
def diff_new_line
......
......@@ -9,7 +9,7 @@ module Gitlab
:author_name, :author_email, :parent_ids,
:committer_name, :committer_email
delegate :parents, :diffs, :tree, :stats, :to_patch,
delegate :parents, :tree, :stats, :to_patch,
to: :raw_commit
def initialize(raw_commit, head = nil)
......@@ -96,6 +96,10 @@ module Gitlab
committed_date
end
def diffs
raw_commit.diffs.map { |diff| Gitlab::Git::Diff.new(diff) }
end
private
def init_from_grit(grit)
......
......@@ -191,6 +191,17 @@ module Gitlab
"#{type}:#{path_with_namespace}"
end
def diffs_between(source_branch, target_branch)
# Only show what is new in the source branch compared to the target branch, not the other way around.
# The linex below with merge_base is equivalent to diff with three dots (git diff branch1...branch2)
# From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B"
common_commit = repo.git.native(:merge_base, {}, [target_branch, source_branch]).strip
repo.diff(common_commit, source_branch).map { |diff| Gitlab::Git::Diff.new(diff) }
rescue Grit::Git::GitTimeout
[Gitlab::Git::Diff::BROKEN_DIFF]
end
protected
def decorate_commit(commit, ref = nil)
......
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