Skip to content

Commit 86d825d

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 2c696aa commit 86d825d

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

453453
struct strbuf e2eid;
454+
455+
struct string_list *result_list; /* we do not own this */
454456
};
455457

456458
#define GH__REQUEST_PARAMS_INIT { \
@@ -479,6 +481,7 @@ struct gh__request_params {
479481
.progress_msg = STRBUF_INIT, \
480482
.progress = NULL, \
481483
.e2eid = STRBUF_INIT, \
484+
.result_list = NULL, \
482485
}
483486

484487
static void gh__request_params__release(struct gh__request_params *params)
@@ -511,6 +514,8 @@ static void gh__request_params__release(struct gh__request_params *params)
511514
params->progress = NULL;
512515

513516
strbuf_release(&params->e2eid);
517+
518+
params->result_list = NULL; /* we do not own this */
514519
}
515520

516521
/*
@@ -1871,6 +1876,16 @@ static void install_packfile(struct gh__request_params *params,
18711876
goto cleanup;
18721877
}
18731878

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

1957+
cleanup:
19321958
strbuf_release(&tmp_path);
19331959
}
19341960

@@ -2597,7 +2623,7 @@ static void setup_gvfs_objects_progress(struct gh__request_params *params,
25972623
if (!gh__cmd_opts.show_progress)
25982624
return;
25992625

2600-
if (params->b_is_post && params->object_count > 1) {
2626+
if (params->b_is_post) {
26012627
strbuf_addf(&params->progress_base_phase3_msg,
26022628
"Receiving packfile %ld/%ld with %ld objects",
26032629
num, den, params->object_count);
@@ -2629,6 +2655,8 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
26292655

26302656
params.object_count = 1;
26312657

2658+
params.result_list = result_list;
2659+
26322660
params.headers = http_copy_default_headers();
26332661
params.headers = curl_slist_append(params.headers,
26342662
"X-TFS-FedAuthRedirect: Suppress");
@@ -2641,16 +2669,6 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
26412669

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

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

26942712
params.post_payload = &jw_req.json;
26952713

2714+
params.result_list = result_list;
2715+
26962716
params.headers = http_copy_default_headers();
26972717
params.headers = curl_slist_append(params.headers,
26982718
"X-TFS-FedAuthRedirect: Suppress");
@@ -2720,20 +2740,6 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,
27202740

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

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

0 commit comments

Comments
 (0)