ok/jj
1
0
Fork 0
forked from mirrors/jj

merge: add Merge::is_absent() and Merge::is_present()

These turned out to only be (very marginally) useful in `RefTarget`
right now, but I plan to add a few more uses elsewhere.
This commit is contained in:
Martin von Zweigbergk 2023-08-06 12:26:08 -07:00 committed by Martin von Zweigbergk
parent c65fcabdf8
commit 4b12dba186
2 changed files with 10 additions and 2 deletions

View file

@ -311,6 +311,14 @@ impl<T> Merge<Option<T>> {
Self::resolved(Some(value))
}
pub fn is_absent(&self) -> bool {
matches!(self.as_resolved(), Some(None))
}
pub fn is_present(&self) -> bool {
!self.is_absent()
}
/// Creates lists of `removes` and `adds` from a `Merge` by dropping
/// `None` values. Note that the conversion is lossy: the order of `None`
/// values is not preserved when converting back to a `Merge`.

View file

@ -105,13 +105,13 @@ impl RefTarget {
/// Returns true if this target points to no commit.
pub fn is_absent(&self) -> bool {
matches!(self.merge.as_resolved(), Some(None))
self.merge.is_absent()
}
/// Returns true if this target points to any commit. Conflicting target is
/// always "present" as it should have at least one commit id.
pub fn is_present(&self) -> bool {
!self.is_absent()
self.merge.is_present()
}
/// Whether this target has conflicts.