@@ -953,184 +953,23 @@ static int add_send_request(struct object *obj, struct remote_lock *lock)
953
953
return 1 ;
954
954
}
955
955
956
- static int fetch_index (unsigned char * sha1 )
957
- {
958
- int ret = 0 ;
959
- char * hex = xstrdup (sha1_to_hex (sha1 ));
960
- char * filename ;
961
- char * url ;
962
- char tmpfile [PATH_MAX ];
963
- long prev_posn = 0 ;
964
- char range [RANGE_HEADER_SIZE ];
965
- struct curl_slist * range_header = NULL ;
966
-
967
- FILE * indexfile ;
968
- struct active_request_slot * slot ;
969
- struct slot_results results ;
970
-
971
- /* Don't use the index if the pack isn't there */
972
- url = xmalloc (strlen (repo -> url ) + 64 );
973
- sprintf (url , "%sobjects/pack/pack-%s.pack" , repo -> url , hex );
974
- slot = get_active_slot ();
975
- slot -> results = & results ;
976
- curl_easy_setopt (slot -> curl , CURLOPT_URL , url );
977
- curl_easy_setopt (slot -> curl , CURLOPT_NOBODY , 1 );
978
- if (start_active_slot (slot )) {
979
- run_active_slot (slot );
980
- if (results .curl_result != CURLE_OK ) {
981
- ret = error ("Unable to verify pack %s is available" ,
982
- hex );
983
- goto cleanup_pack ;
984
- }
985
- } else {
986
- ret = error ("Unable to start request" );
987
- goto cleanup_pack ;
988
- }
989
-
990
- if (has_pack_index (sha1 )) {
991
- ret = 0 ;
992
- goto cleanup_pack ;
993
- }
994
-
995
- if (push_verbosely )
996
- fprintf (stderr , "Getting index for pack %s\n" , hex );
997
-
998
- sprintf (url , "%sobjects/pack/pack-%s.idx" , repo -> url , hex );
999
-
1000
- filename = sha1_pack_index_name (sha1 );
1001
- snprintf (tmpfile , sizeof (tmpfile ), "%s.temp" , filename );
1002
- indexfile = fopen (tmpfile , "a" );
1003
- if (!indexfile ) {
1004
- ret = error ("Unable to open local file %s for pack index" ,
1005
- tmpfile );
1006
- goto cleanup_pack ;
1007
- }
1008
-
1009
- slot = get_active_slot ();
1010
- slot -> results = & results ;
1011
- curl_easy_setopt (slot -> curl , CURLOPT_NOBODY , 0 );
1012
- curl_easy_setopt (slot -> curl , CURLOPT_HTTPGET , 1 );
1013
- curl_easy_setopt (slot -> curl , CURLOPT_FILE , indexfile );
1014
- curl_easy_setopt (slot -> curl , CURLOPT_WRITEFUNCTION , fwrite );
1015
- curl_easy_setopt (slot -> curl , CURLOPT_URL , url );
1016
- curl_easy_setopt (slot -> curl , CURLOPT_HTTPHEADER , no_pragma_header );
1017
- slot -> local = indexfile ;
1018
-
1019
- /*
1020
- * If there is data present from a previous transfer attempt,
1021
- * resume where it left off
1022
- */
1023
- prev_posn = ftell (indexfile );
1024
- if (prev_posn > 0 ) {
1025
- if (push_verbosely )
1026
- fprintf (stderr ,
1027
- "Resuming fetch of index for pack %s at byte %ld\n" ,
1028
- hex , prev_posn );
1029
- sprintf (range , "Range: bytes=%ld-" , prev_posn );
1030
- range_header = curl_slist_append (range_header , range );
1031
- curl_easy_setopt (slot -> curl , CURLOPT_HTTPHEADER , range_header );
1032
- }
1033
-
1034
- if (start_active_slot (slot )) {
1035
- run_active_slot (slot );
1036
- if (results .curl_result != CURLE_OK ) {
1037
- ret = error ("Unable to get pack index %s\n%s" , url ,
1038
- curl_errorstr );
1039
- goto cleanup_index ;
1040
- }
1041
- } else {
1042
- ret = error ("Unable to start request" );
1043
- goto cleanup_index ;
1044
- }
1045
-
1046
- ret = move_temp_to_file (tmpfile , filename );
1047
-
1048
- cleanup_index :
1049
- fclose (indexfile );
1050
- slot -> local = NULL ;
1051
- cleanup_pack :
1052
- free (url );
1053
- free (hex );
1054
- return ret ;
1055
- }
1056
-
1057
- static int setup_index (unsigned char * sha1 )
1058
- {
1059
- struct packed_git * new_pack ;
1060
-
1061
- if (fetch_index (sha1 ))
1062
- return -1 ;
1063
-
1064
- new_pack = parse_pack_index (sha1 );
1065
- if (!new_pack )
1066
- return -1 ; /* parse_pack_index() already issued error message */
1067
- new_pack -> next = repo -> packs ;
1068
- repo -> packs = new_pack ;
1069
- return 0 ;
1070
- }
1071
-
1072
956
static int fetch_indices (void )
1073
957
{
1074
- unsigned char sha1 [20 ];
1075
- char * url ;
1076
- struct strbuf buffer = STRBUF_INIT ;
1077
- char * data ;
1078
- int i = 0 ;
1079
-
1080
- struct active_request_slot * slot ;
1081
- struct slot_results results ;
958
+ int ret ;
1082
959
1083
960
if (push_verbosely )
1084
961
fprintf (stderr , "Getting pack list\n" );
1085
962
1086
- url = xmalloc (strlen (repo -> url ) + 20 );
1087
- sprintf (url , "%sobjects/info/packs" , repo -> url );
1088
-
1089
- slot = get_active_slot ();
1090
- slot -> results = & results ;
1091
- curl_easy_setopt (slot -> curl , CURLOPT_FILE , & buffer );
1092
- curl_easy_setopt (slot -> curl , CURLOPT_WRITEFUNCTION , fwrite_buffer );
1093
- curl_easy_setopt (slot -> curl , CURLOPT_URL , url );
1094
- curl_easy_setopt (slot -> curl , CURLOPT_HTTPHEADER , NULL );
1095
- if (start_active_slot (slot )) {
1096
- run_active_slot (slot );
1097
- if (results .curl_result != CURLE_OK ) {
1098
- strbuf_release (& buffer );
1099
- free (url );
1100
- if (results .http_code == 404 )
1101
- return 0 ;
1102
- else
1103
- return error ("%s" , curl_errorstr );
1104
- }
1105
- } else {
1106
- strbuf_release (& buffer );
1107
- free (url );
1108
- return error ("Unable to start request" );
1109
- }
1110
- free (url );
1111
-
1112
- data = buffer .buf ;
1113
- while (i < buffer .len ) {
1114
- switch (data [i ]) {
1115
- case 'P' :
1116
- i ++ ;
1117
- if (i + 52 < buffer .len &&
1118
- !prefixcmp (data + i , " pack-" ) &&
1119
- !prefixcmp (data + i + 46 , ".pack\n" )) {
1120
- get_sha1_hex (data + i + 6 , sha1 );
1121
- setup_index (sha1 );
1122
- i += 51 ;
1123
- break ;
1124
- }
1125
- default :
1126
- while (data [i ] != '\n' )
1127
- i ++ ;
1128
- }
1129
- i ++ ;
963
+ switch (http_get_info_packs (repo -> url , & repo -> packs )) {
964
+ case HTTP_OK :
965
+ case HTTP_MISSING_TARGET :
966
+ ret = 0 ;
967
+ break ;
968
+ default :
969
+ ret = -1 ;
1130
970
}
1131
971
1132
- strbuf_release (& buffer );
1133
- return 0 ;
972
+ return ret ;
1134
973
}
1135
974
1136
975
static void one_remote_object (const char * hex )
0 commit comments