Skip to content

Commit c6f1409

Browse files
committed
feat: add tree_with_rewrites::Change(Ref)::source_mode_and_id|mode_and_id()
1 parent 62655b3 commit c6f1409

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

gix-diff/src/tree_with_rewrites/change.rs

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,34 @@ impl<'a> ChangeRef<'a> {
434434
}
435435
}
436436

437+
/// Return the current mode of this instance, along with its object id.
438+
pub fn entry_mode_and_id(&self) -> (gix_object::tree::EntryMode, &gix_hash::oid) {
439+
match self {
440+
ChangeRef::Addition { entry_mode, id, .. }
441+
| ChangeRef::Deletion { entry_mode, id, .. }
442+
| ChangeRef::Modification { entry_mode, id, .. }
443+
| ChangeRef::Rewrite { entry_mode, id, .. } => (*entry_mode, id),
444+
}
445+
}
446+
447+
/// Return the *previous* mode and id of the resource where possible, i.e. the source of a rename or copy, or a modification.
448+
pub fn source_entry_mode_and_id(&self) -> (gix_object::tree::EntryMode, &gix_hash::oid) {
449+
match self {
450+
ChangeRef::Addition { entry_mode, id, .. }
451+
| ChangeRef::Deletion { entry_mode, id, .. }
452+
| ChangeRef::Modification {
453+
previous_entry_mode: entry_mode,
454+
previous_id: id,
455+
..
456+
}
457+
| ChangeRef::Rewrite {
458+
source_entry_mode: entry_mode,
459+
source_id: id,
460+
..
461+
} => (*entry_mode, id),
462+
}
463+
}
464+
437465
/// Return the *current* location of the resource, i.e. the destination of a rename or copy, or the
438466
/// location at which an addition, deletion or modification took place.
439467
pub fn location(&self) -> &'a BStr {
@@ -478,6 +506,34 @@ impl Change {
478506
}
479507
}
480508

509+
/// Return the current mode of this instance, along with its object id.
510+
pub fn entry_mode_and_id(&self) -> (gix_object::tree::EntryMode, &gix_hash::oid) {
511+
match self {
512+
Change::Addition { entry_mode, id, .. }
513+
| Change::Deletion { entry_mode, id, .. }
514+
| Change::Modification { entry_mode, id, .. }
515+
| Change::Rewrite { entry_mode, id, .. } => (*entry_mode, id),
516+
}
517+
}
518+
519+
/// Return the *previous* mode and id of the resource where possible, i.e. the source of a rename or copy, or a modification.
520+
pub fn source_entry_mode_and_id(&self) -> (gix_object::tree::EntryMode, &gix_hash::oid) {
521+
match self {
522+
Change::Addition { entry_mode, id, .. }
523+
| Change::Deletion { entry_mode, id, .. }
524+
| Change::Modification {
525+
previous_entry_mode: entry_mode,
526+
previous_id: id,
527+
..
528+
}
529+
| Change::Rewrite {
530+
source_entry_mode: entry_mode,
531+
source_id: id,
532+
..
533+
} => (*entry_mode, id),
534+
}
535+
}
536+
481537
/// Return the *current* location of the resource, i.e. the destination of a rename or copy, or the
482538
/// location at which an addition, deletion or modification took place.
483539
pub fn location(&self) -> &BStr {

0 commit comments

Comments
 (0)