cvsimport: remove last use of repo-config from git standard tools
[git/fastimport.git] / builtin-tar-tree.c
blobb04719ef20929d40ef0c898c37616a5e7316f272
1 /*
2 * Copyright (c) 2005, 2006 Rene Scharfe
3 */
4 #include "cache.h"
5 #include "commit.h"
6 #include "tar.h"
7 #include "builtin.h"
8 #include "quote.h"
10 static const char tar_tree_usage[] =
11 "git-tar-tree [--remote=<repo>] <tree-ish> [basedir]\n"
12 "*** Note that this command is now deprecated; use git-archive instead.";
14 int cmd_tar_tree(int argc, const char **argv, const char *prefix)
17 * git-tar-tree is now a wrapper around git-archive --format=tar
19 * $0 --remote=<repo> arg... ==>
20 * git-archive --format=tar --remote=<repo> arg...
21 * $0 tree-ish ==>
22 * git-archive --format=tar tree-ish
23 * $0 tree-ish basedir ==>
24 * git-archive --format-tar --prefix=basedir tree-ish
26 int i;
27 const char **nargv = xcalloc(sizeof(*nargv), argc + 2);
28 char *basedir_arg;
29 int nargc = 0;
31 nargv[nargc++] = "git-archive";
32 nargv[nargc++] = "--format=tar";
34 if (2 <= argc && !prefixcmp(argv[1], "--remote=")) {
35 nargv[nargc++] = argv[1];
36 argv++;
37 argc--;
39 switch (argc) {
40 default:
41 usage(tar_tree_usage);
42 break;
43 case 3:
44 /* base-path */
45 basedir_arg = xmalloc(strlen(argv[2]) + 11);
46 sprintf(basedir_arg, "--prefix=%s/", argv[2]);
47 nargv[nargc++] = basedir_arg;
48 /* fallthru */
49 case 2:
50 /* tree-ish */
51 nargv[nargc++] = argv[1];
53 nargv[nargc] = NULL;
55 fprintf(stderr,
56 "*** git-tar-tree is now deprecated.\n"
57 "*** Running git-archive instead.\n***");
58 for (i = 0; i < nargc; i++) {
59 fputc(' ', stderr);
60 sq_quote_print(stderr, nargv[i]);
62 fputc('\n', stderr);
63 return cmd_archive(nargc, nargv, prefix);
66 /* ustar header + extended global header content */
67 #define RECORDSIZE (512)
68 #define HEADERSIZE (2 * RECORDSIZE)
70 int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
72 char buffer[HEADERSIZE];
73 struct ustar_header *header = (struct ustar_header *)buffer;
74 char *content = buffer + RECORDSIZE;
75 ssize_t n;
77 n = read_in_full(0, buffer, HEADERSIZE);
78 if (n < HEADERSIZE)
79 die("git-get-tar-commit-id: read error");
80 if (header->typeflag[0] != 'g')
81 return 1;
82 if (memcmp(content, "52 comment=", 11))
83 return 1;
85 n = write_in_full(1, content + 11, 41);
86 if (n < 41)
87 die("git-get-tar-commit-id: write error");
89 return 0;