rbtools.clients.mercurial¶
A client for Mercurial.
Classes
|
A client for Mercurial. |
|
A patcher that applies Mercurial patches to a tree. |
Types of references in Mercurial. |
- class rbtools.clients.mercurial.MercurialClient(*, executable: str = 'hg', **kwargs)[source]¶
Bases:
BaseSCMClientA client for Mercurial.
This is a wrapper around the hg executable that fetches repository information and generates compatible diffs.
- __firstlineno__ = 371¶
- __static_attributes__ = ('_exe', '_hg_env', '_hg_root', '_hgext_path', '_hidden_changesets_supported', '_initted', '_remote_path', '_remote_path_candidates', '_svn_info', '_type', 'hgrc')¶
- can_get_file_content: bool = True[source]¶
Whether the tool can get files at specific revisions.
Added in version 5.0.
- Type:
- check_dependencies() None[source]¶
Check whether all base dependencies are available.
This checks for the presence of hg (or whichever executable is passed in to the client’s constructor) in the system path.
Added in version 4.0.
- Raises:
rbtools.clients.errors.SCMClientDependencyError – A hg tool could not be found.
- create_commit(message: str, author: PatchAuthor | None, run_editor: bool, files: Sequence[str] | None = None, all_files: bool = False) None[source]¶
Create a commit based on the provided message and author.
Changed in version 6.0: The
authorcan now beNone, for cases where author information is not available (e.g. authors who have private profiles).- Parameters:
message (
str) – The commit message to use.author (
rbtools.diffs.patches.PatchAuthor) –The author of the commit.
Changed in version 6.0: This can now be
None, for cases where author information is not available (e.g. authors who have private profiles).run_editor (
bool) – Whether to run the user’s editor on the commit message before committing.files (
listofstr, optional) – The list of filenames to commit.all_files (
bool, optional) – Whether to commit all changed files, ignoring thefilesargument.
- Raises:
rbtools.clients.errors.CreateCommitError – The commit message could not be created. It may have been aborted by the user.
- diff(revisions: SCMClientRevisionSpec | None, *, include_files: Sequence[str] | None = None, exclude_patterns: Sequence[str] | None = None, with_parent_diff: bool = True, **kwargs) SCMClientDiffResult[source]¶
Perform a diff using the given revisions.
This will generate a Git-style diff and parent diff (if needed) for the provided revisions. The diff will contain additional metadata headers used by Review Board to locate the appropriate revisions from the repository.
- Parameters:
revisions (
dict) – A dictionary of revisions, as returned byparse_revision_spec().include_files (
listofstr, optional) – A list of files to whitelist during the diff generation.exclude_patterns (
listofstr, optional) – A list of shell-style glob patterns to blacklist during diff generation.with_parent_diff (
bool, optional) – Whether or not to include the parent diff in the result.**kwargs (
dict, unused) – Unused keyword arguments.
- Returns:
A dictionary containing keys documented in
SCMClientDiffResult.- Return type:
- get_commit_history(revisions: SCMClientRevisionSpec) list[SCMClientCommitHistoryItem] | None[source]¶
Return the commit history specified by the revisions.
- Parameters:
revisions (
dict) – A dictionary of revisions to generate history for, as returned byparse_revision_spec().- Returns:
This list of history entries, in order.
- Return type:
- Raises:
rbtools.clients.errors.SCMError – The history is non-linear or there is a commit with no parents.
- get_current_bookmark() str[source]¶
Return the name of the current bookmark.
- Returns:
A string with the name of the current bookmark.
- Return type:
- get_file_content(*, filename: str, revision: str) bytes[source]¶
Return the contents of a file at a given revision.
Added in version 5.0.
- get_file_size(*, filename: str, revision: str) int[source]¶
Return the size of a file at a given revision.
Added in version 5.0.
- get_hg_ref_type(ref: str) str[source]¶
Return the type of a reference in Mercurial.
This can be used to determine if something is a bookmark, branch, tag, or revision.
- Parameters:
ref (
str) – The reference to return the type for.- Returns:
The reference type. This will be a value in
MercurialRefType.- Return type:
- get_local_path() str | None[source]¶
Return the local path to the working tree.
- Returns:
The filesystem path of the repository on the client system.
- Return type:
- get_raw_commit_message(revisions: SCMClientRevisionSpec) str[source]¶
Return the raw commit message.
This extracts all descriptions in the given revision range and concatenates them, most recent ones going first.
- get_repository_info() RepositoryInfo | None[source]¶
Return repository information for the current working tree.
- Returns:
The repository info structure.
- Return type:
- has_pending_changes() bool[source]¶
Check if there are changes waiting to be committed.
- Returns:
Trueif the working directory has been modified, otherwise returnsFalse.- Return type:
- property hg_root: str | None[source]¶
Return the root of the working directory.
This will return the root directory of the current repository. If the current working directory is not inside a mercurial repository, this returns None.
- Type:
Return whether the repository supports hidden changesets.
Mercurial 1.9 and above support hidden changesets. These are changesets that have been hidden from regular repository view. They still exist and are accessible, but only if the –hidden command argument is specified.
Since we may encounter hidden changesets (e.g. the user specifies hidden changesets as part of the revision spec), we need to be aware of hidden changesets.
- Type:
- merge(target: str, destination: str, message: str, author: PatchAuthor | None, squash: bool = False, run_editor: bool = False, close_branch: bool = False, **kwargs) None[source]¶
Merge the target branch with destination branch.
Changed in version 6.0: The
authorcan now beNone, for cases where author information is not available (e.g. authors who have private profiles).- Parameters:
target (
str) – The name of the branch to merge.destination (
str) – The name of the branch to merge into.message (
str) – The commit message to use.author (
rbtools.diffs.patches.PatchAuthor) –The author of the commit.
Changed in version 6.0: This can now be
None, for cases where author information is not available (e.g. authors who have private profiles).squash (
bool, optional) – Whether to squash the commits or do a plain merge. This is not used for Mercurial.run_editor (
bool, optional) – Whether to run the user’s editor on the commit message before committing.close_branch (
bool, optional) – Whether to delete the branch after merging.**kwargs (
dict, unused) – Additional keyword arguments passed, for future expansion.
- Raises:
rbtools.clients.errors.MergeError – An error occurred while merging the branch.
- parse_revision_spec(revisions: Sequence[str] | None = None) 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], and the parent diff (if necessary) will include (parent, base].
If zero revisions are passed in, this will return the outgoing changes from the parent of the working directory.
If a single revision is passed in, this will return the parent of that revision for “base” and the passed-in revision for “tip”. This will result in generating a diff for the changeset specified.
If two revisions are passed in, they will be used for the “base” and “tip” revisions, respectively.
In all cases, a parent base will be calculated automatically from changesets not present on the remote.
- Parameters:
revisions (
listofstr, optional) – A list of revisions as specified by the user.- Returns:
The parsed revision spec.
See
SCMClientRevisionSpecfor the format of this dictionary.This always populates
baseandtip.commit_idandparent_basemay also be populated.- 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.
- patcher_cls[source]¶
alias of
MercurialPatcher
- scan_for_server(repository_info: RepositoryInfo) str | None[source]¶
Find the Review Board server matching this repository.
- Parameters:
repository_info (
rbtools.clients.base.repository.RepositoryInfo) – The repository information structure.- Returns:
The Review Board server URL, if available.
- Return type:
- scmclient_id: str = 'mercurial'[source]¶
The unique ID of the client.
Added in version 4.0: This will be required in RBTools 5.0.
- Type:
- server_tool_ids: ClassVar[Sequence[str] | None] = ['mercurial', 'subversion'][source]¶
A comma-separated list of SCMClient IDs on the server.
This supersedes
server_tool_nameswhen running on a version of Review Board that supports passing tool IDs to the repositories list API.Added in version 5.0.1.
- Type:
- server_tool_names: ClassVar[str | None] = 'Mercurial,Subversion'[source]¶
A comma-separated list of SCMClient names on the server.
Added in version 3.0.
- Type:
- supports_commit_history: bool = True[source]¶
Whether the SCM client can generate a commit history.
- Type:
- supports_diff_exclude_patterns: bool = True[source]¶
Whether the SCM client supports excluding files from the diff.
- Type:
- class rbtools.clients.mercurial.MercurialPatcher(*, scmclient: TSCMClient, **kwargs: Unpack[PatcherKwargs])[source]¶
Bases:
SCMClientPatcher[MercurialClient]A patcher that applies Mercurial patches to a tree.
This applies patches using hg import and to manually handle added and deleted empty files.
The patcher supports tracking conflicts and partially-applied patches.
Added in version 5.1.
- __annotations_cache__ = {}¶
- __firstlineno__ = 70¶
- __static_attributes__ = ()¶
- apply_patches() Iterator[PatchResult][source]¶
Internal function to apply the patches.
If applying files without committing, we’ll open all the files and apply in one hg import operation, helping Mercurial apply them correctly and without triggering an “uncommitted changes” error.
If we’re applying while committing, we’ll use the default Patcher logic to apply and commit them one-by-one.
- Yields:
rbtools.diffs.patches.PatchResult– The result of each patch application, whether the patch applied successfully or with normal patch failures.- Raises:
rbtools.diffs.errors.ApplyPatchResult – There was an error attempting to apply a patch. This won’t be raised simply for conflicts or normal patch failures. It may be raised for errors encountered during the patching process.
- apply_single_patch(*, patch: Patch, patch_num: int) PatchResult[source]¶
Internal function to 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: