1
1
use crate :: { Change , Index } ;
2
- use git_repository as git;
3
- use git_repository:: prelude:: ObjectIdExt ;
2
+ use gix:: prelude:: ObjectIdExt ;
4
3
use std:: sync:: atomic:: AtomicBool ;
5
4
6
5
mod delegate;
@@ -29,57 +28,59 @@ pub enum Order {
29
28
#[ allow( missing_docs) ]
30
29
pub enum Error {
31
30
#[ error( "Couldn't update marker reference" ) ]
32
- ReferenceEdit ( #[ from] git :: reference:: edit:: Error ) ,
31
+ ReferenceEdit ( #[ from] gix :: reference:: edit:: Error ) ,
33
32
#[ error( "Failed to parse rev-spec to determine which revisions to diff" ) ]
34
- RevParse ( #[ from] git:: revision:: spec:: parse:: Error ) ,
33
+ RevParse ( #[ from] gix:: revision:: spec:: parse:: Error ) ,
34
+ #[ error( transparent) ]
35
+ DiffRewrites ( #[ from] gix:: object:: tree:: diff:: rewrites:: Error ) ,
35
36
#[ error( "Couldn't find blob that showed up when diffing trees" ) ]
36
- FindObject ( #[ from] git :: object:: find:: existing:: Error ) ,
37
+ FindObject ( #[ from] gix :: object:: find:: existing:: Error ) ,
37
38
#[ error( "Couldn't get the tree of a commit for diffing purposes" ) ]
38
- PeelToTree ( #[ from] git :: object:: peel:: to_kind:: Error ) ,
39
+ PeelToTree ( #[ from] gix :: object:: peel:: to_kind:: Error ) ,
39
40
#[ error( "Failed to diff two trees to find changed crates" ) ]
40
- Diff ( #[ from] git :: object:: blob:: diff:: init:: Error ) ,
41
+ Diff ( #[ from] gix :: object:: blob:: diff:: init:: Error ) ,
41
42
#[ error( transparent) ]
42
- DiffForEach ( #[ from] git :: object:: tree:: diff:: for_each:: Error ) ,
43
+ DiffForEach ( #[ from] gix :: object:: tree:: diff:: for_each:: Error ) ,
43
44
#[ error( "Failed to decode {line:?} in file {file_name:?} as crate version" ) ]
44
45
VersionDecode {
45
46
source : serde_json:: Error ,
46
47
file_name : bstr:: BString ,
47
48
line : bstr:: BString ,
48
49
} ,
49
50
#[ error( transparent) ]
50
- FindRemote ( #[ from] git :: remote:: find:: existing:: Error ) ,
51
+ FindRemote ( #[ from] gix :: remote:: find:: existing:: Error ) ,
51
52
#[ error( transparent) ]
52
- FindReference ( #[ from] git :: reference:: find:: existing:: Error ) ,
53
+ FindReference ( #[ from] gix :: reference:: find:: existing:: Error ) ,
53
54
#[ error( transparent) ]
54
- Connect ( #[ from] git :: remote:: connect:: Error ) ,
55
+ Connect ( #[ from] gix :: remote:: connect:: Error ) ,
55
56
#[ error( transparent) ]
56
- PrepareFetch ( #[ from] git :: remote:: fetch:: prepare:: Error ) ,
57
+ PrepareFetch ( #[ from] gix :: remote:: fetch:: prepare:: Error ) ,
57
58
#[ error( transparent) ]
58
- Fetch ( #[ from] git :: remote:: fetch:: Error ) ,
59
+ Fetch ( #[ from] gix :: remote:: fetch:: Error ) ,
59
60
#[ error( transparent) ]
60
- InitAnonymousRemote ( #[ from] git :: remote:: init:: Error ) ,
61
+ InitAnonymousRemote ( #[ from] gix :: remote:: init:: Error ) ,
61
62
#[ error( "Could not find local tracking branch for remote branch {name:?} in any of {} fetched refs" , mappings. len( ) ) ]
62
63
NoMatchingBranch {
63
64
name : String ,
64
- mappings : Vec < git :: remote:: fetch:: Mapping > ,
65
+ mappings : Vec < gix :: remote:: fetch:: Mapping > ,
65
66
} ,
66
67
}
67
68
68
69
/// Find changes without modifying the underling repository
69
70
impl Index {
70
71
/// As `peek_changes_with_options()`, but without the options.
71
- pub fn peek_changes ( & self ) -> Result < ( Vec < Change > , git :: hash:: ObjectId ) , Error > {
72
+ pub fn peek_changes ( & self ) -> Result < ( Vec < Change > , gix :: hash:: ObjectId ) , Error > {
72
73
self . peek_changes_with_options (
73
- git :: progress:: Discard ,
74
+ gix :: progress:: Discard ,
74
75
& AtomicBool :: default ( ) ,
75
76
Order :: ImplementationDefined ,
76
77
)
77
78
}
78
79
79
80
/// As `peek_changes()` but provides changes similar to those in the crates index.
80
- pub fn peek_changes_ordered ( & self ) -> Result < ( Vec < Change > , git :: hash:: ObjectId ) , Error > {
81
+ pub fn peek_changes_ordered ( & self ) -> Result < ( Vec < Change > , gix :: hash:: ObjectId ) , Error > {
81
82
self . peek_changes_with_options (
82
- git :: progress:: Discard ,
83
+ gix :: progress:: Discard ,
83
84
& AtomicBool :: default ( ) ,
84
85
Order :: AsInCratesIndex ,
85
86
)
@@ -110,17 +111,17 @@ impl Index {
110
111
progress : P ,
111
112
should_interrupt : & AtomicBool ,
112
113
order : Order ,
113
- ) -> Result < ( Vec < Change > , git :: hash:: ObjectId ) , Error >
114
+ ) -> Result < ( Vec < Change > , gix :: hash:: ObjectId ) , Error >
114
115
where
115
- P : git :: Progress ,
116
+ P : gix :: Progress ,
116
117
P :: SubProgress : ' static ,
117
118
{
118
119
let repo = & self . repo ;
119
120
let from = repo
120
121
. find_reference ( self . seen_ref_name )
121
122
. ok ( )
122
123
. and_then ( |r| r. try_id ( ) . map ( |id| id. detach ( ) ) )
123
- . unwrap_or_else ( || git :: hash:: ObjectId :: empty_tree ( repo. object_hash ( ) ) ) ;
124
+ . unwrap_or_else ( || gix :: hash:: ObjectId :: empty_tree ( repo. object_hash ( ) ) ) ;
124
125
let to = {
125
126
let mut remote = self
126
127
. remote_name
@@ -131,12 +132,12 @@ impl Index {
131
132
. head ( )
132
133
. ok ( )
133
134
. and_then ( |head| {
134
- head. into_remote ( git :: remote:: Direction :: Fetch )
135
+ head. into_remote ( gix :: remote:: Direction :: Fetch )
135
136
. and_then ( |r| r. ok ( ) )
136
137
} )
137
138
. or_else ( || {
138
139
self . repo
139
- . find_default_remote ( git :: remote:: Direction :: Fetch )
140
+ . find_default_remote ( gix :: remote:: Direction :: Fetch )
140
141
. and_then ( |r| r. ok ( ) )
141
142
} )
142
143
} )
@@ -145,11 +146,11 @@ impl Index {
145
146
. unwrap_or_else ( || {
146
147
self . repo
147
148
. head ( ) ?
148
- . into_remote ( git :: remote:: Direction :: Fetch )
149
+ . into_remote ( gix :: remote:: Direction :: Fetch )
149
150
. map ( |r| r. map_err ( Error :: from) )
150
151
. or_else ( || {
151
152
self . repo
152
- . find_default_remote ( git :: remote:: Direction :: Fetch )
153
+ . find_default_remote ( gix :: remote:: Direction :: Fetch )
153
154
. map ( |r| r. map_err ( Error :: from) )
154
155
} )
155
156
. unwrap_or_else ( || {
@@ -158,18 +159,18 @@ impl Index {
158
159
. map_err ( Into :: into)
159
160
} )
160
161
} ) ?;
161
- if remote. refspecs ( git :: remote:: Direction :: Fetch ) . is_empty ( ) {
162
+ if remote. refspecs ( gix :: remote:: Direction :: Fetch ) . is_empty ( ) {
162
163
let spec = format ! (
163
164
"+refs/heads/{branch}:refs/remotes/{remote}/{branch}" ,
164
165
remote = self . remote_name. as_deref( ) . unwrap_or( "origin" ) ,
165
166
branch = self . branch_name,
166
167
) ;
167
168
remote
168
- . replace_refspecs ( Some ( spec. as_str ( ) ) , git :: remote:: Direction :: Fetch )
169
+ . replace_refspecs ( Some ( spec. as_str ( ) ) , gix :: remote:: Direction :: Fetch )
169
170
. expect ( "valid statically known refspec" ) ;
170
171
}
171
- let res: git :: remote:: fetch:: Outcome = remote
172
- . connect ( git :: remote:: Direction :: Fetch , progress) ?
172
+ let res: gix :: remote:: fetch:: Outcome = remote
173
+ . connect ( gix :: remote:: Direction :: Fetch , progress) ?
173
174
. prepare_fetch ( Default :: default ( ) ) ?
174
175
. receive ( should_interrupt) ?;
175
176
let branch_name = format ! ( "refs/heads/{}" , self . branch_name) ;
@@ -178,7 +179,7 @@ impl Index {
178
179
. mappings
179
180
. iter ( )
180
181
. find_map ( |m| match & m. remote {
181
- git :: remote:: fetch:: Source :: Ref ( r) => ( r. unpack ( ) . 0 == branch_name)
182
+ gix :: remote:: fetch:: Source :: Ref ( r) => ( r. unpack ( ) . 0 == branch_name)
182
183
. then_some ( m. local . as_ref ( ) )
183
184
. flatten ( ) ,
184
185
_ => None ,
@@ -217,21 +218,22 @@ impl Index {
217
218
/// If a specific order is required, the changes must be sorted by the caller.
218
219
pub fn changes_between_commits (
219
220
& self ,
220
- from : impl Into < git :: hash:: ObjectId > ,
221
- to : impl Into < git :: hash:: ObjectId > ,
221
+ from : impl Into < gix :: hash:: ObjectId > ,
222
+ to : impl Into < gix :: hash:: ObjectId > ,
222
223
) -> Result < Vec < Change > , Error > {
223
- let into_tree = |id : git :: hash:: ObjectId | -> Result < git :: Tree < ' _ > , Error > {
224
+ let into_tree = |id : gix :: hash:: ObjectId | -> Result < gix :: Tree < ' _ > , Error > {
224
225
Ok ( id
225
226
. attach ( & self . repo )
226
227
. object ( ) ?
227
- . peel_to_kind ( git :: object:: Kind :: Tree ) ?
228
+ . peel_to_kind ( gix :: object:: Kind :: Tree ) ?
228
229
. into_tree ( ) )
229
230
} ;
230
231
let from = into_tree ( from. into ( ) ) ?;
231
232
let to = into_tree ( to. into ( ) ) ?;
232
233
let mut delegate = Delegate :: default ( ) ;
233
- from. changes ( )
234
+ from. changes ( ) ?
234
235
. track_filename ( )
236
+ . track_rewrites ( None )
235
237
. for_each_to_obtain_tree ( & to, |change| delegate. handle ( change) ) ?;
236
238
delegate. into_result ( )
237
239
}
@@ -250,8 +252,8 @@ impl Index {
250
252
/// that the changes are actually in in case one of the invariants wasn't met.
251
253
pub fn changes_between_ancestor_commits (
252
254
& self ,
253
- ancestor_commit : impl Into < git :: hash:: ObjectId > ,
254
- current_commit : impl Into < git :: hash:: ObjectId > ,
255
+ ancestor_commit : impl Into < gix :: hash:: ObjectId > ,
256
+ current_commit : impl Into < gix :: hash:: ObjectId > ,
255
257
) -> Result < ( Vec < Change > , Order ) , Error > {
256
258
let from_commit = ancestor_commit. into ( ) ;
257
259
let to_commit = current_commit. into ( ) ;
@@ -274,9 +276,9 @@ impl Index {
274
276
/// Return a list of commits like `from_commit..=to_commits`.
275
277
fn commit_ancestry (
276
278
& self ,
277
- ancestor_commit : git :: hash:: ObjectId ,
278
- current_commit : git :: hash:: ObjectId ,
279
- ) -> Option < Vec < git :: hash:: ObjectId > > {
279
+ ancestor_commit : gix :: hash:: ObjectId ,
280
+ current_commit : gix :: hash:: ObjectId ,
281
+ ) -> Option < Vec < gix :: hash:: ObjectId > > {
280
282
let time_in_seconds_since_epoch = ancestor_commit
281
283
. attach ( & self . repo )
282
284
. object ( )
@@ -291,7 +293,7 @@ impl Index {
291
293
. attach ( & self . repo )
292
294
. ancestors ( )
293
295
. sorting (
294
- git :: traverse:: commit:: Sorting :: ByCommitTimeNewestFirstCutoffOlderThan {
296
+ gix :: traverse:: commit:: Sorting :: ByCommitTimeNewestFirstCutoffOlderThan {
295
297
time_in_seconds_since_epoch,
296
298
} ,
297
299
)
@@ -322,7 +324,7 @@ impl Index {
322
324
/// As `fetch_changes_with_options()`, but without the options.
323
325
pub fn fetch_changes ( & self ) -> Result < Vec < Change > , Error > {
324
326
self . fetch_changes_with_options (
325
- git :: progress:: Discard ,
327
+ gix :: progress:: Discard ,
326
328
& AtomicBool :: default ( ) ,
327
329
Order :: ImplementationDefined ,
328
330
)
@@ -331,7 +333,7 @@ impl Index {
331
333
/// As `fetch_changes()`, but returns an ordered result.
332
334
pub fn fetch_changes_ordered ( & self ) -> Result < Vec < Change > , Error > {
333
335
self . fetch_changes_with_options (
334
- git :: progress:: Discard ,
336
+ gix :: progress:: Discard ,
335
337
& AtomicBool :: default ( ) ,
336
338
Order :: AsInCratesIndex ,
337
339
)
@@ -362,7 +364,7 @@ impl Index {
362
364
order : Order ,
363
365
) -> Result < Vec < Change > , Error >
364
366
where
365
- P : git :: Progress ,
367
+ P : gix :: Progress ,
366
368
P :: SubProgress : ' static ,
367
369
{
368
370
let ( changes, to) = self . peek_changes_with_options ( progress, should_interrupt, order) ?;
@@ -371,12 +373,12 @@ impl Index {
371
373
}
372
374
373
375
/// Set the last seen reference to the given Oid. It will be created if it does not yet exists.
374
- pub fn set_last_seen_reference ( & self , to : git :: hash:: ObjectId ) -> Result < ( ) , Error > {
376
+ pub fn set_last_seen_reference ( & self , to : gix :: hash:: ObjectId ) -> Result < ( ) , Error > {
375
377
let repo = self . repository ( ) ;
376
378
repo. reference (
377
379
self . seen_ref_name ,
378
380
to,
379
- git :: refs:: transaction:: PreviousValue :: Any ,
381
+ gix :: refs:: transaction:: PreviousValue :: Any ,
380
382
"updating seen-ref head to latest fetched commit" ,
381
383
) ?;
382
384
Ok ( ( ) )
0 commit comments