| @@ -9,7 +9,9 @@ use std::{ · 8 unmodified lines |
| 9 | path::{Path, PathBuf}, | 9 | path::{Path, PathBuf}, |
| 10 | }; | 10 | }; |
| 11 | | 11 | |
| | 12 | /// The error used in the [`graph`][crate::graph] module. |
| 12 | #[derive(thiserror::Error, Debug)] | 13 | #[derive(thiserror::Error, Debug)] |
| | 14 | #[allow(missing_docs)] |
| 13 | pub enum Error { | 15 | pub enum Error { |
| 14 | #[error("{}", .path.display())] | 16 | #[error("{}", .path.display())] |
| 15 | File { | 17 | File { |
| @@ -41,10 +43,12 @@ pub enum Error { · 25 unmodified lines |
| 41 | | 43 | |
| 42 | /// Instantiate a `Graph` from various sources. | 44 | /// Instantiate a `Graph` from various sources. |
| 43 | impl Graph { | 45 | impl Graph { |
| | 46 | /// Instantiate a commit graph from `path` which may be a directory containing graph files or the graph file itself. |
| 44 | pub fn at(path: impl AsRef<Path>) -> Result<Self, Error> { | 47 | pub fn at(path: impl AsRef<Path>) -> Result<Self, Error> { |
| 45 | Self::try_from(path.as_ref()) | 48 | Self::try_from(path.as_ref()) |
| 46 | } | 49 | } |
| 47 | | 50 | |
| | 51 | /// Instantiate a commit graph from the directory containing all of its files. |
| 48 | pub fn from_commit_graphs_dir(path: impl AsRef<Path>) -> Result<Self, Error> { | 52 | pub fn from_commit_graphs_dir(path: impl AsRef<Path>) -> Result<Self, Error> { |
| 49 | let commit_graphs_dir = path.as_ref(); | 53 | let commit_graphs_dir = path.as_ref(); |
| 50 | let chain_file_path = commit_graphs_dir.join("commit-graph-chain"); | 54 | let chain_file_path = commit_graphs_dir.join("commit-graph-chain"); |
| @@ -67,6 +71,8 @@ impl Graph { · 16 unmodified lines |
| 67 | Self::new(files) | 71 | Self::new(files) |
| 68 | } | 72 | } |
| 69 | | 73 | |
| | 74 | /// Instantiate a commit graph from a `.git/objects/info/commit-graph` or |
| | 75 | /// `.git/objects/info/commit-graphs/graph-*.graph` file. |
| 70 | pub fn from_file(path: impl AsRef<Path>) -> Result<Self, Error> { | 76 | pub fn from_file(path: impl AsRef<Path>) -> Result<Self, Error> { |
| 71 | let path = path.as_ref(); | 77 | let path = path.as_ref(); |
| 72 | let file = File::at(path).map_err(|e| Error::File { | 78 | let file = File::at(path).map_err(|e| Error::File { |
| @@ -76,11 +82,13 @@ impl Graph { · 3 unmodified lines |
| 76 | Self::new(vec![file]) | 82 | Self::new(vec![file]) |
| 77 | } | 83 | } |
| 78 | | 84 | |
| | 85 | /// Instantiate a commit graph from an `.git/objects/info` directory. |
| 79 | pub fn from_info_dir(info_dir: impl AsRef<Path>) -> Result<Self, Error> { | 86 | pub fn from_info_dir(info_dir: impl AsRef<Path>) -> Result<Self, Error> { |
| 80 | Self::from_file(info_dir.as_ref().join("commit-graph")) | 87 | Self::from_file(info_dir.as_ref().join("commit-graph")) |
| 81 | .or_else(|_| Self::from_commit_graphs_dir(info_dir.as_ref().join("commit-graphs"))) | 88 | .or_else(|_| Self::from_commit_graphs_dir(info_dir.as_ref().join("commit-graphs"))) |
| 82 | } | 89 | } |
| 83 | | 90 | |
| | 91 | /// Create a new commit graph from a list of `files`. |
| 84 | pub fn new(files: Vec<File>) -> Result<Self, Error> { | 92 | pub fn new(files: Vec<File>) -> Result<Self, Error> { |
| 85 | let num_commits: u64 = files.iter().map(|f| u64::from(f.num_commits())).sum(); | 93 | let num_commits: u64 = files.iter().map(|f| u64::from(f.num_commits())).sum(); |
| 86 | if num_commits > u64::from(MAX_COMMITS) { | 94 | if num_commits > u64::from(MAX_COMMITS) { |