2013-07-08 20:56:53 +00:00
|
|
|
#ifndef CONNECT_H
|
|
|
|
#define CONNECT_H
|
|
|
|
|
2018-07-09 21:35:39 +00:00
|
|
|
#include "protocol.h"
|
2018-07-09 19:25:32 +00:00
|
|
|
|
2013-07-08 20:56:53 +00:00
|
|
|
#define CONNECT_VERBOSE (1u << 0)
|
2013-11-28 19:49:17 +00:00
|
|
|
#define CONNECT_DIAG_URL (1u << 1)
|
2016-02-03 04:09:14 +00:00
|
|
|
#define CONNECT_IPV4 (1u << 2)
|
|
|
|
#define CONNECT_IPV6 (1u << 3)
|
git_connect(): fix corner cases in downgrading v2 to v0
There's code in git_connect() that checks whether we are doing a push
with protocol_v2, and if so, drops us to protocol_v0 (since we know
how to do v2 only for fetches). But it misses some corner cases:
1. it checks the "prog" variable, which is actually the path to
receive-pack on the remote side. By default this is just
"git-receive-pack", but it could be an arbitrary string (like
"/path/to/git receive-pack", etc). We'd accidentally stay in v2
mode in this case.
2. besides "receive-pack" and "upload-pack", there's one other value
we'd expect: "upload-archive" for handling "git archive --remote".
Like receive-pack, this doesn't understand v2, and should use the
v0 protocol.
In practice, neither of these causes bugs in the real world so far. We
do send a "we understand v2" probe to the server, but since no server
implements v2 for anything but upload-pack, it's simply ignored. But
this would eventually become a problem if we do implement v2 for those
endpoints, as older clients would falsely claim to understand it,
leading to a server response they can't parse.
We can fix (1) by passing in both the program path and the "name" of the
operation. I treat the name as a string here, because that's the pattern
set in transport_connect(), which is one of our callers (we were simply
throwing away the "name" value there before).
We can fix (2) by allowing only known-v2 protocols ("upload-pack"),
rather than blocking unknown ones ("receive-pack" and "upload-archive").
That will mean whoever eventually implements v2 push will have to adjust
this list, but that's reasonable. We'll do the safe, conservative thing
(sticking to v0) by default, and anybody working on v2 will quickly
realize this spot needs to be updated.
The new tests cover the receive-pack and upload-archive cases above, and
re-confirm that we allow v2 with an arbitrary "--upload-pack" path (that
already worked before this patch, of course, but it would be an easy
thing to break if we flipped the allow/block logic without also handling
"name" separately).
Here are a few miscellaneous implementation notes, since I had to do a
little head-scratching to understand who calls what:
- transport_connect() is called only for git-upload-archive. For
non-http git remotes, that resolves to the virtual connect_git()
function (which then calls git_connect(); confused yet?). So
plumbing through "name" in connect_git() covers that.
- for regular fetches and pushes, callers use higher-level functions
like transport_fetch_refs(). For non-http git remotes, that means
calling git_connect() under the hood via connect_setup(). And that
uses the "for_push" flag to decide which name to use.
- likewise, plumbing like fetch-pack and send-pack may call
git_connect() directly; they each know which name to use.
- for remote helpers (including http), we already have separate
parameters for "name" and "exec" (another name for "prog"). In
process_connect_service(), we feed the "name" to the helper via
"connect" or "stateless-connect" directives.
There's also a "servpath" option, which can be used to tell the
helper about the "exec" path. But no helpers we implement support
it! For http it would be useless anyway (no reasonable server
implementation will allow you to send a shell command to run the
server). In theory it would be useful for more obscure helpers like
remote-ext, but even there it is not implemented.
It's tempting to get rid of it simply to reduce confusion, but we
have publicly documented it since it was added in fa8c097cc9
(Support remote helpers implementing smart transports, 2009-12-09),
so it's possible some helper in the wild is using it.
- So for v2, helpers (again, including http) are mainly used via
stateless-connect, driven by the main program. But they do still
need to decide whether to do a v2 probe. And so there's similar
logic in remote-curl.c's discover_refs() that looks for
"git-receive-pack". But it's not buggy in the same way. Since it
doesn't support servpath, it is always dealing with a "service"
string like "git-receive-pack". And since it doesn't support
straight "connect", it can't be used for "upload-archive".
So we could leave that spot alone. But I've updated it here to match
the logic we're changing in connect_git(). That seems like the least
confusing thing for somebody who has to touch both of these spots
later (say, to add v2 push support). I didn't add a new test to make
sure this doesn't break anything; we already have several tests (in
t5551 and elsewhere) that make sure we are using v2 over http.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2023-03-17 19:08:51 +00:00
|
|
|
struct child_process *git_connect(int fd[2], const char *url, const char *name, const char *prog, int flags);
|
2019-04-29 08:28:14 +00:00
|
|
|
int finish_connect(struct child_process *conn);
|
|
|
|
int git_connection_is_socket(struct child_process *conn);
|
|
|
|
int server_supports(const char *feature);
|
|
|
|
int parse_feature_request(const char *features, const char *feature);
|
2023-04-14 21:25:20 +00:00
|
|
|
const char *server_feature_value(const char *feature, size_t *len_ret);
|
2019-04-29 08:28:14 +00:00
|
|
|
int url_is_local_not_ssh(const char *url);
|
2013-07-08 20:56:53 +00:00
|
|
|
|
2018-03-14 18:31:45 +00:00
|
|
|
struct packet_reader;
|
2019-04-29 08:28:14 +00:00
|
|
|
enum protocol_version discover_version(struct packet_reader *reader);
|
2018-03-14 18:31:45 +00:00
|
|
|
|
2020-05-25 19:58:56 +00:00
|
|
|
int server_supports_hash(const char *desired, int *feature_supported);
|
2023-04-14 21:25:20 +00:00
|
|
|
const char *parse_feature_value(const char *feature_list, const char *feature, size_t *lenp, size_t *offset);
|
2022-12-13 10:52:58 +00:00
|
|
|
int server_supports_v2(const char *c);
|
|
|
|
void ensure_server_supports_v2(const char *c);
|
2020-05-25 19:58:53 +00:00
|
|
|
int server_feature_v2(const char *c, const char **v);
|
2019-04-29 08:28:14 +00:00
|
|
|
int server_supports_feature(const char *c, const char *feature,
|
2019-04-29 08:28:23 +00:00
|
|
|
int die_on_error);
|
2018-03-15 17:31:21 +00:00
|
|
|
|
2020-05-19 10:54:00 +00:00
|
|
|
void check_stateless_delimiter(int stateless_rpc,
|
|
|
|
struct packet_reader *reader,
|
|
|
|
const char *error);
|
|
|
|
|
2013-07-08 20:56:53 +00:00
|
|
|
#endif
|