History

Promote file-format constants to `git_commitgraph::file` module.

This will let future code that writes commit graphs use those constants.

Conor Davis committed 5 years ago

Commit 0afd3541 parent b559dd03 files · +30 −28Browse files

Showing the changes to git-commitgraph/src (3 of 3 files). Show all

Unified · Split

3 files
  1. git-commitgraph/src/file/commit.rs +1 −8
  2. git-commitgraph/src/file/init.rs +5 −12
  3. git-commitgraph/src/file/mod.rs +24 −8
git-commitgraph/src/file/commit.rs+1−8
@@ -9,7 +9,7 @@ use byteorder::{BigEndian, ByteOrder}; · 8 unmodified lines
9use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;9use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;
10 10
11use crate::{11use 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 .
32const NO_PARENT: u32 = 0x7000_0000;
33const EXTENDED_EDGES_MASK: u32 = 0x8000_0000;
34
35/// A commit as stored in a [`File`].30/// A commit as stored in a [`File`].
36pub struct Commit<'a> {31pub 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
243const LAST_EXTENDED_EDGE_MASK: u32 = 0x8000_0000;
244
245enum ExtraEdge {238enum ExtraEdge {
246 Internal(graph::Position),239 Internal(graph::Position),
247 Last(graph::Position),240 Last(graph::Position),
git-commitgraph/src/file/init.rs+5−12
@@ -9,9 +9,11 @@ use byteorder::{BigEndian, ByteOrder}; · 8 unmodified lines
9use filebuffer::FileBuffer;9use filebuffer::FileBuffer;
10use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;10use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;
11 11
12use crate::file::{File, COMMIT_DATA_ENTRY_SIZE, FAN_LEN, SIGNATURE};12use crate::file::{
13 13 ChunkId, File, BASE_GRAPHS_LIST_CHUNK_ID, CHUNK_LOOKUP_SIZE, COMMIT_DATA_CHUNK_ID, COMMIT_DATA_ENTRY_SIZE,
14type 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
54const CHUNK_LOOKUP_SIZE: usize = 12;
55const HEADER_LEN: usize = 8;
56const TRAILER_LEN: usize = SHA1_SIZE;56const TRAILER_LEN: usize = SHA1_SIZE;
57const MIN_FILE_SIZE: usize = HEADER_LEN + ((MIN_CHUNKS + 1) * CHUNK_LOOKUP_SIZE) + TRAILER_LEN;57const MIN_FILE_SIZE: usize = HEADER_LEN + ((MIN_CHUNKS + 1) * CHUNK_LOOKUP_SIZE) + TRAILER_LEN;
58const OID_LOOKUP_ENTRY_SIZE: usize = SHA1_SIZE;
59 58
60// Required chunks: OIDF, OIDL, CDAT59// Required chunks: OIDF, OIDL, CDAT
61const MIN_CHUNKS: usize = 3;60const MIN_CHUNKS: usize = 3;
62const BASE_GRAPHS_LIST_CHUNK_ID: ChunkId = *b"BASE";
63const COMMIT_DATA_CHUNK_ID: ChunkId = *b"CDAT";
64const EXTENDED_EDGES_LIST_CHUNK_ID: ChunkId = *b"EDGE";
65const OID_FAN_CHUNK_ID: ChunkId = *b"OIDF";
66const OID_LOOKUP_CHUNK_ID: ChunkId = *b"OIDL";
67const SENTINEL_CHUNK_ID: ChunkId = [0u8; 4];
68 61
69impl File {62impl File {
70 /// Try to parse the commit graph file at `path`.63 /// Try to parse the commit graph file at `path`.
git-commitgraph/src/file/mod.rs+24−8
@@ -1,12 +1,6 @@
1//! Operations on a single commit-graph file.1//! Operations on a single commit-graph file.
2 2
3mod access;3pub use self::{commit::Commit, init::Error};
4
5pub mod commit;
6pub use commit::Commit;
7
8mod init;
9pub mod verify;
10 4
11use std::{5use std::{
12 fmt::{Display, Formatter},6 fmt::{Display, Formatter},
@@ -16,12 +10,34 @@ use std::{ · 3 unmodified lines
16 10
17use filebuffer::FileBuffer;11use filebuffer::FileBuffer;
18use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;12use git_hash::SIZE_OF_SHA1_DIGEST as SHA1_SIZE;
19pub use init::Error;
20 13
14mod access;
15pub mod commit;
16mod init;
17pub mod verify;
18
19const CHUNK_LOOKUP_SIZE: usize = 12;
21const COMMIT_DATA_ENTRY_SIZE: usize = SHA1_SIZE + 16;20const COMMIT_DATA_ENTRY_SIZE: usize = SHA1_SIZE + 16;
22const FAN_LEN: usize = 256;21const FAN_LEN: usize = 256;
22const HEADER_LEN: usize = 8;
23const OID_LOOKUP_ENTRY_SIZE: usize = SHA1_SIZE;
24
23const SIGNATURE: &[u8] = b"CGPH";25const SIGNATURE: &[u8] = b"CGPH";
24 26
27type ChunkId = [u8; 4];
28const BASE_GRAPHS_LIST_CHUNK_ID: ChunkId = *b"BASE";
29const COMMIT_DATA_CHUNK_ID: ChunkId = *b"CDAT";
30const EXTENDED_EDGES_LIST_CHUNK_ID: ChunkId = *b"EDGE";
31const OID_FAN_CHUNK_ID: ChunkId = *b"OIDF";
32const OID_LOOKUP_CHUNK_ID: ChunkId = *b"OIDL";
33const 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 .
37const NO_PARENT: u32 = 0x7000_0000;
38const EXTENDED_EDGES_MASK: u32 = 0x8000_0000;
39const 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 multiple43/// All operations on a `File` are local to that graph file. Since a commit graph can span multiple

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t