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 ...@@ -68,8 +68,8 @@ class Note < ActiveRecord::Base
def diff def diff
if noteable.diffs.present? if noteable.diffs.present?
noteable.diffs.select do |d| noteable.diffs.select do |d|
if d.b_path if d.new_path
Digest::SHA1.hexdigest(d.b_path) == diff_file_index Digest::SHA1.hexdigest(d.new_path) == diff_file_index
end end
end.first end.first
end end
...@@ -80,7 +80,7 @@ class Note < ActiveRecord::Base ...@@ -80,7 +80,7 @@ class Note < ActiveRecord::Base
end end
def diff_file_name def diff_file_name
diff.b_path diff.new_path
end end
def diff_new_line def diff_new_line
......
...@@ -9,7 +9,7 @@ module Gitlab ...@@ -9,7 +9,7 @@ module Gitlab
:author_name, :author_email, :parent_ids, :author_name, :author_email, :parent_ids,
:committer_name, :committer_email :committer_name, :committer_email
delegate :parents, :diffs, :tree, :stats, :to_patch, delegate :parents, :tree, :stats, :to_patch,
to: :raw_commit to: :raw_commit
def initialize(raw_commit, head = nil) def initialize(raw_commit, head = nil)
...@@ -96,6 +96,10 @@ module Gitlab ...@@ -96,6 +96,10 @@ module Gitlab
committed_date committed_date
end end
def diffs
raw_commit.diffs.map { |diff| Gitlab::Git::Diff.new(diff) }
end
private private
def init_from_grit(grit) def init_from_grit(grit)
......
...@@ -191,6 +191,17 @@ module Gitlab ...@@ -191,6 +191,17 @@ module Gitlab
"#{type}:#{path_with_namespace}" "#{type}:#{path_with_namespace}"
end 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 protected
def decorate_commit(commit, ref = nil) 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