This will let future code that writes commit graphs use those constants.
Showing the changes to git-commitgraph/src (3 of 3 files). Show all
Unified · Split
| @@ -9,7 +9,7 @@ use byteorder::{BigEndian, ByteOrder}; · 8 unmodified lines | |||
| 9 | use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE; | 9 | use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE; |
| 10 | 10 | ||
| 11 | use crate::{ | 11 | use crate::{ |
| 12 | file::{self, File}, | 12 | file::{self, File, EXTENDED_EDGES_MASK, LAST_EXTENDED_EDGE_MASK, NO_PARENT}, |
| 13 | graph, | 13 | graph, |
| 14 | }; | 14 | }; |
| 15 | 15 | ||
| @@ -27,11 +27,6 @@ pub enum Error { · 11 unmodified lines | |||
| 27 | SecondParentWithoutFirstParent(git_hash::ObjectId), | 27 | SecondParentWithoutFirstParent(git_hash::ObjectId), |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | // Note that git's commit-graph-format.txt as of v2.28.0 gives an incorrect value 0x0700_0000 for | ||
| 31 | // NO_PARENT. Fixed in https://github.com/git/git/commit/4d515253afcef985e94400adbfed7044959f9121 . | ||
| 32 | const NO_PARENT: u32 = 0x7000_0000; | ||
| 33 | const EXTENDED_EDGES_MASK: u32 = 0x8000_0000; | ||
| 34 | |||
| 35 | /// A commit as stored in a [`File`]. | 30 | /// A commit as stored in a [`File`]. |
| 36 | pub struct Commit<'a> { | 31 | pub struct Commit<'a> { |
| 37 | file: &'a File, | 32 | file: &'a File, |
| @@ -240,8 +235,6 @@ impl ParentEdge { · 202 unmodified lines | |||
| 240 | } | 235 | } |
| 241 | } | 236 | } |
| 242 | 237 | ||
| 243 | const LAST_EXTENDED_EDGE_MASK: u32 = 0x8000_0000; | ||
| 244 | |||
| 245 | enum ExtraEdge { | 238 | enum ExtraEdge { |
| 246 | Internal(graph::Position), | 239 | Internal(graph::Position), |
| 247 | Last(graph::Position), | 240 | Last(graph::Position), |
| @@ -9,9 +9,11 @@ use byteorder::{BigEndian, ByteOrder}; · 8 unmodified lines | |||
| 9 | use filebuffer::FileBuffer; | 9 | use filebuffer::FileBuffer; |
| 10 | use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE; | 10 | use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE; |
| 11 | 11 | ||
| 12 | use crate::file::{File, COMMIT_DATA_ENTRY_SIZE, FAN_LEN, SIGNATURE}; | 12 | use crate::file::{ |
| 13 | 13 | ChunkId, File, BASE_GRAPHS_LIST_CHUNK_ID, CHUNK_LOOKUP_SIZE, COMMIT_DATA_CHUNK_ID, COMMIT_DATA_ENTRY_SIZE, | |
| 14 | type ChunkId = [u8; 4]; | 14 | EXTENDED_EDGES_LIST_CHUNK_ID, FAN_LEN, HEADER_LEN, OID_FAN_CHUNK_ID, OID_LOOKUP_CHUNK_ID, OID_LOOKUP_ENTRY_SIZE, |
| 15 | SENTINEL_CHUNK_ID, SIGNATURE, | ||
| 16 | }; | ||
| 15 | 17 | ||
| 16 | /// The error used in [`File::at()`]. | 18 | /// The error used in [`File::at()`]. |
| 17 | #[derive(thiserror::Error, Debug)] | 19 | #[derive(thiserror::Error, Debug)] |
| @@ -51,20 +53,11 @@ pub enum Error { · 33 unmodified lines | |||
| 51 | UnsupportedVersion(u8), | 53 | UnsupportedVersion(u8), |
| 52 | } | 54 | } |
| 53 | 55 | ||
| 54 | const CHUNK_LOOKUP_SIZE: usize = 12; | ||
| 55 | const HEADER_LEN: usize = 8; | ||
| 56 | const TRAILER_LEN: usize = SHA1_SIZE; | 56 | const TRAILER_LEN: usize = SHA1_SIZE; |
| 57 | const MIN_FILE_SIZE: usize = HEADER_LEN + ((MIN_CHUNKS + 1) * CHUNK_LOOKUP_SIZE) + TRAILER_LEN; | 57 | const MIN_FILE_SIZE: usize = HEADER_LEN + ((MIN_CHUNKS + 1) * CHUNK_LOOKUP_SIZE) + TRAILER_LEN; |
| 58 | const OID_LOOKUP_ENTRY_SIZE: usize = SHA1_SIZE; | ||
| 59 | 58 | ||
| 60 | // Required chunks: OIDF, OIDL, CDAT | 59 | // Required chunks: OIDF, OIDL, CDAT |
| 61 | const MIN_CHUNKS: usize = 3; | 60 | const MIN_CHUNKS: usize = 3; |
| 62 | const BASE_GRAPHS_LIST_CHUNK_ID: ChunkId = *b"BASE"; | ||
| 63 | const COMMIT_DATA_CHUNK_ID: ChunkId = *b"CDAT"; | ||
| 64 | const EXTENDED_EDGES_LIST_CHUNK_ID: ChunkId = *b"EDGE"; | ||
| 65 | const OID_FAN_CHUNK_ID: ChunkId = *b"OIDF"; | ||
| 66 | const OID_LOOKUP_CHUNK_ID: ChunkId = *b"OIDL"; | ||
| 67 | const SENTINEL_CHUNK_ID: ChunkId = [0u8; 4]; | ||
| 68 | 61 | ||
| 69 | impl File { | 62 | impl File { |
| 70 | /// Try to parse the commit graph file at `path`. | 63 | /// Try to parse the commit graph file at `path`. |
| @@ -1,12 +1,6 @@ | |||
| 1 | //! Operations on a single commit-graph file. | 1 | //! Operations on a single commit-graph file. |
| 2 | 2 | ||
| 3 | mod access; | 3 | pub use self::{commit::Commit, init::Error}; |
| 4 | |||
| 5 | pub mod commit; | ||
| 6 | pub use commit::Commit; | ||
| 7 | |||
| 8 | mod init; | ||
| 9 | pub mod verify; | ||
| 10 | 4 | ||
| 11 | use std::{ | 5 | use std::{ |
| 12 | fmt::{Display, Formatter}, | 6 | fmt::{Display, Formatter}, |
| @@ -16,12 +10,34 @@ use std::{ · 3 unmodified lines | |||
| 16 | 10 | ||
| 17 | use filebuffer::FileBuffer; | 11 | use filebuffer::FileBuffer; |
| 18 | use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE; | 12 | use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE; |
| 19 | pub use init::Error; | ||
| 20 | 13 | ||
| 14 | mod access; | ||
| 15 | pub mod commit; | ||
| 16 | mod init; | ||
| 17 | pub mod verify; | ||
| 18 | |||
| 19 | const CHUNK_LOOKUP_SIZE: usize = 12; | ||
| 21 | const COMMIT_DATA_ENTRY_SIZE: usize = SHA1_SIZE + 16; | 20 | const COMMIT_DATA_ENTRY_SIZE: usize = SHA1_SIZE + 16; |
| 22 | const FAN_LEN: usize = 256; | 21 | const FAN_LEN: usize = 256; |
| 22 | const HEADER_LEN: usize = 8; | ||
| 23 | const OID_LOOKUP_ENTRY_SIZE: usize = SHA1_SIZE; | ||
| 24 | |||
| 23 | const SIGNATURE: &[u8] = b"CGPH"; | 25 | const SIGNATURE: &[u8] = b"CGPH"; |
| 24 | 26 | ||
| 27 | type ChunkId = [u8; 4]; | ||
| 28 | const BASE_GRAPHS_LIST_CHUNK_ID: ChunkId = *b"BASE"; | ||
| 29 | const COMMIT_DATA_CHUNK_ID: ChunkId = *b"CDAT"; | ||
| 30 | const EXTENDED_EDGES_LIST_CHUNK_ID: ChunkId = *b"EDGE"; | ||
| 31 | const OID_FAN_CHUNK_ID: ChunkId = *b"OIDF"; | ||
| 32 | const OID_LOOKUP_CHUNK_ID: ChunkId = *b"OIDL"; | ||
| 33 | const SENTINEL_CHUNK_ID: ChunkId = [0u8; 4]; | ||
| 34 | |||
| 35 | // Note that git's commit-graph-format.txt as of v2.28.0 gives an incorrect value 0x0700_0000 for | ||
| 36 | // NO_PARENT. Fixed in https://github.com/git/git/commit/4d515253afcef985e94400adbfed7044959f9121 . | ||
| 37 | const NO_PARENT: u32 = 0x7000_0000; | ||
| 38 | const EXTENDED_EDGES_MASK: u32 = 0x8000_0000; | ||
| 39 | const LAST_EXTENDED_EDGE_MASK: u32 = 0x8000_0000; | ||
| 40 | |||
| 25 | /// A single commit-graph file. | 41 | /// A single commit-graph file. |
| 26 | /// | 42 | /// |
| 27 | /// All operations on a `File` are local to that graph file. Since a commit graph can span multiple | 43 | /// All operations on a `File` are local to that graph file. Since a commit graph can span multiple |