• 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.mercurial
  • 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.mercurial¶

    A client for Mercurial.

    Classes

    MercurialClient([executable])

    A client for Mercurial.

    MercurialRefType()

    Types of references in Mercurial.

    class rbtools.clients.mercurial.MercurialRefType[source]¶

    Bases: object

    Types of references in Mercurial.

    REVISION = 'revision'[source]¶

    Revision hashes.

    BRANCH = 'branch'[source]¶

    Branch names.

    BOOKMARK = 'bookmark'[source]¶

    Bookmark names.

    TAG = 'tag'[source]¶

    Tag names.

    UNKNOWN = 'unknown'[source]¶

    Unknown references.

    class rbtools.clients.mercurial.MercurialClient(executable='hg', **kwargs)[source]¶

    Bases: BaseSCMClient

    A client for Mercurial.

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

    scmclient_id: str = 'mercurial'[source]¶

    The unique ID of the client.

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

    Type:

    str

    name: str = 'Mercurial'[source]¶

    The name of the client.

    Type:

    str

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

    A comma-separated list of SCMClient names on the server

    New in version 3.0.

    Type:

    str

    supports_commit_history: bool = True[source]¶

    Whether the SCM client can generate a commit history.

    Type:

    bool

    supports_diff_exclude_patterns: bool = True[source]¶

    Whether the SCM client supports excluding files from the diff.

    Type:

    bool

    supports_parent_diffs: bool = True[source]¶

    Whether the SCM client supports generating parent diffs.

    New in version 3.0.

    Type:

    bool

    can_bookmark: bool = True[source]¶

    Whether new bookmarks can be created.

    Type:

    bool

    can_branch: bool = True[source]¶

    Whether new branches can be created.

    Type:

    bool

    can_merge: bool = True[source]¶

    Whether the SCM can create merges.

    Type:

    bool

    PRE_CREATION = '/dev/null'[source]¶
    PRE_CREATION_DATE = 'Thu Jan 01 00:00:00 1970 +0000'[source]¶
    NO_PARENT = '0000000000000000000000000000000000000000'[source]¶
    __init__(executable='hg', **kwargs)[source]¶

    Initialize the client.

    Parameters:

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

    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.

    New in version 4.0.

    Raises:

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

    property hidden_changesets_supported[source]¶

    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.

    property hg_root[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.

    get_commit_history(revisions)[source]¶

    Return the commit history specified by the revisions.

    Parameters:

    revisions (dict) – A dictionary of revisions to generate history for, as returned by parse_revision_spec().

    Returns:

    This list of history entries, in order.

    Return type:

    list of dict

    Raises:

    rbtools.clients.errors.SCMError – The history is non-linear or there is a commit with no parents.

    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:

    rbtools.clients.base.repository.RepositoryInfo

    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], 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 (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.

    commit_id and parent_base may also be populated.

    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.

    get_hg_ref_type(ref)[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 (unicode) – The reference to return the type for.

    Returns:

    The reference type. This will be a value in MercurialRefType.

    Return type:

    unicode

    get_raw_commit_message(revisions)[source]¶

    Return the raw commit message.

    This extracts all descriptions in the given revision range and concatenates them, most recent ones going first.

    Parameters:

    revisions (dict) – A dictionary containing base and tip keys.

    Returns:

    The commit messages of all commits between (base, tip].

    Return type:

    unicode

    diff(revisions: SCMClientRevisionSpec, *, include_files: List[str] = [], exclude_patterns: List[str] = [], 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 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.

    • 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:

    dict

    create_commit(message, author, run_editor, files=[], all_files=False)[source]¶

    Commit the given modified files.

    This is expected to be called after applying a patch. This commits the patch using information from the review request, opening the commit message in $EDITOR to allow the user to update it.

    Parameters:
    • message (unicode) – The commit message to use.

    • author (object) – The author of the commit. This is expected to have fullname and email attributes.

    • run_editor (bool) – Whether to run the user’s editor on the commmit message before committing.

    • files (list of unicode, optional) – The list of filenames to commit.

    • all_files (bool, optional) – Whether to commit all changed files, ignoring the files argument.

    Raises:

    rbtools.clients.errors.CreateCommitError – The commit message could not be created. It may have been aborted by the user.

    merge(target, destination, message, author, squash=False, run_editor=False, close_branch=False, **kwargs)[source]¶

    Merge the target branch with destination branch.

    Parameters:
    • target (unicode) – The name of the branch to merge.

    • destination (unicode) – The name of the branch to merge into.

    • message (unicode) – The commit message to use.

    • author (object) – The author of the commit. This is expected to have fullname and email attributes.

    • 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 commmit 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.

    scan_for_server(repository_info)[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:

    unicode

    has_pending_changes()[source]¶

    Check if there are changes waiting to be committed.

    Returns:

    True if the working directory has been modified, otherwise returns False.

    Return type:

    bool

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

    Apply the given patch.

    This will take the given patch file and apply it to the working directory.

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

    • base_path (unicode, unused) – The base path that the diff was generated in. All hg diffs are absolute to the repository root, so this is unused.

    • base_dir (unicode, unused) – The path of the current working directory relative to the root of the repository. All hg diffs are absolute to the repository root, so this is unused.

    • p (unicode, 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, p_num, revert=False)[source]¶

    Return whether any empty files in the patch are applied.

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

    • p_num (unicode) – 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()[source]¶

    Return whether the RB server supports added/deleted empty files.

    Returns:

    True if the Review Board server supports showing empty files.

    Return type:

    bool

    get_current_bookmark()[source]¶

    Return the name of the current bookmark.

    Returns:

    A string with the name of the current bookmark.

    Return type:

    unicode

    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]