diff --git a/lib/rugged_adapter/git_layer_rugged.rb b/lib/rugged_adapter/git_layer_rugged.rb index 4a79162..18bdb2b 100644 --- a/lib/rugged_adapter/git_layer_rugged.rb +++ b/lib/rugged_adapter/git_layer_rugged.rb @@ -654,11 +654,7 @@ def log(commit = Gollum::Git.default_ref_for_repo(@repo), path = nil, options = def lstree(sha, options = {}) results = [] @repo.lookup(sha).tree.walk(:postorder) do |root, entry| - entry[:sha] = entry[:oid] - entry[:mode] = entry[:filemode].to_s(8) - entry[:type] = entry[:type].to_s - entry[:path] = "#{root}#{entry[:name]}" - results << entry + results << ::Gollum::Git::Tree.tree_entry_from_rugged_hash(entry, root) end results end @@ -689,6 +685,16 @@ def find_branch(search_list) class Tree + def self.tree_entry_from_rugged_hash(entry, root = '') + { + sha: entry[:oid], + mode: entry[:filemode], + type: entry[:type].to_s, + name: entry[:name], + path: "#{root}#{entry[:name]}" + } + end + def initialize(tree) @tree = tree end @@ -719,10 +725,22 @@ def /(file) def blobs blobs = [] - @tree.each_blob {|blob| blobs << Gollum::Git::Blob.new(@tree.owner.lookup(blob[:oid]), blob) } + @tree.each_blob {|blob| blobs << blob_for_tree_entry(blob) } blobs end + def find_blob(&block) + return nil unless block_given? + blob = @tree.each_blob.find {|blob| yield blob[:name] } + blob ? blob_for_tree_entry(blob) : nil + end + + private + + def blob_for_tree_entry(blob) + Gollum::Git::Blob.new(@tree.owner.lookup(blob[:oid]), self.class.tree_entry_from_rugged_hash(blob)) + end + end end