Mercurial > public > mercurial-scm > hg-stable
changeset 52985:a60d1eb74dc6
pyo3: add `update` module
This is a transliteration of the `update` module from `hg-cpython`.
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Tue, 18 Feb 2025 11:47:51 +0100 |
parents | a39680ec3e76 |
children | 1a99bdbdb71b |
files | rust/hg-pyo3/src/lib.rs rust/hg-pyo3/src/update.rs |
diffstat | 2 files changed, 51 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/rust/hg-pyo3/src/lib.rs Tue Feb 18 11:45:50 2025 +0100 +++ b/rust/hg-pyo3/src/lib.rs Tue Feb 18 11:47:51 2025 +0100 @@ -12,6 +12,7 @@ mod revlog; mod store; mod transaction; +mod update; mod utils; #[pymodule] @@ -29,6 +30,7 @@ m.add_submodule(&dirstate::init_module(py, &dotted_name)?)?; m.add_submodule(&discovery::init_module(py, &dotted_name)?)?; m.add_submodule(&revlog::init_module(py, &dotted_name)?)?; + m.add_submodule(&update::init_module(py, &dotted_name)?)?; m.add("GraphError", py.get_type::<exceptions::GraphError>())?; Ok(()) }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rust/hg-pyo3/src/update.rs Tue Feb 18 11:47:51 2025 +0100 @@ -0,0 +1,49 @@ +// update.rs +// +// Copyright 2025 Mercurial developers +// +// This software may be used and distributed according to the terms of the +// GNU General Public License version 2 or any later version. + +//! Bindings for the `hg::update` module provided by the +//! `hg-core` package. +//! +//! From Python, this will be seen as `mercurial.pyo3_rustext.update` +use pyo3::prelude::*; + +use hg::progress::{HgProgressBar, Progress}; +use hg::update::update_from_null as core_update_from_null; +use hg::BaseRevision; +use pyo3::types::PyBytes; + +use crate::exceptions::FallbackError; +use crate::repo::repo_from_path; +use crate::utils::{new_submodule, with_sigint_wrapper, HgPyErrExt}; + +/// See [`core_update_from_null`]. +#[pyfunction] +#[pyo3(signature = (repo_path, to, num_cpus))] +pub fn update_from_null( + repo_path: &Bound<'_, PyBytes>, + to: BaseRevision, + num_cpus: Option<usize>, +) -> PyResult<usize> { + log::trace!("Using update from null fastpath"); + let repo = repo_from_path(repo_path)?; + let progress: &dyn Progress = &HgProgressBar::new("updating"); + + with_sigint_wrapper(repo_path.py(), || { + core_update_from_null(&repo, to.into(), progress, num_cpus) + })? + .into_pyerr(repo_path.py()) +} + +pub fn init_module<'py>( + py: Python<'py>, + package: &str, +) -> PyResult<Bound<'py, PyModule>> { + let m = new_submodule(py, package, "update")?; + m.add("FallbackError", py.get_type::<FallbackError>())?; + m.add_function(wrap_pyfunction!(update_from_null, &m)?)?; + Ok(m) +}