summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/models/note.rb6
-rw-r--r--lib/gitlab/git/commit.rb6
-rw-r--r--lib/gitlab/git/repository.rb11
3 files changed, 19 insertions, 4 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index 8274b866568..7b7e6e99df4 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -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
diff --git a/lib/gitlab/git/commit.rb b/lib/gitlab/git/commit.rb
index 27b866893f9..e5e48ec4882 100644
--- a/lib/gitlab/git/commit.rb
+++ b/lib/gitlab/git/commit.rb
@@ -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)
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index b8eba8881d5..96fd610077c 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -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)