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 | 68 | def diff |
| 69 | 69 | if noteable.diffs.present? |
| 70 | 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 | 73 | end |
| 74 | 74 | end.first |
| 75 | 75 | end |
| ... | ... | @@ -80,7 +80,7 @@ class Note < ActiveRecord::Base |
| 80 | 80 | end |
| 81 | 81 | |
| 82 | 82 | def diff_file_name |
| 83 | - diff.b_path | |
| 83 | + diff.new_path | |
| 84 | 84 | end |
| 85 | 85 | |
| 86 | 86 | def diff_new_line | ... | ... |
lib/gitlab/git/commit.rb
| ... | ... | @@ -9,7 +9,7 @@ module Gitlab |
| 9 | 9 | :author_name, :author_email, :parent_ids, |
| 10 | 10 | :committer_name, :committer_email |
| 11 | 11 | |
| 12 | - delegate :parents, :diffs, :tree, :stats, :to_patch, | |
| 12 | + delegate :parents, :tree, :stats, :to_patch, | |
| 13 | 13 | to: :raw_commit |
| 14 | 14 | |
| 15 | 15 | def initialize(raw_commit, head = nil) |
| ... | ... | @@ -96,6 +96,10 @@ module Gitlab |
| 96 | 96 | committed_date |
| 97 | 97 | end |
| 98 | 98 | |
| 99 | + def diffs | |
| 100 | + raw_commit.diffs.map { |diff| Gitlab::Git::Diff.new(diff) } | |
| 101 | + end | |
| 102 | + | |
| 99 | 103 | private |
| 100 | 104 | |
| 101 | 105 | def init_from_grit(grit) | ... | ... |
lib/gitlab/git/repository.rb
| ... | ... | @@ -191,6 +191,17 @@ module Gitlab |
| 191 | 191 | "#{type}:#{path_with_namespace}" |
| 192 | 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 | 205 | protected |
| 195 | 206 | |
| 196 | 207 | def decorate_commit(commit, ref = nil) | ... | ... |