diff options
author | scott Chacon <schacon@agadorsparticus.corp.reactrix.com> | 2007-11-12 17:58:02 -0800 |
---|---|---|
committer | scott Chacon <schacon@agadorsparticus.corp.reactrix.com> | 2007-11-12 17:58:02 -0800 |
commit | f590869eaa6a4c7f25a1df8eca171a119fcee7ed (patch) | |
tree | a946f572fc3c9f6cbaef60331a2c6ef7db2b86f1 /lib/git/object.rb | |
parent | 852a0e63d294de874c3311f5e7edf40e2f2ecd60 (diff) | |
download | third_party-ruby-git-f590869eaa6a4c7f25a1df8eca171a119fcee7ed.tar.gz third_party-ruby-git-f590869eaa6a4c7f25a1df8eca171a119fcee7ed.tar.xz third_party-ruby-git-f590869eaa6a4c7f25a1df8eca171a119fcee7ed.zip |
added the tree functions and tests
Diffstat (limited to 'lib/git/object.rb')
-rw-r--r-- | lib/git/object.rb | 60 |
1 files changed, 54 insertions, 6 deletions
diff --git a/lib/git/object.rb b/lib/git/object.rb index 58ea7ab..4886f09 100644 --- a/lib/git/object.rb +++ b/lib/git/object.rb @@ -51,15 +51,61 @@ module Git class Blob < AbstractObject + + def initialize(base, sha, mode = nil) + super(base, sha) + @mode = mode + end + def setup @type = 'blob' end end class Tree < AbstractObject + + @trees = nil + @blobs = nil + + def initialize(base, sha, mode = nil) + super(base, sha) + @mode = mode + end + def setup @type = 'tree' end + + def children + blobs.merge(subtrees) + end + + def blobs + check_tree + @blobs + end + alias_method :files, :blobs + + def trees + check_tree + @trees + end + alias_method :subtrees, :trees + alias_method :subdirectories, :trees + + private + + # actually run the git command + def check_tree + if !@trees + @trees = {} + @blobs = {} + data = @base.lib.ls_tree(@sha) + data['tree'].each { |k, d| @trees[k] = Tree.new(@base, d[:sha], d[:mode]) } + data['blob'].each { |k, d| @blobs[k] = Blob.new(@base, d[:sha], d[:mode]) } + end + end + end class Commit < AbstractObject @@ -123,12 +169,14 @@ module Git # see if this object has been initialized and do so if not def check_commit - data = @base.lib.commit_data(@sha) - @committer = Git::Author.new(data['committer']) - @author = Git::Author.new(data['author']) - @tree = Tree.new(@base, data['tree']) - @parents = data['parent'].map{ |sha| Commit.new(@base, sha) } - @message = data['message'].chomp + if !@tree + data = @base.lib.commit_data(@sha) + @committer = Git::Author.new(data['committer']) + @author = Git::Author.new(data['author']) + @tree = Tree.new(@base, data['tree']) + @parents = data['parent'].map{ |sha| Commit.new(@base, sha) } + @message = data['message'].chomp + end end end |