Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

  • Loading branch information...
commit f38eecb1c9a1cd50b5f535a75a5c56e45cd64456 1 parent 67fc8d2
@schacon schacon authored rtomayko committed
View
1  lib/grit/git-ruby/git_object.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
View
7 lib/grit/git-ruby/internal/raw_object.rb
@@ -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
4 lib/grit/git.rb
@@ -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
8 lib/grit/repo.rb
@@ -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
#
Please sign in to comment.
Something went wrong with that request. Please try again.