History

[commitgraph] Take `info` dir as arg, not `objects` dir.

This gives callers more freedom in how their directories are structured.

Conor Davis committed 6 years ago

Commit 36953e01 parent d1f0e9c5 files · +11 −10Browse files

Showing the changes to git-commitgraph (5 of 5 files). Show all

Unified · Split

5 files
  1. git-commitgraph/src/graph/init.rs +7 −6
  2. git-commitgraph/tests/access/octopus_merges.rs +1 −1
  3. git-commitgraph/tests/access/single_commit.rs +1 −1
  4. git-commitgraph/tests/access/single_parent.rs +1 −1
  5. git-commitgraph/tests/access/two_parents.rs +1 −1
git-commitgraph/src/graph/init.rs+7−6
@@ -48,18 +48,19 @@ quick_error! { · 47 unmodified lines
4848 }
4949
5050 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")))
5354 }
5455
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");
5758 let file = GraphFile::at(&single_graph_file).map_err(|e| Error::GraphFile(e, single_graph_file.clone()))?;
5859 Self::new(vec![file])
5960 }
6061
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();
6364 let chain_file_path = commit_graphs_dir.join("commit-graph-chain");
6465 let chain_file = std::fs::File::open(&chain_file_path).map_err(|e| Error::Io(e, chain_file_path.clone()))?;
6566 let mut files: Vec<GraphFile> = Vec::new();
git-commitgraph/tests/access/octopus_merges.rs+1−1
@@ -26,7 +26,7 @@ fn v1() -> Result<(), Box<dyn std::error::Error>> { · 25 unmodified lines
2626 let three_parents_id = hex_to_id(THREE_PARENTS);
2727 let four_parents_id = hex_to_id(FOUR_PARENTS);
2828
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"))?;
3030 assert_eq!(cg.num_commits(), 7);
3131 assert_eq!(cg.id_at(ROOT_INDEX), root_id.to_borrowed());
3232 assert_eq!(cg.id_at(COMMIT1_INDEX), commit1_id.to_borrowed());
git-commitgraph/tests/access/single_commit.rs+1−1
@@ -7,7 +7,7 @@ const COMMIT: &[u8] = b"771fa42310bb3d221f4cf82613a491b0957d2003"; · 6 unmodified lines
77 fn v1() -> Result<(), Box<dyn std::error::Error>> {
88 let commit_id = hex_to_id(COMMIT);
99
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"))?;
1111 assert_eq!(cg.num_commits(), 1);
1212 assert_eq!(cg.id_at(GraphPosition(0)), commit_id.to_borrowed());
1313 assert_eq!(cg.iter_ids().collect::<Vec<_>>(), vec![commit_id.to_borrowed()]);
git-commitgraph/tests/access/single_parent.rs+1−1
@@ -9,7 +9,7 @@ fn v1() -> Result<(), Box<dyn std::error::Error>> { · 8 unmodified lines
99 let parent_id = hex_to_id(PARENT);
1010 let child_id = hex_to_id(CHILD);
1111
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"))?;
1313 assert_eq!(cg.num_commits(), 2);
1414 assert_eq!(cg.id_at(GraphPosition(0)), child_id.to_borrowed());
1515 assert_eq!(
git-commitgraph/tests/access/two_parents.rs+1−1
@@ -14,7 +14,7 @@ fn v1() -> Result<(), Box<dyn std::error::Error>> { · 13 unmodified lines
1414 let parent2_id = hex_to_id(PARENT2);
1515 let merge_id = hex_to_id(MERGE);
1616
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"))?;
1818 assert_eq!(cg.num_commits(), 3);
1919 assert_eq!(cg.id_at(PARENT1_INDEX), parent1_id.to_borrowed());
2020 assert_eq!(cg.id_at(PARENT2_INDEX), parent2_id.to_borrowed());

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t