diff --git a/app/helpers/diff_helper.rb b/app/helpers/diff_helper.rb
index a7eedafe314812d3460232d12f7c072e8de3717d..346b04e40f0412b734249f4a984a40c5a8b693dc 100644
--- a/app/helpers/diff_helper.rb
+++ b/app/helpers/diff_helper.rb
@@ -100,10 +100,11 @@ module DiffHelper
     end
   end
 
-  def diff_file_html_data(project, diff_commit, diff_file)
+  def diff_file_html_data(project, diff_file)
+    commit = diff_file.content_commit || commit_for_diff(diff_file)
     {
       blob_diff_path: namespace_project_blob_diff_path(project.namespace, project,
-                                                       tree_join(diff_commit.id, diff_file.file_path))
+                                                       tree_join(commit.id, diff_file.file_path))
     }
   end
 
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 078ca8f4e13659121bf9abb2ea328ea15b9726be..da2fcaa9cd1af32ea72440b1d3579e67cc4b75cb 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -653,16 +653,6 @@ class Repository
     end
   end
 
-  def blob_for_diff(commit, diff)
-    blob_at(commit.id, diff.file_path)
-  end
-
-  def prev_blob_for_diff(commit, diff)
-    if commit.parent_id
-      blob_at(commit.parent_id, diff.old_path)
-    end
-  end
-
   def refs_contains_sha(ref_type, sha)
     args = %W(#{Gitlab.config.git.bin_path} #{ref_type} --contains #{sha})
     names = Gitlab::Popen.popen(args, path_to_repo).first
diff --git a/app/views/notify/repository_push_email.html.haml b/app/views/notify/repository_push_email.html.haml
index f1532371b2efe8defee0da749a442ab4dd5241fd..c161ecc3463a262fcca6dee0e5e0637b48b2d04c 100644
--- a/app/views/notify/repository_push_email.html.haml
+++ b/app/views/notify/repository_push_email.html.haml
@@ -72,12 +72,11 @@
             The diff for this file was not included because it is too large.
           - else
             %hr
-            - diff_commit = diff_file.deleted_file ? @message.diff_refs.first : @message.diff_refs.last
-            - blob = @message.project.repository.blob_for_diff(diff_commit, diff_file)
+            - blob = diff_file.blob
             - if blob && blob.respond_to?(:text?) && blob_text_viewable?(blob)
               %table.code.white
                 - diff_file.highlighted_diff_lines.each do |line|
-                  = render "projects/diffs/line", {line: line, diff_file: diff_file, line_code: nil, plain: true}
+                  = render "projects/diffs/line", line: line, diff_file: diff_file, plain: true
             - else
               No preview for this file type
           %br
diff --git a/app/views/projects/diffs/_diffs.html.haml b/app/views/projects/diffs/_diffs.html.haml
index 151780addc5fbb3aefc21b8c1e04992d69a04fb1..8f25228269241e3c8e8064ce22f6ec1d52b0c595 100644
--- a/app/views/projects/diffs/_diffs.html.haml
+++ b/app/views/projects/diffs/_diffs.html.haml
@@ -23,8 +23,8 @@
 
 .files
   - diff_files.each_with_index do |diff_file, index|
-    - diff_commit = commit_for_diff(diff_file)
-    - blob = project.repository.blob_for_diff(diff_commit, diff_file)
+    - diff_commit = diff_file.content_commit || commit_for_diff(diff_file)
+    - blob = diff_file.blob(diff_commit)
     - next unless blob
     - blob.load_all_data!(project.repository) unless blob.only_display_raw?
 
diff --git a/app/views/projects/diffs/_file.html.haml b/app/views/projects/diffs/_file.html.haml
index 2395ea3c275fc3171bb9f13f83fc0ab61b236474..8fc5237e935c006b3247512adf3a3b4ba5072d45 100644
--- a/app/views/projects/diffs/_file.html.haml
+++ b/app/views/projects/diffs/_file.html.haml
@@ -1,4 +1,4 @@
-.diff-file.file-holder{id: "diff-#{i}", data: diff_file_html_data(project, diff_commit, diff_file)}
+.diff-file.file-holder{id: "diff-#{i}", data: diff_file_html_data(project, diff_file)}
   .file-title{id: "file-path-#{hexdigest(diff_file.file_path)}"}
     - if diff_file.diff.submodule?
       %span
@@ -52,7 +52,7 @@
     - elsif blob.only_display_raw?
       .nothing-here-block This file is too large to display.
     - elsif blob.image?
-      - old_file = project.repository.prev_blob_for_diff(diff_commit, diff_file)
-      = render "projects/diffs/image", diff_file: diff_file, old_file: old_file, file: blob, index: i, diff_refs: diff_refs
+      - old_blob = diff_file.old_blob(diff_commit)
+      = render "projects/diffs/image", diff_file: diff_file, old_file: old_blob, file: blob, index: i
     - else
       .nothing-here-block No preview for this file type
diff --git a/lib/gitlab/diff/file.rb b/lib/gitlab/diff/file.rb
index e422c333341f2a071d9e10ba3abeace414d7a8cd..8a5c19609e4fcf4bf93cff2576b892e18a5d5ebc 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