skip types that we dont need for frontend

This commit is contained in:
Kiril Videlov 2024-01-18 14:45:55 +01:00 committed by Kiril Videlov
parent b9b72fe7e2
commit 8d564a6b45
2 changed files with 18 additions and 51 deletions

View File

@ -10,43 +10,26 @@ use super::Repository;
/// The type of change /// The type of change
#[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum ChangeType { pub enum ChangeType {
/// No changes
Unmodified,
/// Entry does not exist in old version /// Entry does not exist in old version
Added, Added,
/// Entry does not exist in new version /// Entry does not exist in new version
Deleted, Deleted,
/// Entry content changed between old and new /// Entry content changed between old and new
Modified, Modified,
/// Entry was renamed between old and new
Renamed,
/// Entry was copied from another old entry
Copied,
/// Entry is ignored item in workdir
Ignored,
/// Entry is untracked item in workdir
Untracked,
/// Type of entry changed between old and new
Typechange,
/// Entry is unreadable
Unreadable,
/// Entry in the index is conflicted
Conflicted,
} }
impl From<git2::Delta> for ChangeType { impl From<git2::Delta> for ChangeType {
fn from(v: git2::Delta) -> Self { fn from(v: git2::Delta) -> Self {
use git2::Delta as D;
use ChangeType as C;
match v { match v {
git2::Delta::Unmodified => ChangeType::Unmodified, D::Untracked | D::Added => C::Added,
git2::Delta::Added => ChangeType::Added, D::Modified
git2::Delta::Deleted => ChangeType::Deleted, | D::Unmodified
git2::Delta::Modified => ChangeType::Modified, | D::Renamed
git2::Delta::Renamed => ChangeType::Renamed, | D::Copied
git2::Delta::Copied => ChangeType::Copied, | D::Typechange
git2::Delta::Ignored => ChangeType::Ignored, | D::Conflicted => C::Modified,
git2::Delta::Untracked => ChangeType::Untracked, D::Ignored | D::Unreadable | D::Deleted => C::Deleted,
git2::Delta::Typechange => ChangeType::Typechange,
git2::Delta::Unreadable => ChangeType::Unreadable,
git2::Delta::Conflicted => ChangeType::Conflicted,
} }
} }
} }
@ -265,7 +248,7 @@ fn hunks_by_filepath(
new_lines: 0, new_lines: 0,
diff: String::new(), diff: String::new(),
binary: false, binary: false,
change_type: ChangeType::Unmodified, change_type: ChangeType::Modified,
}], }],
) )
} else { } else {
@ -299,7 +282,7 @@ mod tests {
new_lines: 1, new_lines: 1,
diff: "@@ -0,0 +1 @@\n+hello\n\\ No newline at end of file\n".to_string(), diff: "@@ -0,0 +1 @@\n+hello\n\\ No newline at end of file\n".to_string(),
binary: false, binary: false,
change_type: ChangeType::Untracked, change_type: ChangeType::Modified,
}] }]
); );
} }
@ -322,7 +305,7 @@ mod tests {
new_lines: 0, new_lines: 0,
diff: String::new(), diff: String::new(),
binary: false, binary: false,
change_type: ChangeType::Unmodified, change_type: ChangeType::Modified,
}] }]
); );
} }
@ -346,7 +329,7 @@ mod tests {
new_lines: 0, new_lines: 0,
diff: String::new(), diff: String::new(),
binary: false, binary: false,
change_type: ChangeType::Unmodified, change_type: ChangeType::Modified,
}] }]
); );
assert_eq!( assert_eq!(
@ -358,7 +341,7 @@ mod tests {
new_lines: 0, new_lines: 0,
diff: String::new(), diff: String::new(),
binary: false, binary: false,
change_type: ChangeType::Unmodified, change_type: ChangeType::Modified,
}] }]
); );
} }
@ -389,7 +372,7 @@ mod tests {
new_lines: 0, new_lines: 0,
diff: "71ae6e216f38164b6633e25d35abb043c3785af6".to_string(), diff: "71ae6e216f38164b6633e25d35abb043c3785af6".to_string(),
binary: true, binary: true,
change_type: ChangeType::Untracked, change_type: ChangeType::Modified,
}] }]
); );
} }
@ -432,7 +415,7 @@ mod tests {
new_lines: 0, new_lines: 0,
diff: "3fc41b9ae6836a94f41c78b4ce69d78b6e7080f1".to_string(), diff: "3fc41b9ae6836a94f41c78b4ce69d78b6e7080f1".to_string(),
binary: true, binary: true,
change_type: ChangeType::Untracked, change_type: ChangeType::Modified,
}] }]
); );
} }

View File

@ -2,28 +2,12 @@ import 'reflect-metadata';
import { Type, Transform } from 'class-transformer'; import { Type, Transform } from 'class-transformer';
export enum ChangeType { export enum ChangeType {
/// No changes
Unmodified,
/// Entry does not exist in old version /// Entry does not exist in old version
Added, Added,
/// Entry does not exist in new version /// Entry does not exist in new version
Deleted, Deleted,
/// Entry content changed between old and new /// Entry content changed between old and new
Modified, Modified
/// Entry was renamed between old and new
Renamed,
/// Entry was copied from another old entry
Copied,
/// Entry is ignored item in workdir
Ignored,
/// Entry is untracked item in workdir
Untracked,
/// Type of entry changed between old and new
Typechange,
/// Entry is unreadable
Unreadable,
/// Entry in the index is conflicted
Conflicted
} }
export class Hunk { export class Hunk {