Mercurial > public > mercurial-scm > hg-stable
changeset 52984:a39680ec3e76
pyo3: add a `repo` module
This will host all repo-related operations. For now, this only contains the
transliteration of the `repo_from_path` util from `hg-cpython`, but will
later probably grow.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Tue, 18 Feb 2025 11:45:50 +0100 |
parents | 69d40a9778fe |
children | a60d1eb74dc6 |
files | rust/hg-pyo3/src/lib.rs rust/hg-pyo3/src/repo.rs |
diffstat | 2 files changed, 22 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-pyo3/src/lib.rs Tue Feb 18 11:44:21 2025 +0100 +++ b/rust/hg-pyo3/src/lib.rs Tue Feb 18 11:45:50 2025 +0100 @@ -7,6 +7,7 @@ mod exceptions; mod node; mod path; +mod repo; mod revision; mod revlog; mod store;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rust/hg-pyo3/src/repo.rs Tue Feb 18 11:45:50 2025 +0100 @@ -0,0 +1,21 @@ +use hg::{config::Config, repo::Repo, utils::files::get_path_from_bytes}; +use pyo3::{ + types::{PyBytes, PyBytesMethods}, + Bound, PyResult, +}; + +use crate::utils::HgPyErrExt; + +/// Get a repository from a given [`PyObject`] path, and bubble up any error +/// that comes up. +pub fn repo_from_path(repo_path: &Bound<'_, PyBytes>) -> PyResult<Repo> { + // TODO make the Config a Python class and downcast it here, otherwise we + // lose CLI args and runtime overrides done in Python. + let config = Config::load_non_repo().into_pyerr(repo_path.py())?; + let repo = Repo::find( + &config, + Some(get_path_from_bytes(repo_path.as_bytes()).to_owned()), + ) + .into_pyerr(repo_path.py())?; + Ok(repo) +}