lib/mercurial-ruby/command.rb in mercurial-ruby-0.7.0 vs lib/mercurial-ruby/command.rb in mercurial-ruby-0.7.1
- old
+ new
@@ -1,11 +1,16 @@
require 'timeout'
require 'digest/md5'
+require 'open4'
module Mercurial
class CommandError < Error; end
+ #
+ # This class represents a command that will be executed in a shell. You probably don't want to deal with this yourself,
+ # use the {Mercurial::Shell Shell} class instead.
+ #
class Command
attr_accessor :command, :repository, :use_cache, :timeout
def initialize(cmd, options={})
@command = cmd
@@ -45,28 +50,29 @@
end
def execution_proc
Proc.new do
debug(command)
- result, error = '', ''
- Open3.popen3(command) do |_, stdout, stderr|
+ result, error, = '', ''
+ status = Open4.popen4(command) do |pid, stdin, stdout, stderr|
Timeout.timeout(timeout) do
while tmp = stdout.read(102400)
result += tmp
end
end
while tmp = stderr.read(1024)
error += tmp
end
end
- raise_error_if_needed(error)
+ raise_error_if_needed(status, error)
result
end
end
- def raise_error_if_needed(error)
+ def raise_error_if_needed(status, error)
+ return if status.exitstatus == 0
if error && error != ''
raise CommandError, error
end
end
@@ -75,10 +81,10 @@
end
def debug(msg)
if Mercurial.configuration.debug_mode
puts msg
- end
+ end
end
end
end