hg/
lib.rs

1// Copyright 2018 Georges Racinet <gracinet@anybox.fr>
2//
3// This software may be used and distributed according to the terms of the
4// GNU General Public License version 2 or any later version.
5mod ancestors;
6pub mod dagops;
7pub use ancestors::{AncestorsIterator, LazyAncestors, MissingAncestors};
8pub mod testing;  // unconditionally built, for use from integration tests
9
10/// Mercurial revision numbers
11///
12/// As noted in revlog.c, revision numbers are actually encoded in
13/// 4 bytes, and are liberally converted to ints, whence the i32
14pub type Revision = i32;
15
16
17/// Marker expressing the absence of a parent
18///
19/// Independently of the actual representation, `NULL_REVISION` is guaranteed
20/// to be smaller that all existing revisions.
21pub const NULL_REVISION: Revision = -1;
22
23/// Same as `mercurial.node.wdirrev`
24///
25/// This is also equal to `i32::max_value()`, but it's better to spell
26/// it out explicitely, same as in `mercurial.node`
27pub const WORKING_DIRECTORY_REVISION: Revision = 0x7fffffff;
28
29/// The simplest expression of what we need of Mercurial DAGs.
30pub trait Graph {
31    /// Return the two parents of the given `Revision`.
32    ///
33    /// Each of the parents can be independently `NULL_REVISION`
34    fn parents(&self, Revision) -> Result<[Revision; 2], GraphError>;
35}
36
37#[derive(Clone, Debug, PartialEq)]
38pub enum GraphError {
39    ParentOutOfRange(Revision),
40    WorkingDirectoryUnsupported,
41}