Mercurial > public > mercurial-scm > hg-stable
view rust/hg-core/src/lib.rs @ 42330:e240bec26626
rust-dirstate: add rust-cpython bindings to the new parse/pack functions
This allows for Python code to call `parse/pack_dirstate` transparently.
These bindings are heavy given the relatively simple task, as they are bound
to implementation details of both the C and Python code. They will be slimmed
down in future patches and eventually completely removed once more of the
dirstate code has been refactored/rewritten in Rust.
Both functions emulate the mutate-on-loop style of the Python and C
implementations by looping over changed items in the compatibility layer,
instead of at the core functions.
Differential Revision: https://phab.mercurial-scm.org/D6349
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Mon, 06 May 2019 22:50:34 +0200 |
parents | d1786c1d34fa |
children | e8f3740cc067 |
line wrap: on
line source
// Copyright 2018 Georges Racinet <gracinet@anybox.fr> // // This software may be used and distributed according to the terms of the // GNU General Public License version 2 or any later version. extern crate byteorder; extern crate memchr; mod ancestors; pub mod dagops; pub use ancestors::{AncestorsIterator, LazyAncestors, MissingAncestors}; mod dirstate; pub mod discovery; pub mod testing; // unconditionally built, for use from integration tests pub use dirstate::{ pack_dirstate, parse_dirstate, CopyVec, CopyVecEntry, DirstateEntry, DirstateParents, DirstateVec, }; /// Mercurial revision numbers /// /// As noted in revlog.c, revision numbers are actually encoded in /// 4 bytes, and are liberally converted to ints, whence the i32 pub type Revision = i32; /// Marker expressing the absence of a parent /// /// Independently of the actual representation, `NULL_REVISION` is guaranteed /// to be smaller that all existing revisions. pub const NULL_REVISION: Revision = -1; /// Same as `mercurial.node.wdirrev` /// /// This is also equal to `i32::max_value()`, but it's better to spell /// it out explicitely, same as in `mercurial.node` pub const WORKING_DIRECTORY_REVISION: Revision = 0x7fffffff; /// The simplest expression of what we need of Mercurial DAGs. pub trait Graph { /// Return the two parents of the given `Revision`. /// /// Each of the parents can be independently `NULL_REVISION` fn parents(&self, Revision) -> Result<[Revision; 2], GraphError>; } #[derive(Clone, Debug, PartialEq)] pub enum GraphError { ParentOutOfRange(Revision), WorkingDirectoryUnsupported, } #[derive(Clone, Debug, PartialEq)] pub enum DirstateParseError { TooLittleData, Overflow, CorruptedEntry(String), } #[derive(Debug, PartialEq)] pub enum DirstatePackError { CorruptedEntry(String), CorruptedParent, BadSize(usize, usize), } impl From<std::io::Error> for DirstatePackError { fn from(e: std::io::Error) -> Self { DirstatePackError::CorruptedEntry(e.to_string()) } } impl From<std::io::Error> for DirstateParseError { fn from(e: std::io::Error) -> Self { DirstateParseError::CorruptedEntry(e.to_string()) } }