https://svn.lrde.epita.fr/svn/lrdetools/trunk
Index: ChangeLog from Nicolas Pouillard ertai@lrde.epita.fr
Fix a bug woth error handlers.
* vcs/lib/vcs/vcs.rb: Use a class variable to store them. * vcs/lib/vcs/app.rb: Split a line to store the real vcs instance.
app.rb | 9 +++++++-- vcs.rb | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-)
Index: vcs/lib/vcs/vcs.rb --- vcs/lib/vcs/vcs.rb (revision 254) +++ vcs/lib/vcs/vcs.rb (working copy) @@ -245,7 +245,6 @@
def initialize ( aCmd ) @cmd = aCmd.to_cmd - @handlers = Set.new @runner = Commands::Runners::System.new @h = HighLine.new self.cmd_data_factory = VcsCmdDataFactory.new(:output => STDOUT, :error => STDERR) @@ -329,6 +328,8 @@ delegate_to_cmd_data Vcs.output_io_methods
@@checkers = Set.new + OrderedHash.import! + @@handlers = OHash.new
def run! ( command, files=[], options={} ) flush @@ -417,18 +418,18 @@ def with_cache ( path=nil, description=nil, &block ) loc = block.source_location # FIXME verify that this type of cache is working return @@cache[loc].dup if @@cache.has_key? loc - if path.exist? - logger.info "#{path} already exists" - return path.read - end unless path.nil? if description.nil? raise ArgumentError, "need a description for #{path}" end - error_handling do + error_handling(path) do logger.info "#{path}: Contains your #{description}" if path.exist? end end + if path.exist? + logger.info "#{path} already exists" + return path.read + end begin logger.info "Creating a new `#{path}' file ..." path.open('w') { |f| result = with(f, &block) } @@ -533,12 +534,12 @@ alias_command :checkin, :commit alias_command :populate, :add
- def error_handling ( meth=nil, &block ) - @handlers << ((block.nil?)? method(meth) : block) + def error_handling ( meth_or_path, &block ) + @@handlers[meth_or_path] = (block.nil?)? method(meth_or_path) : block end
def call_handlers - @handlers.each { |block| block[] } + @@handlers.each { |k, v| v[k] } end
def call_conf_checkers Index: vcs/lib/vcs/app.rb --- vcs/lib/vcs/app.rb (revision 254) +++ vcs/lib/vcs/app.rb (working copy) @@ -106,12 +106,17 @@ ".head_cut! exit end - vcs = @@all_vcs[Vcs.default.to_s.downcase.to_sym].new.run_argv(ARGV) + vcs = @@all_vcs[Vcs.default.to_s.downcase.to_sym].new + vcs.run_argv(ARGV)
rescue SystemExit => ex raise ex rescue Exception => ex - vcs.call_handlers unless vcs.nil? + if vcs.nil? + logger.error { "No Vcs instanciated" } + else + vcs.call_handlers + end err = ex.to_s.sub(/.$/, '') logger.debug { err = ex.long_pp ; "Backtrace enabled:" } err = ex.inspect if err.empty?