def find_hunks
      raise "can't create patch from empty diff" if @lines.empty?
      hunks = []
      cur_hunk = [@lines.first]
      cur_line_nums = @lines.first.line_numbers.dup
      @lines[1..-1].each do |line|
        case line
        when Leg::Line::Unchanged
          cur_line_nums[0] = cur_line_nums[0].nil? ? line.line_numbers[0] : (cur_line_nums[0] + 1)
          cur_line_nums[1] = cur_line_nums[1].nil? ? line.line_numbers[1] : (cur_line_nums[1] + 1)
        when Leg::Line::Added
          cur_line_nums[1] = cur_line_nums[1].nil? ? line.line_numbers[1] : (cur_line_nums[1] + 1)
        when Leg::Line::Removed
          cur_line_nums[0] = cur_line_nums[0].nil? ? line.line_numbers[0] : (cur_line_nums[0] + 1)
        when Leg::Line::Folded
          raise "can't create patch from diff with folded lines"
        end

        old_match = (line.line_numbers[0].nil? || line.line_numbers[0] == cur_line_nums[0])
        new_match = (line.line_numbers[1].nil? || line.line_numbers[1] == cur_line_nums[1])

        if !old_match || !new_match
          hunks << cur_hunk

          cur_hunk = []
          cur_line_nums = line.line_numbers.dup
        end

        cur_hunk << line
      end
      hunks << cur_hunk
      hunks
    end
def find_hunks
      raise "can't create patch from empty diff" if @lines.empty?
      hunks = []
      cur_hunk = [@lines.first]
      cur_line_nums = @lines.first.line_numbers.dup
      @lines[1..-1].each do |line|
        case line
        when Leg::Line::Unchanged
          cur_line_nums[0] = cur_line_nums[0].nil? ? line.line_numbers[0] : (cur_line_nums[0] + 1)
          cur_line_nums[1] = cur_line_nums[1].nil? ? line.line_numbers[1] : (cur_line_nums[1] + 1)
        when Leg::Line::Added
          cur_line_nums[1] = cur_line_nums[1].nil? ? line.line_numbers[1] : (cur_line_nums[1] + 1)
        when Leg::Line::Removed
          cur_line_nums[0] = cur_line_nums[0].nil? ? line.line_numbers[0] : (cur_line_nums[0] + 1)
        when Leg::Line::Folded
          raise "can't create patch from diff with folded lines"
        end

        old_match = (line.line_numbers[0].nil? || line.line_numbers[0] == cur_line_nums[0])
        new_match = (line.line_numbers[1].nil? || line.line_numbers[1] == cur_line_nums[1])

        if !old_match || !new_match
          hunks << cur_hunk

          cur_hunk = []
          cur_line_nums = line.line_numbers.dup
        end

        cur_hunk << line
      end
      hunks << cur_hunk
      hunks
    end
:(