Permalink
Browse files

start using the GitRuby::GitObject types in the Git data api

  • Loading branch information...
1 parent 67fc8d2 commit f38eecb1c9a1cd50b5f535a75a5c56e45cd64456 @schacon schacon committed with rtomayko Jun 16, 2011
Showing with 20 additions and 0 deletions.
  1. +1 −0 lib/grit/git-ruby/git_object.rb
  2. +7 −0 lib/grit/git-ruby/internal/raw_object.rb
  3. +4 −0 lib/grit/git.rb
  4. +8 −0 lib/grit/repo.rb
@@ -49,6 +49,7 @@ def to_s
# base class for all git objects (blob, tree, commit, tag)
class GitObject
attr_accessor :repository
+ attr_accessor :sha
def GitObject.from_raw(rawobject, repository = nil)
case rawobject.type
@@ -31,6 +31,13 @@ def initialize(type, content)
def sha1
Digest::SHA1.digest("%s %d\0" % [@type, @content.length] + @content)
end
+
+ def to_hash
+ {
+ :type => @type,
+ :content => @content
+ }
+ end
end
end
end
View
@@ -56,6 +56,10 @@ def get_raw_object(object_id)
ruby_git.get_raw_object_by_sha1(object_id).content
end
+ def get_git_object(object_id)
+ ruby_git.get_raw_object_by_sha1(object_id).to_hash
+ end
+
def object_exists?(object_id)
ruby_git.object_exists?(object_id)
end
View
@@ -519,6 +519,14 @@ def lstree(treeish = 'master', options = {})
revs
end
+ def object(sha)
+ obj = git.get_git_object(sha)
+ raw = Grit::GitRuby::Internal::RawObject.new(obj[:type], obj[:content])
+ object = Grit::GitRuby::GitObject.from_raw(raw)
+ object.sha = sha
+ object
+ end
+
# The Blob object for the given id
# +id+ is the SHA1 id of the blob
#

0 comments on commit f38eecb

Please sign in to comment.