History

[commitgraph] Rename GraphFile -> File.

Conor Davis committed 6 years ago

Commit f4518221 parent d8c20078 files · +42 −42Browse files

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

Unified · Split

8 files
  1. git-commitgraph/src/file/access.rs +5 −5
  2. git-commitgraph/src/file/commit.rs +4 −4
  3. git-commitgraph/src/file/init.rs +15 −15
  4. git-commitgraph/src/file/mod.rs +3 −3
  5. git-commitgraph/src/graph/access.rs +3 −3
  6. git-commitgraph/src/graph/init.rs +8 −8
  7. git-commitgraph/src/graph/mod.rs +2 −2
  8. git-commitgraph/src/lib.rs +2 −2
git-commitgraph/src/file/access.rsrenamed from git-commitgraph/src/graph_file/access.rs+5−5
@@ -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};
22 use crate::Commit;
33 use git_object::{borrowed, HashKind, SHA1_SIZE};
44 use std::convert::{TryFrom, TryInto};
55 use std::fmt::{Debug, Formatter};
66 use std::path::Path;
77
8−impl GraphFile {
8+impl File {
99 /// Returns the commit data for the commit located at the given lex position.
1010 ///
1111 /// `pos` must range from 0 to self.num_commits().
@@ -94,7 +94,7 @@ impl GraphFile { · 82 unmodified lines
9494 }
9595 }
9696
97−impl GraphFile {
97+impl File {
9898 /// Returns the byte slice for the given commit in this file's Commit Data (CDAT) chunk.
9999 pub(crate) fn commit_data_bytes(&self, pos: LexPosition) -> &[u8] {
100100 assert!(
@@ -117,8 +117,8 @@ impl GraphFile { · 16 unmodified lines
117117 }
118118 }
119119
120−impl Debug for GraphFile {
120+impl Debug for File {
121121 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())
123123 }
124124 }
git-commitgraph/src/file/commit.rsrenamed from git-commitgraph/src/graph_file/commit.rs+4−4
@@ -1,5 +1,5 @@
1+use crate::file::{File, LexPosition};
12 use crate::graph::GraphPosition;
2−use crate::graph_file::{GraphFile, LexPosition};
33 use byteorder::{BigEndian, ByteOrder};
44 use git_object::{borrowed, owned, SHA1_SIZE};
55 use quick_error::quick_error;
@@ -40,7 +40,7 @@ const NO_PARENT: u32 = 0x7000_0000; · 34 unmodified lines
4040 const EXTENDED_EDGES_MASK: u32 = 0x8000_0000;
4141
4242 pub struct Commit<'a> {
43− file: &'a GraphFile,
43+ file: &'a File,
4444 lex_pos: LexPosition,
4545 // We can parse the below fields lazily if needed.
4646 commit_timestamp: u64,
@@ -51,7 +51,7 @@ pub struct Commit<'a> { · 4 unmodified lines
5151 }
5252
5353 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 {
5555 let bytes = file.commit_data_bytes(pos);
5656 Commit {
5757 file,
@@ -121,7 +121,7 @@ impl<'a> Eq for Commit<'a> {} · 63 unmodified lines
121121
122122 impl<'a> PartialEq for Commit<'a> {
123123 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
125125 }
126126 }
127127
git-commitgraph/src/file/init.rsrenamed from git-commitgraph/src/graph_file/init.rs+15−15
@@ -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};
22 use bstr::ByteSlice;
33 use byteorder::{BigEndian, ByteOrder};
44 use filebuffer::FileBuffer;
@@ -15,7 +15,7 @@ quick_error! { · 10 unmodified lines
1515 pub enum Error {
1616 BaseGraphMismatch(from_header: u8, from_chunk: u32) {
1717 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",
1919 BASE_GRAPHS_LIST_CHUNK_ID.as_bstr(),
2020 from_chunk,
2121 from_header,
@@ -34,7 +34,7 @@ quick_error! { · 12 unmodified lines
3434 display("{}", msg)
3535 }
3636 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())
3838 }
3939 // This error case is disabled, as git allows extra garbage in the extra edges list.
4040 // ExtraEdgesOverflow {
@@ -44,17 +44,17 @@ quick_error! { · 3 unmodified lines
4444 display("Commit-graph chunk {:?} has invalid size: {}", id.as_bstr(), msg)
4545 }
4646 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())
4848 source(err)
4949 }
5050 MissingChunk(id: ChunkId) {
5151 display("Missing required chunk {:?}", id.as_bstr())
5252 }
5353 UnsupportedHashVersion(version: u8) {
54− display("Commit-graph graph_file uses unsupported hash version: {}", version)
54+ display("Commit-graph file uses unsupported hash version: {}", version)
5555 }
5656 UnsupportedVersion(version: u8) {
57− display("Unsupported commit-graph graph_file version: {}", version)
57+ display("Unsupported commit-graph file version: {}", version)
5858 }
5959 }
6060 }
@@ -73,13 +73,13 @@ const OID_FAN_CHUNK_ID: ChunkId = *b"OIDF"; · 12 unmodified lines
7373 const OID_LOOKUP_CHUNK_ID: ChunkId = *b"OIDL";
7474 const SENTINEL_CHUNK_ID: ChunkId = [0u8; 4];
7575
76−impl GraphFile {
77− pub fn at(path: impl AsRef<Path>) -> Result<GraphFile, Error> {
76+impl File {
77+ pub fn at(path: impl AsRef<Path>) -> Result<File, Error> {
7878 Self::try_from(path.as_ref())
7979 }
8080 }
8181
82−impl TryFrom<&Path> for GraphFile {
82+impl TryFrom<&Path> for File {
8383 type Error = Error;
8484
8585 fn try_from(path: &Path) -> Result<Self, Self::Error> {
@@ -87,14 +87,14 @@ impl TryFrom<&Path> for GraphFile { · 1 unmodified line
8787 let data_size = data.len();
8888 if data_size < MIN_FILE_SIZE {
8989 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(),
9191 ));
9292 }
9393
9494 let mut ofs = 0;
9595 if &data[ofs..ofs + SIGNATURE.len()] != SIGNATURE {
9696 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(),
9898 ));
9999 }
100100 ofs += SIGNATURE.len();
@@ -126,7 +126,7 @@ impl TryFrom<&Path> for GraphFile { · 25 unmodified lines
126126 let chunk_lookup_end = ofs + ((chunk_count as usize + 1) * CHUNK_LOOKUP_SIZE);
127127 if chunk_lookup_end > data_size {
128128 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",
130130 chunk_count
131131 )));
132132 }
@@ -168,7 +168,7 @@ impl TryFrom<&Path> for GraphFile { · 35 unmodified lines
168168 if next_chunk_offset >= data_size {
169169 return Err(Error::InvalidChunkSize(
170170 chunk_id,
171− "chunk extends beyond end of graph_file".to_string(),
171+ "chunk extends beyond end of file".to_string(),
172172 ));
173173 }
174174
@@ -260,7 +260,7 @@ impl TryFrom<&Path> for GraphFile { · 85 unmodified lines
260260 }
261261 if chunk_id != SENTINEL_CHUNK_ID {
262262 return Err(Error::Corrupt(format!(
263− "Commit-graph graph_file has invalid last chunk ID: {:?}",
263+ "Commit-graph file has invalid last chunk ID: {:?}",
264264 chunk_id.as_bstr()
265265 )));
266266 }
@@ -289,7 +289,7 @@ impl TryFrom<&Path> for GraphFile { · 22 unmodified lines
289289 commit_data_count,
290290 ));
291291 }
292− Ok(GraphFile {
292+ Ok(File {
293293 base_graph_count,
294294 base_graphs_list_offset,
295295 commit_data_offset,
git-commitgraph/src/file/mod.rsrenamed from git-commitgraph/src/graph_file/mod.rs+3−3
@@ -16,9 +16,9 @@ const SIGNATURE: &[u8] = b"CGPH"; · 15 unmodified lines
1616
1717 /// A single commit-graph file.
1818 ///
19−/// All operations on a `GraphFile` are local to that graph file. Since a commit graph can span
20−/// multiple files, all interesting graph operations belong on `Graph`.
21−pub struct GraphFile {
19+/// All operations on a `File` are local to that graph file. Since a commit graph can span multiple
20+/// files, all interesting graph operations belong on `Graph`.
21+pub struct File {
2222 base_graph_count: u8,
2323 base_graphs_list_offset: Option<usize>,
2424 commit_data_offset: usize,
git-commitgraph/src/graph/access.rs+3−3
@@ -1,5 +1,5 @@
1+use crate::file::{File, LexPosition};
12 use crate::graph::GraphPosition;
2−use crate::graph_file::{GraphFile, LexPosition};
33 use crate::{Commit, Graph};
44 use git_object::borrowed;
55
@@ -72,12 +72,12 @@ impl Graph { · 66 unmodified lines
7272 }
7373
7474 struct LookupByIdResult<'a> {
75− pub file: &'a GraphFile,
75+ pub file: &'a File,
7676 pub graph_pos: GraphPosition,
7777 pub lex_pos: LexPosition,
7878 }
7979
8080 struct LookupByPositionResult<'a> {
81− pub file: &'a GraphFile,
81+ pub file: &'a File,
8282 pub lex_pos: LexPosition,
8383 }
git-commitgraph/src/graph/init.rs+8−8
@@ -1,5 +1,5 @@
1−use crate::graph_file::GraphFile;
2−use crate::{graph_file, Graph, MAX_COMMITS};
1+use crate::file::File;
2+use crate::{file, Graph, MAX_COMMITS};
33 use git_object::HashKind;
44 use quick_error::quick_error;
55 use std::io::{BufRead, BufReader};
@@ -11,7 +11,7 @@ quick_error! { · 5 unmodified lines
1111 Corrupt(msg: String, path: PathBuf) {
1212 display("{}", msg)
1313 }
14− GraphFile(err: graph_file::Error, path: PathBuf) {
14+ File(err: file::Error, path: PathBuf) {
1515 display("{}", path.display())
1616 source(err)
1717 }
@@ -25,7 +25,7 @@ quick_error! { · 7 unmodified lines
2525 )
2626 }
2727 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())
2929 source(err)
3030 }
3131 TooManyCommits(num_commits: u64) {
@@ -46,7 +46,7 @@ impl Graph { · 14 unmodified lines
4646
4747 pub fn from_single_file(info_dir: impl AsRef<Path>) -> Result<Self, Error> {
4848 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()))?;
5050 Self::new(vec![file])
5151 }
5252
@@ -54,17 +54,17 @@ impl Graph { · 1 unmodified line
5454 let commit_graphs_dir = commit_graphs_dir.as_ref();
5555 let chain_file_path = commit_graphs_dir.join("commit-graph-chain");
5656 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();
5858 for line in BufReader::new(chain_file).lines() {
5959 let line = line.map_err(|e| Error::Io(e, chain_file_path.clone()))?;
6060 let graph_filename = format!("graph-{}.graph", line);
6161 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()))?);
6363 }
6464 Self::new(files)
6565 }
6666
67− pub fn new(files: Vec<GraphFile>) -> Result<Self, Error> {
67+ pub fn new(files: Vec<File>) -> Result<Self, Error> {
6868 let num_commits: u64 = files.iter().map(|f| f.num_commits() as u64).sum();
6969 if num_commits > MAX_COMMITS as u64 {
7070 return Err(Error::TooManyCommits(num_commits));
git-commitgraph/src/graph/mod.rs+2−2
@@ -1,7 +1,7 @@
11 mod access;
22 mod init;
33
4−use crate::graph_file::GraphFile;
4+use crate::file::File;
55 use std::fmt::{Display, Formatter};
66
77 /// A complete commit graph.
@@ -10,7 +10,7 @@ use std::fmt::{Display, Formatter}; · 2 unmodified lines
1010 /// may come from one or more `objects/info/commit-graphs/graph-*.graph` files. These files are
1111 /// generated via `git commit-graph write ...` commands.
1212 pub struct Graph {
13− files: Vec<GraphFile>,
13+ files: Vec<File>,
1414 }
1515
1616 #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
git-commitgraph/src/lib.rs+2−2
@@ -1,10 +1,10 @@
11 #![forbid(unsafe_code)]
22 #![deny(rust_2018_idioms)]
33
4+pub mod file;
45 pub mod graph;
5−pub mod graph_file;
66
7+pub use file::commit::Commit;
78 pub use graph::{Graph, GraphPosition};
8−pub use graph_file::commit::Commit;
99
1010 pub const MAX_COMMITS: u32 = (1 << 30) + (1 << 29) + (1 << 28) - 1;