Initial revision of "git", the information manager from hell
[git.git] / cat-file.c
1 #include "cache.h"
2
3 int main(int argc, char **argv)
4 {
5         unsigned char sha1[20];
6         char type[20];
7         void *buf;
8         unsigned long size;
9         char template[] = "temp_git_file_XXXXXX";
10         int fd;
11
12         if (argc != 2 || get_sha1_hex(argv[1], sha1))
13                 usage("cat-file: cat-file <sha1>");
14         buf = read_sha1_file(sha1, type, &size);
15         if (!buf)
16                 exit(1);
17         fd = mkstemp(template);
18         if (fd < 0)
19                 usage("unable to create tempfile");
20         if (write(fd, buf, size) != size)
21                 strcpy(type, "bad");
22         printf("%s: %s\n", template, type);
23 }