Skip to content

Commit

Permalink
gvfs-helper: move result-list construction into install functions
Browse files Browse the repository at this point in the history
gvfs-helper prints a "loose <oid>" or "packfile <name>" messages after
they are received to help invokers update their in-memory caches.
Move the code to accumulate these messages in the result_list into
the install_* functions rather than waiting until the end.

POST requests containing 1 object may return a loose object or a packfile
depending on whether the object is a commit or non-commit.  Delaying the
message generation just complicated the caller.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
  • Loading branch information
jeffhostetler authored and dscho committed Aug 8, 2023
1 parent d813b86 commit 494fb4e
Showing 1 changed file with 32 additions and 26 deletions.
58 changes: 32 additions & 26 deletions gvfs-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ struct gh__request_params {
struct progress *progress;

struct strbuf e2eid;

struct string_list *result_list; /* we do not own this */
};

#define GH__REQUEST_PARAMS_INIT { \
Expand Down Expand Up @@ -476,6 +478,7 @@ struct gh__request_params {
.progress_msg = STRBUF_INIT, \
.progress = NULL, \
.e2eid = STRBUF_INIT, \
.result_list = NULL, \
}

static void gh__request_params__release(struct gh__request_params *params)
Expand Down Expand Up @@ -508,6 +511,8 @@ static void gh__request_params__release(struct gh__request_params *params)
params->progress = NULL;

strbuf_release(&params->e2eid);

params->result_list = NULL; /* we do not own this */
}

/*
Expand Down Expand Up @@ -1865,6 +1870,16 @@ static void install_packfile(struct gh__request_params *params,
goto cleanup;
}


if (params->result_list) {
struct strbuf result_msg = STRBUF_INIT;

strbuf_addf(&result_msg, "packfile %s",
params->final_packfile_filename.buf);
string_list_append(params->result_list, result_msg.buf);
strbuf_release(&result_msg);
}

cleanup:
child_process_clear(&ip);
}
Expand Down Expand Up @@ -1921,8 +1936,19 @@ static void install_loose(struct gh__request_params *params,
"could not install loose object '%s'",
params->loose_path.buf);
status->ec = GH__ERROR_CODE__COULD_NOT_INSTALL_LOOSE;
goto cleanup;
}

if (params->result_list) {
struct strbuf result_msg = STRBUF_INIT;

strbuf_addf(&result_msg, "loose %s",
oid_to_hex(&params->loose_oid));
string_list_append(params->result_list, result_msg.buf);
strbuf_release(&result_msg);
}

cleanup:
strbuf_release(&tmp_path);
}

Expand Down Expand Up @@ -2577,7 +2603,7 @@ static void setup_gvfs_objects_progress(struct gh__request_params *params,
if (!gh__cmd_opts.show_progress)
return;

if (params->b_is_post && params->object_count > 1) {
if (params->b_is_post) {
strbuf_addf(&params->progress_base_phase3_msg,
"Receiving packfile %ld/%ld with %ld objects",
num, den, params->object_count);
Expand Down Expand Up @@ -2609,6 +2635,8 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,

params.object_count = 1;

params.result_list = result_list;

params.headers = http_copy_default_headers();
params.headers = curl_slist_append(params.headers,
"X-TFS-FedAuthRedirect: Suppress");
Expand All @@ -2621,16 +2649,6 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,

do_req__with_fallback(component_url.buf, &params, status);

if (status->ec == GH__ERROR_CODE__OK) {
struct strbuf msg = STRBUF_INIT;

strbuf_addf(&msg, "loose %s",
oid_to_hex(&params.loose_oid));

string_list_append(result_list, msg.buf);
strbuf_release(&msg);
}

gh__request_params__release(&params);
strbuf_release(&component_url);
}
Expand All @@ -2642,7 +2660,7 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
* consumed (along with the filename of the resulting packfile).
*
* However, if we only have 1 oid (remaining) in the OIDSET, the
* server will respond to our POST with a loose object rather than
* server *MAY* respond to our POST with a loose object rather than
* a packfile with 1 object.
*
* Append a message to the result_list describing the result.
Expand Down Expand Up @@ -2673,6 +2691,8 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,

params.post_payload = &jw_req.json;

params.result_list = result_list;

params.headers = http_copy_default_headers();
params.headers = curl_slist_append(params.headers,
"X-TFS-FedAuthRedirect: Suppress");
Expand Down Expand Up @@ -2700,20 +2720,6 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,

do_req__with_fallback("gvfs/objects", &params, status);

if (status->ec == GH__ERROR_CODE__OK) {
struct strbuf msg = STRBUF_INIT;

if (params.object_count > 1)
strbuf_addf(&msg, "packfile %s",
params.final_packfile_filename.buf);
else
strbuf_addf(&msg, "loose %s",
oid_to_hex(&params.loose_oid));

string_list_append(result_list, msg.buf);
strbuf_release(&msg);
}

gh__request_params__release(&params);
jw_release(&jw_req);
}
Expand Down

0 comments on commit 494fb4e

Please sign in to comment.