@@ -123,7 +123,7 @@ impl GitRemote {
123
123
124
124
let resolved_commit_hash = match locked_rev {
125
125
Some ( rev) => db. contains ( rev) . then_some ( rev) ,
126
- None => reference . resolve ( & db. repo ) . ok ( ) ,
126
+ None => resolve_ref ( reference , & db. repo ) . ok ( ) ,
127
127
} ;
128
128
if let Some ( rev) = resolved_commit_hash {
129
129
return Ok ( ( db, rev) ) ;
@@ -148,7 +148,7 @@ impl GitRemote {
148
148
. with_context ( || format ! ( "failed to clone into: {}" , into. display( ) ) ) ?;
149
149
let rev = match locked_rev {
150
150
Some ( rev) => rev,
151
- None => reference . resolve ( & repo) ?,
151
+ None => resolve_ref ( reference , & repo) ?,
152
152
} ;
153
153
154
154
Ok ( (
@@ -207,56 +207,54 @@ impl GitDatabase {
207
207
self . repo . revparse_single ( & oid. to_string ( ) ) . is_ok ( )
208
208
}
209
209
210
- /// [`GitReference::resolve `]s this reference with this database.
210
+ /// [`resolve_ref `]s this reference with this database.
211
211
pub fn resolve ( & self , r : & GitReference ) -> CargoResult < git2:: Oid > {
212
- r . resolve ( & self . repo )
212
+ resolve_ref ( r , & self . repo )
213
213
}
214
214
}
215
215
216
- impl GitReference {
217
- /// Resolves self to an object ID with objects the `repo` currently has.
218
- pub fn resolve ( & self , repo : & git2:: Repository ) -> CargoResult < git2:: Oid > {
219
- let id = match self {
220
- // Note that we resolve the named tag here in sync with where it's
221
- // fetched into via `fetch` below.
222
- GitReference :: Tag ( s) => ( || -> CargoResult < git2:: Oid > {
223
- let refname = format ! ( "refs/remotes/origin/tags/{}" , s) ;
224
- let id = repo. refname_to_id ( & refname) ?;
225
- let obj = repo. find_object ( id, None ) ?;
226
- let obj = obj. peel ( ObjectType :: Commit ) ?;
227
- Ok ( obj. id ( ) )
228
- } ) ( )
229
- . with_context ( || format ! ( "failed to find tag `{}`" , s) ) ?,
230
-
231
- // Resolve the remote name since that's all we're configuring in
232
- // `fetch` below.
233
- GitReference :: Branch ( s) => {
234
- let name = format ! ( "origin/{}" , s) ;
235
- let b = repo
236
- . find_branch ( & name, git2:: BranchType :: Remote )
237
- . with_context ( || format ! ( "failed to find branch `{}`" , s) ) ?;
238
- b. get ( )
239
- . target ( )
240
- . ok_or_else ( || anyhow:: format_err!( "branch `{}` did not have a target" , s) ) ?
241
- }
216
+ /// Resolves [`GitReference`] to an object ID with objects the `repo` currently has.
217
+ pub fn resolve_ref ( gitref : & GitReference , repo : & git2:: Repository ) -> CargoResult < git2:: Oid > {
218
+ let id = match gitref {
219
+ // Note that we resolve the named tag here in sync with where it's
220
+ // fetched into via `fetch` below.
221
+ GitReference :: Tag ( s) => ( || -> CargoResult < git2:: Oid > {
222
+ let refname = format ! ( "refs/remotes/origin/tags/{}" , s) ;
223
+ let id = repo. refname_to_id ( & refname) ?;
224
+ let obj = repo. find_object ( id, None ) ?;
225
+ let obj = obj. peel ( ObjectType :: Commit ) ?;
226
+ Ok ( obj. id ( ) )
227
+ } ) ( )
228
+ . with_context ( || format ! ( "failed to find tag `{}`" , s) ) ?,
229
+
230
+ // Resolve the remote name since that's all we're configuring in
231
+ // `fetch` below.
232
+ GitReference :: Branch ( s) => {
233
+ let name = format ! ( "origin/{}" , s) ;
234
+ let b = repo
235
+ . find_branch ( & name, git2:: BranchType :: Remote )
236
+ . with_context ( || format ! ( "failed to find branch `{}`" , s) ) ?;
237
+ b. get ( )
238
+ . target ( )
239
+ . ok_or_else ( || anyhow:: format_err!( "branch `{}` did not have a target" , s) ) ?
240
+ }
242
241
243
- // We'll be using the HEAD commit
244
- GitReference :: DefaultBranch => {
245
- let head_id = repo. refname_to_id ( "refs/remotes/origin/HEAD" ) ?;
246
- let head = repo. find_object ( head_id, None ) ?;
247
- head. peel ( ObjectType :: Commit ) ?. id ( )
248
- }
242
+ // We'll be using the HEAD commit
243
+ GitReference :: DefaultBranch => {
244
+ let head_id = repo. refname_to_id ( "refs/remotes/origin/HEAD" ) ?;
245
+ let head = repo. find_object ( head_id, None ) ?;
246
+ head. peel ( ObjectType :: Commit ) ?. id ( )
247
+ }
249
248
250
- GitReference :: Rev ( s) => {
251
- let obj = repo. revparse_single ( s) ?;
252
- match obj. as_tag ( ) {
253
- Some ( tag) => tag. target_id ( ) ,
254
- None => obj. id ( ) ,
255
- }
249
+ GitReference :: Rev ( s) => {
250
+ let obj = repo. revparse_single ( s) ?;
251
+ match obj. as_tag ( ) {
252
+ Some ( tag) => tag. target_id ( ) ,
253
+ None => obj. id ( ) ,
256
254
}
257
- } ;
258
- Ok ( id )
259
- }
255
+ }
256
+ } ;
257
+ Ok ( id )
260
258
}
261
259
262
260
impl < ' a > GitCheckout < ' a > {
@@ -1404,7 +1402,7 @@ fn github_fast_path(
1404
1402
return Ok ( FastPathRev :: Indeterminate ) ;
1405
1403
}
1406
1404
1407
- let local_object = reference . resolve ( repo) . ok ( ) ;
1405
+ let local_object = resolve_ref ( reference , repo) . ok ( ) ;
1408
1406
1409
1407
let github_branch_name = match reference {
1410
1408
GitReference :: Branch ( branch) => branch,
0 commit comments