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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
use crateObjectId;
/// One candidate tree leaf or collapsed sparse directory, with a byte path and cached stat data.
///
/// Fields are editable drafts. [`super::Index::new`] and [`super::Index::replace_entries`] check
/// paths and relationships before accepting them. Paths must have nonempty `/`-separated
/// components other than `.`, `..`, or `.git`, and contain no NUL. Sparse directories add one
/// trailing slash. No UTF-8, case folding,
/// platform aliases, backslashes, drive letters or checkout-safety checks are applied.
/// IDs are preserved even when zero; object existence and type remain caller obligations.
///
/// ```
/// use girt::index::{Entry, Mode, Stage};
/// use girt::{ObjectFormat, ObjectId};
/// let entry = Entry::new(
/// b"run.sh".to_vec(),
/// Mode::Executable,
/// ObjectId::for_blob(ObjectFormat::Sha1, b"#!/bin/sh\n"),
/// );
/// assert_eq!(entry.stage, Stage::Normal);
/// assert_eq!(entry.stat.size, 0); // Constructed entries have no observed filesystem metadata.
/// ```
/// Canonical index modes. Sparse directories name trees; gitlinks name submodule commits.
/// An entry's position in a conflict, ordered by its on-disk stage number.
///
/// A path has either one normal entry or any nonempty subset of stages 1, 2 and 3. Missing
/// sides represent absent files. Duplicate stages and mixing normal/conflict entries are invalid.
/// This set is exhaustive because the on-disk stage occupies exactly two bits.
///
/// Keep each conflict side under the same path; resolving it replaces those sides with one
/// [`Stage::Normal`] entry. Stage numbers describe merge inputs, not separate working files.
///
/// ```
/// use girt::index::{Entry, Index, Limits, Mode, Stage};
/// use girt::{ObjectFormat, ObjectId};
///
/// let format = ObjectFormat::Sha1;
/// let ours = Entry::new(
/// b"file".to_vec(),
/// Mode::Regular,
/// ObjectId::for_blob(format, b"ours"),
/// )
/// .with_stage(Stage::Ours);
/// let theirs = Entry::new(
/// b"file".to_vec(),
/// Mode::Regular,
/// ObjectId::for_blob(format, b"theirs"),
/// )
/// .with_stage(Stage::Theirs);
///
/// let mut index = Index::new(format, vec![theirs, ours.clone()], Limits::default())?;
/// assert_eq!(index.entries()[0].stage, Stage::Ours);
///
/// index.replace_entries(vec![ours.with_stage(Stage::Normal)], Limits::default())?;
/// assert_eq!(index.entries().len(), 1);
/// # Ok::<(), girt::index::Error>(())
/// ```
/// Raw seconds and nanosecond words retained exactly from the index.
///
/// These are unsigned on-disk words, not host timestamps. No range validation, clock conversion,
/// precision inference or comparison is performed, including for the nanosecond word.
/// Cached filesystem metadata, retaining every on-disk word exactly.
///
/// Zero is useful for constructed entries that need later refresh. Callers must account for Git's
/// racy-stat rules before trusting cached data; this API does not detect worktree modifications.