Registry / devops / mercurial

mercurial

JSON →
library7.2.2pypypi✓ verified 85d ago

Mercurial is a fast, scalable, and distributed revision control (version control) system designed for efficient handling of projects of any size. It is primarily implemented in Python, with performance-critical parts in C and Rust. The library is actively maintained with regular releases, with version 7.2.1 being the latest stable release as of April 1, 2026.

pip install mercurial
INSTALL
IMPORT
SIG · MERCURIAL
M
mercurial
devopspythonv7.2.2
Install
3.2s avg
Import
801ms
Disk
51MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v7.2.2 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.836s · 48.7MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 3.2s · import 0.766s · 53MB
51MB installed
● package 51MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ui, hg
from mercurial import ui, hg
These are common imports for interacting with Mercurial's core API, typically when writing extensions or programmatic tools that embed Mercurial functionality.

This quickstart demonstrates how to programmatically initialize a Mercurial repository, create a file, and commit it using the internal `mercurial` Python API. This approach is typically used for developing Mercurial extensions or deeply embedded functionality. For simpler command-line interactions from Python, external libraries like `hglib` (for command server) or `hgapi` (wrapping CLI) might be considered as they offer a more stable API than the internal `mercurial` modules.

import os import shutil from mercurial import ui, hg # Create a dummy directory for the repository repo_path = 'my_test_repo' if os.path.exists(repo_path): shutil.rmtree(repo_path) os.makedirs(repo_path) # Initialize a new Mercurial repository repo = hg.repository(ui.ui(), repo_path, create=True) print(f"Repository initialized at: {repo_path}") # Create a file file_path = os.path.join(repo_path, 'hello.txt') with open(file_path, 'w') as f: f.write('Hello, Mercurial!') print(f"Created file: {file_path}") # Add and commit the file # Note: Mercurial's internal API for add/commit can be complex. # This example uses `add` and then `commit` via the repo object. # For simpler CLI-like interaction, consider `hglib` or `hgapi`. # The 'add' command is implicitly handled by `commit` for untracked files in newer versions/contexts, # but explicitly adding first is generally safer for robust scripts. repo.add([file_path]) repo.commit(text='Initial commit', user='Test User <test@example.com>') print("File committed.") # Verify the commit (optional: run hg log in the directory to confirm) # You would typically interact with changesets, manifests, etc. for more complex verification. logs = repo.changelog.read() # Read changelog to get revision info if logs: latest_rev = repo.changelog.tip() print(f"Latest revision: {latest_rev.node()[:12]}") print(f"Commit message: {latest_rev.description()}") # Clean up the test repository (optional) shutil.rmtree(repo_path) print(f"Cleaned up {repo_path}")
hg --version
Debug
Known issues
gotchaDirect use of Mercurial's internal Python API (e.g., `from mercurial import ...`) is primarily intended for writing extensions and is considered unstable. Its license is GPL-2.0-or-later. For stable, permissive-licensed programmatic interaction, consider `hgapi` which wraps the command-line interface, or `hglib` for the command server.
fix
For general repository operations from Python, evaluate using `hgapi` or `hglib`. If writing an extension, consult the official Mercurial extension development guides and be prepared for internal API changes.
affects: All versions
breakingMercurial has adjusted its Python version support over time. Version 6.9 dropped support for Python 3.6 and 3.7. Version 7.2.0 was likely the last to support Python 3.9, with future releases focusing on newer Python versions (e.g., 3.14, 3.15).
fix
Ensure your project uses Python >=3.9. For future compatibility, plan to upgrade Python versions as Mercurial support shifts. Check release notes for specific version requirements.
affects: 7.2.0 and later for Python 3.9; 6.9 and later for Python 3.6/3.7
breakingMercurial 7.0 introduced compliance with PEP 517 for packaging. This means `setup.py` can no longer be called directly for building; instead, PyPA's `build` package should be used. This primarily affects maintainers who build Mercurial from source or create custom distributions.
fix
If building Mercurial from source, use standard PEP 517 build tools (e.g., `python -m build`). Refer to the release notes for build-time dependencies (`wheel`, `setuptools`, `setuptools_scm`, `docutils`).
affects: 7.0 and later
breakingThe 7.2.1 release included a 'large import-cycle-breaking series' due to Python typing efforts. This refactoring, involving new files, may make merges more difficult for existing extension maintainers and could break older extensions that relied on specific internal import paths or structures.
fix
Extension maintainers should carefully review the raw changes and refactoring mentioned in the 7.2.1 release notes and adapt their extensions accordingly.
affects: 7.2.1 and later
Errors
Common errors & fixes
hg: command not found
The Mercurial executable ('hg') is not located in any directory specified in your system's PATH environment variable, preventing the shell from finding and executing the command.
fix
Add the directory where Mercurial is installed (e.g., C:\Program Files\Mercurial\ or /usr/local/bin) to your system's PATH environment variable.
abort: push creates new remote heads on branch 'default'!
The remote repository has new changes that are not present in your local repository, meaning your local push would create a divergent history ('new heads').
fix
First, pull the latest changes from the remote (`hg pull`), then merge them with your local changes (`hg merge`), commit the merged result (`hg commit -m "Merge..."`), and finally push (`hg push`).
abort: No such file or directory: /path/to/.hg/store/data/...
Mercurial cannot access or find a critical file within its internal repository structure, often due to manual deletion, filesystem corruption, or an incomplete/corrupted clone/update.
fix
Run `hg verify` to check the repository for corruption. If corruption is found and recent, consider re-cloning the repository. For specific missing `.hg` files, ensure they haven't been accidentally deleted or permissions aren't preventing access.
Mercurial will not let you commit files with unresolved merge conflicts.
After performing an `hg merge` operation, some files have conflicting changes that Mercurial could not automatically resolve, and these conflicts must be manually addressed before a commit can be made.
fix
Manually edit each file listed as 'U' (unresolved) by `hg status` to resolve the conflicts. Once a file is fixed, run `hg resolve -m <filename>` to mark it as resolved. Repeat for all conflicting files, then `hg commit`.
Upgrade
Version history
7.2.2latest on PyPI · released May 7, 2026
Audit
Dependencies
pythonrequiredMercurial requires Python 3.9 or newer. As of version 7.2.0, Python 3.9 support is likely to be deprecated in future releases.
zstdoptionalOptional dependency for improved ZSTD compression/decompression functionality, falling back to system package if vendored module is not available.
Agent activity
4 hits · last 30 days
ahrefsbot
1
Resources
mercurial — pip install mercurial · libregistry