Last active
August 29, 2015 14:12
-
-
Save ifyouseewendy/9bdf7ad7173f9c78026c to your computer and use it in GitHub Desktop.
Update git history of author and email.
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
File.open("stats/stats_#{Time.now.to_i}.tsv","w") do |of| | |
lines = `git log --format=format:"%an\t%ae\t%ce"`.split("\n").uniq | |
stats = lines.reduce({}) do |ret, line| | |
author, a_email, c_email = line.strip.split("\t") | |
ret[author] ||= {} | |
ret[author][:a_email] ||= [] | |
ret[author][:c_email] ||= [] | |
ret[author][:a_email] << a_email unless ret[author][:a_email].include? a_email | |
ret[author][:c_email] << c_email unless ret[author][:c_email].include? c_email | |
ret | |
end | |
of.puts %w(Author AuthorEmail CommitterEmail).join("\t") | |
stats.sort_by{|k,v| k}.each do |k, v| | |
a_email = v[:a_email].empty? ? '-' : v[:a_email].join(', ') | |
c_email = v[:c_email].empty? ? '-' : v[:c_email].join(', ') | |
of.puts [k, a_email, c_email].join("\t") | |
end | |
end |
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
git filter-branch -f --commit-filter ' | |
char="[[:alnum:]!#\$%&\*\+/=?^_\`{|}~-]"; | |
name_part="(${char}+\.*${char}+)"; | |
domain="([[:alnum:]]([[:alnum:]-]*[[:alnum:]])?)+\.[[:alnum:]\(]([[:alnum:]-]*[[:alnum:]\)])?"; | |
begin="(^|[[:space:]])"; | |
end="($|[[:space:]])"; | |
other_email="${begin}${name_part}@${domain}${end}"; | |
umeng_email="${begin}${name_part}@umeng.com"; | |
email="$GIT_AUTHOR_EMAIL"; | |
# CAUTION | |
# `echo` will interrupt `git filter-branch`, | |
# copy out the script to debug. | |
if [[ $email =~ $umeng_email ]]; then | |
git commit-tree "$@"; | |
elif [[ $email =~ $other_email ]]; then | |
name=${BASH_REMATCH[2]}; | |
domain=${BASH_REMATCH[3]}; | |
# Need an absolute path when doing `git filter-branch`, remember to change yours. | |
updated_name=`ruby /path/to/update_name.rb $name`; | |
if [[ $updated_name = "" ]]; then | |
author_email="[email protected]"; | |
updated_name="$name"; | |
else | |
author_email="[email protected]"; | |
fi | |
GIT_AUTHOR_NAME="$updated_name"; | |
GIT_AUTHOR_EMAIL="$author_email"; | |
GIT_COMMITTER_EMAIL="$author_email"; | |
git commit-tree "$@"; | |
else | |
git commit-tree "$@"; | |
fi | |
' -- HEAD | |
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
char="[[:alnum:]!#\$%&\*\+/=?^_\`{|}~-]"; | |
name_part="(${char}+\.*${char}+)"; | |
domain="([[:alnum:]]([[:alnum:]-]*[[:alnum:]])?)+\.[[:alnum:]\(]([[:alnum:]-]*[[:alnum:]\)])?"; | |
begin="(^|[[:space:]])"; | |
end="($|[[:space:]])"; | |
other_email="${begin}${name_part}@${domain}${end}"; | |
umeng_email="${begin}${name_part}@umeng.com"; | |
# email="[email protected]" | |
# email="lt@lt-ThinkPad-R400.(none)" | |
# email="[email protected]" | |
# echo ${BASH_REMATCH[0]} => [email protected] | |
# echo ${BASH_REMATCH[1]} => | |
# echo ${BASH_REMATCH[2]} => joe.smith | |
# echo ${BASH_REMATCH[3]} => example | |
# $GIT_AUTHOR_EMAIL="[email protected]"; | |
email="$GIT_AUTHOR_EMAIL"; | |
if [[ $email =~ $umeng_email ]]; then | |
git commit-tree "$@"; | |
elif [[ $email =~ $other_email ]]; then | |
name=${BASH_REMATCH[2]}; | |
domain=${BASH_REMATCH[3]}; | |
# Need an absolute path when doing git filter-branch, remember to change yours. | |
updated_name=`ruby /path/to/update_name.rb $name`; | |
if [[ $updated_name = "" ]]; then | |
author_email="[email protected]"; | |
updated_name="$name"; | |
else | |
author_email="[email protected]"; | |
fi | |
GIT_AUTHOR_NAME="$updated_name"; | |
GIT_AUTHOR_EMAIL="$author_email"; | |
GIT_COMMITTER_EMAIL="$author_email"; | |
git commit-tree "$@"; | |
else | |
git commit-tree "$@"; | |
fi |
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
mapping = File.read( File.expand_path('../mapping.txt', __FILE__) ).lines.reduce({}) do |ret, line| | |
umeng_name, *names = line.strip.split(/\s/) | |
names.each{|n| ret[n] = umeng_name } | |
ret | |
end | |
File.open('log', 'a') do |of| | |
of.puts mapping[ARGV[0]] || '' | |
end | |
puts mapping[ARGV[0]] || '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment