Code

mailinfo: iconv does not like "latin-1" -- should spell it "latin1"
[git.git] / peek-remote.c
1 #include "cache.h"
2 #include "refs.h"
3 #include "pkt-line.h"
4 #include <sys/wait.h>
6 static const char peek_remote_usage[] =
7 "git-peek-remote [--exec=upload-pack] [host:]directory";
8 static const char *exec = "git-upload-pack";
10 static int peek_remote(int fd[2])
11 {
12         struct ref *ref;
14         get_remote_heads(fd[0], &ref, 0, NULL, 0);
15         packet_flush(fd[1]);
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 }
24 int main(int argc, char **argv)
25 {
26         int i, ret;
27         char *dest = NULL;
28         int fd[2];
29         pid_t pid;
30         int nongit = 0;
32         setup_git_directory_gently(&nongit);
34         for (i = 1; i < argc; i++) {
35                 char *arg = argv[i];
37                 if (*arg == '-') {
38                         if (!strncmp("--exec=", arg, 7))
39                                 exec = arg + 7;
40                         else
41                                 usage(peek_remote_usage);
42                         continue;
43                 }
44                 dest = arg;
45                 break;
46         }
47         if (!dest || i != argc - 1)
48                 usage(peek_remote_usage);
50         pid = git_connect(fd, dest, exec);
51         if (pid < 0)
52                 return 1;
53         ret = peek_remote(fd);
54         close(fd[0]);
55         close(fd[1]);
56         finish_connect(pid);
57         return ret;
58 }