mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
vcs.rb: fix srcdir in VCS::GIT
* tool/vcs.rb (VCS::GIT.cmd_args): add chdir option to arguments for IO.popen if srcdir is a local path. unless -srcdir command line option is given, srcdir is the default URL. [ruby-core:78036] [Bug #12908] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56668 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
121ce4ac90
commit
5443a9fdb5
1 changed files with 36 additions and 15 deletions
51
tool/vcs.rb
51
tool/vcs.rb
|
@ -120,7 +120,6 @@ class VCS
|
||||||
|
|
||||||
def initialize(path)
|
def initialize(path)
|
||||||
@srcdir = path
|
@srcdir = path
|
||||||
@abs_srcdir = File.realpath(path)
|
|
||||||
super()
|
super()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -322,29 +321,53 @@ class VCS
|
||||||
class GIT < self
|
class GIT < self
|
||||||
register(".git") {|path, dir| File.exist?(File.join(path, dir))}
|
register(".git") {|path, dir| File.exist?(File.join(path, dir))}
|
||||||
|
|
||||||
|
def self.cmd_args(cmds, srcdir = nil)
|
||||||
|
if srcdir and local_path?(srcdir)
|
||||||
|
(opts = cmds.last).kind_of?(Hash) or cmds << (opts = {})
|
||||||
|
opts[:chdir] ||= srcdir
|
||||||
|
end
|
||||||
|
cmds
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.cmd_pipe_at(srcdir, cmds, &block)
|
||||||
|
IO.popen(*cmd_args(cmds, srcdir), &block)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.cmd_read_at(srcdir, cmds)
|
||||||
|
IO.pread(*cmd_args(cmds, srcdir))
|
||||||
|
end
|
||||||
|
|
||||||
def self.get_revisions(path, srcdir = nil)
|
def self.get_revisions(path, srcdir = nil)
|
||||||
gitcmd = %W[git]
|
gitcmd = %W[git]
|
||||||
logcmd = gitcmd + %W[log -n1 --date=iso]
|
logcmd = gitcmd + %W[log -n1 --date=iso]
|
||||||
logcmd << "--grep=^ *git-svn-id: .*@[0-9][0-9]*"
|
logcmd << "--grep=^ *git-svn-id: .*@[0-9][0-9]*"
|
||||||
idpat = /git-svn-id: .*?@(\d+) \S+\Z/
|
idpat = /git-svn-id: .*?@(\d+) \S+\Z/
|
||||||
log = IO.pread(logcmd, :chdir => srcdir)
|
log = IO.pread(logcmd)
|
||||||
commit = log[/\Acommit (\w+)/, 1]
|
commit = log[/\Acommit (\w+)/, 1]
|
||||||
last = log[idpat, 1]
|
last = log[idpat, 1]
|
||||||
if path
|
if path
|
||||||
cmd = logcmd
|
cmd = logcmd
|
||||||
cmd += [path] unless path == '.'
|
cmd += [path] unless path == '.'
|
||||||
log = IO.pread(cmd, :chdir => srcdir)
|
log = IO.pread(cmd)
|
||||||
changed = log[idpat, 1]
|
changed = log[idpat, 1]
|
||||||
else
|
else
|
||||||
changed = last
|
changed = last
|
||||||
end
|
end
|
||||||
modified = log[/^Date:\s+(.*)/, 1]
|
modified = log[/^Date:\s+(.*)/, 1]
|
||||||
branch = IO.pread(gitcmd + %W[symbolic-ref HEAD], :chdir => srcdir)[%r'\A(?:refs/heads/)?(.+)', 1]
|
branch = IO.pread(gitcmd + %W[symbolic-ref HEAD])[%r'\A(?:refs/heads/)?(.+)', 1]
|
||||||
title = IO.pread(gitcmd + %W[log --format=%s -n1 #{commit}..HEAD], :chdir => srcdir)
|
title = IO.pread(gitcmd + %W[log --format=%s -n1 #{commit}..HEAD])
|
||||||
title = nil if title.empty?
|
title = nil if title.empty?
|
||||||
[last, changed, modified, branch, title]
|
[last, changed, modified, branch, title]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def cmd_pipe(*cmds, &block)
|
||||||
|
self.class.cmd_pipe_at(@srcdir, cmds, &block)
|
||||||
|
end
|
||||||
|
|
||||||
|
def cmd_read(*cmds)
|
||||||
|
self.class.cmd_read_at(@srcdir, cmds)
|
||||||
|
end
|
||||||
|
|
||||||
Branch = Struct.new(:to_str)
|
Branch = Struct.new(:to_str)
|
||||||
|
|
||||||
def branch(name)
|
def branch(name)
|
||||||
|
@ -359,12 +382,12 @@ class VCS
|
||||||
|
|
||||||
def stable
|
def stable
|
||||||
cmd = %W"git for-each-ref --format=\%(refname:short) refs/heads/ruby_[0-9]*"
|
cmd = %W"git for-each-ref --format=\%(refname:short) refs/heads/ruby_[0-9]*"
|
||||||
branch(IO.pread(cmd, :chdir => srcdir)[/.*^(ruby_\d+_\d+)$/m, 1])
|
branch(cmd_read(cmd)[/.*^(ruby_\d+_\d+)$/m, 1])
|
||||||
end
|
end
|
||||||
|
|
||||||
def branch_list(pat)
|
def branch_list(pat)
|
||||||
cmd = %W"git for-each-ref --format=\%(refname:short) refs/heads/#{pat}"
|
cmd = %W"git for-each-ref --format=\%(refname:short) refs/heads/#{pat}"
|
||||||
IO.popen(cmd, :chdir => srcdir) {|f|
|
cmd_pipe(cmd) {|f|
|
||||||
f.each {|line|
|
f.each {|line|
|
||||||
line.chomp!
|
line.chomp!
|
||||||
yield line
|
yield line
|
||||||
|
@ -375,7 +398,7 @@ class VCS
|
||||||
def grep(pat, tag, *files, &block)
|
def grep(pat, tag, *files, &block)
|
||||||
cmd = %W[git grep -h --perl-regexp #{tag} --]
|
cmd = %W[git grep -h --perl-regexp #{tag} --]
|
||||||
set = block.binding.eval("proc {|match| $~ = match}")
|
set = block.binding.eval("proc {|match| $~ = match}")
|
||||||
IO.popen([cmd, *files], :chdir => srcdir) do |f|
|
cmd_pipe(cmd+files) do |f|
|
||||||
f.grep(pat) do |s|
|
f.grep(pat) do |s|
|
||||||
set[$~]
|
set[$~]
|
||||||
yield s
|
yield s
|
||||||
|
@ -384,7 +407,7 @@ class VCS
|
||||||
end
|
end
|
||||||
|
|
||||||
def export(revision, url, dir, keep_temp = false)
|
def export(revision, url, dir, keep_temp = false)
|
||||||
ret = system("git", "clone", "-s", (@srcdir || '.'), "-b", url, dir)
|
ret = system("git", "clone", "-s", (@srcdir || '.').to_s, "-b", url, dir)
|
||||||
FileUtils.rm_rf("#{dir}/.git") if ret and !keep_temp
|
FileUtils.rm_rf("#{dir}/.git") if ret and !keep_temp
|
||||||
ret
|
ret
|
||||||
end
|
end
|
||||||
|
@ -396,15 +419,13 @@ class VCS
|
||||||
def export_changelog(from, to, path)
|
def export_changelog(from, to, path)
|
||||||
range = [from, to].map do |rev|
|
range = [from, to].map do |rev|
|
||||||
rev or next
|
rev or next
|
||||||
rev = IO.pread({'LANG' => 'C', 'LC_ALL' => 'C'},
|
rev = cmd_read({'LANG' => 'C', 'LC_ALL' => 'C'},
|
||||||
%W"git log -n1 --format=format:%H" <<
|
%W"git log -n1 --format=format:%H" <<
|
||||||
"--grep=^ *git-svn-id: .*@#{rev} ",
|
"--grep=^ *git-svn-id: .*@#{rev} ")
|
||||||
:chdir => @abs_srcdir)
|
|
||||||
rev unless rev.empty?
|
rev unless rev.empty?
|
||||||
end.join('..')
|
end.join('..')
|
||||||
IO.popen({'TZ' => 'JST-9', 'LANG' => 'C', 'LC_ALL' => 'C'},
|
cmd_pipe({'TZ' => 'JST-9', 'LANG' => 'C', 'LC_ALL' => 'C'},
|
||||||
%W"git svn log --date=iso-local --topo-order #{range}",
|
%W"git svn log --date=iso-local --topo-order #{range}") do |r|
|
||||||
:chdir => @abs_srcdir) do |r|
|
|
||||||
open(path, 'w') do |w|
|
open(path, 'w') do |w|
|
||||||
IO.copy_stream(r, w)
|
IO.copy_stream(r, w)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue