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(crate) 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(crate) struct FileMode(EntryMode);
49
50impl FileMode {
51    pub(crate) const fn new(mode: EntryMode) -> Self {
52        Self(mode)
53    }
54
55    pub(crate) fn as_tree_entry_mode(self) -> String {
56        format!("{:o}", self.0)
57    }
58
59    pub(crate) const fn is_reviewable_file(self) -> bool {
60        self.0.is_blob_or_symlink()
61    }
62
63    pub(crate) const fn is_submodule(self) -> bool {
64        self.0.is_commit()
65    }
66}
67
68#[derive(Clone, Debug)]
69pub(crate) struct TrackedFile {
70    pub(crate) path: RepoPath,
71    pub(crate) blob: BlobOid,
72    pub(crate) mode: FileMode,
73}
74
75#[derive(Clone, Debug)]
76pub(crate) struct WorkspaceFile {
77    pub(crate) head: TrackedFile,
78    pub(crate) workspace: TrackedFile,
79}