Skip to content

Commit 743695f

Browse files
committedOct 8, 2024
refactor!: always trackt he full path when producing diffs, but allow to disable it.
1 parent 45b7155 commit 743695f

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed
 

‎gix/src/object/tree/diff/mod.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ impl<'repo> Tree<'repo> {
133133
Ok(Platform {
134134
state: Default::default(),
135135
lhs: self,
136-
location: None,
136+
location: Some(Location::Path),
137137
rewrites: self.repo.config.diff_renames()?.unwrap_or_default().into(),
138138
})
139139
}
@@ -150,13 +150,19 @@ pub struct Platform<'a, 'repo> {
150150

151151
/// Configuration
152152
impl Platform<'_, '_> {
153+
/// Do not keep track of filepaths at all, which will leave all [`location`][Change::location] fields empty.
154+
pub fn no_locations(&mut self) -> &mut Self {
155+
self.location = Some(Location::FileName);
156+
self
157+
}
158+
153159
/// Keep track of file-names, which makes the [`location`][Change::location] field usable with the filename of the changed item.
154160
pub fn track_filename(&mut self) -> &mut Self {
155161
self.location = Some(Location::FileName);
156162
self
157163
}
158164

159-
/// Keep track of the entire path of a change, relative to the repository.
165+
/// Keep track of the entire path of a change, relative to the repository. (default).
160166
///
161167
/// This makes the [`location`][Change::location] field usable.
162168
pub fn track_path(&mut self) -> &mut Self {

‎gix/tests/object/tree/diff.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,9 @@ fn changes_against_tree_modified() -> crate::Result {
2424
let (expected_previous_entry_mode, expected_previous_data, expected_entry_mode, expected_data) =
2525
expected_modifications[i];
2626

27-
assert_eq!(
28-
change.location(),
29-
"",
30-
"without configuration the location field is empty"
27+
assert!(
28+
!change.location().is_empty(),
29+
"without configuration the location field is set"
3130
);
3231
match change {
3332
Change::Modification {

0 commit comments

Comments
 (0)
Please sign in to comment.