2 * Copyright (c) 2005, 2006 Rene Scharfe
9 static const char builtin_get_tar_commit_id_usage
[] =
10 "git get-tar-commit-id";
12 /* ustar header + extended global header content */
13 #define RECORDSIZE (512)
14 #define HEADERSIZE (2 * RECORDSIZE)
16 int cmd_get_tar_commit_id(int argc
, const char **argv UNUSED
, const char *prefix
)
18 char buffer
[HEADERSIZE
];
19 struct ustar_header
*header
= (struct ustar_header
*)buffer
;
20 char *content
= buffer
+ RECORDSIZE
;
26 BUG_ON_NON_EMPTY_PREFIX(prefix
);
29 usage(builtin_get_tar_commit_id_usage
);
31 n
= read_in_full(0, buffer
, HEADERSIZE
);
33 die_errno("git get-tar-commit-id: read error");
35 die_errno("git get-tar-commit-id: EOF before reading tar header");
36 if (header
->typeflag
[0] != TYPEFLAG_GLOBAL_HEADER
)
39 len
= strtol(content
, &end
, 10);
40 if (errno
== ERANGE
|| end
== content
|| len
< 0)
42 if (!skip_prefix(end
, " comment=", &comment
))
44 len
-= comment
- content
;
45 if (len
< 1 || !(len
% 2) ||
46 hash_algo_by_length((len
- 1) / 2) == GIT_HASH_UNKNOWN
)
49 if (write_in_full(1, comment
, len
) < 0)
50 die_errno("git get-tar-commit-id: write error");