diff options
| author | Jack Nagel | 2014-07-29 16:06:07 -0500 | 
|---|---|---|
| committer | Jack Nagel | 2014-07-29 16:22:06 -0500 | 
| commit | a55e196f5f72ef0b1c829007c9b4a68de5c06ef0 (patch) | |
| tree | 9f4948d08439b51340da4496627cc61c6d3e94c5 /Library/Homebrew/patch.rb | |
| parent | 3f12ddbccd8416d4355e0fd0efa8f95bc1a7632f (diff) | |
| download | brew-a55e196f5f72ef0b1c829007c9b4a68de5c06ef0.tar.bz2 | |
Simplify internal representation of patches
 - remove support for IO objects, since we no longer access ::DATA
   directly
 - since we don't need to support IO objects, use a separate class for
   string patches and stop wrapping strings in StringIO ojects
Diffstat (limited to 'Library/Homebrew/patch.rb')
| -rw-r--r-- | Library/Homebrew/patch.rb | 47 | 
1 files changed, 24 insertions, 23 deletions
| diff --git a/Library/Homebrew/patch.rb b/Library/Homebrew/patch.rb index 477eb20a8..53ea0ac6d 100644 --- a/Library/Homebrew/patch.rb +++ b/Library/Homebrew/patch.rb @@ -1,24 +1,19 @@  require 'resource' -require 'stringio'  require 'erb'  module Patch -  def self.create(strip, io, &block) +  def self.create(strip, src, &block)      case strip      when :DATA        DATAPatch.new(:p1) -    when IO, StringIO -      IOPatch.new(strip, :p1)      when String -      IOPatch.new(StringIO.new(strip), :p1) +      StringPatch.new(:p1, strip)      when Symbol -      case io +      case src        when :DATA          DATAPatch.new(strip) -      when IO, StringIO -        IOPatch.new(io, strip)        when String -        IOPatch.new(StringIO.new(io), strip) +        StringPatch.new(strip, src)        else          ExternalPatch.new(strip, &block)        end @@ -53,31 +48,26 @@ module Patch    end  end -class IOPatch +class EmbeddedPatch    attr_writer :owner    attr_reader :strip +  def initialize(strip) +    @strip = strip +  end +    def external?      false    end -  def initialize(io, strip) -    @io     = io -    @strip  = strip +  def contents +    raise NotImplementedError    end    def apply      data = contents.gsub("HOMEBREW_PREFIX", HOMEBREW_PREFIX)      IO.popen("/usr/bin/patch -g 0 -f -#{strip}", "w") { |p| p.write(data) }      raise ErrorDuringExecution, "Applying DATA patch failed" unless $?.success? -  ensure -    # IO and StringIO cannot be marshaled, so remove the reference -    # in case we are indirectly referenced by an exception later. -    @io = nil -  end - -  def contents -    @io.read    end    def inspect @@ -85,11 +75,11 @@ class IOPatch    end  end -class DATAPatch < IOPatch +class DATAPatch < EmbeddedPatch    attr_accessor :path    def initialize(strip) -    @strip = strip +    super      @path = nil    end @@ -105,6 +95,17 @@ class DATAPatch < IOPatch    end  end +class StringPatch < EmbeddedPatch +  def initialize(strip, str) +    super(strip) +    @str = str +  end + +  def contents +    @str +  end +end +  class ExternalPatch    attr_reader :resource, :strip | 
