@@ -1854,9 +1854,10 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
18541854 }
18551855
18561856 for (i = 0 ; i < packfile_uris .nr ; i ++ ) {
1857+ bool created_keep ;
18571858 int j ;
18581859 struct child_process cmd = CHILD_PROCESS_INIT ;
1859- char packname [GIT_MAX_HEXSZ + 1 ];
1860+ char packhash [GIT_MAX_HEXSZ + 1 ];
18601861 const char * uri = packfile_uris .items [i ].string +
18611862 the_hash_algo -> hexsz + 1 ;
18621863
@@ -1874,16 +1875,17 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
18741875 if (start_command (& cmd ))
18751876 die ("fetch-pack: unable to spawn http-fetch" );
18761877
1877- if (read_in_full (cmd .out , packname , 5 ) < 0 ||
1878- memcmp (packname , "keep\t" , 5 ))
1879- die ("fetch-pack: expected keep then TAB at start of http-fetch output" );
1878+ if (read_in_full (cmd .out , packhash , 5 ) != 5 ||
1879+ (memcmp (packhash , "keep\t" , 5 ) &&
1880+ memcmp (packhash , "pack\t" , 5 )))
1881+ die ("fetch-pack: expected pack or keep then TAB at start of http-fetch output" );
1882+ created_keep = !memcmp (packhash , "keep\t" , 5 );
18801883
1881- if (read_in_full (cmd .out , packname ,
1882- the_hash_algo -> hexsz + 1 ) < 0 ||
1883- packname [the_hash_algo -> hexsz ] != '\n' )
1884- die ("fetch-pack: expected hash then LF at end of http-fetch output" );
1885-
1886- packname [the_hash_algo -> hexsz ] = '\0' ;
1884+ if (read_in_full (cmd .out , packhash ,
1885+ the_hash_algo -> hexsz + 1 ) != the_hash_algo -> hexsz + 1 ||
1886+ packhash [the_hash_algo -> hexsz ] != '\n' )
1887+ die ("fetch-pack: expected hash then LF in http-fetch output" );
1888+ packhash [the_hash_algo -> hexsz ] = '\0' ;
18871889
18881890 parse_gitmodules_oids (cmd .out , & fsck_options .gitmodules_found );
18891891
@@ -1892,16 +1894,17 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args,
18921894 if (finish_command (& cmd ))
18931895 die ("fetch-pack: unable to finish http-fetch" );
18941896
1895- if (memcmp (packfile_uris .items [i ].string , packname ,
1897+ if (memcmp (packfile_uris .items [i ].string , packhash ,
18961898 the_hash_algo -> hexsz ))
18971899 die ("fetch-pack: pack downloaded from %s does not match expected hash %.*s" ,
18981900 uri , (int ) the_hash_algo -> hexsz ,
18991901 packfile_uris .items [i ].string );
19001902
1901- string_list_append_nodup (pack_lockfiles ,
1902- xstrfmt ("%s/pack/pack-%s.keep" ,
1903- repo_get_object_directory (the_repository ),
1904- packname ));
1903+ if (created_keep )
1904+ string_list_append_nodup (pack_lockfiles ,
1905+ xstrfmt ("%s/pack/pack-%s.keep" ,
1906+ repo_get_object_directory (the_repository ),
1907+ packhash ));
19051908 }
19061909 string_list_clear (& packfile_uris , 0 );
19071910 strvec_clear (& index_pack_args );
0 commit comments