diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-04-15 19:02:05 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-04-15 19:02:05 +0300 |
commit | d74d7c7cfb49ead619d21e35f07b1feba8295118 (patch) | |
tree | 13a87df76056f11512c9e8d4740d2aa2d1df2c39 /lib/gitlab/git | |
parent | 6a4a17f3399904b43275c4a2d53322cb2b011aca (diff) | |
download | gitlab-ce-d74d7c7cfb49ead619d21e35f07b1feba8295118.tar.gz |
Update app code to use Gitlab::Git::Diff
Diffstat (limited to 'lib/gitlab/git')
-rw-r--r-- | lib/gitlab/git/commit.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/git/repository.rb | 11 |
2 files changed, 16 insertions, 1 deletions
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) |