[PATCH 3/6] builtin/receive-pack: lift global state out of unpack()
Justin Tobler <[email protected]>
| Newsgroups | org.kernel.vger.git |
|---|---|
| Message-ID | <[email protected]> |
In git-receive-pack(1), writing the packfile to the transaction is handled via `unpack()` which relies on global variables to decide how to invoke the underlying git-index-pack(1) or git-unpack-objects(1) child processes. In a subsequent commit, the `unpack()` logic is moved behind a generic ODB transaction interface to handle writing packfiles and thus can no rely on these globals. Lift the global state out of `unpack()` by instead storing this state in a `struct unpack_opts` that gets passed to the function explicitly. Signed-off-by: Justin Tobler <[email protected]> --- builtin/receive-pack.c | 67 +++++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 23 deletions(-) diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 6da854fca2..8c2d6e5789 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -2333,18 +2333,25 @@ static void push_header_arg(struct strvec *args, struct pack_header *hdr) ntohl(hdr->hdr_version), ntohl(hdr->hdr_entries)); } +struct unpack_opts { + const char *fsck_msg_types; + const char *shallow_file; + off_t max_input_size; + int fsck_objects; + int unpack_limit; + int reject_thin; + int err_fd; + int quiet; +}; + static const char *unpack(struct odb_transaction *transaction, - const char *shallow_file, int err_fd) + const struct unpack_opts *opts) { struct pack_header hdr; const char *hdr_err; int status; struct child_process child = CHILD_PROCESS_INIT; - int fsck_objects = (receive_fsck_objects >= 0 - ? receive_fsck_objects - : transfer_fsck_objects >= 0 - ? transfer_fsck_objects - : 0); + int err_fd = opts->err_fd; hdr_err = parse_pack_header(&hdr); if (hdr_err) { @@ -2353,24 +2360,24 @@ static const char *unpack(struct odb_transaction *transaction, return hdr_err; } - if (shallow_file) { + if (opts->shallow_file) { strvec_push(&child.args, "--shallow-file"); - strvec_push(&child.args, shallow_file); + strvec_push(&child.args, opts->shallow_file); } odb_transaction_env(transaction, &child.env); - if (ntohl(hdr.hdr_entries) < unpack_limit) { + if (ntohl(hdr.hdr_entries) < opts->unpack_limit) { strvec_push(&child.args, "unpack-objects"); push_header_arg(&child.args, &hdr); - if (quiet) + if (opts->quiet) strvec_push(&child.args, "-q"); - if (fsck_objects) + if (opts->fsck_objects) strvec_pushf(&child.args, "--strict%s", - fsck_msg_types.buf); - if (max_input_size) + opts->fsck_msg_types); + if (opts->max_input_size) strvec_pushf(&child.args, "--max-input-size=%"PRIuMAX, - (uintmax_t)max_input_size); + (uintmax_t)opts->max_input_size); child.no_stdout = 1; child.err = err_fd; child.git_cmd = 1; @@ -2391,18 +2398,18 @@ static const char *unpack(struct odb_transaction *transaction, (uintmax_t)getpid(), hostname); - if (!quiet && err_fd) + if (!opts->quiet && err_fd) strvec_push(&child.args, "--show-resolving-progress"); - if (use_sideband) + if (err_fd) strvec_push(&child.args, "--report-end-of-input"); - if (fsck_objects) + if (opts->fsck_objects) strvec_pushf(&child.args, "--strict%s", - fsck_msg_types.buf); - if (!reject_thin) + opts->fsck_msg_types); + if (!opts->reject_thin) strvec_push(&child.args, "--fix-thin"); - if (max_input_size) + if (opts->max_input_size) strvec_pushf(&child.args, "--max-input-size=%"PRIuMAX, - (uintmax_t)max_input_size); + (uintmax_t)opts->max_input_size); child.out = -1; child.err = err_fd; child.git_cmd = 1; @@ -2428,11 +2435,24 @@ static const char *unpack(struct odb_transaction *transaction, static const char *unpack_with_sideband(struct odb_transaction *transaction, const char *shallow_file) { + struct unpack_opts opts = { + .fsck_objects = (receive_fsck_objects >= 0 + ? receive_fsck_objects + : transfer_fsck_objects >= 0 + ? transfer_fsck_objects + : 0), + .fsck_msg_types = fsck_msg_types.buf, + .max_input_size = max_input_size, + .shallow_file = shallow_file, + .unpack_limit = unpack_limit, + .reject_thin = reject_thin, + .quiet = quiet, + }; struct async muxer; const char *ret; if (!use_sideband) - return unpack(transaction, shallow_file, 0); + return unpack(transaction, &opts); use_keepalive = KEEPALIVE_AFTER_NUL; memset(&muxer, 0, sizeof(muxer)); @@ -2441,7 +2461,8 @@ static const char *unpack_with_sideband(struct odb_transaction *transaction, if (start_async(&muxer)) return NULL; - ret = unpack(transaction, shallow_file, muxer.in); + opts.err_fd = muxer.in; + ret = unpack(transaction, &opts); finish_async(&muxer); return ret; -- 2.55.0.424.g13c7afec21