1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/tool/file2lastrev.rb
normal f8d0bdedf1 tool: add descriptions and fix typos
* tool/asm_parse.rb: add description
* tool/change_maker.rb: ditto
* tool/downloader.rb: ditto
* tool/eval.rb: ditto
* tool/expand-config.rb: ditto
* tool/extlibs.rb: ditto
* tool/fake.rb: ditto
* tool/file2lastrev.rb: ditto
* tool/gem-unpack.rb: ditto
* tool/gen_dummy_probes.rb: ditto
* tool/gen_ruby_tapset.rb: ditto
* tool/generic_erb.rb: ditto
* tool/id2token.rb: ditto
* tool/ifchange: ditto
* tool/insns2vm.rb: ditto
* tool/instruction.rb: ditto
* tool/jisx0208.rb: ditto
* tool/merger.rb: ditto
* tool/mkrunnable.rb: ditto
* tool/node_name.rb: ditto
* tool/parse.rb: ditto
* tool/rbinstall.rb: ditto
* tool/rbuninstall.rb: ditto
* tool/rmdirs: ditto
* tool/runruby.rb: ditto
* tool/strip-rdoc.rb: ditto
* tool/vcs.rb: ditto
* tool/vtlh.rb: ditto
* tool/ytab.sed: ditto
* tool/enc-unicode.rb: fix typo
* tool/mk_call_iseq_optimized.rb: ditto
* tool/update-deps: ditto
  [ruby-core:76215] [Bug #12539]
  by Noah Gibbs <the.codefolio.guy@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-07-02 21:01:04 +00:00

97 lines
2.3 KiB
Ruby
Executable file

#!/usr/bin/env ruby
# Gets the most recent revision of a file in a VCS-agnostic way.
# Used by Doxygen, Makefiles and merger.rb.
require 'optparse'
# this file run with BASERUBY, which may be older than 1.9, so no
# require_relative
require File.expand_path('../vcs', __FILE__)
Program = $0
@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
end
@suppress_not_found = false
format = '%Y-%m-%dT%H:%M:%S%z'
srcdir = nil
parser = OptionParser.new {|opts|
opts.on("--srcdir=PATH", "use PATH as source directory") do |path|
srcdir = path
end
opts.on("--changed", "changed rev") do
self.output = :changed
end
opts.on("--revision.h", "RUBY_REVISION macro") do
self.output = :revision_h
end
opts.on("--doxygen", "Doxygen format") do
self.output = :doxygen
end
opts.on("--modified[=FORMAT]", "modified time") do |fmt|
self.output = :modified
format = fmt if fmt
end
opts.on("-q", "--suppress_not_found") do
@suppress_not_found = true
end
}
parser.parse! rescue abort "#{File.basename(Program)}: #{$!}\n#{parser}"
@output =
case @output
when :changed, nil
Proc.new {|last, changed|
changed
}
when :revision_h
Proc.new {|last, changed, modified, branch, title|
[
"#define RUBY_REVISION #{changed || 0}",
if branch
e = '..'
limit = 16
name = branch.sub(/\A(.{#{limit-e.size}}).{#{e.size+1},}/o) {$1+e}
"#define RUBY_BRANCH_NAME #{name.dump}"
end,
if title
"#define RUBY_LAST_COMMIT_TITLE #{title.dump}"
end,
].compact
}
when :doxygen
Proc.new {|last, changed|
"r#{changed}/r#{last}"
}
when :modified
Proc.new {|last, changed, modified|
modified.strftime(format)
}
else
raise "unknown output format `#{@output}'"
end
srcdir ||= File.dirname(File.dirname(Program))
begin
vcs = VCS.detect(srcdir)
rescue VCS::NotFoundError => e
abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found
else
ok = true
(ARGV.empty? ? [nil] : ARGV).each do |arg|
begin
puts @output[*vcs.get_revisions(arg)]
rescue => e
warn "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found
ok = false
end
end
exit ok
end