Skip to content

Commit ef0f7c9

Browse files
jeffhostetlerderrickstolee
authored andcommitted
Merge pull request #220 from jeffhostetler/test-gvfs-helper-2.24
test-gvfs-prococol, t5799: tests for gvfs-helper
2 parents 5373379 + b6b41c9 commit ef0f7c9

File tree

5 files changed

+2913
-33
lines changed

5 files changed

+2913
-33
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,7 @@ else
13781378
endif
13791379

13801380
PROGRAM_OBJS += gvfs-helper.o
1381+
TEST_PROGRAMS_NEED_X += test-gvfs-protocol
13811382

13821383
REMOTE_CURL_PRIMARY = git-remote-http$X
13831384
REMOTE_CURL_ALIASES = git-remote-https$X git-remote-ftp$X git-remote-ftps$X

gvfs-helper.c

Lines changed: 46 additions & 33 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
}
@@ -1873,6 +1888,8 @@ static void install_loose(struct gh__request_params *params,
18731888
/*
18741889
* We expect a loose object when we do a GET -or- when we
18751890
* do a POST with only 1 object.
1891+
*
1892+
* Note that this content type is singular, not plural.
18761893
*/
18771894
if (strcmp(status->content_type.buf,
18781895
"application/x-git-loose-object")) {
@@ -1912,8 +1929,19 @@ static void install_loose(struct gh__request_params *params,
19121929
"could not install loose object '%s'",
19131930
params->loose_path.buf);
19141931
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);
19151942
}
19161943

1944+
cleanup:
19171945
strbuf_release(&tmp_path);
19181946
}
19191947

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

2110-
progress = start_progress(progress_msg, duration);
2138+
if (gh__cmd_opts.show_progress)
2139+
progress = start_progress(progress_msg, duration);
2140+
21112141
while (now < end) {
21122142
display_progress(progress, (now - begin));
21132143

21142144
sleep_millisec(100);
21152145

21162146
now = time(NULL);
21172147
}
2148+
21182149
display_progress(progress, duration);
21192150
stop_progress(&progress);
21202151

@@ -2529,7 +2560,7 @@ static void setup_gvfs_objects_progress(struct gh__request_params *params,
25292560
if (!gh__cmd_opts.show_progress)
25302561
return;
25312562

2532-
if (params->b_is_post && params->object_count > 1) {
2563+
if (params->b_is_post) {
25332564
strbuf_addf(&params->progress_base_phase3_msg,
25342565
"Receiving packfile %ld/%ld with %ld objects",
25352566
num, den, params->object_count);
@@ -2561,6 +2592,8 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
25612592

25622593
params.object_count = 1;
25632594

2595+
params.result_list = result_list;
2596+
25642597
params.headers = http_copy_default_headers();
25652598
params.headers = curl_slist_append(params.headers,
25662599
"X-TFS-FedAuthRedirect: Suppress");
@@ -2573,16 +2606,6 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
25732606

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

2576-
if (status->ec == GH__ERROR_CODE__OK) {
2577-
struct strbuf msg = STRBUF_INIT;
2578-
2579-
strbuf_addf(&msg, "loose %s",
2580-
oid_to_hex(&params.loose_oid));
2581-
2582-
string_list_append(result_list, msg.buf);
2583-
strbuf_release(&msg);
2584-
}
2585-
25862609
gh__request_params__release(&params);
25872610
strbuf_release(&component_url);
25882611
}
@@ -2594,7 +2617,7 @@ static void do__http_get__gvfs_object(struct gh__response_status *status,
25942617
* consumed (along with the filename of the resulting packfile).
25952618
*
25962619
* However, if we only have 1 oid (remaining) in the OIDSET, the
2597-
* 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
25982621
* a packfile with 1 object.
25992622
*
26002623
* Append a message to the result_list describing the result.
@@ -2625,6 +2648,8 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,
26252648

26262649
params.post_payload = &jw_req.json;
26272650

2651+
params.result_list = result_list;
2652+
26282653
params.headers = http_copy_default_headers();
26292654
params.headers = curl_slist_append(params.headers,
26302655
"X-TFS-FedAuthRedirect: Suppress");
@@ -2633,13 +2658,15 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,
26332658
params.headers = curl_slist_append(params.headers,
26342659
"Content-Type: application/json");
26352660
/*
2636-
* We really always want a packfile. But if the payload only
2637-
* requests 1 OID, the server will send us a single loose
2638-
* objects instead. (Apparently the server ignores us when we
2639-
* only send application/x-git-packfile and does it anyway.)
2661+
* If our POST contains more than one object, we want the
2662+
* server to send us a packfile. We DO NOT want the non-standard
2663+
* concatenated loose object format, so we DO NOT send:
2664+
* "Accept: application/x-git-loose-objects" (plural)
26402665
*
2641-
* So to make it clear to my future self, go ahead and add
2642-
* an accept header for loose objects and own it.
2666+
* However, if the payload only requests 1 OID, the server
2667+
* will send us a single loose object instead of a packfile,
2668+
* so we ACK that and send:
2669+
* "Accept: application/x-git-loose-object" (singular)
26432670
*/
26442671
params.headers = curl_slist_append(params.headers,
26452672
"Accept: application/x-git-packfile");
@@ -2650,20 +2677,6 @@ static void do__http_post__gvfs_objects(struct gh__response_status *status,
26502677

26512678
do_req__with_fallback("gvfs/objects", &params, status);
26522679

2653-
if (status->ec == GH__ERROR_CODE__OK) {
2654-
struct strbuf msg = STRBUF_INIT;
2655-
2656-
if (params.object_count > 1)
2657-
strbuf_addf(&msg, "packfile %s",
2658-
params.final_packfile_filename.buf);
2659-
else
2660-
strbuf_addf(&msg, "loose %s",
2661-
oid_to_hex(&params.loose_oid));
2662-
2663-
string_list_append(result_list, msg.buf);
2664-
strbuf_release(&msg);
2665-
}
2666-
26672680
gh__request_params__release(&params);
26682681
jw_release(&jw_req);
26692682
}

t/helper/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/test-tool
22
/test-fake-ssh
3+
/test-gvfs-protocol
34
/test-line-buffer
45
/test-svn-fe

0 commit comments

Comments
 (0)