]> git.ipfire.org Git - thirdparty/git.git/blame - builtin/get-tar-commit-id.c
Git 2.14.4
[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);
52ba03cb 29 if (n < HEADERSIZE)
7e44c935 30 die("git get-tar-commit-id: read error");
52ba03cb
RS
31 if (header->typeflag[0] != 'g')
32 return 1;
e3f1da98 33 if (!skip_prefix(content, "52 comment=", &comment))
52ba03cb
RS
34 return 1;
35
68a423ab 36 if (write_in_full(1, comment, 41) < 0)
0721c314 37 die_errno("git get-tar-commit-id: write error");
52ba03cb
RS
38
39 return 0;
40}