Created
May 24, 2013 02:10
-
-
Save mattak/5640843 to your computer and use it in GitHub Desktop.
android project diff
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# android diff checker | |
# | |
# usage: | |
# adiff app1/src/ app2/src/ | |
# | |
def to_filehash(filelist) | |
hash = {} | |
filelist.each do |path| | |
filename = File.basename(path) | |
hash[filename] = path | |
end | |
hash | |
end | |
def puts_onlyin(dir1, dir2, dir1_hash, dir2_hash) | |
dir1_only = dir1_hash.keys - dir2_hash.keys | |
if dir1_only.size > 0 | |
puts ((" " * 2) + "#{dir1}:") | |
dir1_only.each do |file| | |
str = (" " * 4) + "#{file}:\t #{dir1_hash[file]}" | |
puts str | |
end | |
end | |
end | |
# | |
# MAIN | |
# | |
if ARGV.size != 2 | |
puts "usage: adiff [dir1] [dir2]" | |
exit 0 | |
end | |
DIR1=ARGV[0] | |
DIR2=ARGV[1] | |
DIR1_LIST=`find #{DIR1} -type f`.chomp.split("\n") | |
DIR2_LIST=`find #{DIR2} -type f`.chomp.split("\n") | |
if DIR1_LIST.size < 1 && DIR2_LIST.size < 1 | |
raise "#{DIR1} and #{DIR2} is null!" | |
end | |
if DIR1_LIST.size != DIR2_LIST.size | |
STDERR.puts "#{DIR1}: #{DIR1_LIST.size}" | |
STDERR.puts "#{DIR2}: #{DIR2_LIST.size}" | |
end | |
DIR1_HASH = to_filehash(DIR1_LIST) | |
DIR2_HASH = to_filehash(DIR2_LIST) | |
# CHECK ONLY IN ONE HASH | |
puts "ONLYIN:" | |
puts_onlyin(DIR1, DIR2, DIR1_HASH, DIR2_HASH) | |
puts_onlyin(DIR2, DIR1, DIR2_HASH, DIR1_HASH) | |
# CHECK DIFF | |
puts "DIFF:" | |
DIR1_HASH.each do |name, path| | |
puts ((" " * 2) + "#{name}:") | |
if DIR2_HASH[name] != nil | |
puts ("=" * 80) | |
cmd = "diff #{path} #{DIR2_HASH[name]}" | |
puts cmd | |
system(cmd) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment