##// END OF EJS Templates
contrib: add pull_logger extension...
contrib: add pull_logger extension This extension logs the pull parameters, i.e. the remote and common heads, when pulling from the local repository. The collected data should give an idea of the state of a pair of repositories and allow replaying past synchronisations between them. This is particularly useful for working on data exchange, bundling and caching-related optimisations.

File last commit:

r48833:627cd8f3 default
r50403:79105036 default
Show More
dirs_multiset.rs
124 lines | 3.7 KiB | application/rls-services+xml | RustLexer
Raphaël Gomès
rust-dirstate: create dirstate submodule in hg-cpython...
r42991 // dirs_multiset.rs
//
// Copyright 2019 Raphaël Gomès <rgomes@octobus.net>
//
// 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::dirstate::dirs_multiset` file provided by the
//! `hg-core` package.
use std::cell::RefCell;
use cpython::{
Simon Sapin
rust: Remove support for passing a dict to the Rust pathutil.dirs()...
r48833 exc, ObjectProtocol, PyBytes, PyClone, PyDict, PyErr, PyObject, PyResult,
Python, UnsafePyLeaked,
Raphaël Gomès
rust-dirstate: create dirstate submodule in hg-cpython...
r42991 };
Yuya Nishihara
rust-cpython: replace dyn Iterator<..> of sequence with concrete type...
r43157 use hg::{
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 utils::hg_path::{HgPath, HgPathBuf},
Simon Sapin
rust: Remove support for passing a dict to the Rust pathutil.dirs()...
r48833 DirsMultiset, DirsMultisetIter, DirstateMapError,
Yuya Nishihara
rust-cpython: replace dyn Iterator<..> of sequence with concrete type...
r43157 };
Raphaël Gomès
rust-dirstate: create dirstate submodule in hg-cpython...
r42991
py_class!(pub class Dirs |py| {
Yuya Nishihara
rust-cpython: switch to upstreamed version of PySharedRefCell...
r44703 @shared data inner: DirsMultiset;
Raphaël Gomès
rust-dirstate: create dirstate submodule in hg-cpython...
r42991
// `map` is either a `dict` or a flat iterator (usually a `set`, sometimes
// a `list`)
def __new__(
_cls,
map: PyObject,
) -> PyResult<Self> {
Simon Sapin
rust: Remove support for passing a dict to the Rust pathutil.dirs()...
r48833 let inner = if map.cast_as::<PyDict>(py).is_ok() {
let err = "pathutil.dirs() with a dict should only be used by the Python dirstatemap \
and should not be used when Rust is enabled";
return Err(PyErr::new::<exc::TypeError, _>(py, err.to_string()))
Raphaël Gomès
rust-dirstate: create dirstate submodule in hg-cpython...
r42991 } else {
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 let map: Result<Vec<HgPathBuf>, PyErr> = map
Raphaël Gomès
rust-dirstate: create dirstate submodule in hg-cpython...
r42991 .iter(py)?
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 .map(|o| {
Ok(HgPathBuf::from_bytes(
o?.extract::<PyBytes>(py)?.data(py),
))
})
Raphaël Gomès
rust-dirstate: create dirstate submodule in hg-cpython...
r42991 .collect();
Yuya Nishihara
rust-dirstate: split DirsMultiset constructor per input type...
r43070 DirsMultiset::from_manifest(&map?)
Raphaël Gomès
rust-dirs: handle forgotten `Result`s...
r44315 .map_err(|e| {
PyErr::new::<exc::ValueError, _>(py, e.to_string())
})?
Raphaël Gomès
rust-parsers: switch to parse/pack_dirstate to mutate-on-loop...
r42993 };
Raphaël Gomès
rust-dirstate: create dirstate submodule in hg-cpython...
r42991
Yuya Nishihara
rust-cpython: switch to upstreamed version of PySharedRefCell...
r44703 Self::create_instance(py, inner)
Raphaël Gomès
rust-dirstate: create dirstate submodule in hg-cpython...
r42991 }
def addpath(&self, path: PyObject) -> PyResult<PyObject> {
Yuya Nishihara
rust-cpython: rename inner_shared() to inner()...
r44702 self.inner(py).borrow_mut().add_path(
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 HgPath::new(path.extract::<PyBytes>(py)?.data(py)),
Raphaël Gomès
rust-dirs: address failing tests for `dirs` impl with a temporary fix...
r44227 ).and(Ok(py.None())).or_else(|e| {
match e {
DirstateMapError::EmptyPath => {
Ok(py.None())
},
e => {
Err(PyErr::new::<exc::ValueError, _>(
py,
e.to_string(),
))
}
}
})
Raphaël Gomès
rust-dirstate: create dirstate submodule in hg-cpython...
r42991 }
def delpath(&self, path: PyObject) -> PyResult<PyObject> {
Yuya Nishihara
rust-cpython: rename inner_shared() to inner()...
r44702 self.inner(py).borrow_mut().delete_path(
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 HgPath::new(path.extract::<PyBytes>(py)?.data(py)),
Raphaël Gomès
rust-dirstate: create dirstate submodule in hg-cpython...
r42991 )
.and(Ok(py.None()))
.or_else(|e| {
match e {
Raphaël Gomès
rust-dirs: address failing tests for `dirs` impl with a temporary fix...
r44227 DirstateMapError::EmptyPath => {
Ok(py.None())
},
e => {
Raphaël Gomès
rust-dirstate: create dirstate submodule in hg-cpython...
r42991 Err(PyErr::new::<exc::ValueError, _>(
py,
Raphaël Gomès
rust-dirs: address failing tests for `dirs` impl with a temporary fix...
r44227 e.to_string(),
Raphaël Gomès
rust-dirstate: create dirstate submodule in hg-cpython...
r42991 ))
}
}
})
}
Raphaël Gomès
rust-cpython: add macro for sharing references...
r42997 def __iter__(&self) -> PyResult<DirsMultisetKeysIterator> {
Yuya Nishihara
rust-cpython: rename inner_shared() to inner()...
r44702 let leaked_ref = self.inner(py).leak_immutable();
Yuya Nishihara
rust-cpython: leverage py_shared_iterator::from_inner() where appropriate
r43161 DirsMultisetKeysIterator::from_inner(
Raphaël Gomès
rust-cpython: add macro for sharing references...
r42997 py,
Yuya Nishihara
rust-cpython: make PyLeakedRef operations relatively safe...
r43579 unsafe { leaked_ref.map(py, |o| o.iter()) },
Raphaël Gomès
rust-cpython: add macro for sharing references...
r42997 )
Raphaël Gomès
rust-dirstate: create dirstate submodule in hg-cpython...
r42991 }
def __contains__(&self, item: PyObject) -> PyResult<bool> {
Yuya Nishihara
rust-cpython: rename inner_shared() to inner()...
r44702 Ok(self.inner(py).borrow().contains(HgPath::new(
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 item.extract::<PyBytes>(py)?.data(py).as_ref(),
)))
Raphaël Gomès
rust-dirstate: create dirstate submodule in hg-cpython...
r42991 }
});
Raphaël Gomès
rust-cpython: add macro for sharing references...
r42997
impl Dirs {
pub fn from_inner(py: Python, d: DirsMultiset) -> PyResult<Self> {
Yuya Nishihara
rust-cpython: switch to upstreamed version of PySharedRefCell...
r44703 Self::create_instance(py, d)
Raphaël Gomès
rust-cpython: add macro for sharing references...
r42997 }
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 fn translate_key(
py: Python,
res: &HgPathBuf,
) -> PyResult<Option<PyBytes>> {
Raphaël Gomès
rust: do a clippy pass...
r45500 Ok(Some(PyBytes::new(py, res.as_bytes())))
Raphaël Gomès
rust-cpython: add macro for sharing references...
r42997 }
}
Yuya Nishihara
rust-cpython: rename py_shared_iterator_impl to py_shared_iterator...
r43159 py_shared_iterator!(
Raphaël Gomès
rust-cpython: add macro for sharing references...
r42997 DirsMultisetKeysIterator,
Yuya Nishihara
rust-cpython: switch to upstreamed version of PySharedRefCell...
r44703 UnsafePyLeaked<DirsMultisetIter<'static>>,
Raphaël Gomès
rust-cpython: add macro for sharing references...
r42997 Dirs::translate_key,
Option<PyBytes>
);