2005-05-09 21:33:02 +00:00
|
|
|
/*
|
2006-03-25 22:21:03 +00:00
|
|
|
* Copyright (c) 2005, 2006 Rene Scharfe
|
2005-05-09 21:33:02 +00:00
|
|
|
*/
|
2005-04-28 19:16:43 +00:00
|
|
|
#include "cache.h"
|
2006-01-29 19:05:20 +00:00
|
|
|
#include "commit.h"
|
2006-03-25 22:21:03 +00:00
|
|
|
#include "tar.h"
|
2006-05-23 12:15:31 +00:00
|
|
|
#include "builtin.h"
|
2006-09-24 21:42:01 +00:00
|
|
|
#include "quote.h"
|
2005-04-28 19:16:43 +00:00
|
|
|
|
2006-05-19 01:46:44 +00:00
|
|
|
static const char tar_tree_usage[] =
|
2006-09-24 21:42:01 +00:00
|
|
|
"git-tar-tree [--remote=<repo>] <tree-ish> [basedir]\n"
|
|
|
|
"*** Note that this command is now deprecated; use git-archive instead.";
|
2005-04-28 19:16:43 +00:00
|
|
|
|
2006-09-24 21:42:01 +00:00
|
|
|
int cmd_tar_tree(int argc, const char **argv, const char *prefix)
|
2005-04-28 19:16:43 +00:00
|
|
|
{
|
2006-09-24 21:42:01 +00:00
|
|
|
/*
|
|
|
|
* git-tar-tree is now a wrapper around git-archive --format=tar
|
|
|
|
*
|
|
|
|
* $0 --remote=<repo> arg... ==>
|
|
|
|
* git-archive --format=tar --remote=<repo> arg...
|
|
|
|
* $0 tree-ish ==>
|
|
|
|
* git-archive --format=tar tree-ish
|
|
|
|
* $0 tree-ish basedir ==>
|
|
|
|
* git-archive --format-tar --prefix=basedir tree-ish
|
|
|
|
*/
|
|
|
|
int i;
|
|
|
|
const char **nargv = xcalloc(sizeof(*nargv), argc + 2);
|
|
|
|
char *basedir_arg;
|
|
|
|
int nargc = 0;
|
|
|
|
|
|
|
|
nargv[nargc++] = "git-archive";
|
|
|
|
nargv[nargc++] = "--format=tar";
|
|
|
|
|
|
|
|
if (2 <= argc && !strncmp("--remote=", argv[1], 9)) {
|
|
|
|
nargv[nargc++] = argv[1];
|
|
|
|
argv++;
|
|
|
|
argc--;
|
2005-04-28 19:16:43 +00:00
|
|
|
}
|
2006-09-24 21:42:01 +00:00
|
|
|
switch (argc) {
|
|
|
|
default:
|
2006-05-19 01:46:44 +00:00
|
|
|
usage(tar_tree_usage);
|
2006-09-24 21:42:01 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
/* base-path */
|
|
|
|
basedir_arg = xmalloc(strlen(argv[2]) + 11);
|
|
|
|
sprintf(basedir_arg, "--prefix=%s/", argv[2]);
|
|
|
|
nargv[nargc++] = basedir_arg;
|
|
|
|
/* fallthru */
|
|
|
|
case 2:
|
|
|
|
/* tree-ish */
|
|
|
|
nargv[nargc++] = argv[1];
|
2006-05-19 01:46:44 +00:00
|
|
|
}
|
2006-09-24 21:42:01 +00:00
|
|
|
nargv[nargc] = NULL;
|
|
|
|
|
|
|
|
fprintf(stderr,
|
|
|
|
"*** git-tar-tree is now deprecated.\n"
|
|
|
|
"*** Running git-archive instead.\n***");
|
|
|
|
for (i = 0; i < nargc; i++) {
|
|
|
|
fputc(' ', stderr);
|
|
|
|
sq_quote_print(stderr, nargv[i]);
|
|
|
|
}
|
|
|
|
fputc('\n', stderr);
|
|
|
|
return cmd_archive(nargc, nargv, prefix);
|
2006-05-19 01:46:44 +00:00
|
|
|
}
|
2006-06-10 14:13:41 +00:00
|
|
|
|
|
|
|
/* ustar header + extended global header content */
|
2006-09-24 21:42:01 +00:00
|
|
|
#define RECORDSIZE (512)
|
2006-06-10 14:13:41 +00:00
|
|
|
#define HEADERSIZE (2 * RECORDSIZE)
|
|
|
|
|
2006-07-29 05:44:25 +00:00
|
|
|
int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
|
2006-06-10 14:13:41 +00:00
|
|
|
{
|
|
|
|
char buffer[HEADERSIZE];
|
|
|
|
struct ustar_header *header = (struct ustar_header *)buffer;
|
|
|
|
char *content = buffer + RECORDSIZE;
|
|
|
|
ssize_t n;
|
|
|
|
|
2007-01-08 15:58:08 +00:00
|
|
|
n = read_in_full(0, buffer, HEADERSIZE);
|
2006-06-10 14:13:41 +00:00
|
|
|
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;
|
|
|
|
|
2007-01-08 15:58:23 +00:00
|
|
|
n = write_in_full(1, content + 11, 41);
|
2006-06-10 14:13:41 +00:00
|
|
|
if (n < 41)
|
|
|
|
die("git-get-tar-commit-id: write error");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|