2008-12-22 16:19:08 +03:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2016-07-03 00:01:04 +03:00
|
|
|
# Gets the most recent revision of a file in a VCS-agnostic way.
|
|
|
|
# Used by Doxygen, Makefiles and merger.rb.
|
|
|
|
|
2008-12-22 16:19:08 +03:00
|
|
|
require 'optparse'
|
2013-11-09 17:35:39 +04:00
|
|
|
|
|
|
|
# this file run with BASERUBY, which may be older than 1.9, so no
|
|
|
|
# require_relative
|
2013-11-09 10:20:57 +04:00
|
|
|
require File.expand_path('../vcs', __FILE__)
|
2010-07-17 13:30:54 +04:00
|
|
|
|
|
|
|
Program = $0
|
2010-03-13 11:48:49 +03:00
|
|
|
|
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
|
|
|
|
2015-05-23 12:36:22 +03:00
|
|
|
format = '%Y-%m-%dT%H:%M:%S%z'
|
2010-03-13 11:48:49 +03:00
|
|
|
srcdir = nil
|
2008-12-22 16:19:08 +03:00
|
|
|
parser = OptionParser.new {|opts|
|
2010-03-13 11:48:49 +03:00
|
|
|
opts.on("--srcdir=PATH", "use PATH as source directory") do |path|
|
|
|
|
srcdir = path
|
|
|
|
end
|
2008-12-22 16:19:08 +03:00
|
|
|
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
|
2010-03-13 11:48:49 +03:00
|
|
|
opts.on("--revision.h", "RUBY_REVISION macro") do
|
2009-06-30 11:53:22 +04:00
|
|
|
self.output = :revision_h
|
2008-12-22 16:19:08 +03:00
|
|
|
end
|
2010-03-13 11:48:49 +03:00
|
|
|
opts.on("--doxygen", "Doxygen format") do
|
2009-06-30 11:53:22 +04:00
|
|
|
self.output = :doxygen
|
2008-12-22 16:19:08 +03:00
|
|
|
end
|
2015-05-23 12:36:22 +03:00
|
|
|
opts.on("--modified[=FORMAT]", "modified time") do |fmt|
|
2014-08-22 10:36:46 +04:00
|
|
|
self.output = :modified
|
2015-05-23 12:36:22 +03:00
|
|
|
format = fmt if fmt
|
2014-08-22 10:36:46 +04:00
|
|
|
end
|
2008-12-22 16:19:08 +03:00
|
|
|
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
|
|
|
|
}
|
2010-07-17 13:30:54 +04:00
|
|
|
parser.parse! rescue abort "#{File.basename(Program)}: #{$!}\n#{parser}"
|
2008-12-22 16:19:08 +03:00
|
|
|
|
2015-05-23 12:36:05 +03:00
|
|
|
@output =
|
|
|
|
case @output
|
|
|
|
when :changed, nil
|
2015-12-24 09:35:39 +03:00
|
|
|
Proc.new {|last, changed|
|
2015-05-23 12:36:05 +03:00
|
|
|
changed
|
|
|
|
}
|
|
|
|
when :revision_h
|
2015-12-24 09:35:39 +03:00
|
|
|
Proc.new {|last, changed, modified, branch, title|
|
2015-05-23 12:36:05 +03:00
|
|
|
[
|
|
|
|
"#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
|
2015-12-24 09:35:39 +03:00
|
|
|
Proc.new {|last, changed|
|
2015-05-23 12:36:05 +03:00
|
|
|
"r#{changed}/r#{last}"
|
|
|
|
}
|
|
|
|
when :modified
|
2015-12-24 09:35:39 +03:00
|
|
|
Proc.new {|last, changed, modified|
|
2015-05-23 12:36:22 +03:00
|
|
|
modified.strftime(format)
|
2015-05-23 12:36:05 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
raise "unknown output format `#{@output}'"
|
|
|
|
end
|
|
|
|
|
2012-01-02 17:14:24 +04:00
|
|
|
srcdir ||= File.dirname(File.dirname(Program))
|
2008-12-22 16:19:08 +03:00
|
|
|
begin
|
2010-03-13 11:48:49 +03:00
|
|
|
vcs = VCS.detect(srcdir)
|
|
|
|
rescue VCS::NotFoundError => e
|
2010-07-17 13:30:54 +04:00
|
|
|
abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found
|
2010-03-13 11:48:49 +03:00
|
|
|
else
|
2015-05-23 12:36:05 +03:00
|
|
|
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
|
2010-04-15 15:43:09 +04:00
|
|
|
end
|
2015-05-23 12:36:05 +03:00
|
|
|
exit ok
|
2008-12-22 16:19:08 +03:00
|
|
|
end
|