Skip to content

Commit 0f46d24

Browse files
committed
feat: add tree_with_rewrites::Change(Ref)::previous_location()
That way, it's also possible to obtain the previous location in case of rewrites.
1 parent 9a3a501 commit 0f46d24

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

gix-diff/src/tree_with_rewrites/change.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,17 @@ impl<'a> ChangeRef<'a> {
444444
| ChangeRef::Rewrite { location, .. } => location,
445445
}
446446
}
447+
448+
/// Return the *previous* location of the resource where possible, i.e. the source of a rename or copy, or the
449+
/// location at which an addition, deletion or modification took place.
450+
pub fn source_location(&self) -> &BStr {
451+
match self {
452+
ChangeRef::Addition { location, .. }
453+
| ChangeRef::Deletion { location, .. }
454+
| ChangeRef::Modification { location, .. } => location,
455+
ChangeRef::Rewrite { source_location, .. } => source_location,
456+
}
457+
}
447458
}
448459

449460
impl Change {
@@ -477,4 +488,15 @@ impl Change {
477488
| Change::Rewrite { location, .. } => location.as_bstr(),
478489
}
479490
}
491+
492+
/// Return the *previous* location of the resource where possible, i.e. the source of a rename or copy, or the
493+
/// location at which an addition, deletion or modification took place.
494+
pub fn source_location(&self) -> &BStr {
495+
match self {
496+
Change::Addition { location, .. }
497+
| Change::Deletion { location, .. }
498+
| Change::Modification { location, .. } => location.as_bstr(),
499+
Change::Rewrite { source_location, .. } => source_location.as_bstr(),
500+
}
501+
}
480502
}

0 commit comments

Comments
 (0)