rust/hg-core/src/revlog.rs
author Thomas Klausner <wiz@gatalith.at>
Mon, 15 Nov 2021 12:03:28 +0100
branchstable
changeset 48326 141e38ef8d8f
parent 47961 4d2a5ca060e3
permissions -rw-r--r--
tests: dd status=noxfer is not portable (issue6523) Differential Revision: https://phab.mercurial-scm.org/D11754
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44005
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
     1
// Copyright 2018-2020 Georges Racinet <georges.racinet@octobus.net>
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
     2
//           and Mercurial contributors
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
     3
//
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
     4
// This software may be used and distributed according to the terms of the
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
     5
// GNU General Public License version 2 or any later version.
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
     6
//! Mercurial concepts for handling revision history
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
     7
44143
7f86426fdd2c rust-node: binary Node ID and conversion utilities
Georges Racinet <georges.racinet@octobus.net>
parents: 44142
diff changeset
     8
pub mod node;
44142
63db6657d280 rust-nodemap: building blocks for nodetree structures
Georges Racinet <georges.racinet@octobus.net>
parents: 44088
diff changeset
     9
pub mod nodemap;
46090
9eb07ab3f2d4 rhg: use persistent nodemap when available
Simon Sapin <simon-commits@exyr.org>
parents: 45539
diff changeset
    10
mod nodemap_docket;
45539
aebc976fd7d5 hg-core: add path_encode
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45533
diff changeset
    11
pub mod path_encode;
46431
645ee7225fab rust: Make NodePrefix allocation-free and Copy, remove NodePrefixRef
Simon Sapin <simon.sapin@octobus.net>
parents: 46428
diff changeset
    12
pub use node::{FromHexError, Node, NodePrefix};
45532
c2317b7624fd hg-core: add `Changlog` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45526
diff changeset
    13
pub mod changelog;
47961
4d2a5ca060e3 rust: Add a Filelog struct that wraps Revlog
Simon Sapin <simon.sapin@octobus.net>
parents: 46821
diff changeset
    14
pub mod filelog;
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
    15
pub mod index;
45533
89ac95bd4993 hg-core: add `Manifest` a specialized `Revlog`
Antoine Cezar <antoine.cezar@octobus.net>
parents: 45532
diff changeset
    16
pub mod manifest;
45526
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
    17
pub mod patch;
26c53ee51c68 hg-core: Add a limited read only `revlog` implementation
Antoine Cezar <antoine.cezar@octobus.net>
parents: 44973
diff changeset
    18
pub mod revlog;
44142
63db6657d280 rust-nodemap: building blocks for nodetree structures
Georges Racinet <georges.racinet@octobus.net>
parents: 44088
diff changeset
    19
44005
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    20
/// Mercurial revision numbers
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    21
///
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    22
/// As noted in revlog.c, revision numbers are actually encoded in
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    23
/// 4 bytes, and are liberally converted to ints, whence the i32
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    24
pub type Revision = i32;
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    25
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    26
/// Marker expressing the absence of a parent
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    27
///
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    28
/// Independently of the actual representation, `NULL_REVISION` is guaranteed
44088
b3ec1ea95ee6 rust-core: fix typo in comment
Aay Jay Chan <aayjaychan@itopia.com.hk>
parents: 44005
diff changeset
    29
/// to be smaller than all existing revisions.
44005
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    30
pub const NULL_REVISION: Revision = -1;
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    31
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    32
/// Same as `mercurial.node.wdirrev`
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    33
///
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    34
/// This is also equal to `i32::max_value()`, but it's better to spell
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    35
/// it out explicitely, same as in `mercurial.node`
44973
26114bd6ec60 rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents: 44182
diff changeset
    36
#[allow(clippy::unreadable_literal)]
44005
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    37
pub const WORKING_DIRECTORY_REVISION: Revision = 0x7fffffff;
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    38
46821
e8ae91b1a63d rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46431
diff changeset
    39
pub const WORKING_DIRECTORY_HEX: &str =
e8ae91b1a63d rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46431
diff changeset
    40
    "ffffffffffffffffffffffffffffffffffffffff";
e8ae91b1a63d rhg: raise wdir specific error for `hg debugdata`
Pulkit Goyal <7895pulkit@gmail.com>
parents: 46431
diff changeset
    41
44005
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    42
/// The simplest expression of what we need of Mercurial DAGs.
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    43
pub trait Graph {
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    44
    /// Return the two parents of the given `Revision`.
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    45
    ///
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    46
    /// Each of the parents can be independently `NULL_REVISION`
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    47
    fn parents(&self, rev: Revision) -> Result<[Revision; 2], GraphError>;
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    48
}
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    49
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    50
#[derive(Clone, Debug, PartialEq)]
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    51
pub enum GraphError {
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    52
    ParentOutOfRange(Revision),
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    53
    WorkingDirectoryUnsupported,
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
    54
}
44181
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
    55
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
    56
/// The Mercurial Revlog Index
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
    57
///
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
    58
/// This is currently limited to the minimal interface that is needed for
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
    59
/// the [`nodemap`](nodemap/index.html) module
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
    60
pub trait RevlogIndex {
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
    61
    /// Total number of Revisions referenced in this index
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
    62
    fn len(&self) -> usize;
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
    63
44973
26114bd6ec60 rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents: 44182
diff changeset
    64
    fn is_empty(&self) -> bool {
26114bd6ec60 rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents: 44182
diff changeset
    65
        self.len() == 0
26114bd6ec60 rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents: 44182
diff changeset
    66
    }
26114bd6ec60 rust: do a clippy pass
Raphaël Gomès <rgomes@octobus.net>
parents: 44182
diff changeset
    67
44181
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
    68
    /// Return a reference to the Node or `None` if rev is out of bounds
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
    69
    ///
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
    70
    /// `NULL_REVISION` is not considered to be out of bounds.
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
    71
    fn node(&self, rev: Revision) -> Option<&Node>;
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
    72
}