Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 5610b7c

Browse files
tboegigitster
authored andcommitted
git fetch-pack: add --diag-url
The main purpose is to trace the URL parser called by git_connect() in connect.c The main features of the parser can be listed as this: - parse out host and path for URLs with a scheme (git:// file:// ssh://) - parse host names embedded by [] correctly - extract the port number, if present - separate URLs like "file" (which are local) from URLs like "host:repo" which should use ssh Add the new parameter "--diag-url" to "git fetch-pack", which prints the value for protocol, host and path to stderr and exits. Signed-off-by: Torsten Bögershausen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cabc3c1 commit 5610b7c

File tree

4 files changed

+41
-3
lines changed

4 files changed

+41
-3
lines changed

builtin/fetch-pack.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
static const char fetch_pack_usage[] =
88
"git fetch-pack [--all] [--stdin] [--quiet|-q] [--keep|-k] [--thin] "
99
"[--include-tag] [--upload-pack=<git-upload-pack>] [--depth=<n>] "
10-
"[--no-progress] [-v] [<host>:]<directory> [<refs>...]";
10+
"[--no-progress] [--diag-url] [-v] [<host>:]<directory> [<refs>...]";
1111

1212
static void add_sought_entry_mem(struct ref ***sought, int *nr, int *alloc,
1313
const char *name, int namelen)
@@ -81,6 +81,10 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
8181
args.stdin_refs = 1;
8282
continue;
8383
}
84+
if (!strcmp("--diag-url", arg)) {
85+
args.diag_url = 1;
86+
continue;
87+
}
8488
if (!strcmp("-v", arg)) {
8589
args.verbose = 1;
8690
continue;
@@ -146,10 +150,14 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
146150
fd[0] = 0;
147151
fd[1] = 1;
148152
} else {
153+
int flags = args.verbose ? CONNECT_VERBOSE : 0;
154+
if (args.diag_url)
155+
flags |= CONNECT_DIAG_URL;
149156
conn = git_connect(fd, dest, args.uploadpack,
150-
args.verbose ? CONNECT_VERBOSE : 0);
157+
flags);
158+
if (!conn)
159+
return args.diag_url ? 0 : 1;
151160
}
152-
153161
get_remote_heads(fd[0], NULL, 0, &ref, 0, NULL);
154162

155163
ref = fetch_pack(&args, fd, conn, ref, dest,

connect.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,20 @@ enum protocol {
236236
PROTO_GIT
237237
};
238238

239+
static const char *prot_name(enum protocol protocol)
240+
{
241+
switch (protocol) {
242+
case PROTO_LOCAL:
243+
return "file";
244+
case PROTO_SSH:
245+
return "ssh";
246+
case PROTO_GIT:
247+
return "git";
248+
default:
249+
return "unkown protocol";
250+
}
251+
}
252+
239253
static enum protocol get_protocol(const char *name)
240254
{
241255
if (!strcmp(name, "ssh"))
@@ -670,6 +684,20 @@ struct child_process *git_connect(int fd[2], const char *url,
670684
signal(SIGCHLD, SIG_DFL);
671685

672686
protocol = parse_connect_url(url, &host, &port, &path);
687+
if (flags & CONNECT_DIAG_URL) {
688+
printf("Diag: url=%s\n", url ? url : "NULL");
689+
printf("Diag: protocol=%s\n", prot_name(protocol));
690+
printf("Diag: hostandport=%s", host ? host : "NULL");
691+
if (port)
692+
printf(":%s\n", port);
693+
else
694+
printf("\n");
695+
printf("Diag: path=%s\n", path ? path : "NULL");
696+
free(host);
697+
free(port);
698+
free(path);
699+
return NULL;
700+
}
673701

674702
if (protocol == PROTO_GIT) {
675703
/* These underlying connection commands die() if they

connect.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define CONNECT_H
33

44
#define CONNECT_VERBOSE (1u << 0)
5+
#define CONNECT_DIAG_URL (1u << 1)
56
extern struct child_process *git_connect(int fd[2], const char *url, const char *prog, int flags);
67
extern int finish_connect(struct child_process *conn);
78
extern int git_connection_is_socket(struct child_process *conn);

fetch-pack.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ struct fetch_pack_args {
1414
use_thin_pack:1,
1515
fetch_all:1,
1616
stdin_refs:1,
17+
diag_url:1,
1718
verbose:1,
1819
no_progress:1,
1920
include_tag:1,

0 commit comments

Comments
 (0)