rbtools.clients.svn¶
A client for Subversion.
Classes
|
A client for Subversion. |
|
A patcher that applies Subversion patches to a tree. |
|
Information on a Subversion repository. |
- class rbtools.clients.svn.SVNPatcher(*, scmclient: TSCMClient, **kwargs: Unpack[PatcherKwargs])[source]¶
Bases:
SCMClientPatcher
[SVNClient
]A patcher that applies Subversion patches to a tree.
This applies patches using svn patch and to manually handle added and deleted empty files.
The patcher supports tracking conflicts and partially-applied patches.
New in version 5.1.
- get_default_prefix_level(*, patch: Patch, base_dir: Optional[str] = None) Optional[int] [source]¶
Return the default path prefix strip level for a patch.
This function determines how much of a path to strip by default, if an explicit value isn’t given.
For Subversion, we always strip off any leading
/
.Changed in version 5.0.2:
Added the
base_dir
argument and changed to prefer that if present.
- Parameters:
patch (
rbtools.diffs.patches.Patch
) – The path to generate a default prefix strip level for.base_dir (
str
, optional) –The base directory to use when computing the prefix level, if available.
New in version 5.0.2.
- Returns:
The prefix strip level, or
None
if a clear one could not be determined.- Return type:
- apply_single_patch(*, patch: Patch, patch_num: int) PatchResult [source]¶
Apply a single patch.
This will take a single patch and apply it using Subversion.
- Parameters:
patch (
rbtools.diffs.patches.Patch
) – The patch to apply, opened for reading.patch_num (
int
) – The 1-based index of this patch in the full list of patches.
- Returns:
The result of the patch application, whether the patch applied successfully or with normal patch failures.
- Return type:
- apply_patch_for_empty_files(patch: Patch) bool [source]¶
Attempt to add or delete empty files in the patch.
- Parameters:
patch (
rbtools.diffs.patches.Patch
) – The opened patch to check and possibly apply.- Returns:
True
if there are empty files in the patch that were applied.False
if there were no empty files or the files could not be applied (which will lead to an error).
- __orig_bases__ = (rbtools.clients.base.scmclient.SCMClientPatcher[ForwardRef('SVNClient')],)¶
- __parameters__ = ()¶
- 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:
- server_tool_names: ClassVar[Optional[str]] = 'Subversion'[source]¶
A comma-separated list of SCMClient names on the server.
New in version 3.0.
- Type:
- server_tool_ids: ClassVar[Optional[List[str]]] = ['subversion'][source]¶
A comma-separated list of SCMClient IDs on the server.
This supersedes
server_tool_names
when running on a version of Review Board that supports passing tool IDs to the repositories list API.New in version 5.0.1.
- Type:
- patcher_cls[source]¶
alias of
SVNPatcher
- 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, orTrue
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.
- supports_diff_exclude_patterns: bool = True[source]¶
Whether the SCM client supports excluding files from the diff.
- Type:
- supports_patch_revert: bool = True[source]¶
Whether the SCM client supports reverting patches.
- Type:
- can_get_file_content: bool = True[source]¶
Whether the tool can get files at specific revisions.
New in version 5.0.
- Type:
- __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:
- 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:
- get_repository_info() Optional[RepositoryInfo] [source]¶
Return repository information for the current working tree.
- Returns:
The repository info structure.
- Return type:
- 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:
- 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
ofstr
, 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
andtip
.- Return type:
- 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:
- get_raw_commit_message(revisions: SCMClientRevisionSpec) str [source]¶
Return the raw commit message(s) for the given revisions.
- 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 byparse_revision_spec()
.include_files (
list
ofstr
, optional) – A list of files to whitelist during the diff generation.exclude_patterns (
list
ofstr
, 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:
- 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:
- Returns:
True
if any new files have been scheduled including their history.- Return type:
- 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.
- 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.
- 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
ofbytes
) – 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.
- parse_filename_header(diff_line: bytes) Tuple[str, bytes] [source]¶
Parse the filename header from a diff.
- 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:
- 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
wereTrue
) if an error occurs that is not an authentication error.- Parameters:
svn_args (
list
ofstr
) – A list of additional arguments to add to the SVN command line.*args (
list
) – Additional positional arguments to pass through torbtools.utils.process.execute()
.**kwargs (
dict
) – Additional keyword arguments to pass through torbtools.utils.process.execute()
.
- Returns:
The resulting log output.
- Return type:
- 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.
- get_file_content(*, filename: str, revision: str) bytes [source]¶
Return the contents of a file at a given revision.
New in version 5.0.
- Parameters:
- Returns:
The read file.
- Return type:
- Raises:
rbtools.clients.errors.SCMError – The file could not be found.
- 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 aspath
, 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.
- 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:
- 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.