From 494fb4e7ed9ac94396ea2a16054e5ff358d26cbc Mon Sep 17 00:00:00 2001 From: Jeff Hostetler Date: Wed, 13 Nov 2019 14:19:44 -0500 Subject: [PATCH] gvfs-helper: move result-list construction into install functions gvfs-helper prints a "loose " or "packfile " 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 --- gvfs-helper.c | 58 ++++++++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/gvfs-helper.c b/gvfs-helper.c index d45cd3184eb0e0..3cfd6721340ddd 100644 --- a/gvfs-helper.c +++ b/gvfs-helper.c @@ -448,6 +448,8 @@ struct gh__request_params { struct progress *progress; struct strbuf e2eid; + + struct string_list *result_list; /* we do not own this */ }; #define GH__REQUEST_PARAMS_INIT { \ @@ -476,6 +478,7 @@ struct gh__request_params { .progress_msg = STRBUF_INIT, \ .progress = NULL, \ .e2eid = STRBUF_INIT, \ + .result_list = NULL, \ } static void gh__request_params__release(struct gh__request_params *params) @@ -508,6 +511,8 @@ static void gh__request_params__release(struct gh__request_params *params) params->progress = NULL; strbuf_release(¶ms->e2eid); + + params->result_list = NULL; /* we do not own this */ } /* @@ -1865,6 +1870,16 @@ static void install_packfile(struct gh__request_params *params, goto cleanup; } + + if (params->result_list) { + struct strbuf result_msg = STRBUF_INIT; + + strbuf_addf(&result_msg, "packfile %s", + params->final_packfile_filename.buf); + string_list_append(params->result_list, result_msg.buf); + strbuf_release(&result_msg); + } + cleanup: child_process_clear(&ip); } @@ -1921,8 +1936,19 @@ static void install_loose(struct gh__request_params *params, "could not install loose object '%s'", params->loose_path.buf); status->ec = GH__ERROR_CODE__COULD_NOT_INSTALL_LOOSE; + goto cleanup; + } + + if (params->result_list) { + struct strbuf result_msg = STRBUF_INIT; + + strbuf_addf(&result_msg, "loose %s", + oid_to_hex(¶ms->loose_oid)); + string_list_append(params->result_list, result_msg.buf); + strbuf_release(&result_msg); } +cleanup: strbuf_release(&tmp_path); } @@ -2577,7 +2603,7 @@ static void setup_gvfs_objects_progress(struct gh__request_params *params, if (!gh__cmd_opts.show_progress) return; - if (params->b_is_post && params->object_count > 1) { + if (params->b_is_post) { strbuf_addf(¶ms->progress_base_phase3_msg, "Receiving packfile %ld/%ld with %ld objects", num, den, params->object_count); @@ -2609,6 +2635,8 @@ static void do__http_get__gvfs_object(struct gh__response_status *status, params.object_count = 1; + params.result_list = result_list; + params.headers = http_copy_default_headers(); params.headers = curl_slist_append(params.headers, "X-TFS-FedAuthRedirect: Suppress"); @@ -2621,16 +2649,6 @@ static void do__http_get__gvfs_object(struct gh__response_status *status, do_req__with_fallback(component_url.buf, ¶ms, status); - if (status->ec == GH__ERROR_CODE__OK) { - struct strbuf msg = STRBUF_INIT; - - strbuf_addf(&msg, "loose %s", - oid_to_hex(¶ms.loose_oid)); - - string_list_append(result_list, msg.buf); - strbuf_release(&msg); - } - gh__request_params__release(¶ms); strbuf_release(&component_url); } @@ -2642,7 +2660,7 @@ static void do__http_get__gvfs_object(struct gh__response_status *status, * consumed (along with the filename of the resulting packfile). * * However, if we only have 1 oid (remaining) in the OIDSET, the - * server will respond to our POST with a loose object rather than + * server *MAY* respond to our POST with a loose object rather than * a packfile with 1 object. * * Append a message to the result_list describing the result. @@ -2673,6 +2691,8 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status, params.post_payload = &jw_req.json; + params.result_list = result_list; + params.headers = http_copy_default_headers(); params.headers = curl_slist_append(params.headers, "X-TFS-FedAuthRedirect: Suppress"); @@ -2700,20 +2720,6 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status, do_req__with_fallback("gvfs/objects", ¶ms, status); - if (status->ec == GH__ERROR_CODE__OK) { - struct strbuf msg = STRBUF_INIT; - - if (params.object_count > 1) - strbuf_addf(&msg, "packfile %s", - params.final_packfile_filename.buf); - else - strbuf_addf(&msg, "loose %s", - oid_to_hex(¶ms.loose_oid)); - - string_list_append(result_list, msg.buf); - strbuf_release(&msg); - } - gh__request_params__release(¶ms); jw_release(&jw_req); }