From 251869bc11b185c1b33b96f87271c3930a8aa71f Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 15 Dec 2014 01:02:41 +0000 Subject: vcs.rb: IO.pread * tool/vcs.rb (IO.pread): method to read command output without shell. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48837 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- tool/vcs.rb | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'tool') diff --git a/tool/vcs.rb b/tool/vcs.rb index 590eaad479..430a130b80 100644 --- a/tool/vcs.rb +++ b/tool/vcs.rb @@ -9,6 +9,35 @@ unless File.respond_to? :realpath end end +def IO.pread(*args) + STDERR.puts(*args.inspect) if $DEBUG + popen(*args) {|f|f.read} +end + +if RUBY_VERSION < "1.9" + class IO + @orig_popen = method(:popen) + + if defined?(fork) + def self.popen(command, *rest, &block) + if !(Array === command) + @orig_popen.call(command, *rest, &block) + elsif block + @orig_popen.call("-", *rest) {|f| f ? yield(f) : exec(*command)} + else + @orig_popen.call("-", *rest) or exec(*command) + end + end + else + require 'shellwords' + def self.popen(command, *rest, &block) + command = command.shelljoin if Array === command + @orig_popen.call(command, *rest, &block) + end + end + end +end + class VCS class NotFoundError < RuntimeError; end @@ -98,7 +127,7 @@ class VCS if srcdir and %r'\A(?:[^/]+:|/)' !~ path path = File.join(srcdir, path) end - info_xml = `svn info --xml "#{path}"` + info_xml = IO.pread(%W"svn info --xml #{path}") _, last, _, changed, _ = info_xml.split(/revision="(\d+)"/) modified = info_xml[/([^<>]*)/, 1] [last, changed, modified] @@ -109,11 +138,13 @@ class VCS register(".git") def self.get_revisions(path, srcdir = nil) - logcmd = %Q[git -C "#{srcdir || '.'}" log -n1 --date=iso --grep="^ *git-svn-id: .*@[0-9][0-9]* "] + logcmd = %W[git log -n1 --date=iso] + logcmd[1, 0] = ["-C", srcdir] if srcdir + logcmd << "--grep=^ *git-svn-id: .*@[0-9][0-9]*" idpat = /git-svn-id: .*?@(\d+) \S+\Z/ - last = `#{logcmd}`[idpat, 1] + last = IO.pread(logcmd)[idpat, 1] if path - log = `#{logcmd} "#{path}"` + log = IO.pread(logcmd + [path]) changed = log[idpat, 1] else changed = last -- cgit v1.2.3