Commit d74d7c7cfb49ead619d21e35f07b1feba8295118
1 parent
6a4a17f3
Exists in
master
and in
4 other branches
Update app code to use Gitlab::Git::Diff
Showing
3 changed files
with
19 additions
and
4 deletions
Show diff stats
app/models/note.rb
| @@ -68,8 +68,8 @@ class Note < ActiveRecord::Base | @@ -68,8 +68,8 @@ class Note < ActiveRecord::Base | ||
| 68 | def diff | 68 | def diff |
| 69 | if noteable.diffs.present? | 69 | if noteable.diffs.present? |
| 70 | noteable.diffs.select do |d| | 70 | noteable.diffs.select do |d| |
| 71 | - if d.b_path | ||
| 72 | - Digest::SHA1.hexdigest(d.b_path) == diff_file_index | 71 | + if d.new_path |
| 72 | + Digest::SHA1.hexdigest(d.new_path) == diff_file_index | ||
| 73 | end | 73 | end |
| 74 | end.first | 74 | end.first |
| 75 | end | 75 | end |
| @@ -80,7 +80,7 @@ class Note < ActiveRecord::Base | @@ -80,7 +80,7 @@ class Note < ActiveRecord::Base | ||
| 80 | end | 80 | end |
| 81 | 81 | ||
| 82 | def diff_file_name | 82 | def diff_file_name |
| 83 | - diff.b_path | 83 | + diff.new_path |
| 84 | end | 84 | end |
| 85 | 85 | ||
| 86 | def diff_new_line | 86 | def diff_new_line |
lib/gitlab/git/commit.rb
| @@ -9,7 +9,7 @@ module Gitlab | @@ -9,7 +9,7 @@ module Gitlab | ||
| 9 | :author_name, :author_email, :parent_ids, | 9 | :author_name, :author_email, :parent_ids, |
| 10 | :committer_name, :committer_email | 10 | :committer_name, :committer_email |
| 11 | 11 | ||
| 12 | - delegate :parents, :diffs, :tree, :stats, :to_patch, | 12 | + delegate :parents, :tree, :stats, :to_patch, |
| 13 | to: :raw_commit | 13 | to: :raw_commit |
| 14 | 14 | ||
| 15 | def initialize(raw_commit, head = nil) | 15 | def initialize(raw_commit, head = nil) |
| @@ -96,6 +96,10 @@ module Gitlab | @@ -96,6 +96,10 @@ module Gitlab | ||
| 96 | committed_date | 96 | committed_date |
| 97 | end | 97 | end |
| 98 | 98 | ||
| 99 | + def diffs | ||
| 100 | + raw_commit.diffs.map { |diff| Gitlab::Git::Diff.new(diff) } | ||
| 101 | + end | ||
| 102 | + | ||
| 99 | private | 103 | private |
| 100 | 104 | ||
| 101 | def init_from_grit(grit) | 105 | def init_from_grit(grit) |
lib/gitlab/git/repository.rb
| @@ -191,6 +191,17 @@ module Gitlab | @@ -191,6 +191,17 @@ module Gitlab | ||
| 191 | "#{type}:#{path_with_namespace}" | 191 | "#{type}:#{path_with_namespace}" |
| 192 | end | 192 | end |
| 193 | 193 | ||
| 194 | + def diffs_between(source_branch, target_branch) | ||
| 195 | + # Only show what is new in the source branch compared to the target branch, not the other way around. | ||
| 196 | + # The linex below with merge_base is equivalent to diff with three dots (git diff branch1...branch2) | ||
| 197 | + # From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B" | ||
| 198 | + common_commit = repo.git.native(:merge_base, {}, [target_branch, source_branch]).strip | ||
| 199 | + repo.diff(common_commit, source_branch).map { |diff| Gitlab::Git::Diff.new(diff) } | ||
| 200 | + | ||
| 201 | + rescue Grit::Git::GitTimeout | ||
| 202 | + [Gitlab::Git::Diff::BROKEN_DIFF] | ||
| 203 | + end | ||
| 204 | + | ||
| 194 | protected | 205 | protected |
| 195 | 206 | ||
| 196 | def decorate_commit(commit, ref = nil) | 207 | def decorate_commit(commit, ref = nil) |