Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion http-fetch.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "gettext.h"
#include "hex.h"
#include "http.h"
#include "packfile.h"
#include "run-command.h"
#include "walker.h"
#include "setup.h"
#include "strvec.h"
Expand Down Expand Up @@ -82,7 +84,26 @@ static void fetch_single_packfile(struct object_id *packfile_hash,
{
struct http_pack_request *preq;
struct packfile_progress progress = { 0 };
int ret;
struct strbuf pack_path = STRBUF_INIT;
int fd, ret;

odb_pack_name(the_repository, &pack_path, packfile_hash->hash, "pack");
fd = git_open(pack_path.buf);
strbuf_release(&pack_path);
if (fd >= 0) {
struct child_process ip = CHILD_PROCESS_INIT;

/* Retain index-pack validation, output and keep-file handling. */
ip.git_cmd = 1;
ip.in = fd;
ip.clean_on_exit = 1;
strvec_pushv(&ip.args, index_pack_args);
if (report_progress)
report_packfile_progress(&progress);
if (run_command(&ip))
die("index-pack failed for existing pack");
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Clean up stale partial packs before returning

When a completed pack coexists with pack-<hash>.pack.temp—for example, after an interrupted download followed by another process installing the pack, or a crash after index-pack succeeds—the early return permanently bypasses the cleanup performed by finish_http_pack_request(). Every later invocation takes this branch as well, so a potentially multi-gigabyte partial remains in the object directory indefinitely; remove the obsolete temporary file after the existing pack has been successfully validated.

Useful? React with 👍 / 👎.

}

http_init(NULL, url, 0);

Expand Down
24 changes: 24 additions & 0 deletions t/t5550-http-fetch-dumb.sh
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,30 @@ test_expect_success 'http-fetch --packfile' '
git -C packfileclient cat-file -e "$HASH"
'

test_expect_success 'http-fetch --packfile reuses a completed pack without HTTP' '
git init packfileclient-reuse &&
p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
ls objects/pack/pack-*.pack) &&
git -C packfileclient-reuse index-pack --stdin --keep \
<"$HTTPD_DOCUMENT_ROOT_PATH/repo_pack.git/$p" >out &&
packhash=$(cut -f2 out) &&
pack="packfileclient-reuse/.git/objects/pack/pack-$packhash" &&
>reuse.trace &&
GIT_TRACE_CURL="$TRASH_DIRECTORY/reuse.trace" \
git -C packfileclient-reuse http-fetch --report-progress --packfile="$packhash" \
--index-pack-arg=index-pack --index-pack-arg=--stdin \
--index-pack-arg=--keep \
"$HTTPD_URL/missing.pack" >out &&
printf "bytes 0\npack\t%s\n" "$packhash" >expect &&
test_cmp expect out &&
test_must_be_empty reuse.trace &&
test_path_is_file "$pack.pack" &&
test_path_is_file "$pack.idx" &&
test_path_is_file "$pack.keep" &&
test_path_is_missing "$pack.pack.temp" &&
git -C packfileclient-reuse cat-file -e "$HASH"
'

test_expect_success 'http-fetch --packfile accepts an already complete partial' '
git init packfileclient-complete &&
p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git &&
Expand Down
Loading