Commits

Yuya Nishihara committed 94ad7c8

fix syntax error on Ruby 1.8, which cannot accept argument after splat

Comments (0)

Files changed (2)

lib/hglib/commandbuilder.rb

     end
     module_function :pop_command_opts
 
+    def peek_command_opts(pats)
+      if pats[-1].is_a? Hash
+        pats[-1]
+      else
+        {}
+      end
+    end
+    module_function :peek_command_opts
+
     def build_command_args(name, *pats)
       opts = pop_command_opts(pats)
 

lib/hglib/commander.rb

     def annotate(*pats)  #:yields: changeid, line_content
       opts = pop_command_opts(pats).dup
       opts[:number] = opts[:changeset] = opts[:debug] = true  # rev and full nodeid
-      raw_command_with_buffer ChunkBuffer.new, 'annotate', *pats, opts do |l|
+      pats << opts
+      raw_command_with_buffer ChunkBuffer.new, 'annotate', *pats do |l|
         yield parse_annotate_line(l)
       end
     end
     # If +:output+ is specified, the content will be written to the specified
     # file; otherwise yields each chunk (or return whole content as String.)
     def cat(*pats, &block)  #:yields: chunk
-      opts = pop_command_opts(pats)
+      opts = peek_command_opts(pats)
       if opts.include? :output
-        raw_command('cat', *pats, opts) {}
+        raw_command('cat', *pats) {}
       else
-        raw_command('cat', *pats, opts, &block)
+        raw_command('cat', *pats, &block)
       end
     end
 
     def locate(*pats, &block)
       opts = pop_command_opts(pats).dup
       opts[:print0] = true
+      pats << opts
       chunkbuf = ChunkBuffer.new "\0"
-      raw_command_with_buffer chunkbuf, 'locate', *pats, opts, &block
+      raw_command_with_buffer chunkbuf, 'locate', *pats, &block
     end
     iterable_command :locate
 
     def loglike_command_with_block(name, *pats)  #:yields: changeset
       opts = pop_command_opts(pats).dup
       opts[:template] = LOG_TEMPLATE
+      pats << opts
       chunkbuf = ChunkBuffer.new "\0", Changeset.members.size + 1
-      raw_command_with_buffer chunkbuf, name, *pats, opts do |elems|
+      raw_command_with_buffer chunkbuf, name, *pats do |elems|
         msg = elems.shift  # possibly incoming/outgoing status message
         @logger.info msg.chomp unless msg.empty?
         yield parse_changeset_fields(elems)
     def tagslike_command(name, *pats)
       opts = pop_command_opts(pats).dup
       opts[:debug] = true  # for full digits of nodeid
+      pats << opts
       tagsmap = {}
-      raw_command_with_buffer ChunkBuffer.new, name, *pats, opts do |line|
+      raw_command_with_buffer ChunkBuffer.new, name, *pats do |line|
         name, cid = parse_tag_line line
         tagsmap[name] = cid
       end