Created
December 22, 2016 15:58
-
-
Save ejoubaud/4e4847673c7d8605c2046944b48a01c5 to your computer and use it in GitHub Desktop.
Say you have a file that's been duplicated a few and you want to get an overwiew of how each copy diverged, this gives you a TSV you can import in Excel
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 | |
`for i in market*.sh.erb; do echo $i; git log --format="%ad%x09%h%x09%s" --date=iso -- $i; done > history1.log` | |
lines = File.readlines('history1.log') | |
commits_by_file = lines.reduce(['', Hash.new([])]) { |(current_file, commits_by_file), line| line.include?("\t") ? [current_file, commits_by_file.merge(current_file => (commits_by_file[current_file] + [line]))] : [line, commits_by_file] }.last | |
commits_by_file_parsed = Hash[commits_by_file.map{|file, commits| [file, commits.map{|c|c.split("\t")}.map{|s|{:date => s[0], :sha => s[1], :msg => s[2]}}]}] | |
flat_commits = commits_by_file_parsed.flat_map{|file, commits| commits.map {|commit| commit.merge(:file => file)}} | |
commits = flat_commits.reduce({}) { |mem, commit| new_commit = mem[commit[:sha]] ? mem[commit[:sha]].merge(:files => (mem[commit[:sha]][:files] + [commit[:file]])) : commit.select{|k| k != :file}.merge(:files => [commit[:file]]); mem.merge(commit[:sha] => new_commit) }.values.sort_by{|c| c[:date]} | |
files = commits_by_file.keys | |
commits_with_matrix = commits.map{ |c| c.merge(:line => files.map{|f| c[:files].include?(f) ? 'x' : ''}.join("\t")) } | |
header = "\t\t\t\t" + files.map(&:strip).join("\t") | |
output_lines = commits_with_matrix.map { |c| [c[:date], c[:sha], c[:msg].strip[0..20], "https://github.com/envato/marketplace-aws/commit/#{c[:sha]}", c[:line]].join("\t") } | |
STDOUT.puts header; output_lines.each { |l| STDOUT.puts l }; nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment