##// END OF EJS Templates
errors: add config that lets user get more detailed exit codes...
errors: add config that lets user get more detailed exit codes This adds an experimental config that lets the user get more detailed exit codes. For example, there will be a specific error code for input/user errors. This is part of https://www.mercurial-scm.org/wiki/ErrorCategoriesPlan. I've made the config part of tweakdefaults. I've made the config enabled by default in tests. My reasoning is that we want to see that each specific error case gives the right exit code and we don't want to duplicate all error cases in the entire test suite. It also makes it easy to grep the `.t` files for `[255]` to find which cases we have left to fix. The logic for the current exit codes is quite simple, so I'm not too worried about regressions there. I've added a test case specifically for the "legacy" exit codes. I've set the detailed exit status only for the case of `InterventionRequired` and `SystemExit` for now (the cases where we currently return something other than 255), just to show that it works. Differential Revision: https://phab.mercurial-scm.org/D9238

File last commit:

r45500:26114bd6 default
r46430:21733e8c default
Show More
copymap.rs
118 lines | 3.1 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;
Yuya Nishihara
rust-cpython: move $leaked struct out of macro...
r43447 use crate::dirstate::dirstate_map::DirstateMap;
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 use hg::{utils::hg_path::HgPathBuf, CopyMapIter};
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,
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 res: (&HgPathBuf, &HgPathBuf),
Raphaël Gomès
rust-dirstate: rust-cpython bridge for dirstatemap...
r42999 ) -> PyResult<Option<PyBytes>> {
Raphaël Gomès
rust: do a clippy pass...
r45500 Ok(Some(PyBytes::new(py, res.0.as_bytes())))
Raphaël Gomès
rust-dirstate: rust-cpython bridge for dirstatemap...
r42999 }
fn translate_key_value(
py: Python,
Raphaël Gomès
rust-hgpath: replace all paths and filenames with HgPath/HgPathBuf...
r43227 res: (&HgPathBuf, &HgPathBuf),
Raphaël Gomès
rust-dirstate: rust-cpython bridge for dirstatemap...
r42999 ) -> PyResult<Option<(PyBytes, PyBytes)>> {
let (k, v) = res;
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)>
);