Skip to content

Commit 2ed0037

Browse files
committed
[commitgraph] refactor
1 parent 7026961 commit 2ed0037

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

git-commitgraph/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 <[email protected]>", "Conor Davis <[email protected]>"]
7+
description = "A crate of the gitoxide project dedicated implementing the git commitgraph file format and its maintenance"
8+
authors = ["Conor Davis <[email protected]>", "Sebastian Thiel <[email protected]>"]
99
edition = "2018"
1010

1111
[lib]

git-commitgraph/tests/access/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::{check_common, create_repo, inspect_refs};
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>> {
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>> {
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>> {
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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use std::{
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
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
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
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

0 commit comments

Comments
 (0)