From d9ed18b860f3633bef928022774783f766cca6aa 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 918c88867b9a97..84688a8c087387 100644 --- a/gvfs-helper.c +++ b/gvfs-helper.c @@ -441,6 +441,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 { \ @@ -469,6 +471,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) @@ -501,6 +504,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 */ } /* @@ -1858,6 +1863,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); } @@ -1914,8 +1929,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); } @@ -2570,7 +2596,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); @@ -2602,6 +2628,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"); @@ -2614,16 +2642,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); } @@ -2635,7 +2653,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. @@ -2666,6 +2684,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"); @@ -2693,20 +2713,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); }