2 * Copyright (c) 2005, 2006 Rene Scharfe
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 static const char builtin_get_tar_commit_id_usage[] =
15 "git get-tar-commit-id < <tarfile>";
17 int cmd_tar_tree(int argc, const char **argv, const char *prefix)
20 * "git tar-tree" is now a wrapper around "git archive --format=tar"
22 * $0 --remote=<repo> arg... ==>
23 * git archive --format=tar --remote=<repo> arg...
25 * git archive --format=tar tree-ish
26 * $0 tree-ish basedir ==>
27 * git archive --format-tar --prefix=basedir tree-ish
30 const char **nargv = xcalloc(sizeof(*nargv), argc + 3);
34 nargv[nargc++] = "archive";
35 nargv[nargc++] = "--format=tar";
37 if (2 <= argc && !prefixcmp(argv[1], "--remote=")) {
38 nargv[nargc++] = argv[1];
44 * Because it's just a compatibility wrapper, tar-tree supports only
45 * the old behaviour of reading attributes from the work tree.
47 nargv[nargc++] = "--worktree-attributes";
51 usage(tar_tree_usage);
55 basedir_arg = xmalloc(strlen(argv[2]) + 11);
56 sprintf(basedir_arg, "--prefix=%s/", argv[2]);
57 nargv[nargc++] = basedir_arg;
61 nargv[nargc++] = argv[1];
66 "*** \"git tar-tree\" is now deprecated.\n"
67 "*** Running \"git archive\" instead.\n***");
68 for (i = 0; i < nargc; i++) {
70 sq_quote_print(stderr, nargv[i]);
73 return cmd_archive(nargc, nargv, prefix);
76 /* ustar header + extended global header content */
77 #define RECORDSIZE (512)
78 #define HEADERSIZE (2 * RECORDSIZE)
80 int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
82 char buffer[HEADERSIZE];
83 struct ustar_header *header = (struct ustar_header *)buffer;
84 char *content = buffer + RECORDSIZE;
88 usage(builtin_get_tar_commit_id_usage);
90 n = read_in_full(0, buffer, HEADERSIZE);
92 die("git get-tar-commit-id: read error");
93 if (header->typeflag[0] != 'g')
95 if (memcmp(content, "52 comment=", 11))
98 n = write_in_full(1, content + 11, 41);
100 die_errno("git get-tar-commit-id: write error");