global

def analyze_patchset(patchset, depth = 0)

changes to be made.
the object form of same) and detection of whether the patchset represents
normalization (conversion of the array form of Diff::LCS::Change objects to
This method will analyze the provided patchset to provide a single-pass
def analyze_patchset(patchset, depth = 0)
  fail "Patchset too complex" if depth > 1
  has_changes = false
  new_patchset = []
  # Format:
  # [ # patchset
  #   # hunk (change)
  #   [ # hunk
  #     # change
  #   ]
  # ]
  patchset.each do |hunk|
    case hunk
    when Diff::LCS::Change
      has_changes ||= !hunk.unchanged?
      new_patchset << hunk
    when Array
      # Detect if the 'hunk' is actually an array-format change object.
      if Diff::LCS::Change.valid_action? hunk[0]
        hunk = Diff::LCS::Change.from_a(hunk)
        has_changes ||= !hunk.unchanged?
        new_patchset << hunk
      else
        with_changes, hunk = analyze_patchset(hunk, depth + 1)
        has_changes ||= with_changes
        new_patchset.concat(hunk)
      end
    else
      fail ArgumentError, "Cannot normalise a hunk of class #{hunk.class}."
    end
  end
  [has_changes, new_patchset]
end