Commit 0c5795a49726402d2f2751d8b05d5bbb9dd23511
1 parent
5f4445c3
Exists in
master
and in
4 other branches
serialize parent_ids in commit
Showing
2 changed files
with
12 additions
and
19 deletions
Show diff stats
app/views/commits/_diffs.html.haml
... | ... | @@ -17,14 +17,14 @@ |
17 | 17 | - diffs.each_with_index do |diff, i| |
18 | 18 | - next if diff.diff.empty? |
19 | 19 | - file = Tree.new(@repository, @commit.id, @ref, diff.new_path) |
20 | - - file = (@commit.prev_commit.tree / diff.old_path) unless file | |
20 | + - file = Tree.new(@repository, @commit.parent_id, @ref, diff.old_path) unless file | |
21 | 21 | - next unless file |
22 | 22 | .file{id: "diff-#{i}"} |
23 | 23 | .header |
24 | 24 | - if diff.deleted_file |
25 | 25 | %span= diff.old_path |
26 | 26 | |
27 | - - if @commit.prev_commit | |
27 | + - if @commit.parent_ids.present? | |
28 | 28 | = link_to project_tree_path(@project, tree_join(@commit.prev_commit_id, diff.new_path)), {:class => 'btn btn-tiny pull-right view-file'} do |
29 | 29 | View file @ |
30 | 30 | %span.commit-short-id= @commit.short_id(6) |
... | ... | @@ -43,7 +43,7 @@ |
43 | 43 | - if file.text? |
44 | 44 | = render "commits/text_file", diff: diff, index: i |
45 | 45 | - elsif file.image? |
46 | - - old_file = (@commit.prev_commit.tree / diff.old_path) if !@commit.prev_commit.nil? | |
46 | + - old_file = Tree.new(@repository, @commit.parent_id, @ref, diff.old_path) if @commit.parent_id | |
47 | 47 | = render "commits/image", diff: diff, old_file: old_file, file: file, index: i |
48 | 48 | - else |
49 | 49 | %p.nothing_here_message No preview for this file type | ... | ... |
lib/gitlab/git/commit.rb
... | ... | @@ -5,8 +5,8 @@ module Gitlab |
5 | 5 | module Git |
6 | 6 | class Commit |
7 | 7 | attr_accessor :raw_commit, :head, :refs, |
8 | - :sha, :authored_date, :committed_date, :message, | |
9 | - :author_name, :author_email, | |
8 | + :id, :authored_date, :committed_date, :message, | |
9 | + :author_name, :author_email, :parent_ids, | |
10 | 10 | :committer_name, :committer_email |
11 | 11 | |
12 | 12 | delegate :parents, :diffs, :tree, :stats, :to_patch, |
... | ... | @@ -14,7 +14,7 @@ module Gitlab |
14 | 14 | |
15 | 15 | class << self |
16 | 16 | def serialize_keys |
17 | - %w(sha authored_date committed_date author_name author_email committer_name committer_email message) | |
17 | + %w(id authored_date committed_date author_name author_email committer_name committer_email message parent_ids) | |
18 | 18 | end |
19 | 19 | |
20 | 20 | def find_or_first(repo, commit_id = nil, root_ref) |
... | ... | @@ -88,8 +88,8 @@ module Gitlab |
88 | 88 | @head = head |
89 | 89 | end |
90 | 90 | |
91 | - def id | |
92 | - sha | |
91 | + def sha | |
92 | + id | |
93 | 93 | end |
94 | 94 | |
95 | 95 | def short_id(length = 10) |
... | ... | @@ -109,16 +109,8 @@ module Gitlab |
109 | 109 | author_name != committer_name || author_email != committer_email |
110 | 110 | end |
111 | 111 | |
112 | - def prev_commit | |
113 | - @prev_commit ||= if parents.present? | |
114 | - Commit.new(parents.first) | |
115 | - else | |
116 | - nil | |
117 | - end | |
118 | - end | |
119 | - | |
120 | - def prev_commit_id | |
121 | - prev_commit.try :id | |
112 | + def parent_id | |
113 | + parent_ids.first | |
122 | 114 | end |
123 | 115 | |
124 | 116 | # Shows the diff between the commit's parent and the commit. |
... | ... | @@ -164,7 +156,7 @@ module Gitlab |
164 | 156 | |
165 | 157 | def init_from_grit(grit) |
166 | 158 | @raw_commit = grit |
167 | - @sha = grit.sha | |
159 | + @id = grit.id | |
168 | 160 | @message = grit.message |
169 | 161 | @authored_date = grit.authored_date |
170 | 162 | @committed_date = grit.committed_date |
... | ... | @@ -172,6 +164,7 @@ module Gitlab |
172 | 164 | @author_email = grit.author.email |
173 | 165 | @committer_name = grit.committer.name |
174 | 166 | @committer_email = grit.committer.email |
167 | + @parent_ids = grit.parents.map(&:id) | |
175 | 168 | end |
176 | 169 | |
177 | 170 | def init_from_hash(hash) | ... | ... |