Skip to content

Commit f97ef3b

Browse files
jeffhostetlerderrickstolee
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 6f69b27 commit f97ef3b

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
@@ -441,6 +441,8 @@ struct gh__request_params {
441441
struct progress *progress;
442442

443443
struct strbuf e2eid;
444+
445+
struct string_list *result_list; /* we do not own this */
444446
};
445447

446448
#define GH__REQUEST_PARAMS_INIT { \
@@ -469,6 +471,7 @@ struct gh__request_params {
469471
.progress_msg = STRBUF_INIT, \
470472
.progress = NULL, \
471473
.e2eid = STRBUF_INIT, \
474+
.result_list = NULL, \
472475
}
473476

474477
static void gh__request_params__release(struct gh__request_params *params)
@@ -501,6 +504,8 @@ static void gh__request_params__release(struct gh__request_params *params)
501504
params->progress = NULL;
502505

503506
strbuf_release(&params->e2eid);
507+
508+
params->result_list = NULL; /* we do not own this */
504509
}
505510

506511
/*
@@ -1858,6 +1863,16 @@ static void install_packfile(struct gh__request_params *params,
18581863
goto cleanup;
18591864
}
18601865

1866+
1867+
if (params->result_list) {
1868+
struct strbuf result_msg = STRBUF_INIT;
1869+
1870+
strbuf_addf(&result_msg, "packfile %s",
1871+
params->final_packfile_filename.buf);
1872+
string_list_append(params->result_list, result_msg.buf);
1873+
strbuf_release(&result_msg);
1874+
}
1875+
18611876
cleanup:
18621877
child_process_clear(&ip);
18631878
}
@@ -1914,8 +1929,19 @@ static void install_loose(struct gh__request_params *params,
19141929
"could not install loose object '%s'",
19151930
params->loose_path.buf);
19161931
status->ec = GH__ERROR_CODE__COULD_NOT_INSTALL_LOOSE;
1932+
goto cleanup;
1933+
}
1934+
1935+
if (params->result_list) {
1936+
struct strbuf result_msg = STRBUF_INIT;
1937+
1938+
strbuf_addf(&result_msg, "loose %s",
1939+
oid_to_hex(&params->loose_oid));
1940+
string_list_append(params->result_list, result_msg.buf);
1941+
strbuf_release(&result_msg);
19171942
}
19181943

1944+
cleanup:
19191945
strbuf_release(&tmp_path);
19201946
}
19211947

@@ -2534,7 +2560,7 @@ static void setup_gvfs_objects_progress(struct gh__request_params *params,
25342560
if (!gh__cmd_opts.show_progress)
25352561
return;
25362562

2537-
if (params->b_is_post && params->object_count > 1) {
2563+
if (params->b_is_post) {
25382564
strbuf_addf(&params->progress_base_phase3_msg,
25392565
"Receiving packfile %ld/%ld with %ld objects",
25402566
num, den, params->object_count);
@@ -2566,6 +2592,8 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
25662592

25672593
params.object_count = 1;
25682594

2595+
params.result_list = result_list;
2596+
25692597
params.headers = http_copy_default_headers();
25702598
params.headers = curl_slist_append(params.headers,
25712599
"X-TFS-FedAuthRedirect: Suppress");
@@ -2578,16 +2606,6 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
25782606

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

2581-
if (status->ec == GH__ERROR_CODE__OK) {
2582-
struct strbuf msg = STRBUF_INIT;
2583-
2584-
strbuf_addf(&msg, "loose %s",
2585-
oid_to_hex(&params.loose_oid));
2586-
2587-
string_list_append(result_list, msg.buf);
2588-
strbuf_release(&msg);
2589-
}
2590-
25912609
gh__request_params__release(&params);
25922610
strbuf_release(&component_url);
25932611
}
@@ -2599,7 +2617,7 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
25992617
* consumed (along with the filename of the resulting packfile).
26002618
*
26012619
* However, if we only have 1 oid (remaining) in the OIDSET, the
2602-
* server will respond to our POST with a loose object rather than
2620+
* server *MAY* respond to our POST with a loose object rather than
26032621
* a packfile with 1 object.
26042622
*
26052623
* Append a message to the result_list describing the result.
@@ -2630,6 +2648,8 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,
26302648

26312649
params.post_payload = &jw_req.json;
26322650

2651+
params.result_list = result_list;
2652+
26332653
params.headers = http_copy_default_headers();
26342654
params.headers = curl_slist_append(params.headers,
26352655
"X-TFS-FedAuthRedirect: Suppress");
@@ -2657,20 +2677,6 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,
26572677

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

2660-
if (status->ec == GH__ERROR_CODE__OK) {
2661-
struct strbuf msg = STRBUF_INIT;
2662-
2663-
if (params.object_count > 1)
2664-
strbuf_addf(&msg, "packfile %s",
2665-
params.final_packfile_filename.buf);
2666-
else
2667-
strbuf_addf(&msg, "loose %s",
2668-
oid_to_hex(&params.loose_oid));
2669-
2670-
string_list_append(result_list, msg.buf);
2671-
strbuf_release(&msg);
2672-
}
2673-
26742680
gh__request_params__release(&params);
26752681
jw_release(&jw_req);
26762682
}

0 commit comments

Comments
 (0)