get_diff.rb revision a2b3d5bb602a9a0d970b6640948f1d7d75ce78bf
# depends on GitRepository
if !rugged_commit
[]
else
end
end
else
end
end
end
files_contents = []
end
files_contents = []
end
files_contents = []
current_tree.each do |e|
if e[:type] == :tree
files_contents.concat(gcf_complete(@repo.lookup(e[:oid]), @repo.lookup(parent_tree[e[:name]][:oid]), "#{directory}#{e[:name]}/"))
elsif !parent_tree[e[:name]]
end
end
end
end
files_contents = []
parent_tree.each do |e|
end
end
end
files_contents = []
end
files_contents = []
current_tree.each do |e|
if e[:type] == :blob
files_contents << changed_files_entry(directory, e[:name], :change, @repo.lookup(e[:oid]).content, @repo.lookup(parent_tree[e[:name]][:oid]).content)
elsif !parent_tree[e[:name]]
files_contents << changed_files_entry(directory, e[:name], :add, @repo.lookup(e[:oid]).content, '')
end
end
end
files_contents
end
def gcf_current_deleted(current_tree, parent_tree, directory)
files_contents = []
parent_tree.each do |e|
if e[:type] == :blob && !current_tree[e[:name]]
files_contents << changed_files_entry(directory, e[:name], :delete, '', '')
end
end
files_contents
end
def changed_files_entry(directory, name, type, content_current, content_parent)
mime_info = mime_info(name)
editable = mime_type_editable?(mime_info[:mime_type])
{
name: name,
path: "#{directory}#{name}",
diff: editable ? diff(content_current, content_parent) : '',
type: type,
mime_type: mime_info[:mime_type],
mime_category: mime_info[:mime_category],
editable: editable
}
end
def diff(current, original)
Diffy::Diff.new(original.force_encoding('UTF-8'), current.force_encoding('UTF-8'), include_plus_and_minus_in_html: true, context: 3, include_diff_info: true).to_s(:html)
end
def mime_type_editable?(mime_type)
mime_type.to_s == 'application/xml' || mime_type.to_s.match(/^text\/.*/)
end
end