Showing the changes to git-commitgraph/src (8 of 8 files). Show all
Unified · Split
| @@ -1,11 +1,11 @@ | |||
| 1 | use crate::graph_file::{GraphFile, LexPosition, COMMIT_DATA_ENTRY_SIZE}; | 1 | use crate::file::{File, LexPosition, COMMIT_DATA_ENTRY_SIZE}; |
| 2 | use crate::Commit; | 2 | use crate::Commit; |
| 3 | use git_object::{borrowed, HashKind, SHA1_SIZE}; | 3 | use git_object::{borrowed, HashKind, SHA1_SIZE}; |
| 4 | use std::convert::{TryFrom, TryInto}; | 4 | use std::convert::{TryFrom, TryInto}; |
| 5 | use std::fmt::{Debug, Formatter}; | 5 | use std::fmt::{Debug, Formatter}; |
| 6 | use std::path::Path; | 6 | use std::path::Path; |
| 7 | 7 | ||
| 8 | impl GraphFile { | 8 | impl File { |
| 9 | /// Returns the commit data for the commit located at the given lex position. | 9 | /// Returns the commit data for the commit located at the given lex position. |
| 10 | /// | 10 | /// |
| 11 | /// `pos` must range from 0 to self.num_commits(). | 11 | /// `pos` must range from 0 to self.num_commits(). |
| @@ -94,7 +94,7 @@ impl GraphFile { · 82 unmodified lines | |||
| 94 | } | 94 | } |
| 95 | } | 95 | } |
| 96 | 96 | ||
| 97 | impl GraphFile { | 97 | impl File { |
| 98 | /// Returns the byte slice for the given commit in this file's Commit Data (CDAT) chunk. | 98 | /// Returns the byte slice for the given commit in this file's Commit Data (CDAT) chunk. |
| 99 | pub(crate) fn commit_data_bytes(&self, pos: LexPosition) -> &[u8] { | 99 | pub(crate) fn commit_data_bytes(&self, pos: LexPosition) -> &[u8] { |
| 100 | assert!( | 100 | assert!( |
| @@ -117,8 +117,8 @@ impl GraphFile { · 16 unmodified lines | |||
| 117 | } | 117 | } |
| 118 | } | 118 | } |
| 119 | 119 | ||
| 120 | impl Debug for GraphFile { | 120 | impl Debug for File { |
| 121 | fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | 121 | fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
| 122 | write!(f, r#"GraphFile("{:?}")"#, self.path.display()) | 122 | write!(f, r#"File("{:?}")"#, self.path.display()) |
| 123 | } | 123 | } |
| 124 | } | 124 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | use crate::file::{File, LexPosition}; | ||
| 1 | use crate::graph::GraphPosition; | 2 | use crate::graph::GraphPosition; |
| 2 | use crate::graph_file::{GraphFile, LexPosition}; | ||
| 3 | use byteorder::{BigEndian, ByteOrder}; | 3 | use byteorder::{BigEndian, ByteOrder}; |
| 4 | use git_object::{borrowed, owned, SHA1_SIZE}; | 4 | use git_object::{borrowed, owned, SHA1_SIZE}; |
| 5 | use quick_error::quick_error; | 5 | use quick_error::quick_error; |
| @@ -40,7 +40,7 @@ const NO_PARENT: u32 = 0x7000_0000; · 34 unmodified lines | |||
| 40 | const EXTENDED_EDGES_MASK: u32 = 0x8000_0000; | 40 | const EXTENDED_EDGES_MASK: u32 = 0x8000_0000; |
| 41 | 41 | ||
| 42 | pub struct Commit<'a> { | 42 | pub struct Commit<'a> { |
| 43 | file: &'a GraphFile, | 43 | file: &'a File, |
| 44 | lex_pos: LexPosition, | 44 | lex_pos: LexPosition, |
| 45 | // We can parse the below fields lazily if needed. | 45 | // We can parse the below fields lazily if needed. |
| 46 | commit_timestamp: u64, | 46 | commit_timestamp: u64, |
| @@ -51,7 +51,7 @@ pub struct Commit<'a> { · 4 unmodified lines | |||
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | impl<'a> Commit<'a> { | 53 | impl<'a> Commit<'a> { |
| 54 | pub(crate) fn new(file: &'a GraphFile, pos: LexPosition) -> Self { | 54 | pub(crate) fn new(file: &'a File, pos: LexPosition) -> Self { |
| 55 | let bytes = file.commit_data_bytes(pos); | 55 | let bytes = file.commit_data_bytes(pos); |
| 56 | Commit { | 56 | Commit { |
| 57 | file, | 57 | file, |
| @@ -121,7 +121,7 @@ impl<'a> Eq for Commit<'a> {} · 63 unmodified lines | |||
| 121 | 121 | ||
| 122 | impl<'a> PartialEq for Commit<'a> { | 122 | impl<'a> PartialEq for Commit<'a> { |
| 123 | fn eq(&self, other: &Self) -> bool { | 123 | fn eq(&self, other: &Self) -> bool { |
| 124 | self.file as *const GraphFile == other.file as *const GraphFile && self.lex_pos == other.lex_pos | 124 | self.file as *const File == other.file as *const File && self.lex_pos == other.lex_pos |
| 125 | } | 125 | } |
| 126 | } | 126 | } |
| 127 | 127 | ||
| @@ -1,4 +1,4 @@ | |||
| 1 | use crate::graph_file::{GraphFile, COMMIT_DATA_ENTRY_SIZE, FAN_LEN, SIGNATURE}; | 1 | use crate::file::{File, COMMIT_DATA_ENTRY_SIZE, FAN_LEN, SIGNATURE}; |
| 2 | use bstr::ByteSlice; | 2 | use bstr::ByteSlice; |
| 3 | use byteorder::{BigEndian, ByteOrder}; | 3 | use byteorder::{BigEndian, ByteOrder}; |
| 4 | use filebuffer::FileBuffer; | 4 | use filebuffer::FileBuffer; |
| @@ -15,7 +15,7 @@ quick_error! { · 10 unmodified lines | |||
| 15 | pub enum Error { | 15 | pub enum Error { |
| 16 | BaseGraphMismatch(from_header: u8, from_chunk: u32) { | 16 | BaseGraphMismatch(from_header: u8, from_chunk: u32) { |
| 17 | display( | 17 | display( |
| 18 | "Commit-graph {} chunk contains {} base graphs, but commit-graph graph_file header claims {} base graphs", | 18 | "Commit-graph {} chunk contains {} base graphs, but commit-graph file header claims {} base graphs", |
| 19 | BASE_GRAPHS_LIST_CHUNK_ID.as_bstr(), | 19 | BASE_GRAPHS_LIST_CHUNK_ID.as_bstr(), |
| 20 | from_chunk, | 20 | from_chunk, |
| 21 | from_header, | 21 | from_header, |
| @@ -34,7 +34,7 @@ quick_error! { · 12 unmodified lines | |||
| 34 | display("{}", msg) | 34 | display("{}", msg) |
| 35 | } | 35 | } |
| 36 | DuplicateChunk(id: ChunkId) { | 36 | DuplicateChunk(id: ChunkId) { |
| 37 | display("Commit-graph graph_file contains multiple {:?} chunks", id.as_bstr()) | 37 | display("Commit-graph file contains multiple {:?} chunks", id.as_bstr()) |
| 38 | } | 38 | } |
| 39 | // This error case is disabled, as git allows extra garbage in the extra edges list. | 39 | // This error case is disabled, as git allows extra garbage in the extra edges list. |
| 40 | // ExtraEdgesOverflow { | 40 | // ExtraEdgesOverflow { |
| @@ -44,17 +44,17 @@ quick_error! { · 3 unmodified lines | |||
| 44 | display("Commit-graph chunk {:?} has invalid size: {}", id.as_bstr(), msg) | 44 | display("Commit-graph chunk {:?} has invalid size: {}", id.as_bstr(), msg) |
| 45 | } | 45 | } |
| 46 | Io(err: std::io::Error, path: std::path::PathBuf) { | 46 | Io(err: std::io::Error, path: std::path::PathBuf) { |
| 47 | display("Could not open commit-graph graph_file at '{}'", path.display()) | 47 | display("Could not open commit-graph file at '{}'", path.display()) |
| 48 | source(err) | 48 | source(err) |
| 49 | } | 49 | } |
| 50 | MissingChunk(id: ChunkId) { | 50 | MissingChunk(id: ChunkId) { |
| 51 | display("Missing required chunk {:?}", id.as_bstr()) | 51 | display("Missing required chunk {:?}", id.as_bstr()) |
| 52 | } | 52 | } |
| 53 | UnsupportedHashVersion(version: u8) { | 53 | UnsupportedHashVersion(version: u8) { |
| 54 | display("Commit-graph graph_file uses unsupported hash version: {}", version) | 54 | display("Commit-graph file uses unsupported hash version: {}", version) |
| 55 | } | 55 | } |
| 56 | UnsupportedVersion(version: u8) { | 56 | UnsupportedVersion(version: u8) { |
| 57 | display("Unsupported commit-graph graph_file version: {}", version) | 57 | display("Unsupported commit-graph file version: {}", version) |
| 58 | } | 58 | } |
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| @@ -73,13 +73,13 @@ const OID_FAN_CHUNK_ID: ChunkId = *b"OIDF"; · 12 unmodified lines | |||
| 73 | const OID_LOOKUP_CHUNK_ID: ChunkId = *b"OIDL"; | 73 | const OID_LOOKUP_CHUNK_ID: ChunkId = *b"OIDL"; |
| 74 | const SENTINEL_CHUNK_ID: ChunkId = [0u8; 4]; | 74 | const SENTINEL_CHUNK_ID: ChunkId = [0u8; 4]; |
| 75 | 75 | ||
| 76 | impl GraphFile { | 76 | impl File { |
| 77 | pub fn at(path: impl AsRef<Path>) -> Result<GraphFile, Error> { | 77 | pub fn at(path: impl AsRef<Path>) -> Result<File, Error> { |
| 78 | Self::try_from(path.as_ref()) | 78 | Self::try_from(path.as_ref()) |
| 79 | } | 79 | } |
| 80 | } | 80 | } |
| 81 | 81 | ||
| 82 | impl TryFrom<&Path> for GraphFile { | 82 | impl TryFrom<&Path> for File { |
| 83 | type Error = Error; | 83 | type Error = Error; |
| 84 | 84 | ||
| 85 | fn try_from(path: &Path) -> Result<Self, Self::Error> { | 85 | fn try_from(path: &Path) -> Result<Self, Self::Error> { |
| @@ -87,14 +87,14 @@ impl TryFrom<&Path> for GraphFile { · 1 unmodified line | |||
| 87 | let data_size = data.len(); | 87 | let data_size = data.len(); |
| 88 | if data_size < MIN_FILE_SIZE { | 88 | if data_size < MIN_FILE_SIZE { |
| 89 | return Err(Error::Corrupt( | 89 | return Err(Error::Corrupt( |
| 90 | "Commit-graph graph_file too small even for an empty graph".to_owned(), | 90 | "Commit-graph file too small even for an empty graph".to_owned(), |
| 91 | )); | 91 | )); |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | let mut ofs = 0; | 94 | let mut ofs = 0; |
| 95 | if &data[ofs..ofs + SIGNATURE.len()] != SIGNATURE { | 95 | if &data[ofs..ofs + SIGNATURE.len()] != SIGNATURE { |
| 96 | return Err(Error::Corrupt( | 96 | return Err(Error::Corrupt( |
| 97 | "Commit-graph graph_file does not start with expected signature".to_owned(), | 97 | "Commit-graph file does not start with expected signature".to_owned(), |
| 98 | )); | 98 | )); |
| 99 | } | 99 | } |
| 100 | ofs += SIGNATURE.len(); | 100 | ofs += SIGNATURE.len(); |
| @@ -126,7 +126,7 @@ impl TryFrom<&Path> for GraphFile { · 25 unmodified lines | |||
| 126 | let chunk_lookup_end = ofs + ((chunk_count as usize + 1) * CHUNK_LOOKUP_SIZE); | 126 | let chunk_lookup_end = ofs + ((chunk_count as usize + 1) * CHUNK_LOOKUP_SIZE); |
| 127 | if chunk_lookup_end > data_size { | 127 | if chunk_lookup_end > data_size { |
| 128 | return Err(Error::Corrupt(format!( | 128 | return Err(Error::Corrupt(format!( |
| 129 | "Commit-graph graph_file is too small to hold {} chunks", | 129 | "Commit-graph file is too small to hold {} chunks", |
| 130 | chunk_count | 130 | chunk_count |
| 131 | ))); | 131 | ))); |
| 132 | } | 132 | } |
| @@ -168,7 +168,7 @@ impl TryFrom<&Path> for GraphFile { · 35 unmodified lines | |||
| 168 | if next_chunk_offset >= data_size { | 168 | if next_chunk_offset >= data_size { |
| 169 | return Err(Error::InvalidChunkSize( | 169 | return Err(Error::InvalidChunkSize( |
| 170 | chunk_id, | 170 | chunk_id, |
| 171 | "chunk extends beyond end of graph_file".to_string(), | 171 | "chunk extends beyond end of file".to_string(), |
| 172 | )); | 172 | )); |
| 173 | } | 173 | } |
| 174 | 174 | ||
| @@ -260,7 +260,7 @@ impl TryFrom<&Path> for GraphFile { · 85 unmodified lines | |||
| 260 | } | 260 | } |
| 261 | if chunk_id != SENTINEL_CHUNK_ID { | 261 | if chunk_id != SENTINEL_CHUNK_ID { |
| 262 | return Err(Error::Corrupt(format!( | 262 | return Err(Error::Corrupt(format!( |
| 263 | "Commit-graph graph_file has invalid last chunk ID: {:?}", | 263 | "Commit-graph file has invalid last chunk ID: {:?}", |
| 264 | chunk_id.as_bstr() | 264 | chunk_id.as_bstr() |
| 265 | ))); | 265 | ))); |
| 266 | } | 266 | } |
| @@ -289,7 +289,7 @@ impl TryFrom<&Path> for GraphFile { · 22 unmodified lines | |||
| 289 | commit_data_count, | 289 | commit_data_count, |
| 290 | )); | 290 | )); |
| 291 | } | 291 | } |
| 292 | Ok(GraphFile { | 292 | Ok(File { |
| 293 | base_graph_count, | 293 | base_graph_count, |
| 294 | base_graphs_list_offset, | 294 | base_graphs_list_offset, |
| 295 | commit_data_offset, | 295 | commit_data_offset, |
| @@ -16,9 +16,9 @@ const SIGNATURE: &[u8] = b"CGPH"; · 15 unmodified lines | |||
| 16 | 16 | ||
| 17 | /// A single commit-graph file. | 17 | /// A single commit-graph file. |
| 18 | /// | 18 | /// |
| 19 | /// All operations on a `GraphFile` are local to that graph file. Since a commit graph can span | 19 | /// All operations on a `File` are local to that graph file. Since a commit graph can span multiple |
| 20 | /// multiple files, all interesting graph operations belong on `Graph`. | 20 | /// files, all interesting graph operations belong on `Graph`. |
| 21 | pub struct GraphFile { | 21 | pub struct File { |
| 22 | base_graph_count: u8, | 22 | base_graph_count: u8, |
| 23 | base_graphs_list_offset: Option<usize>, | 23 | base_graphs_list_offset: Option<usize>, |
| 24 | commit_data_offset: usize, | 24 | commit_data_offset: usize, |
| @@ -1,5 +1,5 @@ | |||
| 1 | use crate::file::{File, LexPosition}; | ||
| 1 | use crate::graph::GraphPosition; | 2 | use crate::graph::GraphPosition; |
| 2 | use crate::graph_file::{GraphFile, LexPosition}; | ||
| 3 | use crate::{Commit, Graph}; | 3 | use crate::{Commit, Graph}; |
| 4 | use git_object::borrowed; | 4 | use git_object::borrowed; |
| 5 | 5 | ||
| @@ -72,12 +72,12 @@ impl Graph { · 66 unmodified lines | |||
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | struct LookupByIdResult<'a> { | 74 | struct LookupByIdResult<'a> { |
| 75 | pub file: &'a GraphFile, | 75 | pub file: &'a File, |
| 76 | pub graph_pos: GraphPosition, | 76 | pub graph_pos: GraphPosition, |
| 77 | pub lex_pos: LexPosition, | 77 | pub lex_pos: LexPosition, |
| 78 | } | 78 | } |
| 79 | 79 | ||
| 80 | struct LookupByPositionResult<'a> { | 80 | struct LookupByPositionResult<'a> { |
| 81 | pub file: &'a GraphFile, | 81 | pub file: &'a File, |
| 82 | pub lex_pos: LexPosition, | 82 | pub lex_pos: LexPosition, |
| 83 | } | 83 | } |
| @@ -1,5 +1,5 @@ | |||
| 1 | use crate::graph_file::GraphFile; | 1 | use crate::file::File; |
| 2 | use crate::{graph_file, Graph, MAX_COMMITS}; | 2 | use crate::{file, Graph, MAX_COMMITS}; |
| 3 | use git_object::HashKind; | 3 | use git_object::HashKind; |
| 4 | use quick_error::quick_error; | 4 | use quick_error::quick_error; |
| 5 | use std::io::{BufRead, BufReader}; | 5 | use std::io::{BufRead, BufReader}; |
| @@ -11,7 +11,7 @@ quick_error! { · 5 unmodified lines | |||
| 11 | Corrupt(msg: String, path: PathBuf) { | 11 | Corrupt(msg: String, path: PathBuf) { |
| 12 | display("{}", msg) | 12 | display("{}", msg) |
| 13 | } | 13 | } |
| 14 | GraphFile(err: graph_file::Error, path: PathBuf) { | 14 | File(err: file::Error, path: PathBuf) { |
| 15 | display("{}", path.display()) | 15 | display("{}", path.display()) |
| 16 | source(err) | 16 | source(err) |
| 17 | } | 17 | } |
| @@ -25,7 +25,7 @@ quick_error! { · 7 unmodified lines | |||
| 25 | ) | 25 | ) |
| 26 | } | 26 | } |
| 27 | Io(err: std::io::Error, path: PathBuf) { | 27 | Io(err: std::io::Error, path: PathBuf) { |
| 28 | display("Could not open commit-graph graph_file at '{}'", path.display()) | 28 | display("Could not open commit-graph file at '{}'", path.display()) |
| 29 | source(err) | 29 | source(err) |
| 30 | } | 30 | } |
| 31 | TooManyCommits(num_commits: u64) { | 31 | TooManyCommits(num_commits: u64) { |
| @@ -46,7 +46,7 @@ impl Graph { · 14 unmodified lines | |||
| 46 | 46 | ||
| 47 | pub fn from_single_file(info_dir: impl AsRef<Path>) -> Result<Self, Error> { | 47 | pub fn from_single_file(info_dir: impl AsRef<Path>) -> Result<Self, Error> { |
| 48 | let single_graph_file = info_dir.as_ref().join("commit-graph"); | 48 | let single_graph_file = info_dir.as_ref().join("commit-graph"); |
| 49 | let file = GraphFile::at(&single_graph_file).map_err(|e| Error::GraphFile(e, single_graph_file.clone()))?; | 49 | let file = File::at(&single_graph_file).map_err(|e| Error::File(e, single_graph_file.clone()))?; |
| 50 | Self::new(vec![file]) | 50 | Self::new(vec![file]) |
| 51 | } | 51 | } |
| 52 | 52 | ||
| @@ -54,17 +54,17 @@ impl Graph { · 1 unmodified line | |||
| 54 | let commit_graphs_dir = commit_graphs_dir.as_ref(); | 54 | let commit_graphs_dir = commit_graphs_dir.as_ref(); |
| 55 | let chain_file_path = commit_graphs_dir.join("commit-graph-chain"); | 55 | let chain_file_path = commit_graphs_dir.join("commit-graph-chain"); |
| 56 | let chain_file = std::fs::File::open(&chain_file_path).map_err(|e| Error::Io(e, chain_file_path.clone()))?; | 56 | let chain_file = std::fs::File::open(&chain_file_path).map_err(|e| Error::Io(e, chain_file_path.clone()))?; |
| 57 | let mut files: Vec<GraphFile> = Vec::new(); | 57 | let mut files: Vec<File> = Vec::new(); |
| 58 | for line in BufReader::new(chain_file).lines() { | 58 | for line in BufReader::new(chain_file).lines() { |
| 59 | let line = line.map_err(|e| Error::Io(e, chain_file_path.clone()))?; | 59 | let line = line.map_err(|e| Error::Io(e, chain_file_path.clone()))?; |
| 60 | let graph_filename = format!("graph-{}.graph", line); | 60 | let graph_filename = format!("graph-{}.graph", line); |
| 61 | let graph_file_path = commit_graphs_dir.join(graph_filename); | 61 | let graph_file_path = commit_graphs_dir.join(graph_filename); |
| 62 | files.push(GraphFile::at(&graph_file_path).map_err(|e| Error::GraphFile(e, graph_file_path.clone()))?); | 62 | files.push(File::at(&graph_file_path).map_err(|e| Error::File(e, graph_file_path.clone()))?); |
| 63 | } | 63 | } |
| 64 | Self::new(files) | 64 | Self::new(files) |
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | pub fn new(files: Vec<GraphFile>) -> Result<Self, Error> { | 67 | pub fn new(files: Vec<File>) -> Result<Self, Error> { |
| 68 | let num_commits: u64 = files.iter().map(|f| f.num_commits() as u64).sum(); | 68 | let num_commits: u64 = files.iter().map(|f| f.num_commits() as u64).sum(); |
| 69 | if num_commits > MAX_COMMITS as u64 { | 69 | if num_commits > MAX_COMMITS as u64 { |
| 70 | return Err(Error::TooManyCommits(num_commits)); | 70 | return Err(Error::TooManyCommits(num_commits)); |
| @@ -1,7 +1,7 @@ | |||
| 1 | mod access; | 1 | mod access; |
| 2 | mod init; | 2 | mod init; |
| 3 | 3 | ||
| 4 | use crate::graph_file::GraphFile; | 4 | use crate::file::File; |
| 5 | use std::fmt::{Display, Formatter}; | 5 | use std::fmt::{Display, Formatter}; |
| 6 | 6 | ||
| 7 | /// A complete commit graph. | 7 | /// A complete commit graph. |
| @@ -10,7 +10,7 @@ use std::fmt::{Display, Formatter}; · 2 unmodified lines | |||
| 10 | /// may come from one or more `objects/info/commit-graphs/graph-*.graph` files. These files are | 10 | /// may come from one or more `objects/info/commit-graphs/graph-*.graph` files. These files are |
| 11 | /// generated via `git commit-graph write ...` commands. | 11 | /// generated via `git commit-graph write ...` commands. |
| 12 | pub struct Graph { | 12 | pub struct Graph { |
| 13 | files: Vec<GraphFile>, | 13 | files: Vec<File>, |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] | 16 | #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] |
| @@ -1,10 +1,10 @@ | |||
| 1 | #![forbid(unsafe_code)] | 1 | #![forbid(unsafe_code)] |
| 2 | #![deny(rust_2018_idioms)] | 2 | #![deny(rust_2018_idioms)] |
| 3 | 3 | ||
| 4 | pub mod file; | ||
| 4 | pub mod graph; | 5 | pub mod graph; |
| 5 | pub mod graph_file; | ||
| 6 | 6 | ||
| 7 | pub use file::commit::Commit; | ||
| 7 | pub use graph::{Graph, GraphPosition}; | 8 | pub use graph::{Graph, GraphPosition}; |
| 8 | pub use graph_file::commit::Commit; | ||
| 9 | 9 | ||
| 10 | pub const MAX_COMMITS: u32 = (1 << 30) + (1 << 29) + (1 << 28) - 1; | 10 | pub const MAX_COMMITS: u32 = (1 << 30) + (1 << 29) + (1 << 28) - 1; |