提交 0c5795a4 编写于 作者: D Dmitriy Zaporozhets

serialize parent_ids in commit

上级 5f4445c3
...@@ -17,14 +17,14 @@ ...@@ -17,14 +17,14 @@
- diffs.each_with_index do |diff, i| - diffs.each_with_index do |diff, i|
- next if diff.diff.empty? - next if diff.diff.empty?
- file = Tree.new(@repository, @commit.id, @ref, diff.new_path) - file = Tree.new(@repository, @commit.id, @ref, diff.new_path)
- file = (@commit.prev_commit.tree / diff.old_path) unless file - file = Tree.new(@repository, @commit.parent_id, @ref, diff.old_path) unless file
- next unless file - next unless file
.file{id: "diff-#{i}"} .file{id: "diff-#{i}"}
.header .header
- if diff.deleted_file - if diff.deleted_file
%span= diff.old_path %span= diff.old_path
- if @commit.prev_commit - if @commit.parent_ids.present?
= link_to project_tree_path(@project, tree_join(@commit.prev_commit_id, diff.new_path)), {:class => 'btn btn-tiny pull-right view-file'} do = link_to project_tree_path(@project, tree_join(@commit.prev_commit_id, diff.new_path)), {:class => 'btn btn-tiny pull-right view-file'} do
View file @ View file @
%span.commit-short-id= @commit.short_id(6) %span.commit-short-id= @commit.short_id(6)
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
- if file.text? - if file.text?
= render "commits/text_file", diff: diff, index: i = render "commits/text_file", diff: diff, index: i
- elsif file.image? - elsif file.image?
- old_file = (@commit.prev_commit.tree / diff.old_path) if !@commit.prev_commit.nil? - old_file = Tree.new(@repository, @commit.parent_id, @ref, diff.old_path) if @commit.parent_id
= render "commits/image", diff: diff, old_file: old_file, file: file, index: i = render "commits/image", diff: diff, old_file: old_file, file: file, index: i
- else - else
%p.nothing_here_message No preview for this file type %p.nothing_here_message No preview for this file type
...@@ -5,8 +5,8 @@ module Gitlab ...@@ -5,8 +5,8 @@ module Gitlab
module Git module Git
class Commit class Commit
attr_accessor :raw_commit, :head, :refs, attr_accessor :raw_commit, :head, :refs,
:sha, :authored_date, :committed_date, :message, :id, :authored_date, :committed_date, :message,
:author_name, :author_email, :author_name, :author_email, :parent_ids,
:committer_name, :committer_email :committer_name, :committer_email
delegate :parents, :diffs, :tree, :stats, :to_patch, delegate :parents, :diffs, :tree, :stats, :to_patch,
...@@ -14,7 +14,7 @@ module Gitlab ...@@ -14,7 +14,7 @@ module Gitlab
class << self class << self
def serialize_keys def serialize_keys
%w(sha authored_date committed_date author_name author_email committer_name committer_email message) %w(id authored_date committed_date author_name author_email committer_name committer_email message parent_ids)
end end
def find_or_first(repo, commit_id = nil, root_ref) def find_or_first(repo, commit_id = nil, root_ref)
...@@ -88,8 +88,8 @@ module Gitlab ...@@ -88,8 +88,8 @@ module Gitlab
@head = head @head = head
end end
def id def sha
sha id
end end
def short_id(length = 10) def short_id(length = 10)
...@@ -109,16 +109,8 @@ module Gitlab ...@@ -109,16 +109,8 @@ module Gitlab
author_name != committer_name || author_email != committer_email author_name != committer_name || author_email != committer_email
end end
def prev_commit def parent_id
@prev_commit ||= if parents.present? parent_ids.first
Commit.new(parents.first)
else
nil
end
end
def prev_commit_id
prev_commit.try :id
end end
# Shows the diff between the commit's parent and the commit. # Shows the diff between the commit's parent and the commit.
...@@ -164,7 +156,7 @@ module Gitlab ...@@ -164,7 +156,7 @@ module Gitlab
def init_from_grit(grit) def init_from_grit(grit)
@raw_commit = grit @raw_commit = grit
@sha = grit.sha @id = grit.id
@message = grit.message @message = grit.message
@authored_date = grit.authored_date @authored_date = grit.authored_date
@committed_date = grit.committed_date @committed_date = grit.committed_date
...@@ -172,6 +164,7 @@ module Gitlab ...@@ -172,6 +164,7 @@ module Gitlab
@author_email = grit.author.email @author_email = grit.author.email
@committer_name = grit.committer.name @committer_name = grit.committer.name
@committer_email = grit.committer.email @committer_email = grit.committer.email
@parent_ids = grit.parents.map(&:id)
end end
def init_from_hash(hash) def init_from_hash(hash)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册