#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConflictMarkerState {
Absent,
Present,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum RepositoryOperationState {
Idle,
InProgress,
}
const MARKERS: [char; 3] = ['<', '=', '>'];
const MARKER_LEN: usize = 7;
#[must_use]
pub fn marker_state(content: &str) -> ConflictMarkerState {
if has_conflict_markers(content) {
ConflictMarkerState::Present
} else {
ConflictMarkerState::Absent
}
}
#[must_use]
pub fn has_conflict_markers(content: &str) -> bool {
MARKERS.iter().all(|marker| {
content
.lines()
.any(|line| starts_with_marker(line, *marker))
})
}
#[must_use]
pub const fn refuses(markers: ConflictMarkerState, repository: RepositoryOperationState) -> bool {
matches!(markers, ConflictMarkerState::Present)
&& matches!(repository, RepositoryOperationState::InProgress)
}
fn starts_with_marker(line: &str, marker: char) -> bool {
let mut characters = line.chars();
(0..MARKER_LEN).all(|_| characters.next() == Some(marker))
}