Skip to content

Commit

Permalink
Merge pull request git-for-windows#220 from jeffhostetler/test-gvfs-h…
Browse files Browse the repository at this point in the history
…elper-2.24

test-gvfs-prococol, t5799: tests for gvfs-helper
  • Loading branch information
jeffhostetler authored and derrickstolee committed Feb 21, 2020
2 parents 02ff6cb + 6553313 commit 8713235
Show file tree
Hide file tree
Showing 5 changed files with 2,913 additions and 33 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,7 @@ else
endif

PROGRAM_OBJS += gvfs-helper.o
TEST_PROGRAMS_NEED_X += test-gvfs-protocol

REMOTE_CURL_PRIMARY = git-remote-http$X
REMOTE_CURL_ALIASES = git-remote-https$X git-remote-ftp$X git-remote-ftps$X
Expand Down
79 changes: 46 additions & 33 deletions gvfs-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 { \
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -501,6 +504,8 @@ static void gh__request_params__release(struct gh__request_params *params)
params->progress = NULL;

strbuf_release(&params->e2eid);

params->result_list = NULL; /* we do not own this */
}

/*
Expand Down Expand Up @@ -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);
}
Expand All @@ -1873,6 +1888,8 @@ static void install_loose(struct gh__request_params *params,
/*
* We expect a loose object when we do a GET -or- when we
* do a POST with only 1 object.
*
* Note that this content type is singular, not plural.
*/
if (strcmp(status->content_type.buf,
"application/x-git-loose-object")) {
Expand Down Expand Up @@ -1912,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(&params->loose_oid));
string_list_append(params->result_list, result_msg.buf);
strbuf_release(&result_msg);
}

cleanup:
strbuf_release(&tmp_path);
}

Expand Down Expand Up @@ -2107,14 +2135,17 @@ static void do_throttle_spin(struct gh__request_params *params,
strbuf_addstr(&region, gh__server_type_label[params->server_type]);
trace2_region_enter("gvfs-helper", region.buf, NULL);

progress = start_progress(progress_msg, duration);
if (gh__cmd_opts.show_progress)
progress = start_progress(progress_msg, duration);

while (now < end) {
display_progress(progress, (now - begin));

sleep_millisec(100);

now = time(NULL);
}

display_progress(progress, duration);
stop_progress(&progress);

Expand Down Expand Up @@ -2529,7 +2560,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(&params->progress_base_phase3_msg,
"Receiving packfile %ld/%ld with %ld objects",
num, den, params->object_count);
Expand Down Expand Up @@ -2561,6 +2592,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");
Expand All @@ -2573,16 +2606,6 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,

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

if (status->ec == GH__ERROR_CODE__OK) {
struct strbuf msg = STRBUF_INIT;

strbuf_addf(&msg, "loose %s",
oid_to_hex(&params.loose_oid));

string_list_append(result_list, msg.buf);
strbuf_release(&msg);
}

gh__request_params__release(&params);
strbuf_release(&component_url);
}
Expand All @@ -2594,7 +2617,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.
Expand Down Expand Up @@ -2625,6 +2648,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");
Expand All @@ -2633,13 +2658,15 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,
params.headers = curl_slist_append(params.headers,
"Content-Type: application/json");
/*
* We really always want a packfile. But if the payload only
* requests 1 OID, the server will send us a single loose
* objects instead. (Apparently the server ignores us when we
* only send application/x-git-packfile and does it anyway.)
* If our POST contains more than one object, we want the
* server to send us a packfile. We DO NOT want the non-standard
* concatenated loose object format, so we DO NOT send:
* "Accept: application/x-git-loose-objects" (plural)
*
* So to make it clear to my future self, go ahead and add
* an accept header for loose objects and own it.
* However, if the payload only requests 1 OID, the server
* will send us a single loose object instead of a packfile,
* so we ACK that and send:
* "Accept: application/x-git-loose-object" (singular)
*/
params.headers = curl_slist_append(params.headers,
"Accept: application/x-git-packfile");
Expand All @@ -2650,20 +2677,6 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,

do_req__with_fallback("gvfs/objects", &params, 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(&params.loose_oid));

string_list_append(result_list, msg.buf);
strbuf_release(&msg);
}

gh__request_params__release(&params);
jw_release(&jw_req);
}
Expand Down
1 change: 1 addition & 0 deletions t/helper/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/test-tool
/test-fake-ssh
/test-gvfs-protocol
/test-line-buffer
/test-svn-fe
Loading

0 comments on commit 8713235

Please sign in to comment.