summaryrefslogtreecommitdiff
path: root/tool/vcs.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-15 01:02:41 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-15 01:02:41 +0000
commit251869bc11b185c1b33b96f87271c3930a8aa71f (patch)
treef59cce01b5013fd6d148f9408cdadeaa1cfb1528 /tool/vcs.rb
parente0bcfdd9311780698cc64d57d25e71c9990d56a5 (diff)
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
Diffstat (limited to 'tool/vcs.rb')
-rw-r--r--tool/vcs.rb39
1 files changed, 35 insertions, 4 deletions
diff --git a/tool/vcs.rb b/tool/vcs.rb
index 590eaad..430a130 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[/<date>([^<>]*)/, 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