Change git_connect() to return a struct child_process instead of a pid_t.
[git/git.git] / peek-remote.c
CommitLineData
18705953
JH
1#include "cache.h"
2#include "refs.h"
3#include "pkt-line.h"
18705953
JH
4
5static const char peek_remote_usage[] =
27dca07f
UKK
6"git-peek-remote [--upload-pack=<git-upload-pack>] [<host>:]<directory>";
7static const char *uploadpack = "git-upload-pack";
18705953 8
2718ff09 9static int peek_remote(int fd[2], unsigned flags)
18705953
JH
10{
11 struct ref *ref;
12
2718ff09 13 get_remote_heads(fd[0], &ref, 0, NULL, flags);
18705953
JH
14 packet_flush(fd[1]);
15
16 while (ref) {
17 printf("%s %s\n", sha1_to_hex(ref->old_sha1), ref->name);
18 ref = ref->next;
19 }
20 return 0;
21}
22
23int main(int argc, char **argv)
24{
25 int i, ret;
26 char *dest = NULL;
27 int fd[2];
98158e9c 28 struct child_process *conn;
e44eb3e4 29 int nongit = 0;
2718ff09 30 unsigned flags = 0;
e44eb3e4
JH
31
32 setup_git_directory_gently(&nongit);
18705953
JH
33
34 for (i = 1; i < argc; i++) {
35 char *arg = argv[i];
36
37 if (*arg == '-') {
599065a3 38 if (!prefixcmp(arg, "--upload-pack=")) {
27dca07f
UKK
39 uploadpack = arg + 14;
40 continue;
41 }
599065a3 42 if (!prefixcmp(arg, "--exec=")) {
27dca07f 43 uploadpack = arg + 7;
2718ff09
LT
44 continue;
45 }
46 if (!strcmp("--tags", arg)) {
47 flags |= REF_TAGS;
48 continue;
49 }
50 if (!strcmp("--heads", arg)) {
51 flags |= REF_HEADS;
52 continue;
53 }
54 if (!strcmp("--refs", arg)) {
55 flags |= REF_NORMAL;
56 continue;
57 }
58 usage(peek_remote_usage);
18705953
JH
59 }
60 dest = arg;
61 break;
62 }
2718ff09 63
18705953
JH
64 if (!dest || i != argc - 1)
65 usage(peek_remote_usage);
66
98158e9c 67 conn = git_connect(fd, dest, uploadpack, 0);
2718ff09 68 ret = peek_remote(fd, flags);
18705953
JH
69 close(fd[0]);
70 close(fd[1]);
98158e9c 71 ret |= finish_connect(conn);
8a5dbef8 72 return !!ret;
18705953 73}