Skip to content

Commit ba5cc71

Browse files
committed
refactor
* use items so that abstracting the traversal is easier * remove `gix-ref`
1 parent 78bc6e0 commit ba5cc71

File tree

3 files changed

+16
-21
lines changed

3 files changed

+16
-21
lines changed

gix-blame/Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ gix-diff = { version = "^0.46.0", path = "../gix-diff", default-features = false
1818
gix-object = { version = "^0.44.0", path = "../gix-object" }
1919
gix-hash = { version = "^0.14.2", path = "../gix-hash" }
2020
gix-worktree = { version = "^0.36.0", path = "../gix-worktree", default-features = false, features = ["attributes"] }
21-
22-
# TODO: remove dependencies below this comment by abstracting them away, or passing 'big' types as argument
23-
gix-ref = { version = "^0.47.0", path = "../gix-ref" }
2421
gix-traverse = { version = "^0.41.0", path = "../gix-traverse" }
2522

2623
[dev-dependencies]
24+
gix-ref = { version = "^0.47.0", path = "../gix-ref" }
2725
gix-filter = { version = "^0.13.0", path = "../gix-filter" }
2826
gix-fs = { version = "^0.11.3", path = "../gix-fs" }
2927
gix-index = { version = "^0.35.0", path = "../gix-index" }

gix-blame/src/lib.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ use std::{
77
path::PathBuf,
88
};
99

10-
use gix_diff::blob::{Platform, Sink};
11-
use gix_hash::{oid, ObjectId};
10+
use gix_hash::ObjectId;
11+
use gix_object::bstr::BStr;
1212
use gix_object::FindExt;
13-
use gix_ref::bstr::BStr;
14-
use gix_traverse::commit::Simple;
1513

1614
#[derive(Clone, Copy, Debug, PartialEq)]
1715
pub enum Offset {
@@ -247,7 +245,7 @@ impl ChangeRecorder {
247245
}
248246
}
249247

250-
impl Sink for ChangeRecorder {
248+
impl gix_diff::blob::Sink for ChangeRecorder {
251249
type Out = Vec<Change>;
252250

253251
// “imara-diff will compute a line diff by default”, so each `start` and `end` represents a
@@ -661,13 +659,13 @@ fn coalesce_blame_entries(lines_blamed: Vec<BlameEntry>) -> Vec<BlameEntry> {
661659
}
662660

663661
// TODO: do not instantiate anything, get everything passed as argument.
664-
pub fn blame_file<T: gix_object::Find + gix_object::FindHeader>(
665-
odb: &T,
666-
traverse: &mut Simple<&T, fn(&oid) -> bool>,
667-
resource_cache: &mut Platform,
662+
pub fn blame_file<E>(
663+
odb: impl gix_object::Find + gix_object::FindHeader,
664+
traverse: impl IntoIterator<Item = Result<gix_traverse::commit::Info, E>>,
665+
resource_cache: &mut gix_diff::blob::Platform,
668666
worktree_path: PathBuf,
669667
file_path: &BStr,
670-
) -> Vec<BlameEntry> {
668+
) -> Result<Vec<BlameEntry>, E> {
671669
// TODO
672670
// At a high level, what we want to do is the following:
673671
//
@@ -700,15 +698,13 @@ pub fn blame_file<T: gix_object::Find + gix_object::FindHeader>(
700698
)];
701699
let mut out: Vec<BlameEntry> = vec![];
702700

703-
loop {
704-
let item = traverse.next().unwrap().unwrap();
701+
for item in traverse {
702+
let item = item?;
705703
let suspect = item.id;
706704

707-
let iter = traverse.commit_iter();
708-
let parent_ids = iter.parent_ids().collect::<Vec<_>>();
709-
705+
let parent_ids = item.parent_ids;
710706
if parent_ids.is_empty() {
711-
// I’m not entirely sure this is correct yet. `suspect`, at this point, is the `id` of
707+
// I’m not entirely sure if this is correct yet. `suspect`, at this point, is the `id` of
712708
// the last `item` that was yielded by `traverse`, so it makes sense to assign the
713709
// remaining lines to it, even though we don’t explicitly check whether that is true
714710
// here. We could perhaps use `needed_to_obtain` to compare `suspect` against an empty
@@ -831,5 +827,5 @@ pub fn blame_file<T: gix_object::Find + gix_object::FindHeader>(
831827
// order on insertion.
832828
out.sort_by(|a, b| a.range_in_blamed_file.start.cmp(&b.range_in_blamed_file.start));
833829

834-
coalesce_blame_entries(out)
830+
Ok(coalesce_blame_entries(out))
835831
}

gix-blame/tests/blame.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ macro_rules! mktest {
150150
&mut resource_cache,
151151
worktree_path,
152152
format!("{}.txt", $case).as_str().into(),
153-
);
153+
)
154+
.unwrap();
154155

155156
assert_eq!(lines_blamed.len(), $number_of_lines);
156157

0 commit comments

Comments
 (0)