2 * Copyright (c) 2005, 2006 Rene Scharfe
8 static const char builtin_get_tar_commit_id_usage
[] =
9 "git get-tar-commit-id";
11 /* ustar header + extended global header content */
12 #define RECORDSIZE (512)
13 #define HEADERSIZE (2 * RECORDSIZE)
15 int cmd_get_tar_commit_id(int argc
,
16 const char **argv UNUSED
,
18 struct repository
*repo UNUSED
)
20 char buffer
[HEADERSIZE
];
21 struct ustar_header
*header
= (struct ustar_header
*)buffer
;
22 char *content
= buffer
+ RECORDSIZE
;
28 BUG_ON_NON_EMPTY_PREFIX(prefix
);
31 usage(builtin_get_tar_commit_id_usage
);
33 n
= read_in_full(0, buffer
, HEADERSIZE
);
35 die_errno("git get-tar-commit-id: read error");
37 die_errno("git get-tar-commit-id: EOF before reading tar header");
38 if (header
->typeflag
[0] != TYPEFLAG_GLOBAL_HEADER
)
42 len
= strtol(content
, &end
, 10);
43 if (errno
== ERANGE
|| end
== content
|| len
< 0)
45 if (!skip_prefix(end
, " comment=", &comment
))
47 len
-= comment
- content
;
48 if (len
< 1 || !(len
% 2) ||
49 hash_algo_by_length((len
- 1) / 2) == GIT_HASH_UNKNOWN
)
52 if (write_in_full(1, comment
, len
) < 0)
53 die_errno("git get-tar-commit-id: write error");