1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
macro_rules! izip {
( @closure $p:pat => $tup:expr ) => {
|$p| $tup
};
( @closure $p:pat => ( $($tup:tt)* ) , $_iter:expr $( , $tail:expr )* ) => {
izip!(@closure ($p, b) => ( $($tup)*, b ) $( , $tail )*)
};
($first:expr $(,)*) => {
std::iter::IntoIterator::into_iter($first)
};
($first:expr, $second:expr $(,)*) => {
izip!($first)
.zip($second)
};
( $first:expr $( , $rest:expr )* $(,)* ) => {
izip!($first)
$(
.zip($rest)
)*
.map(
izip!(@closure a => (a) $( , $rest )*)
)
};
}
use filebuffer::FileBuffer;
#[derive(PartialEq, Eq, Ord, PartialOrd, Debug, Hash, Clone, Copy)]
#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))]
pub enum Kind {
V1 = 1,
V2 = 2,
}
impl Default for Kind {
fn default() -> Self {
Kind::V2
}
}
impl Kind {
pub fn hash(&self) -> git_object::HashKind {
match self {
Kind::V1 | Kind::V2 => git_object::HashKind::Sha1,
}
}
}
const FAN_LEN: usize = 256;
pub struct File {
pub(crate) data: FileBuffer,
path: std::path::PathBuf,
kind: Kind,
version: u32,
num_objects: u32,
fan: [u32; FAN_LEN],
}
impl File {
pub fn kind(&self) -> Kind {
self.kind
}
pub fn path(&self) -> &std::path::Path {
&self.path
}
pub fn num_objects(&self) -> u32 {
self.num_objects
}
pub fn version(&self) -> u32 {
self.version
}
}
const V2_SIGNATURE: &[u8] = b"\xfftOc";
pub mod init;
pub(crate) mod access;
pub use access::Entry;
pub mod traverse;
pub(crate) mod util;
pub mod verify;
pub mod write;