History

[commitgraph] refactor

Sebastian Thiel committed 6 years ago

Commit 2ed00371 parent 70269613 files · +15 −11Browse files

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

Unified · Split

3 files
  1. git-commitgraph/Cargo.toml +3 −3
  2. git-commitgraph/tests/access/mod.rs +4 −4
  3. git-commitgraph/tests/commitgraph.rs +8 −4
git-commitgraph/Cargo.toml+3−3
@@ -1,11 +1,11 @@
11 [package]
22 name = "git-commitgraph"
33 version = "0.0.0"
4−repository = "https://github.com/Byron/git-oxide"
4+repository = "https://github.com/Byron/gitxoxide"
55 documentation = "https://git-scm.com/docs/commit-graph#:~:text=The%20commit-graph%20file%20is%20a%20supplemental%20data%20structure,or%20in%20the%20info%20directory%20of%20an%20alternate."
66 license = "MIT/Apache-2.0"
7−description = "A WIP crate of the gitoxide project dedicated implementing the git commitgraph file format and its maintenance"
8−authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>", "Conor Davis <gitoxide@conor.fastmail.fm>"]
7+description = "A crate of the gitoxide project dedicated implementing the git commitgraph file format and its maintenance"
8+authors = ["Conor Davis <gitoxide@conor.fastmail.fm>", "Sebastian Thiel <sebastian.thiel@icloud.com>"]
99 edition = "2018"
1010
1111 [lib]
git-commitgraph/tests/access/mod.rs+4−4
@@ -2,7 +2,7 @@ use crate::{check_common, create_repo, inspect_refs}; · 1 unmodified line
22 use git_commitgraph::Graph;
33
44 #[test]
5−fn single_parent() -> Result<(), Box<dyn std::error::Error>> {
5+fn single_parent() -> crate::Result {
66 let repo_dir = create_repo("single_parent.sh");
77 let refs = inspect_refs(repo_dir.path(), &["parent", "child"]);
88 let cg = Graph::from_info_dir(repo_dir.path().join(".git").join("objects").join("info"))?;
@@ -15,7 +15,7 @@ fn single_parent() -> Result<(), Box<dyn std::error::Error>> { · 6 unmodified lines
1515 }
1616
1717 #[test]
18−fn octupus_merges() -> Result<(), Box<dyn std::error::Error>> {
18+fn octupus_merges() -> crate::Result {
1919 let repo_dir = create_repo("octopus_merges.sh");
2020 let refs = inspect_refs(
2121 repo_dir.path(),
@@ -44,7 +44,7 @@ fn octupus_merges() -> Result<(), Box<dyn std::error::Error>> { · 22 unmodified lines
4444 }
4545
4646 #[test]
47−fn single_commit() -> Result<(), Box<dyn std::error::Error>> {
47+fn single_commit() -> crate::Result {
4848 let repo_dir = create_repo("single_commit.sh");
4949 let refs = inspect_refs(repo_dir.path(), &["commit"]);
5050 let cg = Graph::from_info_dir(repo_dir.path().join(".git").join("objects").join("info"))?;
@@ -56,7 +56,7 @@ fn single_commit() -> Result<(), Box<dyn std::error::Error>> { · 5 unmodified lines
5656 }
5757
5858 #[test]
59−fn two_parents() -> Result<(), Box<dyn std::error::Error>> {
59+fn two_parents() -> crate::Result {
6060 let repo_dir = create_repo("two_parents.sh");
6161 let refs = inspect_refs(repo_dir.path(), &["parent1", "parent2", "child"]);
6262 let cg = Graph::from_info_dir(repo_dir.path().join(".git").join("objects").join("info"))?;
git-commitgraph/tests/commitgraph.rs+8−4
@@ -9,6 +9,8 @@ use std::{ · 8 unmodified lines
99 process::Command,
1010 };
1111
12+type Result = std::result::Result<(), Box<dyn std::error::Error>>;
13+
1214 mod access;
1315
1416 pub fn check_common(cg: &Graph, expected: &HashMap<String, RefInfo, impl BuildHasher>) {
@@ -35,6 +37,7 @@ pub fn check_common(cg: &Graph, expected: &HashMap<String, RefInfo, impl BuildHa · 20 unmodified lines
3537 .expect("find RefInfo by id")
3638 })
3739 .collect();
40+
3841 let commit = cg.commit_at(ref_info.pos());
3942 assert_eq!(commit.id(), ref_info.id());
4043 assert_eq!(commit.root_tree_id(), ref_info.root_tree_id());
@@ -45,7 +48,7 @@ pub fn check_common(cg: &Graph, expected: &HashMap<String, RefInfo, impl BuildHa · 4 unmodified lines
4548 assert_eq!(
4649 commit
4750 .iter_parents()
48− .collect::<Result<Vec<_>, _>>()
51+ .collect::<std::result::Result<Vec<_>, _>>()
4952 .expect("failed to access commit's parents"),
5053 expected_parents.iter().map(|x| x.pos()).collect::<Vec<_>>()
5154 );
@@ -134,10 +137,11 @@ pub fn inspect_refs(repo_dir: impl AsRef<Path>, refs: &[&'static str]) -> HashMa · 82 unmodified lines
134137 infos.sort_by_key(|x| x.1);
135138
136139 let get_pos = |id: borrowed::Id| -> GraphPosition {
137− let pos = infos
140+ let pos: u32 = infos
138141 .binary_search_by_key(&id, |x| x.1.to_borrowed())
139− .expect("sorted_ids to contain id");
140− let pos: u32 = pos.try_into().expect("graph position to fit in u32");
142+ .expect("sorted_ids to contain id")
143+ .try_into()
144+ .expect("graph position to fit in u32");
141145 GraphPosition(pos)
142146 };
143147