Class: Subversion::DiffsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/subwrap/subversion.rb

Defined Under Namespace

Classes: ParseError

Instance Method Summary collapse

Instance Method Details

#parseObject



586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
# File 'lib/subwrap/subversion.rb', line 586

def parse
  diffs = Diffs.new
  current_diff = nil
  @raw_diffs.each_line do |line|
    if line =~ /^Index: (.*)$/
      current_diff = Diff.new($1)
      diffs[current_diff.filename] = current_diff #unless current_diff.nil?
      @state = :immediately_after_filename
      next
    end

    if current_diff.nil?
      raise ParseError.new("The raw diff input didn't begin with 'Index:'!")
    end

    if @state == :immediately_after_filename
      if line =~ /^===================================================================$/ ||
         line =~ /^---.*\(revision \d+\)$/ ||
         line =~ /^\+\+\+.*\(revision \d+\)$/ ||
         line =~ /^@@ .* @@$/
        # Skip
        next
      else
        @state= :inside_the_actual_diff
      end
    end

    if @state == :inside_the_actual_diff
      current_diff.diff << line
    else
      raise ParseError.new("Expected to be in :inside_the_actual_diff state, but was not.")
    end
  end
  diffs.freeze
  diffs
end