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