Skip to content

Commit 9f748c9

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 <[email protected]>
1 parent 0c7e59f commit 9f748c9

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
@@ -450,6 +450,8 @@ struct gh__request_params {
450450
struct progress *progress;
451451

452452
struct strbuf e2eid;
453+
454+
struct string_list *result_list; /* we do not own this */
453455
};
454456

455457
#define GH__REQUEST_PARAMS_INIT { \
@@ -478,6 +480,7 @@ struct gh__request_params {
478480
.progress_msg = STRBUF_INIT, \
479481
.progress = NULL, \
480482
.e2eid = STRBUF_INIT, \
483+
.result_list = NULL, \
481484
}
482485

483486
static void gh__request_params__release(struct gh__request_params *params)
@@ -510,6 +513,8 @@ static void gh__request_params__release(struct gh__request_params *params)
510513
params->progress = NULL;
511514

512515
strbuf_release(&params->e2eid);
516+
517+
params->result_list = NULL; /* we do not own this */
513518
}
514519

515520
/*
@@ -1870,6 +1875,16 @@ static void install_packfile(struct gh__request_params *params,
18701875
goto cleanup;
18711876
}
18721877

1878+
1879+
if (params->result_list) {
1880+
struct strbuf result_msg = STRBUF_INIT;
1881+
1882+
strbuf_addf(&result_msg, "packfile %s",
1883+
params->final_packfile_filename.buf);
1884+
string_list_append(params->result_list, result_msg.buf);
1885+
strbuf_release(&result_msg);
1886+
}
1887+
18731888
cleanup:
18741889
child_process_clear(&ip);
18751890
}
@@ -1926,8 +1941,19 @@ static void install_loose(struct gh__request_params *params,
19261941
"could not install loose object '%s'",
19271942
params->loose_path.buf);
19281943
status->ec = GH__ERROR_CODE__COULD_NOT_INSTALL_LOOSE;
1944+
goto cleanup;
1945+
}
1946+
1947+
if (params->result_list) {
1948+
struct strbuf result_msg = STRBUF_INIT;
1949+
1950+
strbuf_addf(&result_msg, "loose %s",
1951+
oid_to_hex(&params->loose_oid));
1952+
string_list_append(params->result_list, result_msg.buf);
1953+
strbuf_release(&result_msg);
19291954
}
19301955

1956+
cleanup:
19311957
strbuf_release(&tmp_path);
19321958
}
19331959

@@ -2596,7 +2622,7 @@ static void setup_gvfs_objects_progress(struct gh__request_params *params,
25962622
if (!gh__cmd_opts.show_progress)
25972623
return;
25982624

2599-
if (params->b_is_post && params->object_count > 1) {
2625+
if (params->b_is_post) {
26002626
strbuf_addf(&params->progress_base_phase3_msg,
26012627
"Receiving packfile %ld/%ld with %ld objects",
26022628
num, den, params->object_count);
@@ -2628,6 +2654,8 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
26282654

26292655
params.object_count = 1;
26302656

2657+
params.result_list = result_list;
2658+
26312659
params.headers = http_copy_default_headers();
26322660
params.headers = curl_slist_append(params.headers,
26332661
"X-TFS-FedAuthRedirect: Suppress");
@@ -2640,16 +2668,6 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
26402668

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

2643-
if (status->ec == GH__ERROR_CODE__OK) {
2644-
struct strbuf msg = STRBUF_INIT;
2645-
2646-
strbuf_addf(&msg, "loose %s",
2647-
oid_to_hex(&params.loose_oid));
2648-
2649-
string_list_append(result_list, msg.buf);
2650-
strbuf_release(&msg);
2651-
}
2652-
26532671
gh__request_params__release(&params);
26542672
strbuf_release(&component_url);
26552673
}
@@ -2661,7 +2679,7 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
26612679
* consumed (along with the filename of the resulting packfile).
26622680
*
26632681
* However, if we only have 1 oid (remaining) in the OIDSET, the
2664-
* server will respond to our POST with a loose object rather than
2682+
* server *MAY* respond to our POST with a loose object rather than
26652683
* a packfile with 1 object.
26662684
*
26672685
* Append a message to the result_list describing the result.
@@ -2692,6 +2710,8 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,
26922710

26932711
params.post_payload = &jw_req.json;
26942712

2713+
params.result_list = result_list;
2714+
26952715
params.headers = http_copy_default_headers();
26962716
params.headers = curl_slist_append(params.headers,
26972717
"X-TFS-FedAuthRedirect: Suppress");
@@ -2719,20 +2739,6 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,
27192739

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

2722-
if (status->ec == GH__ERROR_CODE__OK) {
2723-
struct strbuf msg = STRBUF_INIT;
2724-
2725-
if (params.object_count > 1)
2726-
strbuf_addf(&msg, "packfile %s",
2727-
params.final_packfile_filename.buf);
2728-
else
2729-
strbuf_addf(&msg, "loose %s",
2730-
oid_to_hex(&params.loose_oid));
2731-
2732-
string_list_append(result_list, msg.buf);
2733-
strbuf_release(&msg);
2734-
}
2735-
27362742
gh__request_params__release(&params);
27372743
jw_release(&jw_req);
27382744
}

0 commit comments

Comments
 (0)