diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-25 09:52:16 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-12-25 09:52:16 +0000 |
commit | af627192b768216371bda06476940d7290b94a31 (patch) | |
tree | 4574e55a2c35b8c3cfcc84d6a6f81fa47aeb8de3 /tool | |
parent | 9b425aed7af824e030cb2ad83d85d3d586d13559 (diff) |
merges r20920, r20936, r20939 and r20966 from trunk into ruby_1_9_1.
* common.mk (revision.h): uses tool/file2lastrev.rb to support
git-svn.
* version.h: changed version string as
`ruby 1.9.1 (2008-12-22 patchlevel-5000 trunk 20912)
[i386-darwin9.6.0]'.
* tool/file2lastrev.rb: wrapper script that abstracts subversion
and git-svn.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@21005 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'tool')
-rw-r--r-- | tool/file2lastrev.rb | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/tool/file2lastrev.rb b/tool/file2lastrev.rb new file mode 100644 index 0000000000..73cc9997a9 --- /dev/null +++ b/tool/file2lastrev.rb @@ -0,0 +1,80 @@ +#!/usr/bin/env ruby + +require 'optparse' +require 'pathname' + +SRCDIR = Pathname(File.dirname($0)).parent.freeze +class VCSNotFoundError < RuntimeError; end + +def detect_vcs(path) + path = SRCDIR + return :svn, path.relative_path_from(SRCDIR) if File.directory?("#{path}/.svn") + return :git, path.relative_path_from(SRCDIR) if File.directory?("#{path}/.git") + raise VCSNotFoundError, "does not seem to be under a vcs" +end + +def get_revisions(path) + ENV['LANG'] = ENV['LC_ALL'] = ENV['LC_MESSAGES'] = 'C' + vcs, path = detect_vcs(path) + + info = case vcs + when :svn + `cd "#{SRCDIR}" && svn info "#{path}"` + when :git + `cd "#{SRCDIR}" && git svn info "#{path}"` + end + + if info =~ /^Revision: (\d+)$/ + last = $1 + else + raise "last revision not found" + end + if info =~ /^Last Changed Rev: (\d+)$/ + changed = $1 + else + raise "changed revision not found" + end + + return last, changed +end + +def raise_if_conflict + raise "you can specify only one of --changed, --revision.h and --doxygen" if $output +end + +parser = OptionParser.new {|opts| + opts.on("--changed", "changed rev") do + raise_if_conflict + $output = :changed + end + opts.on("--revision.h") do + raise_if_conflict + $output = :revision_h + end + opts.on("--doxygen") do + raise_if_conflict + $output = :doxygen + end + opts.on("-q", "--suppress_not_found") do + $suppress_not_found = true + end +} +parser.parse! + + +begin + last, changed = get_revisions(ARGV.shift) +rescue VCSNotFoundError + raise unless $suppress_not_found +end + +case $output +when :changed, nil + puts changed +when :revision_h + puts "#define RUBY_REVISION #{changed}" +when :doxygen + puts "r#{changed}/r#{last}" +else + raise "unknown output format `#{$output}'" +end |