Permalink
Browse files

Merge branch 'posix-spawn'

  • Loading branch information...
2 parents 1b2fe77 + 0822ea6 commit f5838446fb32356548eaa03f374098cabe8d5a94 @tmm1 tmm1 committed Jun 8, 2011
Showing with 14 additions and 459 deletions.
  1. +1 −0 grit.gemspec
  2. +0 −6 lib/grit.rb
  3. +10 −7 lib/grit/git.rb
  4. +0 −45 lib/grit/jruby.rb
  5. +0 −294 lib/grit/process.rb
  6. +3 −3 test/test_git.rb
  7. +0 −104 test/test_process.rb
View
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--charset=UTF-8"]
s.extra_rdoc_files = %w[README.md LICENSE]
+ s.add_dependency('posix-spawn', "~> 0.3.0")
s.add_dependency('mime-types', "~> 1.15")
s.add_dependency('diff-lcs', "~> 1.1")
View
@@ -28,7 +28,6 @@
require 'grit/ruby1.9'
# internal requires
-require 'grit/process'
require 'grit/lazy'
require 'grit/errors'
require 'grit/git-ruby'
@@ -49,11 +48,6 @@
require 'grit/blame'
require 'grit/merge'
-# platform specific requires
-if defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/
- require 'grit/jruby'
-end
-
module Grit
VERSION = '2.4.1'
View
@@ -1,7 +1,10 @@
require 'tempfile'
+require 'posix-spawn'
module Grit
class Git
+ include POSIX::Spawn
+
class GitTimeout < RuntimeError
attr_accessor :command
attr_accessor :bytes_read
@@ -313,12 +316,12 @@ def native(cmd, options = {}, *args, &block)
Grit.log(argv.join(' ')) if Grit.debug
process =
- Grit::Process.new(argv, env,
+ Child.new(env, *(argv + [{
:input => input,
:chdir => chdir,
:timeout => (Grit::Git.git_timeout if timeout == true),
:max => (Grit::Git.git_max_size if timeout == true)
- )
+ }]))
Grit.log(process.out) if Grit.debug
Grit.log(process.err) if Grit.debug
@@ -330,7 +333,7 @@ def native(cmd, options = {}, *args, &block)
else
process.out
end
- rescue Grit::Process::TimeoutExceeded, Grit::Process::MaximumOutputExceeded
+ rescue TimeoutExceeded, MaximumOutputExceeded
raise GitTimeout, argv.join(' ')
end
@@ -422,18 +425,18 @@ def run(prefix, cmd, postfix, options, args, &block)
def sh(command, &block)
process =
- Grit::Process.new(
- command, {},
+ Child.new(
+ command,
:timeout => Git.git_timeout,
:max => Git.git_max_size
)
[process.out, process.err]
- rescue Grit::Process::TimeoutExceeded, Grit::Process::MaximumOutputExceeded
+ rescue TimeoutExceeded, MaximumOutputExceeded
raise GitTimeout, command
end
def wild_sh(command, &block)
- process = Grit::Process.new(command)
+ process = Child.new(command)
[process.out, process.err]
end
View
@@ -1,45 +0,0 @@
-require 'grit/process'
-
-module Grit
- # Override the Grit::Process class's popen4 and waitpid methods to work around
- # various quirks in JRuby.
- class Process
- # Use JRuby's built in IO.popen4 but emulate the special spawn env
- # and options arguments as best we can.
- def popen4(*argv)
- env = (argv.shift if argv[0].is_a?(Hash)) || {}
- opt = (argv.pop if argv[-1].is_a?(Hash)) || {}
-
- # emulate :chdir option
- if opt[:chdir]
- previous_dir = Dir.pwd
- Dir.chdir(opt[:chdir])
- else
- previous_dir = nil
- end
-
- # emulate :env option
- if env.size > 0
- previous_env = ENV
- ENV.merge!(env)
- else
- previous_env = nil
- end
-
- pid, stdin, stdout, stderr = IO.popen4(*argv)
- ensure
- ENV.replace(previous_env) if previous_env
- Dir.chdir(previous_dir) if previous_dir
- end
-
- # JRuby always raises ECHILD on pids returned from its IO.popen4 method
- # for some reason. Return a fake Process::Status object.
- FakeStatus = Struct.new(:pid, :exitstatus, :success?, :fake?)
- def waitpid(pid)
- ::Process::waitpid(pid)
- $?
- rescue Errno::ECHILD
- FakeStatus.new(pid, 0, true, true)
- end
- end
-end
Oops, something went wrong.

0 comments on commit f583844

Please sign in to comment.