Class: Subversion::DiffsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/svn-command/subversion.rb

Defined Under Namespace

Classes: ParseError

Instance Method Summary collapse

Instance Method Details

#parseObject



510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
# File 'lib/svn-command/subversion.rb', line 510

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