summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-10-03 16:47:05 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-10-03 19:07:48 +0900
commitb7ae26e2eec9efb826e4a2d913a67341531c6342 (patch)
treea31f5df570735a64eda65cfbbf0044a11bac8cb5
parentad67adb5f942d463ab378fea21cc21cb15466cbc (diff)
vcs.rb: fix to export git-svn version
* Use the given branch name instead of implicit 'HEAD". * Format like as git-svn when `from` or `to` is SVN revision number.
-rw-r--r--tool/lib/vcs.rb58
1 files changed, 32 insertions, 26 deletions
diff --git a/tool/lib/vcs.rb b/tool/lib/vcs.rb
index 924dfe327a..370530d53f 100644
--- a/tool/lib/vcs.rb
+++ b/tool/lib/vcs.rb
@@ -590,13 +590,15 @@ class VCS
def branch_beginning(url)
cmd_read(%W[ #{COMMAND} log -n1 --format=format:%H
--author=matz --committer=matz --grep=has\ started
- -- version.h include/ruby/version.h])
+ #{url.to_str} -- version.h include/ruby/version.h])
end
def export_changelog(url, from, to, path)
+ svn = nil
from, to = [from, to].map do |rev|
rev or next
if Integer === rev
+ svn = true
rev = cmd_read({'LANG' => 'C', 'LC_ALL' => 'C'},
%W"#{COMMAND} log -n1 --format=format:%H" <<
"--grep=^ *git-svn-id: .*@#{rev} ")
@@ -607,17 +609,21 @@ class VCS
warn "no starting commit found", uplevel: 1
from = nil
end
- unless system(*%W"#{COMMAND} fetch origin refs/notes/commits:refs/notes/commits",
- chdir: @srcdir, exception: false)
+ unless svn or system(*%W"#{COMMAND} fetch origin refs/notes/commits:refs/notes/commits",
+ chdir: @srcdir, exception: false)
abort "Could not fetch notes/commits tree"
end
- to ||= 'HEAD'
+ to ||= url.to_str
if from
arg = ["#{from}^..#{to}"]
else
arg = ["--since=25 Dec 00:00:00", to]
end
- format_changelog(path, arg)
+ if svn
+ format_changelog_as_svn(path, arg)
+ else
+ format_changelog(path, arg)
+ end
end
def format_changelog(path, arg)
@@ -632,6 +638,27 @@ class VCS
system(env, *cmd, chdir: @srcdir, out: path)
end
+ 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)
+ open(path, 'w') do |w|
+ sep = "-"*72 + "\n"
+ w.print sep
+ cmd_pipe(cmd) do |r|
+ while s = r.gets("\0")
+ s.chomp!("\0")
+ author, time, s = s.split("\n", 3)
+ s.sub!(/\n\ngit-svn-id: .*@(\d+) .*\n\Z/, '')
+ rev = $1
+ time = Time.at(time.to_i).getlocal("+09:00").strftime("%F %T %z (%a, %d %b %Y)")
+ lines = s.count("\n") + 1
+ lines = "#{lines} line#{lines == 1 ? '' : 's'}"
+ w.print "r#{rev} | #{author} | #{time} | #{lines}\n\n", s, "\n", sep
+ end
+ end
+ end
+ end
+
def upstream
(branch = cmd_read(%W"#{COMMAND} symbolic-ref --short HEAD")).chomp!
(upstream = cmd_read(%W"#{COMMAND} branch --list --format=%(upstream) #{branch}")).chomp!
@@ -668,27 +695,6 @@ class VCS
SVN.revision_name(rev)
end
- def format_changelog(path, arg)
- cmd = %W"#{COMMAND} log --topo-order --no-notes -z --format=%an%n%at%n%B"
- cmd.concat(arg)
- open(path, 'w') do |w|
- sep = "-"*72
- w.puts sep
- cmd_pipe(cmd) do |r|
- while s = r.gets("\0")
- s.chomp!("\0")
- author, time, s = s.split("\n", 3)
- s.sub!(/\n\ngit-svn-id: .*@(\d+) .*\n\Z/, '')
- rev = $1
- time = Time.at(time.to_i).getlocal("+09:00").strftime("%F %T %z (%a, %d %b %Y)")
- lines = s.count("\n")
- lines = "#{lines} line#{lines == 1 ? '' : 's'}"
- w.puts "r#{rev} | #{author} | #{time} | #{lines}\n\n", s, sep
- end
- end
- end
- end
-
def last_changed_revision
rev = cmd_read(%W"#{COMMAND} svn info"+[STDERR=>[:child, :out]])[/^Last Changed Rev: (\d+)/, 1]
com = cmd_read(%W"#{COMMAND} svn find-rev r#{rev}").chomp