This gives callers more freedom in how their directories are structured.
Showing the changes to git-commitgraph/src (1 of 5 files). Show all
Unified · Split
| @@ -48,18 +48,19 @@ quick_error! { · 47 unmodified lines | |||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | impl Graph { | 50 | impl Graph { |
| 51 | pub fn from_object_dir(object_dir: impl AsRef<Path>) -> Result<Self, Error> { | 51 | pub fn from_info_dir(info_dir: impl AsRef<Path>) -> Result<Self, Error> { |
| 52 | Self::from_single_file(object_dir.as_ref()).or_else(|_| Self::from_split_chain(object_dir.as_ref())) | 52 | Self::from_single_file(info_dir.as_ref()) |
| 53 | .or_else(|_| Self::from_split_chain(info_dir.as_ref().join("commit-graphs"))) | ||
| 53 | } | 54 | } |
| 54 | 55 | ||
| 55 | pub fn from_single_file(object_dir: impl AsRef<Path>) -> Result<Self, Error> { | 56 | pub fn from_single_file(info_dir: impl AsRef<Path>) -> Result<Self, Error> { |
| 56 | let single_graph_file = object_dir.as_ref().join("info").join("commit-graph"); | 57 | let single_graph_file = info_dir.as_ref().join("commit-graph"); |
| 57 | let file = GraphFile::at(&single_graph_file).map_err(|e| Error::GraphFile(e, single_graph_file.clone()))?; | 58 | let file = GraphFile::at(&single_graph_file).map_err(|e| Error::GraphFile(e, single_graph_file.clone()))?; |
| 58 | Self::new(vec![file]) | 59 | Self::new(vec![file]) |
| 59 | } | 60 | } |
| 60 | 61 | ||
| 61 | pub fn from_split_chain(object_dir: impl AsRef<Path>) -> Result<Self, Error> { | 62 | pub fn from_split_chain(commit_graphs_dir: impl AsRef<Path>) -> Result<Self, Error> { |
| 62 | let commit_graphs_dir = object_dir.as_ref().join("info").join("commit-graphs"); | 63 | let commit_graphs_dir = commit_graphs_dir.as_ref(); |
| 63 | let chain_file_path = commit_graphs_dir.join("commit-graph-chain"); | 64 | let chain_file_path = commit_graphs_dir.join("commit-graph-chain"); |
| 64 | let chain_file = std::fs::File::open(&chain_file_path).map_err(|e| Error::Io(e, chain_file_path.clone()))?; | 65 | let chain_file = std::fs::File::open(&chain_file_path).map_err(|e| Error::Io(e, chain_file_path.clone()))?; |
| 65 | let mut files: Vec<GraphFile> = Vec::new(); | 66 | let mut files: Vec<GraphFile> = Vec::new(); |