diff options
author | Douwe Maan <douwe@selenight.nl> | 2016-06-20 19:54:53 +0300 |
---|---|---|
committer | Douwe Maan <douwe@selenight.nl> | 2016-07-07 01:50:58 +0300 |
commit | 9fc0e11e0dbd541c8c0bca60878178ca94ad34e1 (patch) | |
tree | 4ecdb99f6c0247ec8d51eaa1d85aba470a3c890b /lib/gitlab | |
parent | 17ab745e40bf89776ab16de9ba00ebb44d1c85ca (diff) |
Add DiffFile#blob and #old_blob
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/diff/file.rb | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb index e422c333341..8a5c19609e4 100644 --- a/lib/gitlab/diff/file.rb +++ b/lib/gitlab/diff/file.rb @@ -12,6 +12,12 @@ module Gitlab @diff_refs = diff_refs end + def content_commit + return unless diff_refs + + repository.commit(deleted_file ? old_ref : new_ref) + end + def old_ref diff_refs.try(:base_sha) end @@ -56,11 +62,7 @@ module Gitlab end def file_path - if diff.new_path.present? - diff.new_path - elsif diff.old_path.present? - diff.old_path - end + new_path.presence || old_path.presence end def added_lines @@ -70,6 +72,20 @@ module Gitlab def removed_lines diff_lines.count(&:removed?) end + + def old_blob(commit = content_commit) + return unless commit + + parent_id = commit.parent_id + return unless parent_id + + repository.blob_at(parent_id, old_path) + end + + def blob(commit = content_commit) + return unless commit + repository.blob_at(commit.id, file_path) + end end end end |