Skip to content

Commit acdaf94

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 eb9422f commit acdaf94

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

@@ -2583,7 +2609,7 @@ static void setup_gvfs_objects_progress(struct gh__request_params *params,
25832609
if (!gh__cmd_opts.show_progress)
25842610
return;
25852611

2586-
if (params->b_is_post && params->object_count > 1) {
2612+
if (params->b_is_post) {
25872613
strbuf_addf(&params->progress_base_phase3_msg,
25882614
"Receiving packfile %ld/%ld with %ld objects",
25892615
num, den, params->object_count);
@@ -2615,6 +2641,8 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
26152641

26162642
params.object_count = 1;
26172643

2644+
params.result_list = result_list;
2645+
26182646
params.headers = http_copy_default_headers();
26192647
params.headers = curl_slist_append(params.headers,
26202648
"X-TFS-FedAuthRedirect: Suppress");
@@ -2627,16 +2655,6 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
26272655

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

2630-
if (status->ec == GH__ERROR_CODE__OK) {
2631-
struct strbuf msg = STRBUF_INIT;
2632-
2633-
strbuf_addf(&msg, "loose %s",
2634-
oid_to_hex(&params.loose_oid));
2635-
2636-
string_list_append(result_list, msg.buf);
2637-
strbuf_release(&msg);
2638-
}
2639-
26402658
gh__request_params__release(&params);
26412659
strbuf_release(&component_url);
26422660
}
@@ -2648,7 +2666,7 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
26482666
* consumed (along with the filename of the resulting packfile).
26492667
*
26502668
* However, if we only have 1 oid (remaining) in the OIDSET, the
2651-
* server will respond to our POST with a loose object rather than
2669+
* server *MAY* respond to our POST with a loose object rather than
26522670
* a packfile with 1 object.
26532671
*
26542672
* Append a message to the result_list describing the result.
@@ -2679,6 +2697,8 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,
26792697

26802698
params.post_payload = &jw_req.json;
26812699

2700+
params.result_list = result_list;
2701+
26822702
params.headers = http_copy_default_headers();
26832703
params.headers = curl_slist_append(params.headers,
26842704
"X-TFS-FedAuthRedirect: Suppress");
@@ -2706,20 +2726,6 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,
27062726

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

2709-
if (status->ec == GH__ERROR_CODE__OK) {
2710-
struct strbuf msg = STRBUF_INIT;
2711-
2712-
if (params.object_count > 1)
2713-
strbuf_addf(&msg, "packfile %s",
2714-
params.final_packfile_filename.buf);
2715-
else
2716-
strbuf_addf(&msg, "loose %s",
2717-
oid_to_hex(&params.loose_oid));
2718-
2719-
string_list_append(result_list, msg.buf);
2720-
strbuf_release(&msg);
2721-
}
2722-
27232729
gh__request_params__release(&params);
27242730
jw_release(&jw_req);
27252731
}

0 commit comments

Comments
 (0)