• 
      

    Add an object model for DiffX files.

    Review Request #11729 — Created July 17, 2021 and submitted — Latest diff uploaded

    Information

    DiffX
    master

    Reviewers

    This introduces the DOM, the DiffX Object Model, which is a hierarchical
    representation of DiffX files. It can be used to assemble a DiffX file
    section-by-section, or to load in a DiffX file and process or manipulate
    it.

    There's an object for each type of section, organized into a tree. These
    are divided into container and content sections, just as in the
    specification.

    To ease use, consumers really only have to deal with the container
    sections (DiffX, DiffXChangeSection, and DiffXFileSection). The
    content and options for each child content section is accessible via
    forwarding attributes. For example, a DiffXChangeSection's preamble
    text can be accessed directly through a preamble attribute, and the
    preamble encoding can be accessed through preamble_encoding.

    All attributes are type-safe, ensuring there are no problems when
    writing a DiffX file. The classes are also limited in what attributes
    can be set by defining __slots__, which helps to avoid accidentally
    setting the wrong attribute name.

    These objects manage data storage. All reading/writing is still done via
    the underlying stream reader/writer, with specializations to convert
    to-and-from the DOM.

    It's expected that most users of the pydiffx module will use the DOM
    implementaton, as it provides the easiest way of working with DiffX.
    Future updates are planned to automatically calculate insert/line/file
    statistics for metadata and to extract information from vendor-specific
    Unified Diff variants.

    Unit tests pass on Python 2 and 3.

    Used this with an experimental diff parser for Review Board and diff
    generator for RBTools.

    Commits

    Files