[PATCH] git-cat-file: use sha1_object_info() on '-t'.
[alt-git.git] / cat-file.c
blob0076fc5b20a71b4d32add42b8dcb76a22eea4ef6
1 /*
2 * GIT - The information manager from hell
4 * Copyright (C) Linus Torvalds, 2005
5 */
6 #include "cache.h"
8 int main(int argc, char **argv)
10 unsigned char sha1[20];
11 char type[20];
12 void *buf;
13 unsigned long size;
15 if (argc != 3 || get_sha1(argv[2], sha1))
16 usage("git-cat-file [-t | tagname] <sha1>");
18 if (!strcmp("-t", argv[1])) {
19 if (!sha1_object_info(sha1, type, &size)) {
20 printf("%s\n", type);
21 return 0;
23 buf = NULL;
24 } else {
25 buf = read_object_with_reference(sha1, argv[1], &size, NULL);
28 if (!buf)
29 die("git-cat-file %s: bad file", argv[2]);
31 while (size > 0) {
32 long ret = write(1, buf, size);
33 if (ret < 0) {
34 if (errno == EAGAIN)
35 continue;
36 /* Ignore epipe */
37 if (errno == EPIPE)
38 break;
39 die("git-cat-file: %s", strerror(errno));
40 } else if (!ret) {
41 die("git-cat-file: disk full?");
43 size -= ret;
44 buf += ret;
46 return 0;