]> git.ipfire.org Git - thirdparty/git.git/blame - cat-file.c
Documentaion updates.
[thirdparty/git.git] / cat-file.c
CommitLineData
8bc9a0c7
LT
1/*
2 * GIT - The information manager from hell
3 *
4 * Copyright (C) Linus Torvalds, 2005
5 */
e83c5163
LT
6#include "cache.h"
7
8int main(int argc, char **argv)
9{
10 unsigned char sha1[20];
11 char type[20];
12 void *buf;
13 unsigned long size;
e83c5163 14
3c249c95 15 if (argc != 3 || get_sha1(argv[2], sha1))
f16ebbdd 16 usage("git-cat-file [-t | -s | <type>] <sha1>");
11e7d5c5 17
62bb9960 18 if (!strcmp("-t", argv[1]) || !strcmp("-s", argv[1])) {
c62266f3
JH
19 if (!sha1_object_info(sha1, type,
20 argv[1][1] == 's' ? &size : NULL)) {
62bb9960
JH
21 switch (argv[1][1]) {
22 case 't':
23 printf("%s\n", type);
24 break;
25 case 's':
26 printf("%lu\n", size);
27 break;
28 }
f2a06330 29 return 0;
11e7d5c5 30 }
f2a06330 31 buf = NULL;
11e7d5c5
LT
32 } else {
33 buf = read_object_with_reference(sha1, argv[1], &size, NULL);
bf0c6e83
LT
34 }
35
11e7d5c5 36 if (!buf)
bab5583a 37 die("git-cat-file %s: bad file", argv[2]);
11e7d5c5 38
bf0c6e83
LT
39 while (size > 0) {
40 long ret = write(1, buf, size);
41 if (ret < 0) {
42 if (errno == EAGAIN)
43 continue;
44 /* Ignore epipe */
45 if (errno == EPIPE)
46 break;
bab5583a 47 die("git-cat-file: %s", strerror(errno));
2de381f9 48 } else if (!ret) {
bab5583a 49 die("git-cat-file: disk full?");
bf0c6e83
LT
50 }
51 size -= ret;
52 buf += ret;
53 }
54 return 0;
e83c5163 55}