@@ -2,8 +2,8 @@ use std::io;
2
2
use std:: marker:: PhantomData ;
3
3
use std:: path:: Path ;
4
4
5
- use crate :: index:: status:: diff :: { self , Diff } ;
6
- use crate :: index:: status:: { Collector , Status } ;
5
+ use crate :: index:: status:: content :: { self , ContentComparison } ;
6
+ use crate :: index:: status:: { Change , Collector } ;
7
7
use crate :: { fs, read} ;
8
8
use bstr:: BStr ;
9
9
use filetime:: FileTime ;
@@ -62,12 +62,18 @@ impl Default for Options {
62
62
}
63
63
}
64
64
65
- /// Calculates the status of worktree
66
- pub fn status < ' index , T : Send > (
65
+ /// Calculates the changes that need to be applied to an index to obtain a
66
+ /// worktree. Note that this isn't technically quite what this function does
67
+ /// as this also provides some additional information (whether a file has
68
+ /// conflicts) and files that were added with `git add` are shown as a special
69
+ /// changes despite not technically requiring a change to the index (since `gid
70
+ /// add` already added the file to the index) but the naming matches the intuition
71
+ /// of a git user (and matches `git status`/git diff`)
72
+ pub fn changes_to_obtain < ' index , T : Send > (
67
73
index : & ' index mut index:: State ,
68
74
worktree : & Path ,
69
- collector : & mut impl Collector < ' index , Diff = T > ,
70
- diff : & impl Diff < Output = T > ,
75
+ collector : & mut impl Collector < ' index , ContentChange = T > ,
76
+ diff : & impl ContentComparison < Output = T > ,
71
77
options : Options ,
72
78
) -> Result < ( ) , Error > {
73
79
// the order is absoluty critical here
@@ -116,13 +122,13 @@ struct State<'a, 'b> {
116
122
options : & ' a Options ,
117
123
}
118
124
119
- type StatusResult < ' index , T > = Result < ( & ' index index:: Entry , & ' index BStr , Status < T > , bool ) , Error > ;
125
+ type StatusResult < ' index , T > = Result < ( & ' index index:: Entry , & ' index BStr , Change < T > , bool ) , Error > ;
120
126
121
127
impl < ' index > State < ' _ , ' index > {
122
128
fn process < T > (
123
129
& mut self ,
124
130
entry : & ' index mut index:: Entry ,
125
- diff : & impl Diff < Output = T > ,
131
+ diff : & impl ContentComparison < Output = T > ,
126
132
) -> Option < StatusResult < ' index , T > > {
127
133
let conflict = match entry. stage ( ) {
128
134
0 => false ,
@@ -146,8 +152,8 @@ impl<'index> State<'_, 'index> {
146
152
& mut self ,
147
153
entry : & mut index:: Entry ,
148
154
git_path : & BStr ,
149
- diff : & impl Diff < Output = T > ,
150
- ) -> Result < Status < T > , Error > {
155
+ diff : & impl ContentComparison < Output = T > ,
156
+ ) -> Result < Change < T > , Error > {
151
157
// TODO fs caache
152
158
let worktree_path = path:: try_from_bstr ( git_path) . map_err ( |_| Error :: IllformedUtf8 ) ?;
153
159
let worktree_path = self . worktree . join ( worktree_path) ;
@@ -163,24 +169,24 @@ impl<'index> State<'_, 'index> {
163
169
// TODO: submodules:
164
170
// if entry.mode.contains(Mode::COMMIT) &&
165
171
// resolve_gitlink_ref(ce->name, "HEAD", &sub))
166
- return Ok ( Status :: Removed ) ;
172
+ return Ok ( Change :: Removed ) ;
167
173
}
168
174
Ok ( metadata) => metadata,
169
- Err ( err) if err. kind ( ) == io:: ErrorKind :: NotFound => return Ok ( Status :: Removed ) ,
175
+ Err ( err) if err. kind ( ) == io:: ErrorKind :: NotFound => return Ok ( Change :: Removed ) ,
170
176
Err ( err) => {
171
177
return Err ( err. into ( ) ) ;
172
178
}
173
179
} ;
174
180
if self . options . check_added && entry. flags . contains ( index:: entry:: Flags :: INTENT_TO_ADD ) {
175
- return Ok ( Status :: Added ) ;
181
+ return Ok ( Change :: Added ) ;
176
182
}
177
183
let new_stat = index:: entry:: Stat :: from_fs ( & metadata) ?;
178
184
let executable_bit_changed =
179
185
match entry
180
186
. mode
181
187
. change_to_match_fs ( & metadata, self . options . fs . symlink , self . options . fs . executable_bit )
182
188
{
183
- Some ( index:: entry:: mode:: Change :: Type { .. } ) => return Ok ( Status :: TypeChange ) ,
189
+ Some ( index:: entry:: mode:: Change :: Type { .. } ) => return Ok ( Change :: TypeChange ) ,
184
190
Some ( index:: entry:: mode:: Change :: ExecutableBit ) => true ,
185
191
None => false ,
186
192
} ;
@@ -202,7 +208,7 @@ impl<'index> State<'_, 'index> {
202
208
{
203
209
racy_clean = new_stat. is_racy ( self . timestamp , self . options . stat ) ;
204
210
if !racy_clean {
205
- return Ok ( Status :: Unchanged ) ;
211
+ return Ok ( Change :: None ) ;
206
212
}
207
213
}
208
214
@@ -219,15 +225,15 @@ impl<'index> State<'_, 'index> {
219
225
entry. stat . size = 0 ;
220
226
}
221
227
if diff. is_some ( ) || executable_bit_changed {
222
- Ok ( Status :: Modified {
228
+ Ok ( Change :: Modified {
223
229
executable_bit_changed,
224
- diff,
230
+ content_change : diff,
225
231
} )
226
232
} else {
227
233
// don't diff against this file next time since
228
234
// we know the file is unchanged
229
235
entry. stat = new_stat;
230
- Ok ( Status :: Unchanged )
236
+ Ok ( Change :: None )
231
237
}
232
238
}
233
239
}
@@ -237,7 +243,7 @@ struct Reducer<'a, 'index, T: Collector<'index>> {
237
243
phantom : PhantomData < fn ( & ' index ( ) ) > ,
238
244
}
239
245
240
- impl < ' index , T , C : Collector < ' index , Diff = T > > Reduce for Reducer < ' _ , ' index , C > {
246
+ impl < ' index , T , C : Collector < ' index , ContentChange = T > > Reduce for Reducer < ' _ , ' index , C > {
241
247
type Input = Vec < StatusResult < ' index , T > > ;
242
248
243
249
type FeedProduce = ( ) ;
@@ -265,7 +271,7 @@ struct WorktreeFile<'a> {
265
271
options : & ' a Options ,
266
272
}
267
273
268
- impl < ' a > diff :: LazyBlob < ' a , Error > for WorktreeFile < ' a > {
274
+ impl < ' a > content :: LazyBlob < ' a , Error > for WorktreeFile < ' a > {
269
275
fn read ( self ) -> Result < & ' a [ u8 ] , Error > {
270
276
let res = read:: data_to_buf_with_meta (
271
277
self . path ,
0 commit comments