annotate rust/hg-core/src/revlog.rs @ 44597:e62052d0f377

rust-status: only involve ignore mechanism when needed This prevents unnecessary fallbacks to Python, improving performance for `hg update` for instance. On Mozilla-Central a noop update goes from 1.6s down to 700ms. Differential Revision: https://phab.mercurial-scm.org/D8315
author Raphaël Gomès <rgomes@octobus.net>
date Fri, 20 Mar 2020 15:21:34 +0100
parents 9896a8d0d3d2
children 26114bd6ec60
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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;
44182
9896a8d0d3d2 rust-node: handling binary Node prefix
Georges Racinet <georges.racinet@octobus.net>
parents: 44181
diff changeset
10 pub use node::{Node, NodeError, NodePrefix, NodePrefixRef};
44142
63db6657d280 rust-nodemap: building blocks for nodetree structures
Georges Racinet <georges.racinet@octobus.net>
parents: 44088
diff changeset
11
44005
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
12 /// Mercurial revision numbers
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
13 ///
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
14 /// 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
15 /// 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
16 pub type Revision = i32;
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
17
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
18 /// Marker expressing the absence of a parent
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
19 ///
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
20 /// 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
21 /// to be smaller than all existing revisions.
44005
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
22 pub const NULL_REVISION: Revision = -1;
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
23
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
24 /// Same as `mercurial.node.wdirrev`
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 /// 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
27 /// it out explicitely, same as in `mercurial.node`
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
28 pub const WORKING_DIRECTORY_REVISION: Revision = 0x7fffffff;
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
29
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
30 /// 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
31 pub trait Graph {
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
32 /// Return the two parents of the given `Revision`.
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 /// 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
35 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
36 }
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
37
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
38 #[derive(Clone, Debug, PartialEq)]
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
39 pub enum GraphError {
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
40 ParentOutOfRange(Revision),
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
41 WorkingDirectoryUnsupported,
6b332c1fc7fe rust-core: extracted a revlog submodule
Georges Racinet <georges.racinet@octobus.net>
parents:
diff changeset
42 }
44181
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
43
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
44 /// The Mercurial Revlog Index
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
45 ///
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
46 /// 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
47 /// 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
48 pub trait RevlogIndex {
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
49 /// 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
50 fn len(&self) -> usize;
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
51
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
52 /// 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
53 ///
3fb39dc2e356 rust-revlog: a trait for the revlog index
Georges Racinet <georges.racinet@octobus.net>
parents: 44143
diff changeset
54 /// `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
55 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
56 }