2008-12-22 16:19:08 +03:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2009-01-01 00:56:38 +03:00
|
|
|
ENV.delete('PWD')
|
|
|
|
|
2008-12-22 16:19:08 +03:00
|
|
|
require 'optparse'
|
|
|
|
require 'pathname'
|
|
|
|
|
2008-12-23 09:39:48 +03:00
|
|
|
SRCDIR = Pathname(File.dirname($0)).parent.freeze
|
2008-12-22 16:19:08 +03:00
|
|
|
class VCSNotFoundError < RuntimeError; end
|
|
|
|
|
|
|
|
def detect_vcs(path)
|
2008-12-23 09:39:48 +03:00
|
|
|
path = SRCDIR
|
|
|
|
return :svn, path.relative_path_from(SRCDIR) if File.directory?("#{path}/.svn")
|
2009-01-01 10:13:24 +03:00
|
|
|
return :git_svn, path.relative_path_from(SRCDIR) if File.directory?("#{path}/.git/svn")
|
2008-12-23 09:39:48 +03:00
|
|
|
return :git, path.relative_path_from(SRCDIR) if File.directory?("#{path}/.git")
|
2008-12-22 16:19:08 +03:00
|
|
|
raise VCSNotFoundError, "does not seem to be under a vcs"
|
|
|
|
end
|
|
|
|
|
2009-01-13 06:37:24 +03:00
|
|
|
# return a pair of strings, the last revision and the last revision in which
|
|
|
|
# +path+ was modified.
|
2008-12-22 16:19:08 +03:00
|
|
|
def get_revisions(path)
|
|
|
|
vcs, path = detect_vcs(path)
|
|
|
|
|
|
|
|
info = case vcs
|
|
|
|
when :svn
|
2009-01-13 06:37:24 +03:00
|
|
|
info_xml = `cd "#{SRCDIR}" && svn info --xml "#{path}"`
|
|
|
|
_, last, _, changed, _ = info_xml.split(/revision="(\d+)"/)
|
|
|
|
return last, changed
|
2009-01-01 10:13:24 +03:00
|
|
|
when :git_svn
|
2008-12-23 09:49:39 +03:00
|
|
|
`cd "#{SRCDIR}" && git svn info "#{path}"`
|
2009-01-01 10:13:24 +03:00
|
|
|
when :git
|
|
|
|
git_log = `cd "#{SRCDIR}" && git log HEAD~1..HEAD "#{path}"`
|
|
|
|
git_log =~ /git-svn-id: .*?@(\d+)/
|
2009-01-13 06:37:24 +03:00
|
|
|
return $1, $1
|
2008-12-22 16:19:08 +03:00
|
|
|
end
|
|
|
|
|
2008-12-24 14:19:32 +03:00
|
|
|
if /^Revision: (\d+)/ =~ info
|
2008-12-22 16:19:08 +03:00
|
|
|
last = $1
|
|
|
|
else
|
|
|
|
raise "last revision not found"
|
|
|
|
end
|
2008-12-24 14:19:32 +03:00
|
|
|
if /^Last Changed Rev: (\d+)/ =~ info
|
2008-12-22 16:19:08 +03:00
|
|
|
changed = $1
|
|
|
|
else
|
|
|
|
raise "changed revision not found"
|
|
|
|
end
|
|
|
|
|
|
|
|
return last, changed
|
|
|
|
end
|
|
|
|
|
2009-06-30 11:53:22 +04:00
|
|
|
@output = nil
|
|
|
|
def self.output=(output)
|
|
|
|
if @output and @output != output
|
|
|
|
raise "you can specify only one of --changed, --revision.h and --doxygen"
|
|
|
|
end
|
|
|
|
@output = output
|
2008-12-22 16:19:08 +03:00
|
|
|
end
|
2009-06-30 11:53:22 +04:00
|
|
|
@suppress_not_found = false
|
2008-12-22 16:19:08 +03:00
|
|
|
|
|
|
|
parser = OptionParser.new {|opts|
|
|
|
|
opts.on("--changed", "changed rev") do
|
2009-06-30 11:53:22 +04:00
|
|
|
self.output = :changed
|
2008-12-22 16:19:08 +03:00
|
|
|
end
|
|
|
|
opts.on("--revision.h") do
|
2009-06-30 11:53:22 +04:00
|
|
|
self.output = :revision_h
|
2008-12-22 16:19:08 +03:00
|
|
|
end
|
|
|
|
opts.on("--doxygen") do
|
2009-06-30 11:53:22 +04:00
|
|
|
self.output = :doxygen
|
2008-12-22 16:19:08 +03:00
|
|
|
end
|
|
|
|
opts.on("-q", "--suppress_not_found") do
|
2009-06-30 11:53:22 +04:00
|
|
|
@suppress_not_found = true
|
2008-12-22 16:19:08 +03:00
|
|
|
end
|
|
|
|
}
|
|
|
|
parser.parse!
|
|
|
|
|
|
|
|
|
|
|
|
begin
|
|
|
|
last, changed = get_revisions(ARGV.shift)
|
|
|
|
rescue VCSNotFoundError
|
2009-06-30 11:53:22 +04:00
|
|
|
raise unless @suppress_not_found
|
2008-12-22 16:19:08 +03:00
|
|
|
end
|
|
|
|
|
2009-06-30 11:53:22 +04:00
|
|
|
case @output
|
2008-12-22 16:19:08 +03:00
|
|
|
when :changed, nil
|
|
|
|
puts changed
|
|
|
|
when :revision_h
|
2009-01-15 14:45:01 +03:00
|
|
|
puts "#define RUBY_REVISION #{changed.to_i}"
|
2008-12-22 16:19:08 +03:00
|
|
|
when :doxygen
|
|
|
|
puts "r#{changed}/r#{last}"
|
|
|
|
else
|
2009-06-30 11:53:22 +04:00
|
|
|
raise "unknown output format `#{@output}'"
|
2008-12-22 16:19:08 +03:00
|
|
|
end
|