2005-05-10 05:33:02 +08:00
|
|
|
/*
|
2006-03-26 06:21:03 +08:00
|
|
|
* Copyright (c) 2005, 2006 Rene Scharfe
|
2005-05-10 05:33:02 +08:00
|
|
|
*/
|
2005-04-29 03:16:43 +08:00
|
|
|
#include "cache.h"
|
2006-01-30 03:05:20 +08:00
|
|
|
#include "commit.h"
|
2006-03-26 06:21:03 +08:00
|
|
|
#include "tar.h"
|
2006-05-23 20:15:31 +08:00
|
|
|
#include "builtin.h"
|
2006-09-25 05:42:01 +08:00
|
|
|
#include "quote.h"
|
2005-04-29 03:16:43 +08:00
|
|
|
|
2006-05-19 09:46:44 +08:00
|
|
|
static const char tar_tree_usage[] =
|
2006-09-25 05:42:01 +08:00
|
|
|
"git-tar-tree [--remote=<repo>] <tree-ish> [basedir]\n"
|
|
|
|
"*** Note that this command is now deprecated; use git-archive instead.";
|
2005-04-29 03:16:43 +08:00
|
|
|
|
2006-09-25 05:42:01 +08:00
|
|
|
int cmd_tar_tree(int argc, const char **argv, const char *prefix)
|
2005-04-29 03:16:43 +08:00
|
|
|
{
|
2006-09-25 05:42:01 +08: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-29 03:16:43 +08:00
|
|
|
}
|
2006-09-25 05:42:01 +08:00
|
|
|
switch (argc) {
|
|
|
|
default:
|
2006-05-19 09:46:44 +08:00
|
|
|
usage(tar_tree_usage);
|
2006-09-25 05:42:01 +08: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 09:46:44 +08:00
|
|
|
}
|
2006-09-25 05:42:01 +08: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 09:46:44 +08:00
|
|
|
}
|
2006-06-10 22:13:41 +08:00
|
|
|
|
|
|
|
/* ustar header + extended global header content */
|
2006-09-25 05:42:01 +08:00
|
|
|
#define RECORDSIZE (512)
|
2006-06-10 22:13:41 +08:00
|
|
|
#define HEADERSIZE (2 * RECORDSIZE)
|
|
|
|
|
2006-07-29 13:44:25 +08:00
|
|
|
int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
|
2006-06-10 22:13:41 +08:00
|
|
|
{
|
|
|
|
char buffer[HEADERSIZE];
|
|
|
|
struct ustar_header *header = (struct ustar_header *)buffer;
|
|
|
|
char *content = buffer + RECORDSIZE;
|
|
|
|
ssize_t n;
|
|
|
|
|
2007-01-08 23:58:08 +08:00
|
|
|
n = read_in_full(0, buffer, HEADERSIZE);
|
2006-06-10 22:13:41 +08: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 23:58:23 +08:00
|
|
|
n = write_in_full(1, content + 11, 41);
|
2006-06-10 22:13:41 +08:00
|
|
|
if (n < 41)
|
|
|
|
die("git-get-tar-commit-id: write error");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|