Details
Details
- Reviewers
kevincox - Group Reviewers
hg-reviewers - Commits
- rHGd26e4a434fe5: rust: run rfmt on all hg-core/hg-cpython code
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
( )
kevincox |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | rust/hg-core/src/dirstate/dirs_multiset.rs (4 lines) | |||
M | rust/hg-cpython/src/dagops.rs (2 lines) | |||
M | rust/hg-cpython/src/exceptions.rs (27 lines) | |||
M | rust/hg-cpython/src/lib.rs (20 lines) |
Commit | Parents | Author | Summary | Date |
---|---|---|---|---|
Raphaël Gomès | Jul 1 2019, 4:50 AM |
let val = entry.get().clone(); | let val = entry.get().clone(); | ||||
if val > 1 { | if val > 1 { | ||||
entry.insert(val - 1); | entry.insert(val - 1); | ||||
break; | break; | ||||
} | } | ||||
entry.remove(); | entry.remove(); | ||||
} | } | ||||
Entry::Vacant(_) => { | Entry::Vacant(_) => { | ||||
return Err(DirstateMapError::PathNotFound(path.to_owned())) | return Err(DirstateMapError::PathNotFound( | ||||
path.to_owned(), | |||||
)) | |||||
} | } | ||||
}; | }; | ||||
pos = subpath.len(); | pos = subpath.len(); | ||||
if pos == 0 { | if pos == 0 { | ||||
break; | break; | ||||
} | } | ||||
} | } |
// dagops.rs | // dagops.rs | ||||
// | // | ||||
// Copyright 2019 Georges Racinet <georges.racinet@octobus.net> | // Copyright 2019 Georges Racinet <georges.racinet@octobus.net> | ||||
// | // | ||||
// This software may be used and distributed according to the terms of the | // This software may be used and distributed according to the terms of the | ||||
// GNU General Public License version 2 or any later version. | // GNU General Public License version 2 or any later version. | ||||
//! Bindings for the `hg::dagops` module provided by the | //! Bindings for the `hg::dagops` module provided by the | ||||
//! `hg-core` package. | //! `hg-core` package. | ||||
//! | //! | ||||
//! From Python, this will be seen as `mercurial.rustext.dagop` | //! From Python, this will be seen as `mercurial.rustext.dagop` | ||||
use crate::conversion::{py_set, rev_pyiter_collect}; | |||||
use cindex::Index; | use cindex::Index; | ||||
use cpython::{PyDict, PyModule, PyObject, PyResult, Python}; | use cpython::{PyDict, PyModule, PyObject, PyResult, Python}; | ||||
use crate::conversion::{py_set, rev_pyiter_collect}; | |||||
use exceptions::GraphError; | use exceptions::GraphError; | ||||
use hg::dagops; | use hg::dagops; | ||||
use hg::Revision; | use hg::Revision; | ||||
use std::collections::HashSet; | use std::collections::HashSet; | ||||
/// Using the the `index`, return heads out of any Python iterable of Revisions | /// Using the the `index`, return heads out of any Python iterable of Revisions | ||||
/// | /// | ||||
/// This is the Rust counterpart for `mercurial.dagop.headrevs` | /// This is the Rust counterpart for `mercurial.dagop.headrevs` |
// ancestors.rs | // ancestors.rs | ||||
// | // | ||||
// Copyright 2018 Georges Racinet <gracinet@anybox.fr> | // Copyright 2018 Georges Racinet <gracinet@anybox.fr> | ||||
// | // | ||||
// This software may be used and distributed according to the terms of the | // This software may be used and distributed according to the terms of the | ||||
// GNU General Public License version 2 or any later version. | // GNU General Public License version 2 or any later version. | ||||
//! Bindings for Rust errors | //! Bindings for Rust errors | ||||
//! | //! | ||||
//! [`GraphError`] exposes `hg::GraphError` as a subclass of `ValueError` | //! [`GraphError`] exposes `hg::GraphError` as a subclass of `ValueError` | ||||
//! but some variants of `hg::GraphError` can be converted directly to other | //! but some variants of `hg::GraphError` can be converted directly to other | ||||
//! existing Python exceptions if appropriate. | //! existing Python exceptions if appropriate. | ||||
//! | //! | ||||
//! [`GraphError`]: struct.GraphError.html | //! [`GraphError`]: struct.GraphError.html | ||||
use cpython::exc::{ValueError, RuntimeError}; | use cpython::exc::{RuntimeError, ValueError}; | ||||
use cpython::{PyErr, Python, exc}; | use cpython::{exc, PyErr, Python}; | ||||
use hg; | use hg; | ||||
py_exception!(rustext, GraphError, ValueError); | py_exception!(rustext, GraphError, ValueError); | ||||
impl GraphError { | impl GraphError { | ||||
pub fn pynew(py: Python, inner: hg::GraphError) -> PyErr { | pub fn pynew(py: Python, inner: hg::GraphError) -> PyErr { | ||||
match inner { | match inner { | ||||
hg::GraphError::ParentOutOfRange(r) => { | hg::GraphError::ParentOutOfRange(r) => { | ||||
GraphError::new(py, ("ParentOutOfRange", r)) | GraphError::new(py, ("ParentOutOfRange", r)) | ||||
} | } | ||||
hg::GraphError::WorkingDirectoryUnsupported => { | hg::GraphError::WorkingDirectoryUnsupported => { | ||||
match py | match py | ||||
.import("mercurial.error") | .import("mercurial.error") | ||||
.and_then(|m| m.get(py, "WdirUnsupported")) | .and_then(|m| m.get(py, "WdirUnsupported")) | ||||
{ | { | ||||
Err(e) => e, | Err(e) => e, | ||||
Ok(cls) => PyErr::from_instance(py, cls), | Ok(cls) => PyErr::from_instance(py, cls), | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
py_exception!(rustext, PatternError, RuntimeError); | py_exception!(rustext, PatternError, RuntimeError); | ||||
py_exception!(rustext, PatternFileError, RuntimeError); | py_exception!(rustext, PatternFileError, RuntimeError); | ||||
impl PatternError { | impl PatternError { | ||||
pub fn pynew(py: Python, inner: hg::PatternError) -> PyErr { | pub fn pynew(py: Python, inner: hg::PatternError) -> PyErr { | ||||
match inner { | match inner { | ||||
hg::PatternError::UnsupportedSyntax(m) => { | hg::PatternError::UnsupportedSyntax(m) => { | ||||
PatternError::new(py, ("PatternError", m)) | PatternError::new(py, ("PatternError", m)) | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
impl PatternFileError { | impl PatternFileError { | ||||
pub fn pynew(py: Python, inner: hg::PatternFileError) -> PyErr { | pub fn pynew(py: Python, inner: hg::PatternFileError) -> PyErr { | ||||
match inner { | match inner { | ||||
hg::PatternFileError::IO(e) => { | hg::PatternFileError::IO(e) => { | ||||
let value = ( | let value = (e.raw_os_error().unwrap_or(2), e.to_string()); | ||||
e.raw_os_error().unwrap_or(2), | |||||
e.to_string() | |||||
); | |||||
PyErr::new::<exc::IOError, _>(py, value) | PyErr::new::<exc::IOError, _>(py, value) | ||||
} | } | ||||
hg::PatternFileError::Pattern(e, l) => { | hg::PatternFileError::Pattern(e, l) => match e { | ||||
match e { | hg::PatternError::UnsupportedSyntax(m) => { | ||||
hg::PatternError::UnsupportedSyntax(m) => | |||||
PatternFileError::new(py, ("PatternFileError", m, l)) | PatternFileError::new(py, ("PatternFileError", m, l)) | ||||
} | } | ||||
} | }, | ||||
} | } | ||||
} | } | ||||
} | } |
extern crate cpython; | extern crate cpython; | ||||
extern crate hg; | extern crate hg; | ||||
extern crate libc; | extern crate libc; | ||||
pub mod ancestors; | pub mod ancestors; | ||||
mod cindex; | mod cindex; | ||||
mod conversion; | mod conversion; | ||||
pub mod dagops; | pub mod dagops; | ||||
pub mod dirstate; | |||||
pub mod discovery; | pub mod discovery; | ||||
pub mod exceptions; | pub mod exceptions; | ||||
pub mod dirstate; | |||||
pub mod filepatterns; | pub mod filepatterns; | ||||
py_module_initializer!(rustext, initrustext, PyInit_rustext, |py, m| { | py_module_initializer!(rustext, initrustext, PyInit_rustext, |py, m| { | ||||
m.add( | m.add( | ||||
py, | py, | ||||
"__doc__", | "__doc__", | ||||
"Mercurial core concepts - Rust implementation", | "Mercurial core concepts - Rust implementation", | ||||
)?; | )?; | ||||
let dotted_name: String = m.get(py, "__name__")?.extract(py)?; | let dotted_name: String = m.get(py, "__name__")?.extract(py)?; | ||||
m.add(py, "ancestor", ancestors::init_module(py, &dotted_name)?)?; | m.add(py, "ancestor", ancestors::init_module(py, &dotted_name)?)?; | ||||
m.add(py, "dagop", dagops::init_module(py, &dotted_name)?)?; | m.add(py, "dagop", dagops::init_module(py, &dotted_name)?)?; | ||||
m.add(py, "discovery", discovery::init_module(py, &dotted_name)?)?; | m.add(py, "discovery", discovery::init_module(py, &dotted_name)?)?; | ||||
m.add(py, "dirstate", dirstate::init_module(py, &dotted_name)?)?; | m.add(py, "dirstate", dirstate::init_module(py, &dotted_name)?)?; | ||||
m.add(py, "filepatterns", filepatterns::init_module(py, &dotted_name)?)?; | m.add( | ||||
py, | |||||
"filepatterns", | |||||
filepatterns::init_module(py, &dotted_name)?, | |||||
)?; | |||||
m.add(py, "GraphError", py.get_type::<exceptions::GraphError>())?; | m.add(py, "GraphError", py.get_type::<exceptions::GraphError>())?; | ||||
m.add(py, "PatternFileError", py.get_type::<exceptions::PatternFileError>())?; | m.add( | ||||
m.add(py, "PatternError", py.get_type::<exceptions::PatternError>())?; | py, | ||||
"PatternFileError", | |||||
py.get_type::<exceptions::PatternFileError>(), | |||||
)?; | |||||
m.add( | |||||
py, | |||||
"PatternError", | |||||
py.get_type::<exceptions::PatternError>(), | |||||
)?; | |||||
Ok(()) | Ok(()) | ||||
}); | }); |