]> git.ipfire.org Git - thirdparty/git.git/blame - cat-file.c
Update "convert-cache" to handle git itself.
[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
bf0c6e83 15 if (argc != 3 || get_sha1_hex(argv[2], sha1))
2de381f9 16 usage("cat-file [-t | tagname] <sha1>");
e83c5163 17 buf = read_sha1_file(sha1, type, &size);
2de381f9
PB
18 if (!buf)
19 die("cat-file %s: bad file", argv[2]);
bf0c6e83
LT
20 if (!strcmp("-t", argv[1])) {
21 buf = type;
22 size = strlen(type);
23 type[size] = '\n';
24 size++;
25 } else if (strcmp(type, argv[1])) {
2de381f9 26 die("cat-file %s: bad tag", argv[2]);
bf0c6e83
LT
27 }
28
29 while (size > 0) {
30 long ret = write(1, buf, size);
31 if (ret < 0) {
32 if (errno == EAGAIN)
33 continue;
34 /* Ignore epipe */
35 if (errno == EPIPE)
36 break;
2de381f9
PB
37 die("cat-file: %s", strerror(errno));
38 } else if (!ret) {
39 die("cat-file: disk full?");
bf0c6e83
LT
40 }
41 size -= ret;
42 buf += ret;
43 }
44 return 0;
e83c5163 45}