This gives callers more freedom in how their directories are structured.
Showing the changes to git-commitgraph (5 of 5 files). Show all
Unified · Split
| @@ -48,18 +48,19 @@ quick_error! { · 47 unmodified lines | ||
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | impl Graph { |
| 51 | − pub fn from_object_dir(object_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())) | |
| 51 | + pub fn from_info_dir(info_dir: impl AsRef<Path>) -> Result<Self, Error> { | |
| 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 | − let single_graph_file = object_dir.as_ref().join("info").join("commit-graph"); | |
| 56 | + pub fn from_single_file(info_dir: impl AsRef<Path>) -> Result<Self, Error> { | |
| 57 | + let single_graph_file = info_dir.as_ref().join("commit-graph"); | |
| 57 | 58 | let file = GraphFile::at(&single_graph_file).map_err(|e| Error::GraphFile(e, single_graph_file.clone()))?; |
| 58 | 59 | Self::new(vec![file]) |
| 59 | 60 | } |
| 60 | 61 | |
| 61 | − pub fn from_split_chain(object_dir: impl AsRef<Path>) -> Result<Self, Error> { | |
| 62 | − let commit_graphs_dir = object_dir.as_ref().join("info").join("commit-graphs"); | |
| 62 | + pub fn from_split_chain(commit_graphs_dir: impl AsRef<Path>) -> Result<Self, Error> { | |
| 63 | + let commit_graphs_dir = commit_graphs_dir.as_ref(); | |
| 63 | 64 | let chain_file_path = commit_graphs_dir.join("commit-graph-chain"); |
| 64 | 65 | let chain_file = std::fs::File::open(&chain_file_path).map_err(|e| Error::Io(e, chain_file_path.clone()))?; |
| 65 | 66 | let mut files: Vec<GraphFile> = Vec::new(); |
| @@ -26,7 +26,7 @@ fn v1() -> Result<(), Box<dyn std::error::Error>> { · 25 unmodified lines | ||
| 26 | 26 | let three_parents_id = hex_to_id(THREE_PARENTS); |
| 27 | 27 | let four_parents_id = hex_to_id(FOUR_PARENTS); |
| 28 | 28 | |
| 29 | − let cg = Graph::from_object_dir(fixture_path("v1/octopus_merges"))?; | |
| 29 | + let cg = Graph::from_info_dir(fixture_path("v1/octopus_merges/info"))?; | |
| 30 | 30 | assert_eq!(cg.num_commits(), 7); |
| 31 | 31 | assert_eq!(cg.id_at(ROOT_INDEX), root_id.to_borrowed()); |
| 32 | 32 | assert_eq!(cg.id_at(COMMIT1_INDEX), commit1_id.to_borrowed()); |
| @@ -7,7 +7,7 @@ const COMMIT: &[u8] = b"771fa42310bb3d221f4cf82613a491b0957d2003"; · 6 unmodified lines | ||
| 7 | 7 | fn v1() -> Result<(), Box<dyn std::error::Error>> { |
| 8 | 8 | let commit_id = hex_to_id(COMMIT); |
| 9 | 9 | |
| 10 | − let cg = Graph::from_object_dir(fixture_path("v1/single_commit"))?; | |
| 10 | + let cg = Graph::from_info_dir(fixture_path("v1/single_commit/info"))?; | |
| 11 | 11 | assert_eq!(cg.num_commits(), 1); |
| 12 | 12 | assert_eq!(cg.id_at(GraphPosition(0)), commit_id.to_borrowed()); |
| 13 | 13 | assert_eq!(cg.iter_ids().collect::<Vec<_>>(), vec![commit_id.to_borrowed()]); |
| @@ -9,7 +9,7 @@ fn v1() -> Result<(), Box<dyn std::error::Error>> { · 8 unmodified lines | ||
| 9 | 9 | let parent_id = hex_to_id(PARENT); |
| 10 | 10 | let child_id = hex_to_id(CHILD); |
| 11 | 11 | |
| 12 | − let cg = Graph::from_object_dir(fixture_path("v1/single_parent"))?; | |
| 12 | + let cg = Graph::from_info_dir(fixture_path("v1/single_parent/info"))?; | |
| 13 | 13 | assert_eq!(cg.num_commits(), 2); |
| 14 | 14 | assert_eq!(cg.id_at(GraphPosition(0)), child_id.to_borrowed()); |
| 15 | 15 | assert_eq!( |
| @@ -14,7 +14,7 @@ fn v1() -> Result<(), Box<dyn std::error::Error>> { · 13 unmodified lines | ||
| 14 | 14 | let parent2_id = hex_to_id(PARENT2); |
| 15 | 15 | let merge_id = hex_to_id(MERGE); |
| 16 | 16 | |
| 17 | − let cg = Graph::from_object_dir(fixture_path("v1/two_parents"))?; | |
| 17 | + let cg = Graph::from_info_dir(fixture_path("v1/two_parents/info"))?; | |
| 18 | 18 | assert_eq!(cg.num_commits(), 3); |
| 19 | 19 | assert_eq!(cg.id_at(PARENT1_INDEX), parent1_id.to_borrowed()); |
| 20 | 20 | assert_eq!(cg.id_at(PARENT2_INDEX), parent2_id.to_borrowed()); |