From 52ba03cbb1c718093946f5254187082bd7b32845 Mon Sep 17 00:00:00 2001 From: Rene Scharfe Date: Sat, 10 Jun 2006 16:13:41 +0200 Subject: Built-in git-get-tar-commit-id By being an internal command git-get-commit-id can make use of struct ustar_header and other stuff and stops wasting precious disk space. Note: I recycled one of the two "tar-tree" entries instead of splitting that cleanup into a separate patch. Signed-off-by: Rene Scharfe Signed-off-by: Junio C Hamano --- builtin-tar-tree.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'builtin-tar-tree.c') diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c index 7663b9bd8e..58a8ccd4d6 100644 --- a/builtin-tar-tree.c +++ b/builtin-tar-tree.c @@ -402,3 +402,28 @@ int cmd_tar_tree(int argc, const char **argv, char **envp) return remote_tar(argc, argv); return generate_tar(argc, argv, envp); } + +/* ustar header + extended global header content */ +#define HEADERSIZE (2 * RECORDSIZE) + +int cmd_get_tar_commit_id(int argc, const char **argv, char **envp) +{ + char buffer[HEADERSIZE]; + struct ustar_header *header = (struct ustar_header *)buffer; + char *content = buffer + RECORDSIZE; + ssize_t n; + + n = xread(0, buffer, HEADERSIZE); + if (n < HEADERSIZE) + die("git-get-tar-commit-id: read error"); + if (header->typeflag[0] != 'g') + return 1; + if (memcmp(content, "52 comment=", 11)) + return 1; + + n = xwrite(1, content + 11, 41); + if (n < 41) + die("git-get-tar-commit-id: write error"); + + return 0; +} -- cgit v1.2.3