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