SVN repository is already retired

This commit is contained in:
Hiroshi SHIBATA 2025-04-18 19:51:54 +09:00
parent 0232c31555
commit 8bf14b048f
Notes: git 2025-04-18 21:33:27 +00:00

View File

@ -271,155 +271,6 @@ class VCS
code
end
class SVN < self
register(".svn")
COMMAND = ENV['SVN'] || 'svn'
def self.revision_name(rev)
"r#{rev}"
end
def _get_revisions(path, srcdir = nil)
if srcdir and self.class.local_path?(path)
path = File.join(srcdir, path)
end
if srcdir
info_xml = IO.pread(%W"#{COMMAND} info --xml #{srcdir}")
info_xml = nil unless info_xml[/<url>(.*)<\/url>/, 1] == path.to_s
end
info_xml ||= IO.pread(%W"#{COMMAND} info --xml #{path}")
_, last, _, changed, _ = info_xml.split(/revision="(\d+)"/)
modified = info_xml[/<date>([^<>]*)/, 1]
branch = info_xml[%r'<relative-url>\^/(?:branches/|tags/)?([^<>]+)', 1]
[Integer(last), Integer(changed), modified, branch]
end
def self.search_root(path)
return unless local_path?(path)
parent = File.realpath(path)
begin
parent = File.dirname(wkdir = parent)
return wkdir if File.directory?(wkdir + "/.svn")
end until parent == wkdir
end
def get_info
@info ||= IO.pread(%W"#{COMMAND} info --xml #{@srcdir}")
end
def url
@url ||= begin
url = get_info[/<root>(.*)<\/root>/, 1]
@url = URI.parse(url+"/") if url
end
end
def wcroot
@wcroot ||= begin
info = get_info
@wcroot = info[/<wcroot-abspath>(.*)<\/wcroot-abspath>/, 1]
@wcroot ||= self.class.search_root(@srcdir)
end
end
def branch(name)
return trunk if name == "trunk"
url + "branches/#{name}"
end
def tag(name)
url + "tags/#{name}"
end
def trunk
url + "trunk"
end
alias master trunk
def branch_list(pat)
IO.popen(%W"#{COMMAND} ls #{branch('')}") do |f|
f.each do |line|
line.chomp!
line.chomp!('/')
yield(line) if File.fnmatch?(pat, line)
end
end
end
def grep(pat, tag, *files, &block)
cmd = %W"#{COMMAND} cat"
files.map! {|n| File.join(tag, n)} if tag
set = block.binding.eval("proc {|match| $~ = match}")
IO.popen([cmd, *files]) do |f|
f.grep(pat) do |s|
set[$~]
yield s
end
end
end
def export(revision, url, dir, keep_temp = false)
if @srcdir and (rootdir = wcroot)
srcdir = File.realpath(@srcdir)
rootdir << "/"
if srcdir.start_with?(rootdir)
subdir = srcdir[rootdir.size..-1]
subdir = nil if subdir.empty?
FileUtils.mkdir_p(svndir = dir+"/.svn")
FileUtils.ln_s(Dir.glob(rootdir+"/.svn/*"), svndir)
system(COMMAND, "-q", "revert", "-R", subdir || ".", :chdir => dir) or return false
FileUtils.rm_rf(svndir) unless keep_temp
if subdir
tmpdir = Dir.mktmpdir("tmp-co.", "#{dir}/#{subdir}")
File.rename(tmpdir, tmpdir = "#{dir}/#{File.basename(tmpdir)}")
FileUtils.mv(Dir.glob("#{dir}/#{subdir}/{.[^.]*,..?*,*}"), tmpdir)
begin
Dir.rmdir("#{dir}/#{subdir}")
end until (subdir = File.dirname(subdir)) == '.'
FileUtils.mv(Dir.glob("#{tmpdir}/#{subdir}/{.[^.]*,..?*,*}"), dir)
Dir.rmdir(tmpdir)
end
return self
end
end
IO.popen(%W"#{COMMAND} export -r #{revision} #{url} #{dir}") do |pipe|
pipe.each {|line| /^A/ =~ line or yield line}
end
self if $?.success?
end
def after_export(dir)
super
FileUtils.rm_rf(dir+"/.svn")
end
def branch_beginning(url)
# `--limit` of svn-log is useless in this case, because it is
# applied before `--search`.
rev = IO.pread(%W[ #{COMMAND} log --xml
--search=matz --search-and=has\ started
-- #{url}/version.h])[/<logentry\s+revision="(\d+)"/m, 1]
rev.to_i if rev
end
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|
IO.copy_stream(r, path)
end
end
def commit
args = %W"#{COMMAND} commit"
if dryrun?
VCS.dump(args, "commit: ")
return true
end
system(*args)
end
end
class GIT < self
register(".git") do |path, dir|
SAFE_DIRECTORIES ||=
@ -533,15 +384,6 @@ class VCS
rev[0, 10]
end
def revision_handler(rev)
case rev
when Integer
SVN
else
super
end
end
def without_gitconfig
envs = (%w'HOME XDG_CONFIG_HOME' + ENV.keys.grep(/\AGIT_/)).each_with_object({}) do |v, h|
h[v] = ENV.delete(v)
@ -616,7 +458,7 @@ class VCS
def export(revision, url, dir, keep_temp = false)
system(COMMAND, "clone", "-c", "advice.detachedHead=false", "-s", (@srcdir || '.').to_s, "-b", url, dir) or return
(Integer === revision ? GITSVN : GIT).new(File.expand_path(dir))
GIT.new(File.expand_path(dir))
end
def branch_beginning(url)
@ -626,22 +468,15 @@ class VCS
end
def export_changelog(url = '@', from = nil, to = nil, _path = nil, path: _path, base_url: nil)
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} ")
end
rev unless rev.empty?
end
unless (from && /./.match(from)) or ((from = branch_beginning(url)) && /./.match(from))
warn "no starting commit found", uplevel: 1
from = nil
end
if svn or system(*%W"#{COMMAND} fetch origin refs/notes/commits:refs/notes/commits",
if system(*%W"#{COMMAND} fetch origin refs/notes/commits:refs/notes/commits",
chdir: @srcdir, exception: false)
system(*%W"#{COMMAND} fetch origin refs/notes/log-fix:refs/notes/log-fix",
chdir: @srcdir, exception: false)
@ -655,21 +490,17 @@ class VCS
arg = ["--since=25 Dec 00:00:00", to]
end
writer =
if svn
format_changelog_as_svn(path, arg)
else
if base_url == true
remote, = upstream
if remote &&= cmd_read(env, %W[#{COMMAND} remote get-url --no-push #{remote}])
remote.chomp!
# hack to redirect git.r-l.o to github
remote.sub!(/\Agit@git\.ruby-lang\.org:/, 'git@github.com:ruby/')
remote.sub!(/\Agit@(.*?):(.*?)(?:\.git)?\z/, 'https://\1/\2/commit/')
end
base_url = remote
if base_url == true
remote, = upstream
if remote &&= cmd_read(env, %W[#{COMMAND} remote get-url --no-push #{remote}])
remote.chomp!
# hack to redirect git.r-l.o to github
remote.sub!(/\Agit@git\.ruby-lang\.org:/, 'git@github.com:ruby/')
remote.sub!(/\Agit@(.*?):(.*?)(?:\.git)?\z/, 'https://\1/\2/commit/')
end
format_changelog(path, arg, base_url)
base_url = remote
end
format_changelog(path, arg, base_url)
if !path or path == '-'
writer[$stdout]
else
@ -774,27 +605,6 @@ class VCS
end
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)
proc 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!
@ -826,46 +636,6 @@ class VCS
end
end
class GITSVN < GIT
def self.revision_name(rev)
SVN.revision_name(rev)
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
return rev, com
end
def commit(opts = {})
rev, com = last_changed_revision
head = cmd_read(%W"#{COMMAND} symbolic-ref --short HEAD").chomp
commits = cmd_read([COMMAND, "log", "--reverse", "--format=%H %ae %ce", "#{com}..@"], "rb").split("\n")
commits.each_with_index do |l, i|
r, a, c = l.split(' ')
dcommit = [COMMAND, "svn", "dcommit"]
dcommit.insert(-2, "-n") if dryrun?
dcommit << "--add-author-from" unless a == c
dcommit << r
system(*dcommit) or return false
system(COMMAND, "checkout", head) or return false
system(COMMAND, "rebase") or return false
end
if rev
old = [cmd_read(%W"#{COMMAND} log -1 --format=%H").chomp]
old << cmd_read(%W"#{COMMAND} svn reset -r#{rev}")[/^r#{rev} = (\h+)/, 1]
3.times do
sleep 2
system(*%W"#{COMMAND} pull --no-edit --rebase")
break unless old.include?(cmd_read(%W"#{COMMAND} log -1 --format=%H").chomp)
end
end
true
end
end
class Null < self
def get_revisions(path, srcdir = nil)
@modified ||= Time.now - 10