1 // Copyright 2018-2020 Georges Racinet <georges.racinet@octobus.net> 2 // and Mercurial contributors 3 // 4 // This software may be used and distributed according to the terms of the 5 // GNU General Public License version 2 or any later version. 6 //! Mercurial concepts for handling revision history 7 8 pub mod node; 9 pub mod nodemap; 10 mod nodemap_docket; 11 pub mod path_encode; 12 pub use node::{FromHexError, Node, NodePrefix}; 13 pub mod changelog; 14 pub mod filelog; 15 pub mod index; 16 pub mod manifest; 17 pub mod patch; 18 pub mod revlog; 19 20 /// Mercurial revision numbers 21 /// 22 /// As noted in revlog.c, revision numbers are actually encoded in 23 /// 4 bytes, and are liberally converted to ints, whence the i32 24 pub type Revision = i32; 25 26 /// Marker expressing the absence of a parent 27 /// 28 /// Independently of the actual representation, `NULL_REVISION` is guaranteed 29 /// to be smaller than all existing revisions. 30 pub const NULL_REVISION: Revision = -1; 31 32 /// Same as `mercurial.node.wdirrev` 33 /// 34 /// This is also equal to `i32::max_value()`, but it's better to spell 35 /// it out explicitely, same as in `mercurial.node` 36 #[allow(clippy::unreadable_literal)] 37 pub const WORKING_DIRECTORY_REVISION: Revision = 0x7fffffff; 38 39 pub const WORKING_DIRECTORY_HEX: &str = 40 "ffffffffffffffffffffffffffffffffffffffff"; 41 42 /// The simplest expression of what we need of Mercurial DAGs. 43 pub trait Graph { 44 /// Return the two parents of the given `Revision`. 45 /// 46 /// Each of the parents can be independently `NULL_REVISION` parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError>47 fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError>; 48 } 49 50 #[derive(Clone, Debug, PartialEq)] 51 pub enum GraphError { 52 ParentOutOfRange(Revision), 53 WorkingDirectoryUnsupported, 54 } 55 56 /// The Mercurial Revlog Index 57 /// 58 /// This is currently limited to the minimal interface that is needed for 59 /// the [`nodemap`](nodemap/index.html) module 60 pub trait RevlogIndex { 61 /// Total number of Revisions referenced in this index len(&self) -> usize62 fn len(&self) -> usize; 63 is_empty(&self) -> bool64 fn is_empty(&self) -> bool { 65 self.len() == 0 66 } 67 68 /// Return a reference to the Node or `None` if rev is out of bounds 69 /// 70 /// `NULL_REVISION` is not considered to be out of bounds. node(&self, rev: Revision) -> Option<&Node>71 fn node(&self, rev: Revision) -> Option<&Node>; 72 } 73