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
|
2019-07-15 02:34:24 +03:00
|
|
|
require File.expand_path('../lib/vcs', __FILE__)
|
2022-11-01 06:29:46 +03:00
|
|
|
require File.expand_path('../lib/output', __FILE__)
|
2010-07-17 13:30:54 +04:00
|
|
|
|
|
|
|
Program = $0
|
2010-03-13 11:48:49 +03:00
|
|
|
|
2022-11-01 05:43:22 +03:00
|
|
|
@format = nil
|
|
|
|
def self.format=(format)
|
|
|
|
if @format and @format != format
|
2009-06-30 11:53:22 +04:00
|
|
|
raise "you can specify only one of --changed, --revision.h and --doxygen"
|
|
|
|
end
|
2022-11-01 05:43:22 +03:00
|
|
|
@format = format
|
2008-12-22 16:19:08 +03:00
|
|
|
end
|
2009-06-30 11:53:22 +04:00
|
|
|
@suppress_not_found = false
|
2019-05-30 20:52:41 +03:00
|
|
|
@limit = 20
|
2022-11-01 06:29:46 +03:00
|
|
|
@output = Output.new
|
2008-12-22 16:19:08 +03:00
|
|
|
|
2022-11-01 05:43:22 +03:00
|
|
|
time_format = '%Y-%m-%dT%H:%M:%S%z'
|
2019-09-06 19:00:14 +03:00
|
|
|
vcs = nil
|
2022-12-13 10:34:30 +03:00
|
|
|
create_only = false
|
2019-09-06 19:00:14 +03:00
|
|
|
OptionParser.new {|opts|
|
|
|
|
opts.banner << " paths..."
|
|
|
|
vcs_options = VCS.define_options(opts)
|
2022-11-02 05:37:54 +03:00
|
|
|
opts.new {@output.def_options(opts)}
|
2022-10-12 16:03:35 +03:00
|
|
|
srcdir = nil
|
2019-09-06 19:00:14 +03:00
|
|
|
opts.new
|
2010-03-13 11:48:49 +03:00
|
|
|
opts.on("--srcdir=PATH", "use PATH as source directory") do |path|
|
2022-10-12 16:03:35 +03:00
|
|
|
abort "#{File.basename(Program)}: srcdir is already set" if srcdir
|
|
|
|
srcdir = path
|
2022-11-02 05:37:54 +03:00
|
|
|
@output.vpath.add(srcdir)
|
2010-03-13 11:48:49 +03:00
|
|
|
end
|
2008-12-22 16:19:08 +03:00
|
|
|
opts.on("--changed", "changed rev") do
|
2022-11-01 05:43:22 +03:00
|
|
|
self.format = :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
|
2022-11-01 05:43:22 +03:00
|
|
|
self.format = :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
|
2022-11-01 05:43:22 +03:00
|
|
|
self.format = :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|
|
2022-11-01 05:43:22 +03:00
|
|
|
self.format = :modified
|
|
|
|
time_format = fmt if fmt
|
2014-08-22 10:36:46 +04:00
|
|
|
end
|
2019-05-30 20:52:41 +03:00
|
|
|
opts.on("--limit=NUM", "limit branch name length (#@limit)", Integer) do |n|
|
|
|
|
@limit = n
|
|
|
|
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
|
2019-09-06 19:00:14 +03:00
|
|
|
opts.order! rescue abort "#{File.basename(Program)}: #{$!}\n#{opts}"
|
2022-10-12 16:03:35 +03:00
|
|
|
begin
|
|
|
|
vcs = VCS.detect(srcdir || ".", vcs_options, opts.new)
|
|
|
|
rescue VCS::NotFoundError => e
|
|
|
|
abort "#{File.basename(Program)}: #{e.message}" unless @suppress_not_found
|
|
|
|
opts.remove
|
2022-09-29 14:03:51 +03:00
|
|
|
(vcs = VCS::Null.new(nil)).set_options(vcs_options)
|
2022-12-13 10:34:30 +03:00
|
|
|
if @format == :revision_h
|
|
|
|
create_only = true # don't overwrite existing revision.h when .git doesn't exist
|
|
|
|
end
|
2019-09-06 19:00:14 +03:00
|
|
|
end
|
2008-12-22 16:19:08 +03:00
|
|
|
}
|
|
|
|
|
2022-11-01 05:43:22 +03:00
|
|
|
formatter =
|
|
|
|
case @format
|
2015-05-23 12:36:05 +03:00
|
|
|
when :changed, nil
|
2015-12-24 09:35:39 +03:00
|
|
|
Proc.new {|last, changed|
|
2022-11-02 07:31:42 +03:00
|
|
|
changed || ""
|
2015-05-23 12:36:05 +03:00
|
|
|
}
|
|
|
|
when :revision_h
|
2015-12-24 09:35:39 +03:00
|
|
|
Proc.new {|last, changed, modified, branch, title|
|
2022-11-01 06:29:46 +03:00
|
|
|
vcs.revision_header(last, modified, modified, branch, title, limit: @limit).join("\n")
|
2015-05-23 12:36:05 +03:00
|
|
|
}
|
|
|
|
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|
|
2022-11-01 05:43:22 +03:00
|
|
|
modified.strftime(time_format)
|
2015-05-23 12:36:05 +03:00
|
|
|
}
|
|
|
|
else
|
2022-11-01 05:43:22 +03:00
|
|
|
raise "unknown output format `#{@format}'"
|
2015-05-23 12:36:05 +03:00
|
|
|
end
|
|
|
|
|
2019-09-06 19:00:14 +03:00
|
|
|
ok = true
|
|
|
|
(ARGV.empty? ? [nil] : ARGV).each do |arg|
|
|
|
|
begin
|
2022-11-02 07:31:42 +03:00
|
|
|
data = formatter[*vcs.get_revisions(arg)]
|
|
|
|
data.sub!(/(?<!\A|\n)\z/, "\n")
|
2022-12-13 10:34:30 +03:00
|
|
|
@output.write(data, overwrite: true, create_only: create_only)
|
2019-09-06 19:00:14 +03:00
|
|
|
rescue => e
|
|
|
|
warn "#{File.basename(Program)}: #{e.message}"
|
|
|
|
ok = false
|
2010-04-15 15:43:09 +04:00
|
|
|
end
|
2008-12-22 16:19:08 +03:00
|
|
|
end
|
2019-09-06 19:00:14 +03:00
|
|
|
exit ok
|