2 # converted from the gitrb project
5 # Matthias Lederhofer <matled@gmx.net>
6 # Simon 'corecode' Schubert <corecode@fs.ei.tum.de>
8 # provides native ruby access to git objects and pack files
11 require 'git/raw/internal/object'
12 require 'git/raw/internal/pack'
13 require 'git/raw/internal/loose'
14 require 'git/raw/object'
20 def initialize(git_dir)
22 @loose = Raw::Internal::LooseStorage.new(git_path("objects"))
32 puts "**#{p[s].type}**"
33 if p[s].type.to_s == 'commit'
43 o = get_raw_object_by_sha1(sha)
44 c = Git::Raw::Object.from_raw(o)
48 object(sha).raw_content
51 def log(sha, count = 30)
55 while sha && (i < count) do
56 o = get_raw_object_by_sha1(sha)
57 c = Git::Raw::Object.from_raw(o)
59 output += "commit #{sha}\n"
60 output += o.content + "\n"
69 def get_object_by_sha1(sha1)
70 r = get_raw_object_by_sha1(sha1)
72 Object.from_raw(r, self)
75 def get_raw_object_by_sha1(sha1)
76 sha1 = [sha1].pack("H*")
88 # try packs again, maybe the object got packed in the meantime
101 return "#@git_dir/#{path}"
107 @packs.each do |pack|
111 Dir.open(git_path("objects/pack/")) do |dir|
113 if entry =~ /\.pack$/i
114 @packs << Git::Raw::Internal::PackStorage.new(git_path("objects/pack/" \