Created
May 25, 2012 14:06
-
-
Save jedi4ever/2788325 to your computer and use it in GitHub Desktop.
Show changelog of what changed in mercurial repo + subrepos
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
def subrepo_changed?(from = 'tip~1',to = 'tip') | |
command = "hg status --rev #{from}:#{to} -m -a -r -d -S .hgsubstate" | |
result = `#{command}`.include?("M .hgsubstate") | |
return result | |
end | |
def subrepo_changes(from,to) | |
command = "hg diff -S -r #{from}..#{to} .hgsubstate" | |
result = `#{command}` | |
changes = result.split(/\n/).select{ |c| c.match(/^[-+][a-z0-9]/) } | |
module_changes = Hash.new | |
changes.each do |c| | |
revision, name = c[1..-1].split(' ') | |
module_changes[name] = Hash.new if module_changes[name].nil? | |
module_changes[name][:from] = revision if c.start_with?('-') | |
module_changes[name][:to] = revision if c.start_with?('+') | |
end | |
return module_changes | |
end | |
def show_log(from,to) | |
command = "hg log -r#{from}:#{to} --style changelog" | |
result = `#{command}` | |
puts result | |
end | |
def show_changes(from,to) | |
# Show log from - to revision | |
show_log(from,to) | |
# Now recurse subrepos | |
if subrepo_changed?(from,to) | |
changes = subrepo_changes(from,to) | |
changes.each do |name, revisions| | |
puts "---- #{name} -----------------------------------" | |
Dir.chdir(name) | |
show_changes(revisions[:from],revisions[:to]) | |
levels = name.match(File::Separator) | |
if levels.nil? | |
levels_back = 1 | |
else | |
levels_back = levels.size + 1 | |
end | |
levels_back.times { Dir.chdir('..') } | |
end | |
end | |
end | |
unless ARGV.size == 1 | |
puts "Usage: ruby whatchanged.rb [numberofrevisionsago]" | |
exit | |
end | |
from = "tip~#{ARGV[0].to_i-1}" | |
to = 'tip' | |
show_changes(from,to) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment