Skip to content

Commit

Permalink
Cleaning Git::Object a little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
robertodecurnex committed Jan 15, 2014
1 parent 2116cf9 commit 209d9aa
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions lib/git/object.rb
Expand Up @@ -94,27 +94,24 @@ def blob?

class Tree < AbstractObject

@trees = nil
@blobs = nil

def initialize(base, sha, mode = nil)
super(base, sha)
@mode = mode
@trees = nil
@blobs = nil
end

def children
blobs.merge(subtrees)
end

def blobs
check_tree
@blobs
@blobs ||= check_tree[:blobs]
end
alias_method :files, :blobs

def trees
check_tree
@trees
@trees ||= check_tree[:trees]
end
alias_method :subtrees, :trees
alias_method :subdirectories, :trees
Expand All @@ -135,13 +132,23 @@ def tree?

# actually run the git command
def check_tree
unless @trees
@trees = {}
@blobs = {}
data = @base.lib.ls_tree(@objectish)
data['tree'].each { |k, d| @trees[k] = Git::Object::Tree.new(@base, d[:sha], d[:mode]) }
data['blob'].each { |k, d| @blobs[k] = Git::Object::Blob.new(@base, d[:sha], d[:mode]) }
@trees = {}
@blobs = {}

data = @base.lib.ls_tree(@objectish)

data['tree'].each do |key, tree|
@trees[key] = Git::Object::Tree.new(@base, tree[:sha], tree[:mode])
end

data['blob'].each do |key, blob|
@blobs[key] = Git::Object::Blob.new(@base, blob[:sha], blob[:mode])
end

{
:trees => @trees,
:blobs => @blobs
}
end

end
Expand Down

0 comments on commit 209d9aa

Please sign in to comment.