зеркало из https://github.com/github/ruby.git
vcs.rb: do not use -C for older git
* tool/vcs.rb (IO.popen): support :chdir option. * tool/vcs.rb (VCS::GIT.get_revisions): use :chdir option instead of -C option which is not supported by older git. [ruby-dev:48880] [Bug #10890] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
5b4afd0281
Коммит
673af3e9f2
|
@ -1,3 +1,11 @@
|
||||||
|
Mon Feb 23 23:19:42 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* tool/vcs.rb (IO.popen): support :chdir option.
|
||||||
|
|
||||||
|
* tool/vcs.rb (VCS::GIT.get_revisions): use :chdir option instead
|
||||||
|
of -C option which is not supported by older git.
|
||||||
|
[ruby-dev:48880] [Bug #10890]
|
||||||
|
|
||||||
Mon Feb 23 15:26:39 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Mon Feb 23 15:26:39 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* string.c (rb_str_split_m): raise ArgumentError at broken string
|
* string.c (rb_str_split_m): raise ArgumentError at broken string
|
||||||
|
|
50
tool/vcs.rb
50
tool/vcs.rb
|
@ -21,19 +21,39 @@ if RUBY_VERSION < "1.9"
|
||||||
|
|
||||||
if defined?(fork)
|
if defined?(fork)
|
||||||
def self.popen(command, *rest, &block)
|
def self.popen(command, *rest, &block)
|
||||||
if !(Array === command)
|
if Hash === (opts = rest[-1])
|
||||||
@orig_popen.call(command, *rest, &block)
|
dir = opts.delete(:chdir)
|
||||||
elsif block
|
rest pop if opts.empty?
|
||||||
@orig_popen.call("-", *rest) {|f| f ? yield(f) : exec(*command)}
|
end
|
||||||
|
if block
|
||||||
|
@orig_popen.call("-", *rest) do |f|
|
||||||
|
if f
|
||||||
|
yield(f)
|
||||||
|
else
|
||||||
|
Dir.chdir(dir) if dir
|
||||||
|
exec(*command)
|
||||||
|
end
|
||||||
|
end
|
||||||
else
|
else
|
||||||
@orig_popen.call("-", *rest) or exec(*command)
|
f = @orig_popen.call("-", *rest)
|
||||||
|
unless f
|
||||||
|
Dir.chdir(dir) if dir
|
||||||
|
exec(*command)
|
||||||
|
end
|
||||||
|
f
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
require 'shellwords'
|
require 'shellwords'
|
||||||
def self.popen(command, *rest, &block)
|
def self.popen(command, *rest, &block)
|
||||||
|
if Hash === (opts = rest[-1])
|
||||||
|
dir = opts.delete(:chdir)
|
||||||
|
rest pop if opts.empty?
|
||||||
|
end
|
||||||
command = command.shelljoin if Array === command
|
command = command.shelljoin if Array === command
|
||||||
@orig_popen.call(command, *rest, &block)
|
Dir.chdir(dir || ".") do
|
||||||
|
@orig_popen.call(command, *rest, &block)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -255,24 +275,23 @@ class VCS
|
||||||
|
|
||||||
def self.get_revisions(path, srcdir = nil)
|
def self.get_revisions(path, srcdir = nil)
|
||||||
gitcmd = %W[git]
|
gitcmd = %W[git]
|
||||||
gitcmd.push("-C", srcdir) if srcdir
|
|
||||||
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)
|
log = IO.pread(logcmd, :chdir => srcdir)
|
||||||
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)
|
log = IO.pread(cmd, :chdir => srcdir)
|
||||||
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])[%r'\A(?:refs/heads/)?(.+)', 1]
|
branch = IO.pread(gitcmd + %W[symbolic-ref HEAD], :chdir => srcdir)[%r'\A(?:refs/heads/)?(.+)', 1]
|
||||||
title = IO.pread(gitcmd + ["log", "--format=%s", "-n1", "#{commit}..HEAD"])
|
title = IO.pread(gitcmd + %W[log --format=%s -n1 #{commit}..HEAD], :chdir => srcdir)
|
||||||
title = nil if title.empty?
|
title = nil if title.empty?
|
||||||
[last, changed, modified, branch, title]
|
[last, changed, modified, branch, title]
|
||||||
end
|
end
|
||||||
|
@ -291,14 +310,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]*"
|
||||||
cmd[1, 0] = ["-C", @srcdir] if @srcdir
|
branch(IO.pread(cmd, :chdir => srcdir)[/.*^(ruby_\d+_\d+)$/m, 1])
|
||||||
branch(IO.pread(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}"
|
||||||
cmd[1, 0] = ["-C", @srcdir] if @srcdir
|
IO.popen(cmd, :chdir => srcdir) {|f|
|
||||||
IO.popen(cmd) {|f|
|
|
||||||
f.each {|line|
|
f.each {|line|
|
||||||
line.chomp!
|
line.chomp!
|
||||||
yield line
|
yield line
|
||||||
|
@ -308,9 +325,8 @@ 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} --]
|
||||||
cmd[1, 0] = ["-C", @srcdir] if @srcdir
|
|
||||||
set = block.binding.eval("proc {|match| $~ = match}")
|
set = block.binding.eval("proc {|match| $~ = match}")
|
||||||
IO.popen([cmd, *files]) do |f|
|
IO.popen([cmd, *files], :chdir => srcdir) do |f|
|
||||||
f.grep(pat) do |s|
|
f.grep(pat) do |s|
|
||||||
set[$~]
|
set[$~]
|
||||||
yield s
|
yield s
|
||||||
|
|
Загрузка…
Ссылка в новой задаче