• 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 4.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.clients.svn
  • 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.diffs
  • 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.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.checks
  • rbtools.utils.commands
  • rbtools.utils.console
  • rbtools.utils.diffs
  • rbtools.utils.encoding
  • rbtools.utils.errors
  • rbtools.utils.filesystem
  • rbtools.utils.graphs
  • rbtools.utils.match_score
  • rbtools.utils.process
  • rbtools.utils.repository
  • rbtools.utils.review_request
  • rbtools.utils.source_tree
  • rbtools.utils.testbase
  • rbtools.utils.users
  • Glossary
  • General Index
  • Python Module Index
  • Release Notes
  • This documentation covers RBTools 4.x. You can select a version above or view the latest documentation.

    rbtools.clients.svn¶

    A client for Subversion.

    Classes

    SVNClient(**kwargs)

    A client for Subversion.

    SVNRepositoryInfo([path, base_path, uuid, ...])

    Information on a Subversion repository.

    class rbtools.clients.svn.SVNClient(**kwargs)[source]¶

    Bases: BaseSCMClient

    A client for Subversion.

    This is a wrapper around the svn executable that fetches repository information and generates compatible diffs.

    scmclient_id: str = 'svn'[source]¶

    The unique ID of the client.

    New in version 4.0: This will be required in RBTools 5.0.

    Type:

    str

    name: str = 'Subversion'[source]¶

    The name of the client.

    Type:

    str

    server_tool_names: Optional[str] = 'Subversion'[source]¶

    A comma-separated list of SCMClient names on the server

    New in version 3.0.

    Type:

    str

    requires_diff_tool: Union[bool, List[str]] = True[source]¶

    Whether this tool requires a command line diff tool.

    This may be a boolean or a list.

    If a boolean, then this must be False if no command line tool is required, or True if any command line tool supported by RBTools is available (in which case the SCMClient is responsible for ensuring compatibility).

    If a list, then this must be a list of registered diff tool IDs that are compatible.

    New in version 4.0.

    Type:

    bool or list

    supports_diff_exclude_patterns: bool = True[source]¶

    Whether the SCM client supports excluding files from the diff.

    Type:

    bool

    supports_patch_revert: bool = True[source]¶

    Whether the SCM client supports reverting patches.

    Type:

    bool

    INDEX_SEP = b'==================================================================='[source]¶
    INDEX_FILE_RE = re.compile(b'^Index: (.+?)(?:\\t\\((added|deleted)\\))?\\n$')[source]¶
    DIFF_ORIG_FILE_LINE_RE = re.compile(b'^---\\s+.*\\s+\\(.*\\)')[source]¶
    DIFF_NEW_FILE_LINE_RE = re.compile(b'^\\+\\+\\+\\s+.*\\s+\\(.*\\)')[source]¶
    DIFF_COMPLETE_REMOVAL_RE = re.compile(b'^@@ -1,\\d+ \\+0,0 @@$')[source]¶
    ADDED_FILES_RE = re.compile(b'^Index:\\s+(\\S+)\\t\\(added\\)$', re.MULTILINE)[source]¶
    DELETED_FILES_RE = re.compile(b'^Index:\\s+(\\S+)\\t\\(deleted\\)$', re.MULTILINE)[source]¶
    REVISION_WORKING_COPY = '--rbtools-working-copy'[source]¶
    REVISION_CHANGELIST_PREFIX = '--rbtools-changelist:'[source]¶
    VERSION_NUMBER_RE = re.compile('(\\d+)\\.(\\d+)\\.(\\d+)')[source]¶
    SHOW_COPIES_AS_ADDS_MIN_VERSION = (1, 7, 0)[source]¶
    PATCH_MIN_VERSION = (1, 7, 0)[source]¶
    subversion_client_version: Tuple[int, int, int]¶
    __init__(**kwargs) → None[source]¶

    Initialize the client.

    Parameters:

    **kwargs (dict) – Keyword arguments to pass through to the superclass.

    check_dependencies() → None[source]¶

    Check whether all dependencies for the client are available.

    This checks for the presence of svn in the system path.

    New in version 4.0.

    Raises:

    rbtools.clients.errors.SCMClientDependencyError – A git tool could not be found.

    is_remote_only() → bool[source]¶

    Return whether this repository is operating in remote-only mode.

    For SVN, if a user provides the repository URL on the command line or config file, RBTools can proceed without a checkout.

    Returns:

    Whether this repository is operating in remote-only mode.

    Return type:

    bool

    get_local_path() → Optional[str][source]¶

    Return the local path to the working tree.

    Returns:

    The filesystem path of the repository on the client system.

    Return type:

    str

    get_repository_info() → Optional[RepositoryInfo][source]¶

    Return repository information for the current working tree.

    Returns:

    The repository info structure.

    Return type:

    SVNRepositoryInfo

    find_matching_server_repository(repositories: ListResource) → Tuple[Optional[ItemResource], Optional[ItemResource]][source]¶

    Find a match for the repository on the server.

    Parameters:

    repositories (rbtools.api.resource.ListResource) – The fetched repositories.

    Returns:

    A 2-tuple of ItemResource. The first item is the matching repository, and the second is the repository info resource.

    Return type:

    tuple

    parse_revision_spec(revisions: List[str] = []) → SCMClientRevisionSpec[source]¶

    Parse the given revision spec.

    These will be used to generate the diffs to upload to Review Board (or print). The diff for review will include the changes in (base, tip].

    If a single revision is passed in, this will return the parent of that revision for “base” and the passed-in revision for “tip”.

    If zero revisions are passed in, this will return the most recently checked-out revision for ‘base’ and a special string indicating the working copy for “tip”.

    The SVN SCMClient never fills in the ‘parent_base’ key. Users who are using other patch-stack tools who want to use parent diffs with SVN will have to generate their diffs by hand.

    Parameters:

    revisions (list of str, optional) – A list of revisions as specified by the user.

    Returns:

    The parsed revision spec.

    See SCMClientRevisionSpec for the format of this dictionary.

    This always populates base and tip.

    Return type:

    dict

    Raises:
    • rbtools.clients.errors.InvalidRevisionSpecError – The given revisions could not be parsed.

    • rbtools.clients.errors.TooManyRevisionsError – The specified revisions list contained too many revisions.

    scan_for_server(repository_info: RepositoryInfo) → Optional[str][source]¶

    Scan for the reviewboard:url property in the repository.

    This method looks for the reviewboard:url property, which is an alternate (legacy) way of configuring the Review Board server URL inside a subversion repository.

    Parameters:

    repository_info (SVNRepositoryInfo) – The repository information structure.

    Returns:

    The Review Board server URL, if available.

    Return type:

    str

    get_raw_commit_message(revisions: SCMClientRevisionSpec) → str[source]¶

    Return the raw commit message(s) for the given revisions.

    Parameters:

    revisions (dict) – Revisions to get the commit messages for. This will contain tip and base keys.

    Returns:

    The commit messages for all the requested revisions.

    Return type:

    str

    diff(revisions: SCMClientRevisionSpec, *, include_files: List[str] = [], exclude_patterns: List[str] = [], **kwargs) → SCMClientDiffResult[source]¶

    Perform a diff in a Subversion repository.

    If the given revision spec is empty, this will do a diff of the modified files in the working directory. If the spec is a changelist, it will do a diff of the modified files in that changelist. If the spec is a single revision, it will show the changes in that revision. If the spec is two revisions, this will do a diff between the two revisions.

    SVN repositories do not support branches of branches in a way that makes parent diffs possible, so we never return a parent diff.

    Parameters:
    • revisions (dict) – A dictionary of revisions, as returned by parse_revision_spec().

    • include_files (list of str, optional) – A list of files to whitelist during the diff generation.

    • exclude_patterns (list of str, optional) – A list of shell-style glob patterns to blacklist during diff generation.

    • **kwargs (dict, unused) – Unused keyword arguments.

    Returns:

    A dictionary containing keys documented in rbtools.clients.base.scmclient.SCMClientDiffResult.

    Return type:

    dict

    history_scheduled_with_commit(repository_info: RepositoryInfo, changelist: Optional[str], include_files: List[str], exclude_patterns: List[str]) → bool[source]¶

    Return whether any files have history scheduled.

    Parameters:
    • changelist (str) – The changelist name, if specified.

    • include_files (list of str) – A list of files to whitelist during the diff generation.

    • exclude_patterns (list of str) – A list of shell-style glob patterns to blacklist during diff generation.

    Returns:

    True if any new files have been scheduled including their history.

    Return type:

    bool

    find_copyfrom(path: str) → Optional[str][source]¶

    Find the source filename for copied files.

    The output of ‘svn info’ reports the “Copied From” header when invoked on the exact path that was copied. If the current file was copied as a part of a parent or any further ancestor directory, ‘svn info’ will not report the origin. Thus it is needed to ascend from the path until either a copied path is found or there are no more path components to try.

    Parameters:

    path (str) – The filename of the copied file.

    Returns:

    The filename of the source of the copy.

    Return type:

    str

    handle_renames(diff_content: Iterator[bytes]) → Iterator[bytes][source]¶

    Fix up diff headers to properly show renames.

    The output of svn diff is incorrect when the file in question came into being via svn mv/cp. Although the patch for these files are relative to its parent, the diff header doesn’t reflect this. This function fixes the relevant section headers of the patch to portray this relationship.

    Parameters:

    diff_content (iterator of bytes) – The lines of the diff to process.

    Yields:

    bytes – Each processed line of the diff.

    convert_to_absolute_paths(diff_content: Iterator[bytes], repository_info: RepositoryInfo) → Iterator[bytes][source]¶

    Convert relative paths in a diff output to absolute paths.

    This handles paths that have been svn switched to other parts of the repository.

    Parameters:
    • diff_content (iterator of bytes) – The lines of the diff to process.

    • repository_info (SVNRepositoryInfo) – The repository info.

    Yields:

    bytes – Each processed line of the diff.

    svn_info(path, ignore_errors=False)[source]¶

    Return a dict which is the result of ‘svn info’ at a given path.

    Parameters:
    • path (str) – The path to the file being accessed.

    • ignore_errors (bool, optional) – Whether to ignore errors returned by svn info.

    Returns:

    The parsed svn info output.

    Return type:

    dict

    parse_filename_header(diff_line: bytes) → Tuple[str, bytes][source]¶

    Parse the filename header from a diff.

    Parameters:

    diff_line (bytes) – The line of the diff being parsed.

    Returns:

    The parsed header line. The filename will be decoded using the system filesystem encoding.

    Return type:

    tuple of (str, bytes)

    apply_patch(patch_file, base_path, base_dir, p=None, revert=False)[source]¶

    Apply the patch and return a PatchResult indicating its success.

    Changed in version 4.0: This now supports returning information on files with conflicts.

    Parameters:
    • patch_file (str) – The name of the patch file to apply.

    • base_path (str) – The base path that the diff was generated in.

    • base_dir (str) – The path of the current working directory relative to the root of the repository.

    • p (str, optional) – The prefix level of the diff.

    • revert (bool, optional) – Whether the patch should be reverted rather than applied.

    Returns:

    The result of the patch operation.

    Return type:

    rbtools.clients.base.patch.PatchResult

    apply_patch_for_empty_files(patch: bytes, p_num: Union[int, str], revert: bool = False) → bool[source]¶

    Attempt to add or delete empty files in the patch.

    Parameters:
    • patch (bytes) – The contents of the patch.

    • p_num (int) – The prefix level of the diff.

    • revert (bool, optional) – Whether the patch should be reverted rather than applied.

    Returns:

    True if there are empty files in the patch. False if there were no empty files, or if an error occurred while applying the patch.

    supports_empty_files() → bool[source]¶

    Check if the server supports added/deleted empty files.

    Returns:

    Whether the Review Board server supports empty added or deleted files.

    Return type:

    bool

    svn_log_xml(svn_args: List[str], *args, **kwargs) → Optional[bytes][source]¶

    Run SVN log non-interactively and retrieve XML output.

    We cannot run SVN log interactively and retrieve XML output because the authentication prompts will be intermixed with the XML output and cause XML parsing to fail.

    This function returns None (as if none_on_ignored_error were True) if an error occurs that is not an authentication error.

    Parameters:
    • svn_args (list of str) – A list of additional arguments to add to the SVN command line.

    • *args (list) – Additional positional arguments to pass through to rbtools.utils.process.execute().

    • **kwargs (dict) – Additional keyword arguments to pass through to rbtools.utils.process.execute().

    Returns:

    The resulting log output.

    Return type:

    bytes

    Raises:

    rbtools.clients.errors.AuthenticationError – Authentication to the remote repository failed.

    check_options() → None[source]¶

    Verify the command line options.

    Raises:

    rbtools.clients.errors.OptionsCheckError – The supplied command line options were incorrect. In particular, if a file has history scheduled with the commit, the user needs to explicitly choose what behavior they want.

    class rbtools.clients.svn.SVNRepositoryInfo(path: Optional[str] = None, base_path: Optional[str] = None, uuid: Optional[str] = None, local_path: Optional[str] = None, repository_id: Optional[int] = None, tool: Optional[SVNClient] = None)[source]¶

    Bases: RepositoryInfo

    Information on a Subversion repository.

    This stores information on the path and, optionally, UUID of a Subversion repository. It can match a local repository against those on a Review Board server.

    __init__(path: Optional[str] = None, base_path: Optional[str] = None, uuid: Optional[str] = None, local_path: Optional[str] = None, repository_id: Optional[int] = None, tool: Optional[SVNClient] = None) → None[source]¶

    Initialize the repository information.

    Parameters:
    • path (str) – Subversion checkout path.

    • base_path (str) – Root of the Subversion repository.

    • local_path (str) – The local filesystem path for the repository. This can sometimes be the same as path, but may not be (since that can contain a remote repository path).

    • uuid (str) – UUID of the Subversion repository.

    • repository_id (int, optional) – ID of the repository in the API. This is used primarily for testing purposes, and is not guaranteed to be set.

    • tool (rbtools.clients.base.scmclient.BaseSCMClient) – The SCM client.

    uuid: Optional[str]¶

    UUID of the Subversion repository.

    Type:

    str

    repository_id: Optional[int]¶

    ID of the repository in the API.

    This is used primarily for testing purposes, and is not guaranteed to be set.

    Type:

    int

    tool: Optional[SVNClient]¶

    The SVN client that owns this repository information.

    Type:

    SVNClient

    update_from_remote(repository: ItemResource, info: ItemResource) → None[source]¶

    Update the info from a remote repository.

    Parameters:
    • repository (rbtools.api.resource.ItemResource) – The repository resource.

    • info (rbtools.api.resource.ItemResource) – The repository info resource.

    find_server_repository_info(api_root: RootResource) → SVNRepositoryInfo[source]¶

    Return server-side information on the current Subversion repository.

    The point of this function is to find a repository on the server that matches self, even if the paths aren’t the same. (For example, if self uses an ‘http’ path, but the server uses a ‘file’ path for the same repository.) It does this by comparing repository UUIDs. If the repositories use the same path, you’ll get back self, otherwise you’ll get a different SVNRepositoryInfo object (with a different path).

    Deprecated since version 3.0: Commands which need to use the remote repository, or need data from the remote repository such as the base path, should set needs_repository.

    Parameters:

    api_root (rbtools.api.resource.RootResource) – The root resource for the Review Board server.

    Returns:

    The server-side information for this repository.

    Return type:

    SVNRepositoryInfo

    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]