Skip to main content

git_vet/
git_types.rs

1use std::fmt;
2
3use gix::objs::tree::EntryMode;
4use serde::{Serialize, Serializer};
5
6use crate::path::RepoPath;
7
8#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
9pub struct BlobOid(gix::ObjectId);
10
11impl BlobOid {
12    pub(crate) const fn new(oid: gix::ObjectId) -> Self {
13        Self(oid)
14    }
15}
16
17impl Serialize for BlobOid {
18    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
19    where
20        S: Serializer,
21    {
22        serializer.serialize_str(&self.to_string())
23    }
24}
25
26impl fmt::Display for BlobOid {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        write!(f, "{}", self.0)
29    }
30}
31
32#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash, Ord, PartialOrd)]
33pub struct CommitOid(gix::ObjectId);
34
35impl CommitOid {
36    pub(crate) const fn new(oid: gix::ObjectId) -> Self {
37        Self(oid)
38    }
39}
40
41impl fmt::Display for CommitOid {
42    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43        write!(f, "{}", self.0)
44    }
45}
46
47#[derive(Clone, Copy, Debug, Eq, PartialEq)]
48pub struct FileMode(EntryMode);
49
50impl FileMode {
51    pub(crate) const fn new(mode: EntryMode) -> Self {
52        Self(mode)
53    }
54
55    pub(crate) const fn is_reviewable_file(self) -> bool {
56        self.0.is_blob_or_symlink()
57    }
58
59    pub(crate) const fn is_submodule(self) -> bool {
60        self.0.is_commit()
61    }
62}
63
64#[derive(Clone, Debug)]
65pub struct TrackedFile {
66    pub(crate) path: RepoPath,
67    pub(crate) blob: BlobOid,
68}