]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/get-tar-commit-id.c
hash: add a function to lookup hash algorithm by length
[thirdparty/git.git] / builtin / get-tar-commit-id.c
CommitLineData
92747a90 1/*
ae64bbc1 2 * Copyright (c) 2005, 2006 Rene Scharfe
92747a90 3 */
731ab9cc 4#include "cache.h"
c3f92812 5#include "commit.h"
ae64bbc1 6#include "tar.h"
56d1398a 7#include "builtin.h"
fd88d9c8 8#include "quote.h"
731ab9cc 9
e9dd085d 10static const char builtin_get_tar_commit_id_usage[] =
33e8fc87 11"git get-tar-commit-id";
e9dd085d 12
52ba03cb 13/* ustar header + extended global header content */
fd88d9c8 14#define RECORDSIZE (512)
52ba03cb
RS
15#define HEADERSIZE (2 * RECORDSIZE)
16
a633fca0 17int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
52ba03cb
RS
18{
19 char buffer[HEADERSIZE];
20 struct ustar_header *header = (struct ustar_header *)buffer;
21 char *content = buffer + RECORDSIZE;
e3f1da98 22 const char *comment;
52ba03cb
RS
23 ssize_t n;
24
e9dd085d
JN
25 if (argc != 1)
26 usage(builtin_get_tar_commit_id_usage);
27
93d26e4c 28 n = read_in_full(0, buffer, HEADERSIZE);
41dcc4dc
JK
29 if (n < 0)
30 die_errno("git get-tar-commit-id: read error");
61d36330 31 if (n != HEADERSIZE)
41dcc4dc 32 die_errno("git get-tar-commit-id: EOF before reading tar header");
52ba03cb
RS
33 if (header->typeflag[0] != 'g')
34 return 1;
e3f1da98 35 if (!skip_prefix(content, "52 comment=", &comment))
52ba03cb
RS
36 return 1;
37
68a423ab 38 if (write_in_full(1, comment, 41) < 0)
0721c314 39 die_errno("git get-tar-commit-id: write error");
52ba03cb
RS
40
41 return 0;
42}