code: def parse_hunks(diff: str) -> list[Hunk]:
      """Parses a diff into hunks.
  
      Arguments:
        diff: The raw output of git diff.
  
      Returns:
        A list of Hunks.
      """
      diff_pattern = (
          r"diff --git a/.* b/(.*)\n"  # capture file name
          r"(?:\w+ file mode \d+\n)?"  # maybe 'new file mode 100644' or similar
          r"index .*\n"
          r"--- .*\n"
          r"\+\+\+ .*\n"
      )
  
      # capture line number and length from header
      hunk_header_pattern = r"@@ -\d+,\d+ \+(\d+),(\d+) @@.*\n"
  
      # ignore initial empty match
      raw_per_file_hunks = re.split(diff_pattern, diff)[1:]
  
      parsed_hunks = []
  
      for file, raw_hunks in batch(raw_per_file_hunks, 2):
          # ignore initial empty match
          hunks = re.split(
              hunk_header_pattern, raw_hunks, re.MULTILINE
          )[1:]
          for start, length, body in batch(hunks, 3):
              lines = body.split("\n")
              lines = (
                  lines if lines[-1] else lines[:-1]
              )  # trim empty line
              parsed_hunks.append(
                  Hunk(file, int(start), int(length), lines)
              )
  
      return parsed_hunks
  
file_path: tensorflow-upstream/third_party/xla/build_tools/lint/diff_parser.py
imports: import dataclasses
  import re
  import subprocess
  from typing import Generator, Iterable, TypeVar
label_desc: Use image node_id 2 for calling a global function with example usage: parse_hunks(diff) and returns: parsed_hunks