]> git.ipfire.org Git - thirdparty/git.git/blame - cat-file.c
Do ref matching on the sender side rather than on receiver
[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))
62bb9960 16 usage("git-cat-file [-t | -s | tagname] <sha1>");
11e7d5c5 17
62bb9960 18 if (!strcmp("-t", argv[1]) || !strcmp("-s", argv[1])) {
f2a06330 19 if (!sha1_object_info(sha1, type, &size)) {
62bb9960
JH
20 switch (argv[1][1]) {
21 case 't':
22 printf("%s\n", type);
23 break;
24 case 's':
25 printf("%lu\n", size);
26 break;
27 }
f2a06330 28 return 0;
11e7d5c5 29 }
f2a06330 30 buf = NULL;
11e7d5c5
LT
31 } else {
32 buf = read_object_with_reference(sha1, argv[1], &size, NULL);
bf0c6e83
LT
33 }
34
11e7d5c5 35 if (!buf)
bab5583a 36 die("git-cat-file %s: bad file", argv[2]);
11e7d5c5 37
bf0c6e83
LT
38 while (size > 0) {
39 long ret = write(1, buf, size);
40 if (ret < 0) {
41 if (errno == EAGAIN)
42 continue;
43 /* Ignore epipe */
44 if (errno == EPIPE)
45 break;
bab5583a 46 die("git-cat-file: %s", strerror(errno));
2de381f9 47 } else if (!ret) {
bab5583a 48 die("git-cat-file: disk full?");
bf0c6e83
LT
49 }
50 size -= ret;
51 buf += ret;
52 }
53 return 0;
e83c5163 54}