summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-02-08 23:45:51 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-02-08 23:45:51 +0900
commitced09d521c4246e4a973da771ed9b2b60a8fcad3 (patch)
treead0ffe2618412fc7bec86d8b5d7f40a318ba4a37
parent4186cd6435a58a9233ffe52f5d5ee6374d098883 (diff)
vcs.rb: improved export_changelog
* arguments are optional * `path` may be passed as a keyword argument * `nil` or `"-"` path means stdout
-rw-r--r--tool/lib/vcs.rb20
1 files changed, 13 insertions, 7 deletions
diff --git a/tool/lib/vcs.rb b/tool/lib/vcs.rb
index c5e75b987e..1b1b3c5e88 100644
--- a/tool/lib/vcs.rb
+++ b/tool/lib/vcs.rb
@@ -341,7 +341,7 @@ class VCS
rev.to_i if rev
end
- def export_changelog(url, from, to, path)
+ def export_changelog(url = '.', from = nil, to = nil, _path = nil, path: _path)
range = [to || 'HEAD', (from ? from+1 : branch_beginning(url))].compact.join(':')
IO.popen({'TZ' => 'JST-9', 'LANG' => 'C', 'LC_ALL' => 'C'},
%W"#{COMMAND} log -r#{range} #{url}") do |r|
@@ -525,7 +525,7 @@ class VCS
#{url.to_str} -- version.h include/ruby/version.h])
end
- def export_changelog(url, from, to, path)
+ def export_changelog(url = '@', from = nil, to = nil, _path = nil, path: _path)
svn = nil
from, to = [from, to].map do |rev|
rev or next
@@ -554,10 +554,16 @@ class VCS
else
arg = ["--since=25 Dec 00:00:00", to]
end
- if svn
- format_changelog_as_svn(path, arg)
+ writer =
+ if svn
+ format_changelog_as_svn(path, arg)
+ else
+ format_changelog(path, arg)
+ end
+ if !path or path == '-'
+ writer[$stdout]
else
- format_changelog(path, arg)
+ File.open(path, 'wb', &writer)
end
end
@@ -570,7 +576,7 @@ class VCS
end
cmd << date
cmd.concat(arg)
- File.open(path, 'w') do |w|
+ proc do |w|
w.print "-*- coding: utf-8 -*-\n\n"
cmd_pipe(env, cmd, chdir: @srcdir) do |r|
while s = r.gets("\ncommit ")
@@ -616,7 +622,7 @@ class VCS
def format_changelog_as_svn(path, arg)
cmd = %W"#{COMMAND} log --topo-order --no-notes -z --format=%an%n%at%n%B"
cmd.concat(arg)
- File.open(path, 'w') do |w|
+ proc do |w|
sep = "-"*72 + "\n"
w.print sep
cmd_pipe(cmd) do |r|