2008-12-22 08:19:08 -05:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
|
2016-07-02 17:01:04 -04:00
|
|
|
# Gets the most recent revision of a file in a VCS-agnostic way.
|
|
|
|
# Used by Doxygen, Makefiles and merger.rb.
|
|
|
|
|
2008-12-22 08:19:08 -05:00
|
|
|
require 'optparse'
|
2013-11-09 08:35:39 -05:00
|
|
|
|
|
|
|
# this file run with BASERUBY, which may be older than 1.9, so no
|
|
|
|
# require_relative
|
2019-07-14 19:34:24 -04:00
|
|
|
require File.expand_path('../lib/vcs', __FILE__)
|
2010-07-17 05:30:54 -04:00
|
|
|
|
|
|
|
Program = $0
|
2010-03-13 03:48:49 -05:00
|
|
|
|
2009-06-30 03: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 08:19:08 -05:00
|
|
|
end
|
2009-06-30 03:53:22 -04:00
|
|
|
@suppress_not_found = false
|
2019-05-30 13:52:41 -04:00
|
|
|
@limit = 20
|
2008-12-22 08:19:08 -05:00
|
|
|
|
2015-05-23 05:36:22 -04:00
|
|
|
format = '%Y-%m-%dT%H:%M:%S%z'
|
2019-09-06 12:00:14 -04:00
|
|
|
vcs = nil
|
|
|
|
OptionParser.new {|opts|
|
|
|
|
opts.banner << " paths..."
|
|
|
|
vcs_options = VCS.define_options(opts)
|
|
|
|
new_vcs = proc do |path|
|
|
|
|
begin
|
2019-09-06 22:56:23 -04:00
|
|
|
vcs = VCS.detect(path, vcs_options, opts.new)
|
2019-09-06 12:00:14 -04:00
|
|
|
rescue VCS::NotFoundError => e
|
|
|
|
abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found
|
2019-09-06 22:47:21 -04:00
|
|
|
opts.remove
|
2019-09-06 12:00:14 -04:00
|
|
|
end
|
2019-09-06 22:56:23 -04:00
|
|
|
nil
|
2019-09-06 12:00:14 -04:00
|
|
|
end
|
|
|
|
opts.new
|
2010-03-13 03:48:49 -05:00
|
|
|
opts.on("--srcdir=PATH", "use PATH as source directory") do |path|
|
2019-09-06 12:00:14 -04:00
|
|
|
abort "#{File.basename(Program)}: srcdir is already set" if vcs
|
2019-09-06 22:56:23 -04:00
|
|
|
new_vcs[path]
|
2010-03-13 03:48:49 -05:00
|
|
|
end
|
2008-12-22 08:19:08 -05:00
|
|
|
opts.on("--changed", "changed rev") do
|
2009-06-30 03:53:22 -04:00
|
|
|
self.output = :changed
|
2008-12-22 08:19:08 -05:00
|
|
|
end
|
2010-03-13 03:48:49 -05:00
|
|
|
opts.on("--revision.h", "RUBY_REVISION macro") do
|
2009-06-30 03:53:22 -04:00
|
|
|
self.output = :revision_h
|
2008-12-22 08:19:08 -05:00
|
|
|
end
|
2010-03-13 03:48:49 -05:00
|
|
|
opts.on("--doxygen", "Doxygen format") do
|
2009-06-30 03:53:22 -04:00
|
|
|
self.output = :doxygen
|
2008-12-22 08:19:08 -05:00
|
|
|
end
|
2015-05-23 05:36:22 -04:00
|
|
|
opts.on("--modified[=FORMAT]", "modified time") do |fmt|
|
2014-08-22 02:36:46 -04:00
|
|
|
self.output = :modified
|
2015-05-23 05:36:22 -04:00
|
|
|
format = fmt if fmt
|
2014-08-22 02:36:46 -04:00
|
|
|
end
|
2019-05-30 13:52:41 -04:00
|
|
|
opts.on("--limit=NUM", "limit branch name length (#@limit)", Integer) do |n|
|
|
|
|
@limit = n
|
|
|
|
end
|
2008-12-22 08:19:08 -05:00
|
|
|
opts.on("-q", "--suppress_not_found") do
|
2009-06-30 03:53:22 -04:00
|
|
|
@suppress_not_found = true
|
2008-12-22 08:19:08 -05:00
|
|
|
end
|
2019-09-06 12:00:14 -04:00
|
|
|
opts.order! rescue abort "#{File.basename(Program)}: #{$!}\n#{opts}"
|
|
|
|
if vcs
|
|
|
|
vcs.set_options(vcs_options) # options after --srcdir
|
|
|
|
else
|
2019-09-06 22:56:23 -04:00
|
|
|
new_vcs["."]
|
2019-09-06 12:00:14 -04:00
|
|
|
end
|
2008-12-22 08:19:08 -05:00
|
|
|
}
|
2022-09-17 08:16:06 -04:00
|
|
|
unless vcs
|
|
|
|
# Output only release_date when .git is missing
|
2022-09-17 09:24:09 -04:00
|
|
|
puts VCS.release_date if @output == :revision_h
|
2022-09-17 08:16:06 -04:00
|
|
|
exit
|
|
|
|
end
|
2008-12-22 08:19:08 -05:00
|
|
|
|
2022-09-17 09:24:09 -04:00
|
|
|
output =
|
2015-05-23 05:36:05 -04:00
|
|
|
case @output
|
|
|
|
when :changed, nil
|
2015-12-24 01:35:39 -05:00
|
|
|
Proc.new {|last, changed|
|
2015-05-23 05:36:05 -04:00
|
|
|
changed
|
|
|
|
}
|
|
|
|
when :revision_h
|
2015-12-24 01:35:39 -05:00
|
|
|
Proc.new {|last, changed, modified, branch, title|
|
2022-09-17 08:16:06 -04:00
|
|
|
vcs.revision_header(last, modified, modified, branch, title, limit: @limit)
|
2015-05-23 05:36:05 -04:00
|
|
|
}
|
|
|
|
when :doxygen
|
2015-12-24 01:35:39 -05:00
|
|
|
Proc.new {|last, changed|
|
2015-05-23 05:36:05 -04:00
|
|
|
"r#{changed}/r#{last}"
|
|
|
|
}
|
|
|
|
when :modified
|
2015-12-24 01:35:39 -05:00
|
|
|
Proc.new {|last, changed, modified|
|
2015-05-23 05:36:22 -04:00
|
|
|
modified.strftime(format)
|
2015-05-23 05:36:05 -04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
raise "unknown output format `#{@output}'"
|
|
|
|
end
|
|
|
|
|
2019-09-06 12:00:14 -04:00
|
|
|
ok = true
|
|
|
|
(ARGV.empty? ? [nil] : ARGV).each do |arg|
|
|
|
|
begin
|
2022-09-17 09:24:09 -04:00
|
|
|
puts output[*vcs.get_revisions(arg)]
|
2019-09-06 12:00:14 -04:00
|
|
|
rescue => e
|
2022-09-17 09:24:09 -04:00
|
|
|
if @suppress_not_found and VCS::NotFoundError === e
|
|
|
|
puts VCS.release_date if @output == :revision_h
|
|
|
|
next
|
|
|
|
end
|
2019-09-06 12:00:14 -04:00
|
|
|
warn "#{File.basename(Program)}: #{e.message}"
|
|
|
|
ok = false
|
2010-04-15 07:43:09 -04:00
|
|
|
end
|
2008-12-22 08:19:08 -05:00
|
|
|
end
|
2019-09-06 12:00:14 -04:00
|
|
|
exit ok
|