• Get Review Board
  • What's New
  • Products
  • Review Board Code review, image review, and document review
  • Documentation
  • Release Notes
  • Power Pack Enterprise integrations, reports, and enhanced document review
  • Try for 60 Days
  • Purchase
  • RBCommons Review Board as a Service, hosted by us
  • Pricing
  • RBTools Command line tools and Python API for Review Board
  • Documentation
  • Release Notes
  • Review Bot Automated code review, connecting tools you already use
  • Documentation
  • Release Notes
  • RB Gateway Manage Git and Mercurial repositories in your network
  • Documentation
  • Release Notes
  • Learn and Explore
  • What is Code Review?
  • Documentation
  • Frequently Asked Questions
  • Support Options
  • Third-Party Integrations
  • Demo
  • Review Board RBTools Power Pack Review Bot Djblets RB Gateway
    1. RBTools 5.x
    2. Version 5.x
    3. Version 4.x
    4. Version 3.x
    5. Version 2.0
    6. Version 1.0
    7. Version 0.7
    8. Version 0.6
    9. Version 0.5
    10. RBTools Python API
    11. Module and Class References
    12. rbtools.diffs.patches
  • Home
  • Installing RBTools
  • rbt Command
  • Configuration
  • Authenticating to Review Board
  • Repository Configuration
  • Per-User Configuration
  • Team Foundation Server Configuration
  • Commands
  • alias
  • api-get
  • attach
  • clear-cache
  • close
  • diff
  • install
  • land
  • list-repo-types
  • login
  • logout
  • patch
  • post
  • publish
  • review
  • setup-completion
  • setup-repo
  • stamp
  • status
  • status-update
  • RBTools Workflows
  • Using RBTools With Cliosoft SOS
  • Using RBTools with Git
  • Using RBTools with HCL VersionVault and IBM ClearCase
  • Using RBTools With Perforce
  • RBTools Python API
  • Overview of the Python API Client
  • Tutorial
  • Resource-Specific Functionality
  • Module and Class References
  • rbtools
  • rbtools.deprecation
  • rbtools.api
  • rbtools.api.cache
  • rbtools.api.capabilities
  • rbtools.api.client
  • rbtools.api.decode
  • rbtools.api.decorators
  • rbtools.api.errors
  • rbtools.api.factory
  • rbtools.api.request
  • rbtools.api.resource
  • rbtools.api.transport
  • rbtools.api.transport.sync
  • rbtools.api.utils
  • rbtools.clients
  • rbtools.clients.base
  • rbtools.clients.base.patch
  • rbtools.clients.base.registry
  • rbtools.clients.base.repository
  • rbtools.clients.base.scmclient
  • rbtools.clients.errors
  • rbtools.clients.bazaar
  • rbtools.clients.clearcase
  • rbtools.clients.cvs
  • rbtools.clients.git
  • rbtools.clients.mercurial
  • rbtools.clients.perforce
  • rbtools.clients.plastic
  • rbtools.clients.sos
  • rbtools.clients.svn
  • rbtools.clients.tfs
  • rbtools.config
  • rbtools.config.config
  • rbtools.config.loader
  • rbtools.diffs
  • rbtools.diffs.patches
  • rbtools.diffs.patcher
  • rbtools.diffs.tools
  • rbtools.diffs.tools.backends
  • rbtools.diffs.tools.backends.gnu
  • rbtools.diffs.tools.base
  • rbtools.diffs.tools.base.diff_file_result
  • rbtools.diffs.tools.base.diff_tool
  • rbtools.diffs.tools.errors
  • rbtools.diffs.tools.registry
  • rbtools.diffs.writers
  • rbtools.commands
  • rbtools.commands.main
  • rbtools.commands
  • rbtools.commands.base
  • rbtools.commands.base.commands
  • rbtools.commands.base.errors
  • rbtools.commands.base.options
  • rbtools.commands.base.output
  • rbtools.commands.alias
  • rbtools.commands.api_get
  • rbtools.commands.attach
  • rbtools.commands.clearcache
  • rbtools.commands.close
  • rbtools.commands.diff
  • rbtools.commands.info
  • rbtools.commands.install
  • rbtools.commands.land
  • rbtools.commands.list_repo_types
  • rbtools.commands.login
  • rbtools.commands.logout
  • rbtools.commands.patch
  • rbtools.commands.post
  • rbtools.commands.publish
  • rbtools.commands.review
  • rbtools.commands.setup_completion
  • rbtools.commands.setup_repo
  • rbtools.commands.stamp
  • rbtools.commands.status
  • rbtools.commands.status_update
  • rbtools.hooks
  • rbtools.hooks.common
  • rbtools.hooks.git
  • rbtools.testing
  • rbtools.testing.api
  • rbtools.testing.api.payloads
  • rbtools.testing.api.transport
  • rbtools.testing.commands
  • rbtools.testing.testcase
  • rbtools.testing.transport
  • rbtools.utils
  • rbtools.utils.aliases
  • rbtools.utils.browser
  • rbtools.utils.checks
  • rbtools.utils.commands
  • rbtools.utils.console
  • rbtools.utils.diffs
  • rbtools.utils.encoding
  • rbtools.utils.errors
  • rbtools.utils.filesystem
  • rbtools.utils.graphs
  • rbtools.utils.mimetypes
  • rbtools.utils.process
  • rbtools.utils.repository
  • rbtools.utils.review_request
  • rbtools.utils.source_tree
  • rbtools.utils.users
  • Glossary
  • General Index
  • Python Module Index
  • Release Notes
  • rbtools.diffs.patches¶

    Patch information and support for applying patches.

    New in version 5.1: PatchAuthor and PatchResult were moved from rbtools.scmclients.base.patch.

    Classes

    Patch(*[, author, base_dir, content, ...])

    A patch to a repository that can be applied.

    PatchAuthor(*, full_name, email)

    The author of a patch or commit.

    PatchResult(*, applied[, has_conflicts, ...])

    The result of a patch operation.

    class rbtools.diffs.patches.PatchAuthor(*, full_name: str, email: str)[source]¶

    Bases: object

    The author of a patch or commit.

    This wraps the full name and e-mail address of a commit or patch’s author primarily for use in BaseSCMClient.apply_patch().

    Changed in version 5.1:

    • Moved from rbtools.clients.base.patch. That module will provide compatibility imports until RBTools 7.

    Changed in version 4.0:

    • Moved from rbtools.clients. That module still provides compatibility imports until RBTools 7.

    __init__(*, full_name: str, email: str) → None[source]¶

    Initialize the author information.

    Changed in version 5.1: This now requires keyword-only arguments. Support for positional arguments will be removed in RBTools 7.

    Parameters:
    • full_name (str) – The full name of the author.

    • email (str) – The e-mail address of the author.

    full_name: str¶

    The full name of the author.

    New in version 5.1: This was added as a replacement for fullname.

    email: str¶

    The e-mail address of the author.

    property fullname: str[source]¶

    The full name of this author.

    Deprecated since version 5.1: This is deprecated in favor of full_name. It will be removed in RBTools 7.

    Returns:

    The full name of the author.

    Return type:

    bool

    __eq__(other: object) → bool[source]¶

    Return whether this author is equal to another.

    Parameters:

    other (object) – The other object to compare to.

    Returns:

    True if the other object is equal to this one. False if it is not.

    Return type:

    bool

    __repr__() → str[source]¶

    Return a string representation of this object.

    New in version 5.1.

    Returns:

    The string representation.

    Return type:

    str

    __hash__ = None¶
    class rbtools.diffs.patches.Patch(*, author: Optional[PatchAuthor] = None, base_dir: Optional[str] = None, content: Optional[bytes] = None, message: Optional[str] = None, path: Optional[Path] = None, prefix_level: Optional[int] = None)[source]¶

    Bases: object

    A patch to a repository that can be applied.

    This consolidates metadata on the patch (the author and description) along with information needed to apply a patch (the base directory within the repository in which to apply the patch, the patch level, and the patch contents).

    New in version 5.1.

    __init__(*, author: Optional[PatchAuthor] = None, base_dir: Optional[str] = None, content: Optional[bytes] = None, message: Optional[str] = None, path: Optional[Path] = None, prefix_level: Optional[int] = None) → None[source]¶

    Initialize the patch.

    Parameters:
    • author (PatchAuthor, optional) – The author of the patch.

    • base_dir (str, optional) –

      The directory in the repository where the patch was generated.

      This is dependent on the SCM and the method used to generate the patch.

    • content (bytes, optional) –

      The contents of the patch.

      Either this or path must be provided.

    • message (str, optional) – The commit message describing the patch.

    • path (pathlib.Path, optional) –

      The file path where the patch resides.

      Either this or content must be provided.

    • prefix_level (int, optional) –

      The path prefix stripping level to use when applying the patch.

      This is the number of path components to strip from the beginning of each filename in the patch. It’s the equivalent of patch -p<X>.

      If not provided, the patching code will determine a default. This default may not be correct for the patch.

    Raises:

    ValueError – One or more parameters or parameter combinations were invalid.

    author: Optional[PatchAuthor]¶

    The author of the patch.

    This will generally be available if generating a patch from an existing commit.

    base_dir: Optional[str]¶

    The base directory in the repository where the patch was generated.

    This is dependent on the SCM and the method used to generate the patch.

    message: Optional[str]¶

    The commit message describing the patch.

    This will generally be available if generating a patch from an existing commit.

    prefix_level: Optional[int]¶

    The path prefix stripping level to use when applying the patch.

    This is the number of path components to strip from the beginning of each filename in the patch. It’s the equivalent of patch -p<X>.

    open() → Iterator[None][source]¶

    Open the patch for reading.

    Once upon, either the content or the file path can be directly read. Any temporary state will be cleaned up once the patch is no longer open.

    This must be called before accessing :py:attr;`content` or path.

    Context:

    The patch will be available for reading.

    property content: bytes[source]¶

    The raw content of the patch.

    The patch must be opened before this is called.

    Returns:

    The raw patch contents.

    Return type:

    bytes

    Raises:

    IOError – The patch was not opened for reading or could not be read from disk.

    property path: Path[source]¶

    A path to the patch content.

    The returned path may be a temporary file path, which would be automatically deleted once the patch is closed for reading.

    The patch must be opened before this is called.

    Returns:

    The raw patch contents.

    Return type:

    bytes

    Raises:

    IOError – The patch was not opened for reading or a temporary file could not be written to disk.

    __repr__() → str[source]¶

    Return a string representation of the object.

    Returns:

    The string representation.

    Return type:

    str

    class rbtools.diffs.patches.PatchResult(*, applied: bool, has_conflicts: bool = False, conflicting_files: list[str] = [], patch_output: Optional[bytes] = None, patch: Optional[Patch] = None, patch_range: Optional[tuple[int, int]] = None)[source]¶

    Bases: object

    The result of a patch operation.

    This stores state on whether the patch could be applied (fully or partially), whether there are conflicts that can be resolved (as in conflict markers, not reject files), which files conflicted, and the patch output.

    Changed in version 5.1:

    • Moved from rbtools.clients.base.patch. That module will provide compatibility imports until RBTools 7.

    Changed in version 4.0:

    • Moved from rbtools.clients. That module will provide compatibility imports until RBTools 7.

    __init__(*, applied: bool, has_conflicts: bool = False, conflicting_files: list[str] = [], patch_output: Optional[bytes] = None, patch: Optional[Patch] = None, patch_range: Optional[tuple[int, int]] = None) → None[source]¶

    Initialize the object.

    Changed in version 5.1:

    • This now requires keyword-only arguments. Support for positional arguments will be removed in RBTools 7.

    • Added the patch and patch_range arguments.

    Parameters:
    • applied (bool) – Whether the patch was applied.

    • has_conflicts (bool, optional) – Whether the applied patch included conflicts.

    • conflicting_files (list of str, optional) – A list of the filenames containing conflicts.

    • patch_output (bytes, optional) – The output of the patch command.

    • patch (Patch, optional) –

      The patch that was being applied, if available.

      New in version 5.1.

    • patch_range (tuple, optional) –

      The range of patches represented by this result.

      This is in the form of:

      Tuple:
      • 0 (int) – The 1-based starting patch number.

      • 1 (int) – The 1-based ending patch number.

      New in version 5.1.

    applied: bool¶

    Whether the patch was applied.

    This will be True whether the patch was fully applied without issues, or partially applied. Callers sohuld check success to check for a successful application, and has_conflicts to check for conflicts.

    conflicting_files: list[str]¶

    A list of the filenames containing conflicts.

    has_conflicts: bool¶

    Whether the applied patch included conflicts.

    patch: Optional[Patch]¶

    The patch that was being applied.

    This may be None, depending on the method used to apply the patch.

    New in version 5.1.

    patch_output: Optional[bytes]¶

    The output of the patch command.

    patch_range: Optional[tuple[int, int]]¶

    The range of patches represented by this result.

    This is in the form of:

    Tuple:
    • 0 (int) – The 1-based starting patch number.

    • 1 (int) – The 1-based ending patch number.

    New in version 5.1.

    property success: bool[source]¶

    Whether this was a successful patch application.

    __repr__() → str[source]¶

    Return a string representation of the object.

    Returns:

    The string representation.

    Return type:

    str

    Keep up with the latest Review Board releases, security updates, and helpful information.

    About
    News
    Demo
    RBCommons Hosting
    Integrations
    Happy Users
    Support Options
    Documentation
    FAQ
    User Manual
    RBTools
    Administration Guide
    Power Pack
    Release Notes
    Downloads
    Review Board
    RBTools
    Djblets
    Power Pack
    Package Store
    PGP Signatures
    Contributing
    Bug Tracker
    Submit Patches
    Development Setup
    Wiki
    Follow Us
    Mailing Lists
    Reddit
    Twitter
    Mastodon
    Facebook
    YouTube

    Copyright © 2006-2025 Beanbag, Inc. All rights reserved.

    Terms of Service — Privacy Policy — AI Ethics Policy — Branding

    On this page

    • [Top]
    • PatchAuthor
      • PatchAuthor.__init__()
      • PatchAuthor.full_name
      • PatchAuthor.email
      • PatchAuthor.fullname
      • PatchAuthor.__eq__()
      • PatchAuthor.__repr__()
      • PatchAuthor.__hash__
    • Patch
      • Patch.__init__()
      • Patch.author
      • Patch.base_dir
      • Patch.message
      • Patch.prefix_level
      • Patch.open()
      • Patch.content
      • Patch.path
      • Patch.__repr__()
    • PatchResult
      • PatchResult.__init__()
      • PatchResult.applied
      • PatchResult.conflicting_files
      • PatchResult.has_conflicts
      • PatchResult.patch
      • PatchResult.patch_output
      • PatchResult.patch_range
      • PatchResult.success
      • PatchResult.__repr__()