@@ -97,14 +97,15 @@ impl GitRemote {
97
97
// if we can. If that can successfully load our revision then we've
98
98
// populated the database with the latest version of `reference`, so
99
99
// return that database and the rev we resolve to.
100
+ let locked_ref = locked_rev. map ( |oid| GitReference :: Rev ( oid. to_string ( ) ) ) ;
101
+ let reference = locked_ref. as_ref ( ) . unwrap_or ( reference) ;
100
102
if let Some ( mut db) = db {
101
103
fetch (
102
104
& mut db. repo ,
103
105
self . url . as_str ( ) ,
104
106
reference,
105
107
cargo_config,
106
108
RemoteKind :: GitDependency ,
107
- locked_rev,
108
109
)
109
110
. with_context ( || format ! ( "failed to fetch into: {}" , into. display( ) ) ) ?;
110
111
@@ -131,7 +132,6 @@ impl GitRemote {
131
132
reference,
132
133
cargo_config,
133
134
RemoteKind :: GitDependency ,
134
- locked_rev,
135
135
)
136
136
. with_context ( || format ! ( "failed to clone into: {}" , into. display( ) ) ) ?;
137
137
let rev = match locked_rev {
@@ -459,7 +459,6 @@ impl<'a> GitCheckout<'a> {
459
459
& reference,
460
460
cargo_config,
461
461
RemoteKind :: GitDependency ,
462
- None ,
463
462
)
464
463
. with_context ( || {
465
464
format ! (
@@ -841,7 +840,6 @@ pub fn fetch(
841
840
reference : & GitReference ,
842
841
config : & Config ,
843
842
remote_kind : RemoteKind ,
844
- locked_rev : Option < git2:: Oid > ,
845
843
) -> CargoResult < ( ) > {
846
844
if config. frozen ( ) {
847
845
anyhow:: bail!(
@@ -854,7 +852,6 @@ pub fn fetch(
854
852
}
855
853
856
854
let shallow = remote_kind. to_shallow_setting ( repo. is_shallow ( ) , config) ;
857
- let is_shallow = !matches ! ( shallow, gix:: remote:: fetch:: Shallow :: NoChange ) ;
858
855
859
856
// If we're fetching from GitHub, attempt GitHub's special fast path for
860
857
// testing if we've already got an up-to-date copy of the repository.
@@ -884,42 +881,38 @@ pub fn fetch(
884
881
// The `+` symbol on the refspec means to allow a forced (fast-forward)
885
882
// update which is needed if there is ever a force push that requires a
886
883
// fast-forward.
887
- if let Some ( rev) = locked_rev. filter ( |_| is_shallow) {
888
- // If we want a specific revision and know about, obtain that specifically.
889
- refspecs. push ( format ! ( "+{0}:refs/remotes/origin/HEAD" , rev) ) ;
890
- } else {
891
- match reference {
892
- // For branches and tags we can fetch simply one reference and copy it
893
- // locally, no need to fetch other branches/tags.
894
- GitReference :: Branch ( b) => {
895
- refspecs. push ( format ! ( "+refs/heads/{0}:refs/remotes/origin/{0}" , b) ) ;
896
- }
897
- GitReference :: Tag ( t) => {
898
- refspecs. push ( format ! ( "+refs/tags/{0}:refs/remotes/origin/tags/{0}" , t) ) ;
899
- }
884
+ match reference {
885
+ // For branches and tags we can fetch simply one reference and copy it
886
+ // locally, no need to fetch other branches/tags.
887
+ GitReference :: Branch ( b) => {
888
+ refspecs. push ( format ! ( "+refs/heads/{0}:refs/remotes/origin/{0}" , b) ) ;
889
+ }
900
890
901
- GitReference :: DefaultBranch => {
902
- refspecs. push ( String :: from ( "+HEAD :refs/remotes/origin/HEAD" ) ) ;
903
- }
891
+ GitReference :: Tag ( t ) => {
892
+ refspecs. push ( format ! ( "+refs/tags/{0} :refs/remotes/origin/tags/{0}" , t ) ) ;
893
+ }
904
894
905
- GitReference :: Rev ( rev) => {
906
- if rev. starts_with ( "refs/" ) {
907
- refspecs. push ( format ! ( "+{0}:{0}" , rev) ) ;
908
- } else if let Some ( oid_to_fetch) = oid_to_fetch {
909
- refspecs. push ( format ! ( "+{0}:refs/commit/{0}" , oid_to_fetch) ) ;
910
- } else if is_shallow && git2:: Oid :: from_str ( & rev) . is_ok ( ) {
911
- // There is a specific commit to fetch and we will just do so in shallow-mode only
912
- // to not disturb the previous logic. Note that with typical settings for shallowing,
913
- // we will just fetch a specific slice of the history.
914
- refspecs. push ( format ! ( "+{0}:refs/remotes/origin/HEAD" , rev) ) ;
915
- } else {
916
- // We don't know what the rev will point to. To handle this
917
- // situation we fetch all branches and tags, and then we pray
918
- // it's somewhere in there.
919
- refspecs. push ( String :: from ( "+refs/heads/*:refs/remotes/origin/*" ) ) ;
920
- refspecs. push ( String :: from ( "+HEAD:refs/remotes/origin/HEAD" ) ) ;
921
- tags = true ;
922
- }
895
+ GitReference :: DefaultBranch => {
896
+ refspecs. push ( String :: from ( "+HEAD:refs/remotes/origin/HEAD" ) ) ;
897
+ }
898
+
899
+ GitReference :: Rev ( rev) => {
900
+ if rev. starts_with ( "refs/" ) {
901
+ refspecs. push ( format ! ( "+{0}:{0}" , rev) ) ;
902
+ } else if let Some ( oid_to_fetch) = oid_to_fetch {
903
+ refspecs. push ( format ! ( "+{0}:refs/commit/{0}" , oid_to_fetch) ) ;
904
+ } else if is_shallow && rev. parse :: < Oid > ( ) . is_ok ( ) {
905
+ // There is a specific commit to fetch and we will just do so in shallow-mode only
906
+ // to not disturb the previous logic. Note that with typical settings for shallowing,
907
+ // With shallow histories this is a bit fuzzy, and we opt-out for now.
908
+ refspecs. push ( format ! ( "+{0}:refs/remotes/origin/HEAD" , rev) ) ;
909
+ } else {
910
+ // We don't know what the rev will point to. To handle this
911
+ // situation we fetch all branches and tags, and then we pray
912
+ // it's somewhere in there.
913
+ refspecs. push ( String :: from ( "+refs/heads/*:refs/remotes/origin/*" ) ) ;
914
+ refspecs. push ( String :: from ( "+HEAD:refs/remotes/origin/HEAD" ) ) ;
915
+ tags = true ;
923
916
}
924
917
}
925
918
}
0 commit comments