From 9fc0e11e0dbd541c8c0bca60878178ca94ad34e1 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Mon, 20 Jun 2016 18:54:53 +0200 Subject: Add DiffFile#blob and #old_blob --- lib/gitlab/diff/file.rb | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'lib/gitlab/diff') 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 -- cgit v1.2.3