From 07ebb951368ed31bdaebc2e820c62ced22c8bbe4 Mon Sep 17 00:00:00 2001 From: scott Chacon Date: Tue, 27 Nov 2007 08:06:51 -0800 Subject: added Matthias and Simon to credits for the gitrb code fixed an issue with raw object tree formatting added ls_tree implementation in raw git --- lib/git/lib.rb | 16 +++++++++++----- lib/git/raw/internal/loose.rb | 10 ++++++++++ lib/git/raw/internal/mmap.rb | 10 ++++++++++ lib/git/raw/internal/object.rb | 10 ++++++++++ lib/git/raw/internal/pack.rb | 10 ++++++++++ lib/git/raw/object.rb | 28 ++++++++++++++++++++++++++-- lib/git/raw/repository.rb | 19 +++++++++++++++++-- 7 files changed, 94 insertions(+), 9 deletions(-) (limited to 'lib') diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 120d9ce..decd6d4 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -183,16 +183,22 @@ module Git def object_contents(sha) #command('cat-file', ['-p', sha]) - get_raw_repo.cat_file(revparse(sha)) + get_raw_repo.cat_file(revparse(sha)).chomp end def ls_tree(sha) data = {'blob' => {}, 'tree' => {}} - command_lines('ls-tree', sha.to_s).each do |line| - (info, filenm) = line.split("\t") - (mode, type, sha) = info.split - data[type][filenm] = {:mode => mode, :sha => sha} + + get_raw_repo.object(revparse(sha)).entry.each do |e| + data[e.format_type][e.name] = {:mode => e.format_mode, :sha => e.sha1} end + + #command_lines('ls-tree', sha.to_s).each do |line| + # (info, filenm) = line.split("\t") + # (mode, type, sha) = info.split + # data[type][filenm] = {:mode => mode, :sha => sha} + #end + data end diff --git a/lib/git/raw/internal/loose.rb b/lib/git/raw/internal/loose.rb index d8ec6fb..53d4334 100644 --- a/lib/git/raw/internal/loose.rb +++ b/lib/git/raw/internal/loose.rb @@ -1,3 +1,13 @@ +# +# converted from the gitrb project +# +# authors: +# Matthias Lederhofer +# Simon 'corecode' Schubert +# +# provides native ruby access to git objects and pack files +# + require 'zlib' require 'digest/sha1' diff --git a/lib/git/raw/internal/mmap.rb b/lib/git/raw/internal/mmap.rb index 15b5628..78de164 100644 --- a/lib/git/raw/internal/mmap.rb +++ b/lib/git/raw/internal/mmap.rb @@ -1,3 +1,13 @@ +# +# converted from the gitrb project +# +# authors: +# Matthias Lederhofer +# Simon 'corecode' Schubert +# +# provides native ruby access to git objects and pack files +# + begin require 'mmap' rescue LoadError diff --git a/lib/git/raw/internal/object.rb b/lib/git/raw/internal/object.rb index 7f95685..172b917 100644 --- a/lib/git/raw/internal/object.rb +++ b/lib/git/raw/internal/object.rb @@ -1,3 +1,13 @@ +# +# converted from the gitrb project +# +# authors: +# Matthias Lederhofer +# Simon 'corecode' Schubert +# +# provides native ruby access to git objects and pack files +# + require 'digest/sha1' module Git diff --git a/lib/git/raw/internal/pack.rb b/lib/git/raw/internal/pack.rb index 6980a98..8d5141e 100644 --- a/lib/git/raw/internal/pack.rb +++ b/lib/git/raw/internal/pack.rb @@ -1,3 +1,13 @@ +# +# converted from the gitrb project +# +# authors: +# Matthias Lederhofer +# Simon 'corecode' Schubert +# +# provides native ruby access to git objects and pack files +# + require 'zlib' require 'git/raw/internal/object' require 'git/raw/internal/mmap' diff --git a/lib/git/raw/object.rb b/lib/git/raw/object.rb index f10d853..5c3969d 100644 --- a/lib/git/raw/object.rb +++ b/lib/git/raw/object.rb @@ -1,3 +1,13 @@ +# +# converted from the gitrb project +# +# authors: +# Matthias Lederhofer +# Simon 'corecode' Schubert +# +# provides native ruby access to git objects and pack files +# + require 'digest/sha1' module Git @@ -132,6 +142,21 @@ module Git end end + def format_type + case type + when :link + 'link' + when :directory + 'tree' + when :file + 'blob' + end + end + + def format_mode + "%06o" % @mode + end + def raw "%o %s\0%s" % [@mode, @name, [@sha1].pack("H*")] end @@ -160,8 +185,7 @@ module Git def raw_content # TODO: sort correctly #@entry.sort { |a,b| a.name <=> b.name }. - @entry. - collect { |e| e.raw }.join + @entry.collect { |e| [[e.format_mode, e.format_type, e.sha1].join(' '), e.name].join("\t") }.join("\n") end end diff --git a/lib/git/raw/repository.rb b/lib/git/raw/repository.rb index 4a1c897..bd5e971 100644 --- a/lib/git/raw/repository.rb +++ b/lib/git/raw/repository.rb @@ -1,3 +1,13 @@ +# +# converted from the gitrb project +# +# authors: +# Matthias Lederhofer +# Simon 'corecode' Schubert +# +# provides native ruby access to git objects and pack files +# + require 'git/raw/internal/object' require 'git/raw/internal/pack' require 'git/raw/internal/loose' @@ -28,9 +38,14 @@ module Git puts end end - + + def object(sha) + o = get_raw_object_by_sha1(sha) + c = Git::Raw::Object.from_raw(o) + end + def cat_file(sha) - get_raw_object_by_sha1(sha).content rescue nil + object(sha).raw_content end def log(sha, count = 30) -- cgit