parse

in lib/gitlab/diff/parser.rb [7:65]


      def parse(lines, diff_file: nil)
        return [] if lines.blank?

        @lines = lines
        line_obj_index = 0
        line_old = 1
        line_new = 1
        type = nil
        context = nil

        
        
        Enumerator.new do |yielder|
          @lines.each do |line|
            
            
            next if filename?(line) && type.nil?

            full_line = line.delete("\n")

            if line =~ /^@@ -/
              type = "match"

              line_old = line.match(/\-[0-9]*/)[0].to_i.abs rescue 0
              line_new = line.match(/\+[0-9]*/)[0].to_i.abs rescue 0

              next if line_old <= 1 && line_new <= 1 

              yielder << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new, parent_file: diff_file)
              line_obj_index += 1
              next
            elsif line[0] == '\\'
              type = "#{context}-nonewline"

              yielder << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new, parent_file: diff_file)
              line_obj_index += 1
            else
              type = identification_type(line)
              yielder << Gitlab::Diff::Line.new(full_line, type, line_obj_index, line_old, line_new, parent_file: diff_file)
              line_obj_index += 1
            end

            case line[0]
            when "+"
              line_new += 1
              context = :new
            when "-"
              line_old += 1
              context = :old
            when "\\" 
              
            else
              line_new += 1
              line_old += 1
            end
          end
        end
      end