Skip to main content

gix_commitgraph/file/
mod.rs

1//! Operations on a single commit-graph file.
2
3use std::fmt::{Display, Formatter};
4
5pub use self::commit::Commit;
6
7mod access;
8pub mod commit;
9mod init;
10pub mod verify;
11
12const COMMIT_DATA_ENTRY_SIZE_SANS_HASH: usize = 16;
13pub(crate) const FAN_LEN: usize = 256;
14const HEADER_LEN: usize = 8;
15
16const SIGNATURE: &[u8] = b"CGPH";
17
18type ChunkId = gix_chunk::Id;
19const BASE_GRAPHS_LIST_CHUNK_ID: ChunkId = *b"BASE";
20const COMMIT_DATA_CHUNK_ID: ChunkId = *b"CDAT";
21const EXTENDED_EDGES_LIST_CHUNK_ID: ChunkId = *b"EDGE";
22const GENERATION_DATA_CHUNK_ID: ChunkId = *b"GDA2";
23const GENERATION_OVERFLOW_CHUNK_ID: ChunkId = *b"GDO2";
24const OID_FAN_CHUNK_ID: ChunkId = *b"OIDF";
25const OID_LOOKUP_CHUNK_ID: ChunkId = *b"OIDL";
26
27// Note that git's commit-graph-format.txt as of v2.28.0 gives an incorrect value 0x0700_0000 for
28// NO_PARENT. Fixed in https://github.com/git/git/commit/4d515253afcef985e94400adbfed7044959f9121 .
29const NO_PARENT: u32 = 0x7000_0000;
30const EXTENDED_EDGES_MASK: u32 = 0x8000_0000;
31const LAST_EXTENDED_EDGE_MASK: u32 = 0x8000_0000;
32
33/// The position of a given commit within a graph file, starting at 0.
34///
35/// Commits within a graph file are sorted in lexicographical order by OID; a commit's lexicographical position
36/// is its position in this ordering. If a commit graph spans multiple files, each file's commits
37/// start at lexicographical position 0, so it is unique across a single file but is not unique across
38/// the whole commit graph. Each commit also has a graph position ([`Position`][crate::Position]),
39/// which is unique across the whole commit graph.
40/// In order to avoid accidentally mixing lexicographical positions with graph positions, distinct types are used for each.
41#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
42pub struct Position(pub u32);
43
44impl Display for Position {
45    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
46        self.0.fmt(f)
47    }
48}