Skip to content

Commit 78bc6e0

Browse files
committed
Move setup out of blame_file
Don't depend on `gix-filter`, `gix-fs` and `gix-index`.
1 parent 0f7ef0d commit 78bc6e0

File tree

3 files changed

+51
-42
lines changed

3 files changed

+51
-42
lines changed

gix-blame/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ gix-worktree = { version = "^0.36.0", path = "../gix-worktree", default-features
2222
# TODO: remove dependencies below this comment by abstracting them away, or passing 'big' types as argument
2323
gix-ref = { version = "^0.47.0", path = "../gix-ref" }
2424
gix-traverse = { version = "^0.41.0", path = "../gix-traverse" }
25-
gix-fs = { version = "^0.11.3", path = "../gix-fs" }
26-
gix-index = { version = "^0.35.0", path = "../gix-index" }
27-
gix-filter = { version = "^0.13.0", path = "../gix-filter" }
2825

2926
[dev-dependencies]
27+
gix-filter = { version = "^0.13.0", path = "../gix-filter" }
28+
gix-fs = { version = "^0.11.3", path = "../gix-fs" }
29+
gix-index = { version = "^0.35.0", path = "../gix-index" }
3030
gix-odb = { version = "^0.63.0", path = "../gix-odb" }
3131
gix-testtools = { path = "../tests/tools" }

gix-blame/src/lib.rs

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

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

1516
#[derive(Clone, Copy, Debug, PartialEq)]
1617
pub enum Offset {
@@ -661,8 +662,9 @@ fn coalesce_blame_entries(lines_blamed: Vec<BlameEntry>) -> Vec<BlameEntry> {
661662

662663
// TODO: do not instantiate anything, get everything passed as argument.
663664
pub fn blame_file<T: gix_object::Find + gix_object::FindHeader>(
664-
odb: T,
665-
start_id: ObjectId,
665+
odb: &T,
666+
traverse: &mut Simple<&T, fn(&oid) -> bool>,
667+
resource_cache: &mut Platform,
666668
worktree_path: PathBuf,
667669
file_path: &BStr,
668670
) -> Vec<BlameEntry> {
@@ -684,39 +686,6 @@ pub fn blame_file<T: gix_object::Find + gix_object::FindHeader>(
684686
// <---><---><-----><-------><-----><------->
685687
// <---><---><-----><-------><-----><-><-><->
686688

687-
let mut traverse = gix_traverse::commit::Simple::new(Some(start_id), &odb);
688-
689-
let git_dir = worktree_path.join(".git");
690-
let index = gix_index::File::at(git_dir.join("index"), gix_hash::Kind::Sha1, false, Default::default()).unwrap();
691-
let stack = gix_worktree::Stack::from_state_and_ignore_case(
692-
worktree_path.clone(),
693-
false,
694-
gix_worktree::stack::State::AttributesAndIgnoreStack {
695-
attributes: Default::default(),
696-
ignore: Default::default(),
697-
},
698-
&index,
699-
index.path_backing(),
700-
);
701-
let capabilities = gix_fs::Capabilities::probe(&git_dir);
702-
let mut resource_cache = gix_diff::blob::Platform::new(
703-
Default::default(),
704-
gix_diff::blob::Pipeline::new(
705-
gix_diff::blob::pipeline::WorktreeRoots {
706-
old_root: None,
707-
new_root: None,
708-
},
709-
gix_filter::Pipeline::new(Default::default(), Default::default()),
710-
vec![],
711-
gix_diff::blob::pipeline::Options {
712-
large_file_threshold_bytes: 0,
713-
fs: capabilities,
714-
},
715-
),
716-
gix_diff::blob::pipeline::Mode::ToGit,
717-
stack,
718-
);
719-
720689
// Needed for `to_str`.
721690
use gix_object::bstr::ByteSlice;
722691

gix-blame/tests/blame.rs

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,49 @@ macro_rules! mktest {
105105

106106
let head_id = reference.peel_to_id_in_place(&store, &odb).unwrap();
107107

108+
let mut traverse = gix_traverse::commit::Simple::new(Some(head_id), &odb);
109+
110+
let git_dir = worktree_path.join(".git");
111+
let index = gix_index::File::at(
112+
git_dir.join("index"),
113+
gix_hash::Kind::Sha1,
114+
false,
115+
Default::default(),
116+
)
117+
.unwrap();
118+
let stack = gix_worktree::Stack::from_state_and_ignore_case(
119+
worktree_path.clone(),
120+
false,
121+
gix_worktree::stack::State::AttributesAndIgnoreStack {
122+
attributes: Default::default(),
123+
ignore: Default::default(),
124+
},
125+
&index,
126+
index.path_backing(),
127+
);
128+
let capabilities = gix_fs::Capabilities::probe(&git_dir);
129+
let mut resource_cache = gix_diff::blob::Platform::new(
130+
Default::default(),
131+
gix_diff::blob::Pipeline::new(
132+
gix_diff::blob::pipeline::WorktreeRoots {
133+
old_root: None,
134+
new_root: None,
135+
},
136+
gix_filter::Pipeline::new(Default::default(), Default::default()),
137+
vec![],
138+
gix_diff::blob::pipeline::Options {
139+
large_file_threshold_bytes: 0,
140+
fs: capabilities,
141+
},
142+
),
143+
gix_diff::blob::pipeline::Mode::ToGit,
144+
stack,
145+
);
146+
108147
let lines_blamed = blame_file(
109-
odb,
110-
head_id,
148+
&odb,
149+
&mut traverse,
150+
&mut resource_cache,
111151
worktree_path,
112152
format!("{}.txt", $case).as_str().into(),
113153
);

0 commit comments

Comments
 (0)