Skip to content

Commit 7de13d8

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 19e4e92 commit 7de13d8

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

@@ -2570,7 +2596,7 @@ static void setup_gvfs_objects_progress(struct gh__request_params *params,
25702596
if (!gh__cmd_opts.show_progress)
25712597
return;
25722598

2573-
if (params->b_is_post && params->object_count > 1) {
2599+
if (params->b_is_post) {
25742600
strbuf_addf(&params->progress_base_phase3_msg,
25752601
"Receiving packfile %ld/%ld with %ld objects",
25762602
num, den, params->object_count);
@@ -2602,6 +2628,8 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
26022628

26032629
params.object_count = 1;
26042630

2631+
params.result_list = result_list;
2632+
26052633
params.headers = http_copy_default_headers();
26062634
params.headers = curl_slist_append(params.headers,
26072635
"X-TFS-FedAuthRedirect: Suppress");
@@ -2614,16 +2642,6 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
26142642

26152643
do_req__with_fallback(component_url.buf, &params, status);
26162644

2617-
if (status->ec == GH__ERROR_CODE__OK) {
2618-
struct strbuf msg = STRBUF_INIT;
2619-
2620-
strbuf_addf(&msg, "loose %s",
2621-
oid_to_hex(&params.loose_oid));
2622-
2623-
string_list_append(result_list, msg.buf);
2624-
strbuf_release(&msg);
2625-
}
2626-
26272645
gh__request_params__release(&params);
26282646
strbuf_release(&component_url);
26292647
}
@@ -2635,7 +2653,7 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
26352653
* consumed (along with the filename of the resulting packfile).
26362654
*
26372655
* However, if we only have 1 oid (remaining) in the OIDSET, the
2638-
* server will respond to our POST with a loose object rather than
2656+
* server *MAY* respond to our POST with a loose object rather than
26392657
* a packfile with 1 object.
26402658
*
26412659
* Append a message to the result_list describing the result.
@@ -2666,6 +2684,8 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,
26662684

26672685
params.post_payload = &jw_req.json;
26682686

2687+
params.result_list = result_list;
2688+
26692689
params.headers = http_copy_default_headers();
26702690
params.headers = curl_slist_append(params.headers,
26712691
"X-TFS-FedAuthRedirect: Suppress");
@@ -2693,20 +2713,6 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,
26932713

26942714
do_req__with_fallback("gvfs/objects", &params, status);
26952715

2696-
if (status->ec == GH__ERROR_CODE__OK) {
2697-
struct strbuf msg = STRBUF_INIT;
2698-
2699-
if (params.object_count > 1)
2700-
strbuf_addf(&msg, "packfile %s",
2701-
params.final_packfile_filename.buf);
2702-
else
2703-
strbuf_addf(&msg, "loose %s",
2704-
oid_to_hex(&params.loose_oid));
2705-
2706-
string_list_append(result_list, msg.buf);
2707-
strbuf_release(&msg);
2708-
}
2709-
27102716
gh__request_params__release(&params);
27112717
jw_release(&jw_req);
27122718
}

0 commit comments

Comments
 (0)