Add DiffFile#blob and #old_blob
This commit is contained in:
parent
17ab745e40
commit
9fc0e11e0d
|
|
@ -100,10 +100,11 @@ module DiffHelper
|
||||||
end
|
end
|
||||||
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,
|
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
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -653,16 +653,6 @@ class Repository
|
||||||
end
|
end
|
||||||
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)
|
def refs_contains_sha(ref_type, sha)
|
||||||
args = %W(#{Gitlab.config.git.bin_path} #{ref_type} --contains #{sha})
|
args = %W(#{Gitlab.config.git.bin_path} #{ref_type} --contains #{sha})
|
||||||
names = Gitlab::Popen.popen(args, path_to_repo).first
|
names = Gitlab::Popen.popen(args, path_to_repo).first
|
||||||
|
|
|
||||||
|
|
@ -72,12 +72,11 @@
|
||||||
The diff for this file was not included because it is too large.
|
The diff for this file was not included because it is too large.
|
||||||
- else
|
- else
|
||||||
%hr
|
%hr
|
||||||
- diff_commit = diff_file.deleted_file ? @message.diff_refs.first : @message.diff_refs.last
|
- blob = diff_file.blob
|
||||||
- blob = @message.project.repository.blob_for_diff(diff_commit, diff_file)
|
|
||||||
- if blob && blob.respond_to?(:text?) && blob_text_viewable?(blob)
|
- if blob && blob.respond_to?(:text?) && blob_text_viewable?(blob)
|
||||||
%table.code.white
|
%table.code.white
|
||||||
- diff_file.highlighted_diff_lines.each do |line|
|
- 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
|
- else
|
||||||
No preview for this file type
|
No preview for this file type
|
||||||
%br
|
%br
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@
|
||||||
|
|
||||||
.files
|
.files
|
||||||
- diff_files.each_with_index do |diff_file, index|
|
- diff_files.each_with_index do |diff_file, index|
|
||||||
- diff_commit = commit_for_diff(diff_file)
|
- diff_commit = diff_file.content_commit || commit_for_diff(diff_file)
|
||||||
- blob = project.repository.blob_for_diff(diff_commit, diff_file)
|
- blob = diff_file.blob(diff_commit)
|
||||||
- next unless blob
|
- next unless blob
|
||||||
- blob.load_all_data!(project.repository) unless blob.only_display_raw?
|
- blob.load_all_data!(project.repository) unless blob.only_display_raw?
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)}"}
|
.file-title{id: "file-path-#{hexdigest(diff_file.file_path)}"}
|
||||||
- if diff_file.diff.submodule?
|
- if diff_file.diff.submodule?
|
||||||
%span
|
%span
|
||||||
|
|
@ -52,7 +52,7 @@
|
||||||
- elsif blob.only_display_raw?
|
- elsif blob.only_display_raw?
|
||||||
.nothing-here-block This file is too large to display.
|
.nothing-here-block This file is too large to display.
|
||||||
- elsif blob.image?
|
- elsif blob.image?
|
||||||
- old_file = project.repository.prev_blob_for_diff(diff_commit, diff_file)
|
- old_blob = diff_file.old_blob(diff_commit)
|
||||||
= render "projects/diffs/image", diff_file: diff_file, old_file: old_file, file: blob, index: i, diff_refs: diff_refs
|
= render "projects/diffs/image", diff_file: diff_file, old_file: old_blob, file: blob, index: i
|
||||||
- else
|
- else
|
||||||
.nothing-here-block No preview for this file type
|
.nothing-here-block No preview for this file type
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,12 @@ module Gitlab
|
||||||
@diff_refs = diff_refs
|
@diff_refs = diff_refs
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def content_commit
|
||||||
|
return unless diff_refs
|
||||||
|
|
||||||
|
repository.commit(deleted_file ? old_ref : new_ref)
|
||||||
|
end
|
||||||
|
|
||||||
def old_ref
|
def old_ref
|
||||||
diff_refs.try(:base_sha)
|
diff_refs.try(:base_sha)
|
||||||
end
|
end
|
||||||
|
|
@ -56,11 +62,7 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_path
|
def file_path
|
||||||
if diff.new_path.present?
|
new_path.presence || old_path.presence
|
||||||
diff.new_path
|
|
||||||
elsif diff.old_path.present?
|
|
||||||
diff.old_path
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def added_lines
|
def added_lines
|
||||||
|
|
@ -70,6 +72,20 @@ module Gitlab
|
||||||
def removed_lines
|
def removed_lines
|
||||||
diff_lines.count(&:removed?)
|
diff_lines.count(&:removed?)
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue