# HG changeset patch # User Rapha?l Gom?s # Date 1739875671 -3600 # Node ID a60d1eb74dc628a58400b721d6fefa69b94ea7c2 # Parent a39680ec3e7610057c96507923ef58ec5f2b08a7 pyo3: add `update` module This is a transliteration of the `update` module from `hg-cpython`. diff -r a39680ec3e76 -r a60d1eb74dc6 rust/hg-pyo3/src/lib.rs --- 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::())?; Ok(()) } diff -r a39680ec3e76 -r a60d1eb74dc6 rust/hg-pyo3/src/update.rs --- /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, +) -> PyResult { + 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> { + let m = new_submodule(py, package, "update")?; + m.add("FallbackError", py.get_type::())?; + m.add_function(wrap_pyfunction!(update_from_null, &m)?)?; + Ok(m) +}