Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #2814 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

[PATCH] Generator and Subversion when odd number of blank lines

Reported by: François Beausoleil <francois.beausoleil@gmail.com> Assigned to: David
Priority: high Milestone:
Component: Railties Version: 0.14.3
Severity: normal Keywords: generator svn
Cc:

Description

If the number of blank lines in a Subversion working copy is odd, Rails::Generator::Options::ClassMethods#add_general_options! will fail with the following backtrace:

$ ruby script\generate migration -tc AddGamesAndCategories1
odd number of arguments for Hash
  ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../options.rb:130:in `[]'
  ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../options.rb:130:in `add_general_options!'
  ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../options.rb:130:in `call'
  C:/ruby/lib/ruby/1.8/optparse.rb:1308:in `order!'
  C:/ruby/lib/ruby/1.8/optparse.rb:1266:in `catch'
  C:/ruby/lib/ruby/1.8/optparse.rb:1266:in `order!'
  C:/ruby/lib/ruby/1.8/optparse.rb:1346:in `permute!'
  C:/ruby/lib/ruby/1.8/optparse.rb:1373:in `parse!'
  ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../options.rb:89:in `parse!'
  ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../options.rb:85:in `initialize'
  ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../options.rb:85:in `new'
  ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../options.rb:85:in `parse!'
  ./script/../config/../vendor/rails/railties/lib/rails_generator/scripts/../scripts.rb:19:in `run'
  ./script/../config/../vendor/rails/railties/lib/commands/generate.rb:6
  C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require__'
  C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:21:in `require'
  script/generate:3

The solution is to do a compact before flattening the array.

Attachments

generator.patch (1.0 kB) - added by François Beausoleil <francois.beausoleil@gmail.com> on 11/10/05 10:40:26.
Compact the array before flattening and passing to Hash.new
generator-v2.patch (0.9 kB) - added by François Beausoleil <francois.beausoleil@gmail.com> on 11/10/05 11:01:07.
Use a more powerful regex to match files

Change History

11/10/05 10:40:26 changed by François Beausoleil <francois.beausoleil@gmail.com>

  • attachment generator.patch added.

Compact the array before flattening and passing to Hash.new

11/10/05 11:01:07 changed by François Beausoleil <francois.beausoleil@gmail.com>

  • attachment generator-v2.patch added.

Use a more powerful regex to match files

11/10/05 11:02:51 changed by François Beausoleil <francois.beausoleil@gmail.com>

After I submitted the first patch, I noticed that the splitting algorithm would get things wrong for files with a space, or locked files:

M      doc/master documentation.doc
M  L   doc/README_FOR_APP

The new patch uses a regexp to do the matching.

11/10/05 15:50:51 changed by blair

I wouldn't count on any particular appearance of text to the left of the filename.

For example, if you do a copy of the file in there, say 'svn cp foo bar', then you'll end up with this:

$ svn status
A  +   bar

and this will mess up the regex.

A lesson learned from CVS with respect to svn status' output was to have a fixed format where you can count on the columns appearing at a particular position, so your best best is to simply chop the characters where you want them:

Hash[*`svn status`.collect { |e| [e.chomp[7..-1], true]}.compact.flatten]

None of the code that uses this hash cares about its value, but if you wanted it, you could do

Hash[*`svn status`.collect { |e| [e.chomp[7..-1], e[0..6]]}.compact.flatten]

If you have an svn:external, then you'll get the mnessage

Performing status on external item at 'vendor/plugins/exception_notification'

from svn status, but there's no file that should match that string[7..-1], so I wouldn't bother removing its output.

Regards, Blair

11/10/05 16:14:28 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [2972]) Better svn status matching for generators. Closes #2814.