in lib/grit/git-ruby/repository.rb [223:274]
def ls_tree_path(sha, path, append = nil)
tree = get_raw_tree(sha)
if path =~ /\//
paths = path.split('/')
last = path[path.size - 1, 1]
if (last == '/') && (paths.size == 1)
append = append ? File.join(append, paths.first) : paths.first
dir_name = tree.split("\n").select { |p| p.split("\t")[1] == paths.first }.first
raise NoSuchPath if !dir_name
next_sha = dir_name.split(' ')[2]
tree = get_raw_tree(next_sha)
tree = tree.split("\n")
if append
mod_tree = []
tree.each do |ent|
(info, fpath) = ent.split("\t")
mod_tree << [info, File.join(append, fpath)].join("\t")
end
mod_tree
else
tree
end
else
raise NoSuchPath if tree.nil?
next_path = paths.shift
dir_name = tree.split("\n").select { |p| p.split("\t")[1] == next_path }.first
raise NoSuchPath if !dir_name
next_sha = dir_name.split(' ')[2]
next_path = append ? File.join(append, next_path) : next_path
if (last == '/')
ls_tree_path(next_sha, paths.join("/") + '/', next_path)
else
ls_tree_path(next_sha, paths.join("/"), next_path)
end
end
else
raise NoSuchPath if tree.nil?
tree = tree.split("\n")
tree = tree.select { |p| p.split("\t")[1] == path }
if append
mod_tree = []
tree.each do |ent|
(info, fpath) = ent.split("\t")
mod_tree << [info, File.join(append, fpath)].join("\t")
end
mod_tree
else
tree
end
end
end