use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum FileStatus {
Added,
Modified,
Deleted,
Renamed,
Copied,
}
impl FileStatus {
pub fn as_char(&self) -> char {
match self {
FileStatus::Added => 'A',
FileStatus::Modified => 'M',
FileStatus::Deleted => 'D',
FileStatus::Renamed => 'R',
FileStatus::Copied => 'C',
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LineOrigin {
Context,
Addition,
Deletion,
}
#[derive(Debug, Clone)]
pub struct DiffLine {
pub origin: LineOrigin,
pub content: String,
pub old_lineno: Option<u32>,
pub new_lineno: Option<u32>,
}
#[derive(Debug, Clone)]
pub struct DiffHunk {
pub header: String,
pub lines: Vec<DiffLine>,
}
#[derive(Debug, Clone)]
pub struct DiffFile {
pub old_path: Option<PathBuf>,
pub new_path: Option<PathBuf>,
pub status: FileStatus,
pub hunks: Vec<DiffHunk>,
pub is_binary: bool,
}
impl DiffFile {
pub fn display_path(&self) -> &PathBuf {
self.new_path
.as_ref()
.or(self.old_path.as_ref())
.expect("DiffFile must have at least one path")
}
}