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 @@
1[package]1[package]
2name = "git-commitgraph"2name = "git-commitgraph"
3version = "0.0.0"3version = "0.0.0"
4repository = "https://github.com/Byron/git-oxide"4repository = "https://github.com/Byron/gitxoxide"
5documentation = "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."5documentation = "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."
6license = "MIT/Apache-2.0"6license = "MIT/Apache-2.0"
7description = "A WIP crate of the gitoxide project dedicated implementing the git commitgraph file format and its maintenance"7description = "A crate of the gitoxide project dedicated implementing the git commitgraph file format and its maintenance"
8authors = ["Sebastian Thiel <sebastian.thiel@icloud.com>", "Conor Davis <gitoxide@conor.fastmail.fm>"]8authors = ["Conor Davis <gitoxide@conor.fastmail.fm>", "Sebastian Thiel <sebastian.thiel@icloud.com>"]
9edition = "2018"9edition = "2018"
10 10
11[lib]11[lib]
git-commitgraph/tests/access/mod.rs+4−4
@@ -2,7 +2,7 @@ use crate::{check_common, create_repo, inspect_refs}; · 1 unmodified line
2use git_commitgraph::Graph;2use git_commitgraph::Graph;
3 3
4#[test]4#[test]
5fn single_parent() -> Result<(), Box<dyn std::error::Error>> {5fn single_parent() -> crate::Result {
6 let repo_dir = create_repo("single_parent.sh");6 let repo_dir = create_repo("single_parent.sh");
7 let refs = inspect_refs(repo_dir.path(), &["parent", "child"]);7 let refs = inspect_refs(repo_dir.path(), &["parent", "child"]);
8 let cg = Graph::from_info_dir(repo_dir.path().join(".git").join("objects").join("info"))?;8 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
15}15}
16 16
17#[test]17#[test]
18fn octupus_merges() -> Result<(), Box<dyn std::error::Error>> {18fn octupus_merges() -> crate::Result {
19 let repo_dir = create_repo("octopus_merges.sh");19 let repo_dir = create_repo("octopus_merges.sh");
20 let refs = inspect_refs(20 let refs = inspect_refs(
21 repo_dir.path(),21 repo_dir.path(),
@@ -44,7 +44,7 @@ fn octupus_merges() -> Result<(), Box<dyn std::error::Error>> { · 22 unmodified lines
44}44}
45 45
46#[test]46#[test]
47fn single_commit() -> Result<(), Box<dyn std::error::Error>> {47fn single_commit() -> crate::Result {
48 let repo_dir = create_repo("single_commit.sh");48 let repo_dir = create_repo("single_commit.sh");
49 let refs = inspect_refs(repo_dir.path(), &["commit"]);49 let refs = inspect_refs(repo_dir.path(), &["commit"]);
50 let cg = Graph::from_info_dir(repo_dir.path().join(".git").join("objects").join("info"))?;50 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
56}56}
57 57
58#[test]58#[test]
59fn two_parents() -> Result<(), Box<dyn std::error::Error>> {59fn two_parents() -> crate::Result {
60 let repo_dir = create_repo("two_parents.sh");60 let repo_dir = create_repo("two_parents.sh");
61 let refs = inspect_refs(repo_dir.path(), &["parent1", "parent2", "child"]);61 let refs = inspect_refs(repo_dir.path(), &["parent1", "parent2", "child"]);
62 let cg = Graph::from_info_dir(repo_dir.path().join(".git").join("objects").join("info"))?;62 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
9 process::Command,9 process::Command,
10};10};
11 11
12type Result = std::result::Result<(), Box<dyn std::error::Error>>;
13
12mod access;14mod access;
13 15
14pub fn check_common(cg: &Graph, expected: &HashMap<String, RefInfo, impl BuildHasher>) {16pub 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
35 .expect("find RefInfo by id")37 .expect("find RefInfo by id")
36 })38 })
37 .collect();39 .collect();
40
38 let commit = cg.commit_at(ref_info.pos());41 let commit = cg.commit_at(ref_info.pos());
39 assert_eq!(commit.id(), ref_info.id());42 assert_eq!(commit.id(), ref_info.id());
40 assert_eq!(commit.root_tree_id(), ref_info.root_tree_id());43 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
45 assert_eq!(48 assert_eq!(
46 commit49 commit
47 .iter_parents()50 .iter_parents()
48 .collect::<Result<Vec<_>, _>>()51 .collect::<std::result::Result<Vec<_>, _>>()
49 .expect("failed to access commit's parents"),52 .expect("failed to access commit's parents"),
50 expected_parents.iter().map(|x| x.pos()).collect::<Vec<_>>()53 expected_parents.iter().map(|x| x.pos()).collect::<Vec<_>>()
51 );54 );
@@ -134,10 +137,11 @@ pub fn inspect_refs(repo_dir: impl AsRef<Path>, refs: &[&'static str]) -> HashMa · 82 unmodified lines
134 infos.sort_by_key(|x| x.1);137 infos.sort_by_key(|x| x.1);
135 138
136 let get_pos = |id: borrowed::Id| -> GraphPosition {139 let get_pos = |id: borrowed::Id| -> GraphPosition {
137 let pos = infos140 let pos: u32 = infos
138 .binary_search_by_key(&id, |x| x.1.to_borrowed())141 .binary_search_by_key(&id, |x| x.1.to_borrowed())
139 .expect("sorted_ids to contain id");142 .expect("sorted_ids to contain id")
140 let pos: u32 = pos.try_into().expect("graph position to fit in u32");143 .try_into()
144 .expect("graph position to fit in u32");
141 GraphPosition(pos)145 GraphPosition(pos)
142 };146 };
143 147