fitzzftw.patch.parser

Unified Diff and Patch Parsing

This module provides the core logic for deconstructing raw patch data into structured object hierarchies. It acts as a high-performance state machine that transforms streams of strings into validated containers.

Core Components:

  • PatchParser:

    The central engine for parsing diff sequences. It implements a factory pattern for line instantiation and manages the state transition between file-headers, hunk-headers, and content.

  • The Sieve:

    An optimized inline parsing logic within iter_files() that validates the structural integrity of the diff format (e.g., ensuring headers precede content).

Key Features:

  • Strict Validation:

    Raises PatchParseError for malformed sequences to prevent processing corrupted or incomplete patch data.

  • Streaming Architecture:

    Uses generators to process large patch files efficiently without loading the entire content into memory.

  • Extensibility:

    The factory method create_line() allows for customization of how individual lines are categorized and instantiated.

Classes

PatchParser

Handles the parsing of the diff or patch file content.