diff options
author | scott Chacon <schacon@agadorsparticus.corp.reactrix.com> | 2007-11-20 12:07:46 -0800 |
---|---|---|
committer | scott Chacon <schacon@agadorsparticus.corp.reactrix.com> | 2007-11-20 12:07:46 -0800 |
commit | d07a2c04c1599fe707831afdd29397cc36e02fa6 (patch) | |
tree | 8bde8310874c92c4c2a51998ff53166a8e8e2d94 /lib/git/raw/git.rb | |
parent | 2cef1e66c395296620225c7ffd77b772c6ad4215 (diff) | |
download | third_party-ruby-git-d07a2c04c1599fe707831afdd29397cc36e02fa6.tar.gz third_party-ruby-git-d07a2c04c1599fe707831afdd29397cc36e02fa6.tar.xz third_party-ruby-git-d07a2c04c1599fe707831afdd29397cc36e02fa6.zip |
added files from the gitrb project, which seems abandoned, but which is great code
Diffstat (limited to 'lib/git/raw/git.rb')
-rw-r--r-- | lib/git/raw/git.rb | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/lib/git/raw/git.rb b/lib/git/raw/git.rb new file mode 100644 index 0000000..004e795 --- /dev/null +++ b/lib/git/raw/git.rb @@ -0,0 +1,63 @@ +require 'git/internal/object' +require 'git/internal/pack' +require 'git/internal/loose' +require 'git/object' + +module Git + class Repository + def initialize(git_dir) + @git_dir = git_dir + @loose = Internal::LooseStorage.new(git_path("objects")) + @packs = [] + initpacks + end + + def git_path(path) + return "#@git_dir/#{path}" + end + + def get_object_by_sha1(sha1) + r = get_raw_object_by_sha1(sha1) + return nil if !r + Object.from_raw(r, self) + end + + def get_raw_object_by_sha1(sha1) + sha1 = [sha1].pack("H*") + + # try packs + @packs.each do |pack| + o = pack[sha1] + return o if o + end + + # try loose storage + o = @loose[sha1] + return o if o + + # try packs again, maybe the object got packed in the meantime + initpacks + @packs.each do |pack| + o = pack[sha1] + return o if o + end + + nil + end + + def initpacks + @packs.each do |pack| + pack.close + end + @packs = [] + Dir.open(git_path("objects/pack/")) do |dir| + dir.each do |entry| + if entry =~ /\.pack$/i + @packs << Git::Internal::PackStorage.new(git_path("objects/pack/" \ + + entry)) + end + end + end + end + end +end |