@@ -2,8 +2,8 @@ use std::io;
22use std:: marker:: PhantomData ;
33use std:: path:: Path ;
44
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 } ;
77use crate :: { fs, read} ;
88use bstr:: BStr ;
99use filetime:: FileTime ;
@@ -62,12 +62,18 @@ impl Default for Options {
6262 }
6363}
6464
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 > (
6773 index : & ' index mut index:: State ,
6874 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 > ,
7177 options : Options ,
7278) -> Result < ( ) , Error > {
7379 // the order is absoluty critical here
@@ -116,13 +122,13 @@ struct State<'a, 'b> {
116122 options : & ' a Options ,
117123}
118124
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 > ;
120126
121127impl < ' index > State < ' _ , ' index > {
122128 fn process < T > (
123129 & mut self ,
124130 entry : & ' index mut index:: Entry ,
125- diff : & impl Diff < Output = T > ,
131+ diff : & impl ContentComparison < Output = T > ,
126132 ) -> Option < StatusResult < ' index , T > > {
127133 let conflict = match entry. stage ( ) {
128134 0 => false ,
@@ -146,8 +152,8 @@ impl<'index> State<'_, 'index> {
146152 & mut self ,
147153 entry : & mut index:: Entry ,
148154 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 > {
151157 // TODO fs caache
152158 let worktree_path = path:: try_from_bstr ( git_path) . map_err ( |_| Error :: IllformedUtf8 ) ?;
153159 let worktree_path = self . worktree . join ( worktree_path) ;
@@ -163,24 +169,24 @@ impl<'index> State<'_, 'index> {
163169 // TODO: submodules:
164170 // if entry.mode.contains(Mode::COMMIT) &&
165171 // resolve_gitlink_ref(ce->name, "HEAD", &sub))
166- return Ok ( Status :: Removed ) ;
172+ return Ok ( Change :: Removed ) ;
167173 }
168174 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 ) ,
170176 Err ( err) => {
171177 return Err ( err. into ( ) ) ;
172178 }
173179 } ;
174180 if self . options . check_added && entry. flags . contains ( index:: entry:: Flags :: INTENT_TO_ADD ) {
175- return Ok ( Status :: Added ) ;
181+ return Ok ( Change :: Added ) ;
176182 }
177183 let new_stat = index:: entry:: Stat :: from_fs ( & metadata) ?;
178184 let executable_bit_changed =
179185 match entry
180186 . mode
181187 . change_to_match_fs ( & metadata, self . options . fs . symlink , self . options . fs . executable_bit )
182188 {
183- Some ( index:: entry:: mode:: Change :: Type { .. } ) => return Ok ( Status :: TypeChange ) ,
189+ Some ( index:: entry:: mode:: Change :: Type { .. } ) => return Ok ( Change :: TypeChange ) ,
184190 Some ( index:: entry:: mode:: Change :: ExecutableBit ) => true ,
185191 None => false ,
186192 } ;
@@ -202,7 +208,7 @@ impl<'index> State<'_, 'index> {
202208 {
203209 racy_clean = new_stat. is_racy ( self . timestamp , self . options . stat ) ;
204210 if !racy_clean {
205- return Ok ( Status :: Unchanged ) ;
211+ return Ok ( Change :: None ) ;
206212 }
207213 }
208214
@@ -219,15 +225,15 @@ impl<'index> State<'_, 'index> {
219225 entry. stat . size = 0 ;
220226 }
221227 if diff. is_some ( ) || executable_bit_changed {
222- Ok ( Status :: Modified {
228+ Ok ( Change :: Modified {
223229 executable_bit_changed,
224- diff,
230+ content_change : diff,
225231 } )
226232 } else {
227233 // don't diff against this file next time since
228234 // we know the file is unchanged
229235 entry. stat = new_stat;
230- Ok ( Status :: Unchanged )
236+ Ok ( Change :: None )
231237 }
232238 }
233239}
@@ -237,7 +243,7 @@ struct Reducer<'a, 'index, T: Collector<'index>> {
237243 phantom : PhantomData < fn ( & ' index ( ) ) > ,
238244}
239245
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 > {
241247 type Input = Vec < StatusResult < ' index , T > > ;
242248
243249 type FeedProduce = ( ) ;
@@ -265,7 +271,7 @@ struct WorktreeFile<'a> {
265271 options : & ' a Options ,
266272}
267273
268- impl < ' a > diff :: LazyBlob < ' a , Error > for WorktreeFile < ' a > {
274+ impl < ' a > content :: LazyBlob < ' a , Error > for WorktreeFile < ' a > {
269275 fn read ( self ) -> Result < & ' a [ u8 ] , Error > {
270276 let res = read:: data_to_buf_with_meta (
271277 self . path ,
0 commit comments