##// END OF EJS Templates
backout: backed out changeset 5d83a40cd3f8...
backout: backed out changeset 5d83a40cd3f8 This is the re-send of the backout in D11757 that I accidentally queued. I'll rewrite the original commit message: ...sigh We do not have Python 3 packaging for thg on Windows where the vast majority of of users use the thg installer for Mercurial. Until this is done (hopefully this cycle), we're keeping Python. (end of the old commit message) On top of this, we have a solid lead to have competent people take care of this packaging issue for us in time for the 6.1 release, which is really the main reason for us to wait. We're trying our best to make this work, so please bear with us. Differential Revision: https://phab.mercurial-scm.org/D11770

File last commit:

r48882:bf8837e3 default
r49233:0ad593b6 default
Show More
copymap.rs
122 lines | 3.3 KiB | application/rls-services+xml | RustLexer
Raphaël Gomès
rust-dirstate: rust-cpython bridge for dirstatemap...
r42999 // copymap.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 `hg::dirstate::dirstate_map::CopyMap` provided by the
//! `hg-core` package.
Yuya Nishihara
rust-cpython: switch to upstreamed version of PySharedRefCell...
r44703 use cpython::{
PyBytes, PyClone, PyDict, PyObject, PyResult, Python, UnsafePyLeaked,
};
Raphaël Gomès
rust-dirstate: rust-cpython bridge for dirstatemap...
r42999 use std::cell::RefCell;
Simon Sapin
dirstate-v2: Make more APIs fallible, returning Result...
r48126 use crate::dirstate::dirstate_map::v2_error;
Yuya Nishihara
rust-cpython: move $leaked struct out of macro...
r43447 use crate::dirstate::dirstate_map::DirstateMap;
Simon Sapin
dirstate: Remove the flat Rust DirstateMap implementation...
r48882 use hg::dirstate::CopyMapIter;
Simon Sapin
dirstate-v2: Make more APIs fallible, returning Result...
r48126 use hg::dirstate_tree::on_disk::DirstateV2ParseError;
Simon Sapin
rust: Use `&HgPath` instead of `&HgPathBuf` in may APIs...
r47894 use hg::utils::hg_path::HgPath;
Raphaël Gomès
rust-dirstate: rust-cpython bridge for dirstatemap...
r42999
py_class!(pub class CopyMap |py| {
data dirstate_map: DirstateMap;
def __getitem__(&self, key: PyObject) -> PyResult<PyBytes> {
(*self.dirstate_map(py)).copymapgetitem(py, key)
}
def __len__(&self) -> PyResult<usize> {
self.dirstate_map(py).copymaplen(py)
}
def __contains__(&self, key: PyObject) -> PyResult<bool> {
self.dirstate_map(py).copymapcontains(py, key)
}
def get(
&self,
key: PyObject,
default: Option<PyObject> = None
) -> PyResult<Option<PyObject>> {
self.dirstate_map(py).copymapget(py, key, default)
}
def pop(
&self,
key: PyObject,
default: Option<PyObject> = None
) -> PyResult<Option<PyObject>> {
self.dirstate_map(py).copymappop(py, key, default)
}
def __iter__(&self) -> PyResult<CopyMapKeysIterator> {
self.dirstate_map(py).copymapiter(py)
}
// Python's `dict()` builtin works with either a subclass of dict
// or an abstract mapping. Said mapping needs to implement `__getitem__`
// and `keys`.
def keys(&self) -> PyResult<CopyMapKeysIterator> {
self.dirstate_map(py).copymapiter(py)
}
def items(&self) -> PyResult<CopyMapItemsIterator> {
self.dirstate_map(py).copymapitemsiter(py)
}
def iteritems(&self) -> PyResult<CopyMapItemsIterator> {
self.dirstate_map(py).copymapitemsiter(py)
}
def __setitem__(
&self,
key: PyObject,
item: PyObject
) -> PyResult<()> {
self.dirstate_map(py).copymapsetitem(py, key, item)?;
Ok(())
}
def copy(&self) -> PyResult<PyDict> {
self.dirstate_map(py).copymapcopy(py)
}
});
impl CopyMap {
pub fn from_inner(py: Python, dm: DirstateMap) -> PyResult<Self> {
Self::create_instance(py, dm)
}
fn translate_key(
py: Python,
Simon Sapin
dirstate-v2: Make more APIs fallible, returning Result...
r48126 res: Result<(&HgPath, &HgPath), DirstateV2ParseError>,
Raphaël Gomès
rust-dirstate: rust-cpython bridge for dirstatemap...
r42999 ) -> PyResult<Option<PyBytes>> {
Simon Sapin
dirstate-v2: Make more APIs fallible, returning Result...
r48126 let (k, _v) = res.map_err(|e| v2_error(py, e))?;
Ok(Some(PyBytes::new(py, k.as_bytes())))
Raphaël Gomès
rust-dirstate: rust-cpython bridge for dirstatemap...
r42999 }
fn translate_key_value(
py: Python,
Simon Sapin
dirstate-v2: Make more APIs fallible, returning Result...
r48126 res: Result<(&HgPath, &HgPath), DirstateV2ParseError>,
Raphaël Gomès
rust-dirstate: rust-cpython bridge for dirstatemap...
r42999 ) -> PyResult<Option<(PyBytes, PyBytes)>> {
Simon Sapin
dirstate-v2: Make more APIs fallible, returning Result...
r48126 let (k, v) = res.map_err(|e| v2_error(py, e))?;
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 Ok(Some((
Raphaël Gomès
rust: do a clippy pass...
r45500 PyBytes::new(py, k.as_bytes()),
PyBytes::new(py, v.as_bytes()),
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 )))
Raphaël Gomès
rust-dirstate: rust-cpython bridge for dirstatemap...
r42999 }
}
Yuya Nishihara
rust-cpython: rename py_shared_iterator_impl to py_shared_iterator...
r43159 py_shared_iterator!(
Raphaël Gomès
rust-dirstate: rust-cpython bridge for dirstatemap...
r42999 CopyMapKeysIterator,
Yuya Nishihara
rust-cpython: switch to upstreamed version of PySharedRefCell...
r44703 UnsafePyLeaked<CopyMapIter<'static>>,
Raphaël Gomès
rust-dirstate: rust-cpython bridge for dirstatemap...
r42999 CopyMap::translate_key,
Option<PyBytes>
);
Yuya Nishihara
rust-cpython: rename py_shared_iterator_impl to py_shared_iterator...
r43159 py_shared_iterator!(
Raphaël Gomès
rust-dirstate: rust-cpython bridge for dirstatemap...
r42999 CopyMapItemsIterator,
Yuya Nishihara
rust-cpython: switch to upstreamed version of PySharedRefCell...
r44703 UnsafePyLeaked<CopyMapIter<'static>>,
Raphaël Gomès
rust-dirstate: rust-cpython bridge for dirstatemap...
r42999 CopyMap::translate_key_value,
Option<(PyBytes, PyBytes)>
);