def quick_diff(tree1, tree2, path = '.', recurse = true)
changed = []
return changed if tree1 == tree2
t1 = list_tree(tree1) if tree1
t2 = list_tree(tree2) if tree2
t1['blob'].each do |file, hsh|
t2_file = t2['blob'][file] rescue nil
full = File.join(path, file)
if !t2_file
changed << [full, 'added', hsh[:sha], nil]
elsif (hsh[:sha] != t2_file[:sha])
changed << [full, 'modified', hsh[:sha], t2_file[:sha]]
end
end if t1
t2['blob'].each do |file, hsh|
if !t1 || !t1['blob'][file]
changed << [File.join(path, file), 'removed', nil, hsh[:sha]]
end
end if t2
t1['tree'].each do |dir, hsh|
t2_tree = t2['tree'][dir] rescue nil
full = File.join(path, dir)
if !t2_tree
if recurse
changed += quick_diff(hsh[:sha], nil, full, true)
else
changed << [full, 'added', hsh[:sha], nil]
end
elsif (hsh[:sha] != t2_tree[:sha])
if recurse
changed += quick_diff(hsh[:sha], t2_tree[:sha], full, true)
else
changed << [full, 'modified', hsh[:sha], t2_tree[:sha]]
end
end
end if t1
t2['tree'].each do |dir, hsh|
t1_tree = t1['tree'][dir] rescue nil
full = File.join(path, dir)
if !t1_tree
if recurse
changed += quick_diff(nil, hsh[:sha], full, true)
else
changed << [full, 'removed', nil, hsh[:sha]]
end
end
end if t2
changed
end