ewok_rlw.h: add missing 'inline' to function definition
[git/debian.git] / builtin / get-tar-commit-id.c
blob2706fcfaf2261e2ac2eaff5a054d0dd7a9291c0b
1 /*
2 * Copyright (c) 2005, 2006 Rene Scharfe
3 */
4 #include "cache.h"
5 #include "commit.h"
6 #include "tar.h"
7 #include "builtin.h"
8 #include "quote.h"
10 static const char builtin_get_tar_commit_id_usage[] =
11 "git get-tar-commit-id";
13 /* ustar header + extended global header content */
14 #define RECORDSIZE (512)
15 #define HEADERSIZE (2 * RECORDSIZE)
17 int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
19 char buffer[HEADERSIZE];
20 struct ustar_header *header = (struct ustar_header *)buffer;
21 char *content = buffer + RECORDSIZE;
22 const char *comment;
23 ssize_t n;
25 if (argc != 1)
26 usage(builtin_get_tar_commit_id_usage);
28 n = read_in_full(0, buffer, HEADERSIZE);
29 if (n < 0)
30 die_errno("git get-tar-commit-id: read error");
31 if (n != HEADERSIZE)
32 die_errno("git get-tar-commit-id: EOF before reading tar header");
33 if (header->typeflag[0] != 'g')
34 return 1;
35 if (!skip_prefix(content, "52 comment=", &comment))
36 return 1;
38 if (write_in_full(1, comment, 41) < 0)
39 die_errno("git get-tar-commit-id: write error");
41 return 0;