Merge branch 'js/parseopt-abbrev-fix'
[git/peff.git] / peek-remote.c
blob8d20f7c9c626787d157be0f07c18c126e272db52
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 main(int argc, char **argv)
25 int i, ret;
26 char *dest = NULL;
27 int fd[2];
28 struct child_process *conn;
29 int nongit = 0;
30 unsigned flags = 0;
32 setup_git_directory_gently(&nongit);
34 for (i = 1; i < argc; i++) {
35 char *arg = argv[i];
37 if (*arg == '-') {
38 if (!prefixcmp(arg, "--upload-pack=")) {
39 uploadpack = arg + 14;
40 continue;
42 if (!prefixcmp(arg, "--exec=")) {
43 uploadpack = arg + 7;
44 continue;
46 if (!strcmp("--tags", arg)) {
47 flags |= REF_TAGS;
48 continue;
50 if (!strcmp("--heads", arg)) {
51 flags |= REF_HEADS;
52 continue;
54 if (!strcmp("--refs", arg)) {
55 flags |= REF_NORMAL;
56 continue;
58 usage(peek_remote_usage);
60 dest = arg;
61 break;
64 if (!dest || i != argc - 1)
65 usage(peek_remote_usage);
67 conn = git_connect(fd, dest, uploadpack, 0);
68 ret = peek_remote(fd, flags);
69 close(fd[0]);
70 close(fd[1]);
71 ret |= finish_connect(conn);
72 return !!ret;