Skip to content

Commit 5331af2

Browse files
committed
Merge branch 'ab/serve-cleanup'
Code clean-up around "git serve". * ab/serve-cleanup: upload-pack: document and rename --advertise-refs serve.[ch]: remove "serve_options", split up --advertise-refs code {upload,receive}-pack tests: add --advertise-refs tests serve.c: move version line to advertise_capabilities() serve: move transfer.advertiseSID check into session_id_advertise() serve.[ch]: don't pass "struct strvec *keys" to commands serve: use designated initializers transport: use designated initializers transport: rename "fetch" in transport_vtable to "fetch_refs" serve: mark has_capability() as static
2 parents bbeca06 + 98e2d9d commit 5331af2

20 files changed

+298
-128
lines changed

Documentation/git-receive-pack.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ OPTIONS
4141
<directory>::
4242
The repository to sync into.
4343

44+
--http-backend-info-refs::
45+
Used by linkgit:git-http-backend[1] to serve up
46+
`$GIT_URL/info/refs?service=git-receive-pack` requests. See
47+
`--http-backend-info-refs` in linkgit:git-upload-pack[1].
48+
4449
PRE-RECEIVE HOOK
4550
----------------
4651
Before any ref is updated, if $GIT_DIR/hooks/pre-receive file exists

Documentation/git-upload-pack.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ OPTIONS
3636
This fits with the HTTP POST request processing model where
3737
a program may read the request, write a response, and must exit.
3838

39-
--advertise-refs::
40-
Only the initial ref advertisement is output, and the program exits
41-
immediately. This fits with the HTTP GET request model, where
42-
no request content is received but a response must be produced.
39+
--http-backend-info-refs::
40+
Used by linkgit:git-http-backend[1] to serve up
41+
`$GIT_URL/info/refs?service=git-upload-pack` requests. See
42+
"Smart Clients" in link:technical/http-protocol.html[the HTTP
43+
transfer protocols] documentation and "HTTP Transport" in
44+
link:technical/protocol-v2.html[the Git Wire Protocol, Version
45+
2] documentation. Also understood by
46+
linkgit:git-receive-pack[1].
4347

4448
<directory>::
4549
The repository to sync from.

Documentation/technical/http-protocol.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ The client may send Extra Parameters (see
225225
Documentation/technical/pack-protocol.txt) as a colon-separated string
226226
in the Git-Protocol HTTP header.
227227

228+
Uses the `--http-backend-info-refs` option to
229+
linkgit:git-upload-pack[1].
230+
228231
Dumb Server Response
229232
^^^^^^^^^^^^^^^^^^^^
230233
Dumb servers MUST respond with the dumb server reply format.

Documentation/technical/protocol-v2.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ A v2 server would reply:
8181
Subsequent requests are then made directly to the service
8282
`$GIT_URL/git-upload-pack`. (This works the same for git-receive-pack).
8383

84+
Uses the `--http-backend-info-refs` option to
85+
linkgit:git-upload-pack[1].
86+
8487
Capability Advertisement
8588
------------------------
8689

builtin/receive-pack.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2474,7 +2474,8 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
24742474
struct option options[] = {
24752475
OPT__QUIET(&quiet, N_("quiet")),
24762476
OPT_HIDDEN_BOOL(0, "stateless-rpc", &stateless_rpc, NULL),
2477-
OPT_HIDDEN_BOOL(0, "advertise-refs", &advertise_refs, NULL),
2477+
OPT_HIDDEN_BOOL(0, "http-backend-info-refs", &advertise_refs, NULL),
2478+
OPT_ALIAS(0, "advertise-refs", "http-backend-info-refs"),
24782479
OPT_HIDDEN_BOOL(0, "reject-thin-pack-for-testing", &reject_thin, NULL),
24792480
OPT_END()
24802481
};

