52984
|
1 use hg::{config::Config, repo::Repo, utils::files::get_path_from_bytes};
|
|
2 use pyo3::{
|
|
3 types::{PyBytes, PyBytesMethods},
|
|
4 Bound, PyResult,
|
|
5 };
|
|
6
|
|
7 use crate::utils::HgPyErrExt;
|
|
8
|
|
9 /// Get a repository from a given [`PyObject`] path, and bubble up any error
|
|
10 /// that comes up.
|
|
11 pub fn repo_from_path(repo_path: &Bound<'_, PyBytes>) -> PyResult<Repo> {
|
|
12 // TODO make the Config a Python class and downcast it here, otherwise we
|
|
13 // lose CLI args and runtime overrides done in Python.
|
|
14 let config = Config::load_non_repo().into_pyerr(repo_path.py())?;
|
|
15 let repo = Repo::find(
|
|
16 &config,
|
|
17 Some(get_path_from_bytes(repo_path.as_bytes()).to_owned()),
|
|
18 )
|
|
19 .into_pyerr(repo_path.py())?;
|
|
20 Ok(repo)
|
|
21 }
|