Add zlib
[git/pclouds.git] / builtin-peek-remote.c
blob32a8b4dc00c58735fed4f65f083ac0c5a0ab8c53
1 #include "cache.h"
2 #include "refs.h"
3 #include "pkt-line.h"
5 static const char peek_remote_usage[] =
6 "git-peek-remote [--upload-pack=<git-upload-pack>] [<host>:]<directory>";
7 static const char *uploadpack = "git-upload-pack";
9 static int peek_remote(int fd[2], unsigned flags)
11 struct ref *ref;
13 get_remote_heads(fd[0], &ref, 0, NULL, flags);
14 packet_flush(fd[1]);
16 while (ref) {
17 printf("%s %s\n", sha1_to_hex(ref->old_sha1), ref->name);
18 ref = ref->next;
20 return 0;
23 int cmd_peek_remote(int argc, const char **argv, const char *prefix)
25 int i, ret;
26 char *dest = NULL;
27 int fd[2];
28 pid_t pid;
29 int nongit = 0;
30 unsigned flags = 0;
32 for (i = 1; i < argc; i++) {
33 char *arg = argv[i];
35 if (*arg == '-') {
36 if (!prefixcmp(arg, "--upload-pack=")) {
37 uploadpack = arg + 14;
38 continue;
40 if (!prefixcmp(arg, "--exec=")) {
41 uploadpack = arg + 7;
42 continue;
44 if (!strcmp("--tags", arg)) {
45 flags |= REF_TAGS;
46 continue;
48 if (!strcmp("--heads", arg)) {
49 flags |= REF_HEADS;
50 continue;
52 if (!strcmp("--refs", arg)) {
53 flags |= REF_NORMAL;
54 continue;
56 usage(peek_remote_usage);
58 dest = arg;
59 break;
62 if (!dest || i != argc - 1)
63 usage(peek_remote_usage);
65 pid = git_connect(fd, dest, uploadpack, 0);
66 if (pid < 0)
67 return 1;
68 ret = peek_remote(fd, flags);
69 close(fd[0]);
70 close(fd[1]);
71 ret |= finish_connect(pid);
72 return !!ret;