builtin/upload-pack.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,18 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
1616
{
1717
const char *dir;
1818
int strict = 0;
19-
struct upload_pack_options opts = { 0 };
20-
struct serve_options serve_opts = SERVE_OPTIONS_INIT;
19+
int advertise_refs = 0;
20+
int stateless_rpc = 0;
21+
int timeout = 0;
2122
struct option options[] = {
22-
OPT_BOOL(0, "stateless-rpc", &opts.stateless_rpc,
23+
OPT_BOOL(0, "stateless-rpc", &stateless_rpc,
2324
N_("quit after a single request/response exchange")),
24-
OPT_BOOL(0, "advertise-refs", &opts.advertise_refs,
25-
N_("exit immediately after initial ref advertisement")),
25+
OPT_HIDDEN_BOOL(0, "http-backend-info-refs", &advertise_refs,
26+
N_("serve up the info/refs for git-http-backend")),
27+
OPT_ALIAS(0, "advertise-refs", "http-backend-info-refs"),
2628
OPT_BOOL(0, "strict", &strict,
2729
N_("do not try <directory>/.git/ if <directory> is no Git directory")),
28-
OPT_INTEGER(0, "timeout", &opts.timeout,
30+
OPT_INTEGER(0, "timeout", &timeout,
2931
N_("interrupt transfer after <n> seconds of inactivity")),
3032
OPT_END()
3133
};
@@ -38,9 +40,6 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
3840
if (argc != 1)
3941
usage_with_options(upload_pack_usage, options);
4042

41-
if (opts.timeout)
42-
opts.daemon_mode = 1;
43-
4443
setup_path();
4544

4645
dir = argv[0];
@@ -50,21 +49,22 @@ int cmd_upload_pack(int argc, const char **argv, const char *prefix)
5049

5150
switch (determine_protocol_version_server()) {
5251
case protocol_v2:
53-
serve_opts.advertise_capabilities = opts.advertise_refs;
54-
serve_opts.stateless_rpc = opts.stateless_rpc;
55-
serve(&serve_opts);
52+
if (advertise_refs)
53+
protocol_v2_advertise_capabilities();
54+
else
55+
protocol_v2_serve_loop(stateless_rpc);
5656
break;
5757
case protocol_v1:
5858
/*
5959
* v1 is just the original protocol with a version string,
6060
* so just fall through after writing the version string.
6161
*/
62-
if (opts.advertise_refs || !opts.stateless_rpc)
62+
if (advertise_refs || !stateless_rpc)
6363
packet_write_fmt(1, "version 1\n");
6464

6565
/* fallthrough */
6666
case protocol_v0:
67-
upload_pack(&opts);
67+
upload_pack(advertise_refs, stateless_rpc, timeout);
6868
break;
6969
case protocol_unknown_version:
7070
BUG("unknown protocol version");

http-backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ static void get_info_refs(struct strbuf *hdr, char *arg)
534534

535535
if (service_name) {
536536
const char *argv[] = {NULL /* service name */,
537-
"--stateless-rpc", "--advertise-refs",
537+
"--http-backend-info-refs",
538538
".", NULL};
539539
struct rpc_service *svc = select_service(hdr, service_name);
540540

ls-refs.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ static int ls_refs_config(const char *var, const char *value, void *data)
139139
return parse_hide_refs_config(var, value, "uploadpack");
140140
}
141141

142-
int ls_refs(struct repository *r, struct strvec *keys,
143-
struct packet_reader *request)
142+
int ls_refs(struct repository *r, struct packet_reader *request)
144143
{
145144
struct ls_refs_data data;
146145

ls-refs.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
#define LS_REFS_H
33

44
struct repository;
5-
struct strvec;
65
struct packet_reader;
7-
int ls_refs(struct repository *r, struct strvec *keys,
8-
struct packet_reader *request);
6+
int ls_refs(struct repository *r, struct packet_reader *request);
97
int ls_refs_advertise(struct repository *r, struct strbuf *value);
108

119
#endif /* LS_REFS_H */

protocol-caps.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ static void send_info(struct repository *r, struct packet_writer *writer,
7575
strbuf_release(&send_buffer);
7676
}
7777

78-
int cap_object_info(struct repository *r, struct strvec *keys,
79-
struct packet_reader *request)
78+
int cap_object_info(struct repository *r, struct packet_reader *request)
8079
{
8180
struct requested_info info;
8281
struct packet_writer writer;

0 commit comments

Comments
 (0)