Merge branch 'js/bundle-unbundle-fd-reuse-fix'

The code path used when "git fetch" fetches from a bundle file
closed the same file descriptor twice, which sometimes broke things
unexpectedly when the file descriptor was reused, which has been
corrected.

* js/bundle-unbundle-fd-reuse-fix:
  bundle: avoid closing file descriptor twice
This commit is contained in:
Junio C Hamano
2025-02-06 14:56:44 -08:00
3 changed files with 6 additions and 1 deletions

View File

@ -607,8 +607,10 @@ int unbundle(struct repository *r, struct bundle_header *header,
if (!opts)
opts = &opts_fallback;
if (verify_bundle(r, header, opts->flags))
if (verify_bundle(r, header, opts->flags)) {
close(bundle_fd);
return -1;
}
strvec_pushl(&ip.args, "index-pack", "--fix-thin", "--stdin", NULL);

View File

@ -62,6 +62,8 @@ struct unbundle_opts {
*
* Before unbundling, this method will call verify_bundle() with 'flags'
* provided in 'opts'.
*
* Note that the `bundle_fd` will be closed as part of the operation.
*/
int unbundle(struct repository *r, struct bundle_header *header,
int bundle_fd, struct strvec *extra_index_pack_args,

View File

@ -207,6 +207,7 @@ static int fetch_refs_from_bundle(struct transport *transport,
ret = unbundle(the_repository, &data->header, data->fd,
&extra_index_pack_args, &opts);
data->fd = -1; /* `unbundle()` closes the file descriptor */
transport->hash_algo = data->header.hash_algo;
strvec_clear(&extra_index_pack_args);