]>
Commit | Line | Data |
---|---|---|
18705953 JH |
1 | #include "cache.h" |
2 | #include "refs.h" | |
3 | #include "pkt-line.h" | |
18705953 JH |
4 | |
5 | static const char peek_remote_usage[] = | |
6 | "git-peek-remote [--exec=upload-pack] [host:]directory"; | |
7 | static const char *exec = "git-upload-pack"; | |
8 | ||
2718ff09 | 9 | static 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 | ||
23 | int main(int argc, char **argv) | |
24 | { | |
25 | int i, ret; | |
26 | char *dest = NULL; | |
27 | int fd[2]; | |
28 | pid_t pid; | |
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 == '-') { | |
2718ff09 | 38 | if (!strncmp("--exec=", arg, 7)) { |
18705953 | 39 | exec = arg + 7; |
2718ff09 LT |
40 | continue; |
41 | } | |
42 | if (!strcmp("--tags", arg)) { | |
43 | flags |= REF_TAGS; | |
44 | continue; | |
45 | } | |
46 | if (!strcmp("--heads", arg)) { | |
47 | flags |= REF_HEADS; | |
48 | continue; | |
49 | } | |
50 | if (!strcmp("--refs", arg)) { | |
51 | flags |= REF_NORMAL; | |
52 | continue; | |
53 | } | |
54 | usage(peek_remote_usage); | |
18705953 JH |
55 | } |
56 | dest = arg; | |
57 | break; | |
58 | } | |
2718ff09 | 59 | |
18705953 JH |
60 | if (!dest || i != argc - 1) |
61 | usage(peek_remote_usage); | |
62 | ||
63 | pid = git_connect(fd, dest, exec); | |
64 | if (pid < 0) | |
65 | return 1; | |
2718ff09 | 66 | ret = peek_remote(fd, flags); |
18705953 JH |
67 | close(fd[0]); |
68 | close(fd[1]); | |
8a5dbef8 FBH |
69 | ret |= finish_connect(pid); |
70 | return !!ret; | |
18705953 | 71 | } |