Skip to content

Commit 494fb4e

Browse files
jeffhostetlerdscho
authored andcommitted
gvfs-helper: move result-list construction into install functions
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>
1 parent d813b86 commit 494fb4e

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

gvfs-helper.c

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,8 @@ struct gh__request_params {
448448
struct progress *progress;
449449

450450
struct strbuf e2eid;
451+
452+
struct string_list *result_list; /* we do not own this */
451453
};
452454

453455
#define GH__REQUEST_PARAMS_INIT { \
@@ -476,6 +478,7 @@ struct gh__request_params {
476478
.progress_msg = STRBUF_INIT, \
477479
.progress = NULL, \
478480
.e2eid = STRBUF_INIT, \
481+
.result_list = NULL, \
479482
}
480483

481484
static void gh__request_params__release(struct gh__request_params *params)
@@ -508,6 +511,8 @@ static void gh__request_params__release(struct gh__request_params *params)
508511
params->progress = NULL;
509512

510513
strbuf_release(&params->e2eid);
514+
515+
params->result_list = NULL; /* we do not own this */
511516
}
512517

513518
/*
@@ -1865,6 +1870,16 @@ static void install_packfile(struct gh__request_params *params,
18651870
goto cleanup;
18661871
}
18671872

1873+
1874+
if (params->result_list) {
1875+
struct strbuf result_msg = STRBUF_INIT;
1876+
1877+
strbuf_addf(&result_msg, "packfile %s",
1878+
params->final_packfile_filename.buf);
1879+
string_list_append(params->result_list, result_msg.buf);
1880+
strbuf_release(&result_msg);
1881+
}
1882+
18681883
cleanup:
18691884
child_process_clear(&ip);
18701885
}
@@ -1921,8 +1936,19 @@ static void install_loose(struct gh__request_params *params,
19211936
"could not install loose object '%s'",
19221937
params->loose_path.buf);
19231938
status->ec = GH__ERROR_CODE__COULD_NOT_INSTALL_LOOSE;
1939+
goto cleanup;
1940+
}
1941+
1942+
if (params->result_list) {
1943+
struct strbuf result_msg = STRBUF_INIT;
1944+
1945+
strbuf_addf(&result_msg, "loose %s",
1946+
oid_to_hex(&params->loose_oid));
1947+
string_list_append(params->result_list, result_msg.buf);
1948+
strbuf_release(&result_msg);
19241949
}
19251950

1951+
cleanup:
19261952
strbuf_release(&tmp_path);
19271953
}
19281954

@@ -2577,7 +2603,7 @@ static void setup_gvfs_objects_progress(struct gh__request_params *params,
25772603
if (!gh__cmd_opts.show_progress)
25782604
return;
25792605

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

26102636
params.object_count = 1;
26112637

2638+
params.result_list = result_list;
2639+
26122640
params.headers = http_copy_default_headers();
26132641
params.headers = curl_slist_append(params.headers,
26142642
"X-TFS-FedAuthRedirect: Suppress");
@@ -2621,16 +2649,6 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
26212649

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

2624-
if (status->ec == GH__ERROR_CODE__OK) {
2625-
struct strbuf msg = STRBUF_INIT;
2626-
2627-
strbuf_addf(&msg, "loose %s",
2628-
oid_to_hex(&params.loose_oid));
2629-
2630-
string_list_append(result_list, msg.buf);
2631-
strbuf_release(&msg);
2632-
}
2633-
26342652
gh__request_params__release(&params);
26352653
strbuf_release(&component_url);
26362654
}
@@ -2642,7 +2660,7 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
26422660
* consumed (along with the filename of the resulting packfile).
26432661
*
26442662
* However, if we only have 1 oid (remaining) in the OIDSET, the
2645-
* server will respond to our POST with a loose object rather than
2663+
* server *MAY* respond to our POST with a loose object rather than
26462664
* a packfile with 1 object.
26472665
*
26482666
* Append a message to the result_list describing the result.
@@ -2673,6 +2691,8 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,
26732691

26742692
params.post_payload = &jw_req.json;
26752693

2694+
params.result_list = result_list;
2695+
26762696
params.headers = http_copy_default_headers();
26772697
params.headers = curl_slist_append(params.headers,
26782698
"X-TFS-FedAuthRedirect: Suppress");
@@ -2700,20 +2720,6 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,
27002720

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

2703-
if (status->ec == GH__ERROR_CODE__OK) {
2704-
struct strbuf msg = STRBUF_INIT;
2705-
2706-
if (params.object_count > 1)
2707-
strbuf_addf(&msg, "packfile %s",
2708-
params.final_packfile_filename.buf);
2709-
else
2710-
strbuf_addf(&msg, "loose %s",
2711-
oid_to_hex(&params.loose_oid));
2712-
2713-
string_list_append(result_list, msg.buf);
2714-
strbuf_release(&msg);
2715-
}
2716-
27172723
gh__request_params__release(&params);
27182724
jw_release(&jw_req);
27192725
}

0 commit comments

Comments
 (0)