52980
|
1 |
// update.rs
|
|
2 |
//
|
|
3 |
// Copyright 2025 Mercurial developers
|
|
4 |
//
|
|
5 |
// This software may be used and distributed according to the terms of the
|
|
6 |
// GNU General Public License version 2 or any later version.
|
|
7 |
|
|
8 |
//! Bindings for the `hg::update` module provided by the
|
|
9 |
//! `hg-core` package.
|
|
10 |
//!
|
|
11 |
//! From Python, this will be seen as `mercurial.pyo3_rustext.update`
|
|
12 |
use pyo3::prelude::*;
|
|
13 |
|
|
14 |
use hg::progress::{HgProgressBar, Progress};
|
|
15 |
use hg::update::update_from_null as core_update_from_null;
|
|
16 |
use hg::BaseRevision;
|
|
17 |
use pyo3::types::PyBytes;
|
|
18 |
|
|
19 |
use crate::exceptions::FallbackError;
|
|
20 |
use crate::repo::repo_from_path;
|
|
21 |
use crate::utils::{new_submodule, with_sigint_wrapper, HgPyErrExt};
|
|
22 |
|
|
23 |
/// See [`core_update_from_null`].
|
|
24 |
#[pyfunction]
|
|
25 |
#[pyo3(signature = (repo_path, to, num_cpus))]
|
|
26 |
pub fn update_from_null(
|
|
27 |
repo_path: &Bound<'_, PyBytes>,
|
|
28 |
to: BaseRevision,
|
|
29 |
num_cpus: Option<usize>,
|
|
30 |
) -> PyResult<usize> {
|
|
31 |
log::trace!("Using update from null fastpath");
|
|
32 |
let repo = repo_from_path(repo_path)?;
|
|
33 |
let progress: &dyn Progress = &HgProgressBar::new("updating");
|
|
34 |
|
|
35 |
with_sigint_wrapper(repo_path.py(), || {
|
|
36 |
core_update_from_null(&repo, to.into(), progress, num_cpus)
|
|
37 |
})?
|
|
38 |
.into_pyerr(repo_path.py())
|
|
39 |
}
|
|
40 |
|
|
41 |
pub fn init_module<'py>(
|
|
42 |
py: Python<'py>,
|
|
43 |
package: &str,
|
|
44 |
) -> PyResult<Bound<'py, PyModule>> {
|
|
45 |
let m = new_submodule(py, package, "update")?;
|
|
46 |
m.add("FallbackError", py.get_type::<FallbackError>())?;
|
|
47 |
m.add_function(wrap_pyfunction!(update_from_null, &m)?)?;
|
|
48 |
Ok(m)
|
|
49 |
}
|