lib/mercurial-ruby/command.rb in mercurial-ruby-0.5.0 vs lib/mercurial-ruby/command.rb in mercurial-ruby-0.6.0
- old
+ new
@@ -3,16 +3,17 @@
module Mercurial
class CommandError < Error; end
class Command
- attr_accessor :command, :repository, :use_cache
+ attr_accessor :command, :repository, :use_cache, :timeout
def initialize(cmd, options={})
@command = cmd
@repository = options[:repository]
- @use_cache = options[:cache]
+ @use_cache = options[:cache].nil? || options[:cache] == false ? false : true
+ @timeout = options[:timeout] ? options[:timeout].to_i : global_execution_timeout.to_i
end
def execute
if cache_commands?
execute_with_caching
@@ -22,18 +23,18 @@
end
private
def cache_commands?
- repository && use_cache && cache_store
+ repository && !repository.cache_disabled_by_override? && cache_store && use_cache
end
def cache_store
Mercurial.configuration.cache_store
end
- def execution_timeout
+ def global_execution_timeout
Mercurial.configuration.shell_timeout
end
def execute_with_caching
cache_store.fetch(cache_key, &execution_proc)
@@ -43,13 +44,14 @@
execution_proc.call
end
def execution_proc
Proc.new do
- result, error = '', ''
+ debug(command)
+ result, error = '', ''
Open3.popen3(command) do |_, stdout, stderr|
- Timeout.timeout(execution_timeout) do
+ Timeout.timeout(timeout) do
while tmp = stdout.read(102400)
result += tmp
end
end
@@ -69,9 +71,15 @@
end
def cache_key
"hg.#{ repository.mtime }." + Digest::MD5.hexdigest(command)
end
+
+ def debug(msg)
+ if Mercurial.configuration.debug_mode
+ puts msg
+ end
+ end
end
-end
\ No newline at end of file
+end