fix find commits with leading `0` symbols

This commit is contained in:
Alexander Machehin 2013-04-25 21:00:30 +06:00
parent f98cea12b3
commit b7fb0bc619
2 changed files with 8 additions and 5 deletions

View File

@ -22,9 +22,7 @@ class Comment < ActiveRecord::Base
attr_accessible :body, :data
def commentable
# raise commentable_id.inspect
# raise commentable_id.to_s(16).inspect
commit_comment? ? project.repo.commit(commentable_id.to_s(16)) : super # TODO leading zero problem
commit_comment? ? project.repo.commit(Comment.hex_to_commit_hash commentable_id) : super # TODO leading zero problem
end
def commentable=(c)
@ -185,6 +183,11 @@ class Comment < ActiveRecord::Base
end
end
def self.hex_to_commit_hash hex
t = hex.to_s(16)
'0'*(40-t.length) << t
end
protected
def subscribe_on_reply

View File

@ -14,7 +14,7 @@ class GitPresenters::CommitAsMessagePresenter < ApplicationPresenter
else
opts[:project]
end
commit = commit || @project.repo.commit(comment.created_from_commit_hash.to_s(16)) if @project
commit = commit || @project.repo.commit(Comment.hex_to_commit_hash comment.created_from_commit_hash) if @project
if @project && commit
@committer = User.where(:email => commit.committer.email).first || commit.committer
@ -23,7 +23,7 @@ class GitPresenters::CommitAsMessagePresenter < ApplicationPresenter
@commit_message = commit.message
else
@committer = t('layout.commits.unknown_committer')
@commit_hash = comment.created_from_commit_hash.to_s(16)
@commit_hash = Comment.hex_to_commit_hash comment.created_from_commit_hash
@committed_date = @authored_date = comment.created_at
@commit_message = t('layout.commits.deleted')
end