Skip to content

Commit

Permalink
feat: add `tree_with_rewrites::Change(Ref)::source_mode_and_id|mode_a…
Browse files Browse the repository at this point in the history
…nd_id()`
  • Loading branch information
Byron committed Nov 23, 2024
1 parent 62655b3 commit c6f1409
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions gix-diff/src/tree_with_rewrites/change.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,34 @@ impl<'a> ChangeRef<'a> {
}
}

/// Return the current mode of this instance, along with its object id.
pub fn entry_mode_and_id(&self) -> (gix_object::tree::EntryMode, &gix_hash::oid) {
match self {
ChangeRef::Addition { entry_mode, id, .. }
| ChangeRef::Deletion { entry_mode, id, .. }
| ChangeRef::Modification { entry_mode, id, .. }
| ChangeRef::Rewrite { entry_mode, id, .. } => (*entry_mode, id),
}
}

/// Return the *previous* mode and id of the resource where possible, i.e. the source of a rename or copy, or a modification.
pub fn source_entry_mode_and_id(&self) -> (gix_object::tree::EntryMode, &gix_hash::oid) {
match self {
ChangeRef::Addition { entry_mode, id, .. }
| ChangeRef::Deletion { entry_mode, id, .. }
| ChangeRef::Modification {
previous_entry_mode: entry_mode,
previous_id: id,
..
}
| ChangeRef::Rewrite {
source_entry_mode: entry_mode,
source_id: id,
..
} => (*entry_mode, id),
}
}

/// Return the *current* location of the resource, i.e. the destination of a rename or copy, or the
/// location at which an addition, deletion or modification took place.
pub fn location(&self) -> &'a BStr {
Expand Down Expand Up @@ -478,6 +506,34 @@ impl Change {
}
}

/// Return the current mode of this instance, along with its object id.
pub fn entry_mode_and_id(&self) -> (gix_object::tree::EntryMode, &gix_hash::oid) {
match self {
Change::Addition { entry_mode, id, .. }
| Change::Deletion { entry_mode, id, .. }
| Change::Modification { entry_mode, id, .. }
| Change::Rewrite { entry_mode, id, .. } => (*entry_mode, id),
}
}

/// Return the *previous* mode and id of the resource where possible, i.e. the source of a rename or copy, or a modification.
pub fn source_entry_mode_and_id(&self) -> (gix_object::tree::EntryMode, &gix_hash::oid) {
match self {
Change::Addition { entry_mode, id, .. }
| Change::Deletion { entry_mode, id, .. }
| Change::Modification {
previous_entry_mode: entry_mode,
previous_id: id,
..
}
| Change::Rewrite {
source_entry_mode: entry_mode,
source_id: id,
..
} => (*entry_mode, id),
}
}

/// Return the *current* location of the resource, i.e. the destination of a rename or copy, or the
/// location at which an addition, deletion or modification took place.
pub fn location(&self) -> &BStr {
Expand Down

0 comments on commit c6f1409

Please sign in to comment.