2005-05-09 23:33:02 +02:00
|
|
|
/*
|
2006-03-25 23:21:03 +01:00
|
|
|
* Copyright (c) 2005, 2006 Rene Scharfe
|
2005-05-09 23:33:02 +02:00
|
|
|
*/
|
2005-04-28 21:16:43 +02:00
|
|
|
#include "cache.h"
|
2006-01-29 20:05:20 +01:00
|
|
|
#include "commit.h"
|
2006-03-25 23:21:03 +01:00
|
|
|
#include "tar.h"
|
2006-05-23 14:15:31 +02:00
|
|
|
#include "builtin.h"
|
2006-09-24 23:42:01 +02:00
|
|
|
#include "quote.h"
|
2005-04-28 21:16:43 +02:00
|
|
|
|
2009-11-09 16:04:50 +01:00
|
|
|
static const char builtin_get_tar_commit_id_usage[] =
|
|
|
|
"git get-tar-commit-id < <tarfile>";
|
|
|
|
|
2006-06-10 16:13:41 +02:00
|
|
|
/* ustar header + extended global header content */
|
2006-09-24 23:42:01 +02:00
|
|
|
#define RECORDSIZE (512)
|
2006-06-10 16:13:41 +02:00
|
|
|
#define HEADERSIZE (2 * RECORDSIZE)
|
|
|
|
|
2006-07-29 07:44:25 +02:00
|
|
|
int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
|
2006-06-10 16:13:41 +02:00
|
|
|
{
|
|
|
|
char buffer[HEADERSIZE];
|
|
|
|
struct ustar_header *header = (struct ustar_header *)buffer;
|
|
|
|
char *content = buffer + RECORDSIZE;
|
2014-10-04 20:54:50 +02:00
|
|
|
const char *comment;
|
2006-06-10 16:13:41 +02:00
|
|
|
ssize_t n;
|
|
|
|
|
2009-11-09 16:04:50 +01:00
|
|
|
if (argc != 1)
|
|
|
|
usage(builtin_get_tar_commit_id_usage);
|
|
|
|
|
2007-01-08 16:58:08 +01:00
|
|
|
n = read_in_full(0, buffer, HEADERSIZE);
|
2006-06-10 16:13:41 +02:00
|
|
|
if (n < HEADERSIZE)
|
2008-08-31 18:39:19 +02:00
|
|
|
die("git get-tar-commit-id: read error");
|
2006-06-10 16:13:41 +02:00
|
|
|
if (header->typeflag[0] != 'g')
|
|
|
|
return 1;
|
2014-10-04 20:54:50 +02:00
|
|
|
if (!skip_prefix(content, "52 comment=", &comment))
|
2006-06-10 16:13:41 +02:00
|
|
|
return 1;
|
|
|
|
|
2014-10-04 20:54:50 +02:00
|
|
|
n = write_in_full(1, comment, 41);
|
2006-06-10 16:13:41 +02:00
|
|
|
if (n < 41)
|
2009-06-27 17:58:47 +02:00
|
|
|
die_errno("git get-tar-commit-id: write error");
|
2006-06-10 16:13:41 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|