Created
August 7, 2014 20:28
-
-
Save bodepd/744fb569eafbfbf41d00 to your computer and use it in GitHub Desktop.
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
#!/bin/env ruby | |
pwd = Dir.pwd | |
puts "Working out of directory #{pwd}" | |
upstream_dir=File.join(pwd, 'upstream') | |
downstream_dir=File.join(pwd, 'downstream') | |
def system_cmd (cmd, print_output=false) | |
puts "Running cmd: #{cmd}" | |
output = `#{cmd}`.split("\n") | |
if print_output | |
puts output | |
else | |
#puts output | |
end | |
#raise(StandardError, "Cmd #{cmd} failed") unless $?.success? | |
[output, $?.success?] | |
end | |
def get_rev_list(dir, opts='--no-merges') | |
rev_list=[] | |
Dir.chdir(dir) do | |
rev_list=`git rev-list #{opts} HEAD`.split("\n") | |
end | |
rev_list | |
end | |
def checkout(dir, commit, opts='') | |
puts "Checking out upstream: #{commit}" | |
Dir.chdir(dir) do | |
output=`git checkout #{commit} #{opts}` | |
puts output | |
end | |
end | |
# start from origin/master | |
checkout(downstream_dir, 'origin/master') | |
checkout(upstream_dir, 'origin/master') | |
# get all revisions | |
rev_list_down=get_rev_list(downstream_dir) | |
rev_list_up=get_rev_list(upstream_dir) | |
puts "UP revs count #{rev_list_up.size}" | |
# start with first commit from downstream | |
#rev_list_down.reverse.each do |ref| | |
output_size={} | |
ref = rev_list_down.reverse.first | |
checkout(downstream_dir, ref) | |
rev_list_up.each do |ref2| | |
checkout(upstream_dir, ref2) | |
t out = system_cmd('diff -r --exclude=.svn --exclude=.git upstream downstream') | |
if out[1] | |
puts "Upstream #{ref} matches downstream #{ref2}" | |
exit 0 | |
else | |
output_size[out[0].size] ||= {} | |
output_size[out[0].size]["#{ref}_#{ref2}"] = out[0] | |
end | |
end | |
#end | |
puts "Could not find any common anscestor" | |
smallest = output_size.keys.sort.first | |
puts smallest | |
puts output_size[smallest].size | |
puts output_size[smallest].values.first.join("\n") | |
#puts output_size[output_size.keys.sort.first].inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment