You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.5 KiB
104 lines
2.5 KiB
20 years ago
|
/*
|
||
19 years ago
|
* Copyright (c) 2005, 2006 Rene Scharfe
|
||
20 years ago
|
*/
|
||
20 years ago
|
#include "cache.h"
|
||
19 years ago
|
#include "commit.h"
|
||
19 years ago
|
#include "tar.h"
|
||
19 years ago
|
#include "builtin.h"
|
||
19 years ago
|
#include "quote.h"
|
||
20 years ago
|
|
||
19 years ago
|
static const char tar_tree_usage[] =
|
||
17 years ago
|
"git tar-tree [--remote=<repo>] <tree-ish> [basedir]\n"
|
||
17 years ago
|
"*** Note that this command is now deprecated; use \"git archive\" instead.";
|
||
20 years ago
|
|
||
15 years ago
|
static const char builtin_get_tar_commit_id_usage[] =
|
||
|
"git get-tar-commit-id < <tarfile>";
|
||
|
|
||
19 years ago
|
int cmd_tar_tree(int argc, const char **argv, const char *prefix)
|
||
20 years ago
|
{
|
||
19 years ago
|
/*
|
||
17 years ago
|
* "git tar-tree" is now a wrapper around "git archive --format=tar"
|
||
19 years ago
|
*
|
||
|
* $0 --remote=<repo> arg... ==>
|
||
17 years ago
|
* git archive --format=tar --remote=<repo> arg...
|
||
19 years ago
|
* $0 tree-ish ==>
|
||
17 years ago
|
* git archive --format=tar tree-ish
|
||
19 years ago
|
* $0 tree-ish basedir ==>
|
||
17 years ago
|
* git archive --format-tar --prefix=basedir tree-ish
|
||
19 years ago
|
*/
|
||
|
int i;
|
||
16 years ago
|
const char **nargv = xcalloc(sizeof(*nargv), argc + 3);
|
||
19 years ago
|
char *basedir_arg;
|
||
|
int nargc = 0;
|
||
|
|
||
17 years ago
|
nargv[nargc++] = "archive";
|
||
19 years ago
|
nargv[nargc++] = "--format=tar";
|
||
|
|
||
18 years ago
|
if (2 <= argc && !prefixcmp(argv[1], "--remote=")) {
|
||
19 years ago
|
nargv[nargc++] = argv[1];
|
||
|
argv++;
|
||
|
argc--;
|
||
20 years ago
|
}
|
||
16 years ago
|
|
||
|
/*
|
||
|
* Because it's just a compatibility wrapper, tar-tree supports only
|
||
|
* the old behaviour of reading attributes from the work tree.
|
||
|
*/
|
||
|
nargv[nargc++] = "--worktree-attributes";
|
||
|
|
||
19 years ago
|
switch (argc) {
|
||
|
default:
|
||
19 years ago
|
usage(tar_tree_usage);
|
||
19 years ago
|
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];
|
||
19 years ago
|
}
|
||
19 years ago
|
nargv[nargc] = NULL;
|
||
|
|
||
|
fprintf(stderr,
|
||
17 years ago
|
"*** \"git tar-tree\" is now deprecated.\n"
|
||
|
"*** Running \"git archive\" instead.\n***");
|
||
19 years ago
|
for (i = 0; i < nargc; i++) {
|
||
|
fputc(' ', stderr);
|
||
|
sq_quote_print(stderr, nargv[i]);
|
||
|
}
|
||
|
fputc('\n', stderr);
|
||
|
return cmd_archive(nargc, nargv, prefix);
|
||
19 years ago
|
}
|
||
19 years ago
|
|
||
|
/* ustar header + extended global header content */
|
||
19 years ago
|
#define RECORDSIZE (512)
|
||
19 years ago
|
#define HEADERSIZE (2 * RECORDSIZE)
|
||
|
|
||
19 years ago
|
int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
|
||
19 years ago
|
{
|
||
|
char buffer[HEADERSIZE];
|
||
|
struct ustar_header *header = (struct ustar_header *)buffer;
|
||
|
char *content = buffer + RECORDSIZE;
|
||
|
ssize_t n;
|
||
|
|
||
15 years ago
|
if (argc != 1)
|
||
|
usage(builtin_get_tar_commit_id_usage);
|
||
|
|
||
18 years ago
|
n = read_in_full(0, buffer, HEADERSIZE);
|
||
19 years ago
|
if (n < HEADERSIZE)
|
||
17 years ago
|
die("git get-tar-commit-id: read error");
|
||
19 years ago
|
if (header->typeflag[0] != 'g')
|
||
|
return 1;
|
||
|
if (memcmp(content, "52 comment=", 11))
|
||
|
return 1;
|
||
|
|
||
18 years ago
|
n = write_in_full(1, content + 11, 41);
|
||
19 years ago
|
if (n < 41)
|
||
16 years ago
|
die_errno("git get-tar-commit-id: write error");
|
||
19 years ago
|
|
||
|
return 0;
|
||
|
}
|