2 * Copyright (c) 2005, 2006 Rene Scharfe
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
;
28 usage(builtin_get_tar_commit_id_usage
);
30 n
= read_in_full(0, buffer
, HEADERSIZE
);
32 die_errno("git get-tar-commit-id: read error");
34 die_errno("git get-tar-commit-id: EOF before reading tar header");
35 if (header
->typeflag
[0] != 'g')
38 len
= strtol(content
, &end
, 10);
39 if (errno
== ERANGE
|| end
== content
|| len
< 0)
41 if (!skip_prefix(end
, " comment=", &comment
))
43 len
-= comment
- content
;
44 if (len
< 1 || !(len
% 2) ||
45 hash_algo_by_length((len
- 1) / 2) == GIT_HASH_UNKNOWN
)
48 if (write_in_full(1, comment
, len
) < 0)
49 die_errno("git get-tar-commit-id: write error");