]> git.ipfire.org Git - thirdparty/git.git/blame - builtin-tar-tree.c
Merge branch 'jc/maint-imap-config-parse' into maint
[thirdparty/git.git] / builtin-tar-tree.c
CommitLineData
92747a90 1/*
ae64bbc1 2 * Copyright (c) 2005, 2006 Rene Scharfe
92747a90 3 */
731ab9cc 4#include "cache.h"
c3f92812 5#include "commit.h"
ae64bbc1 6#include "tar.h"
56d1398a 7#include "builtin.h"
fd88d9c8 8#include "quote.h"
731ab9cc 9
21754264 10static const char tar_tree_usage[] =
1b1dd23f 11"git tar-tree [--remote=<repo>] <tree-ish> [basedir]\n"
f18d244a 12"*** Note that this command is now deprecated; use \"git archive\" instead.";
731ab9cc 13
e9dd085d
JN
14static const char builtin_get_tar_commit_id_usage[] =
15"git get-tar-commit-id < <tarfile>";
16
fd88d9c8 17int cmd_tar_tree(int argc, const char **argv, const char *prefix)
731ab9cc 18{
fd88d9c8 19 /*
f18d244a 20 * "git tar-tree" is now a wrapper around "git archive --format=tar"
fd88d9c8
JH
21 *
22 * $0 --remote=<repo> arg... ==>
f18d244a 23 * git archive --format=tar --remote=<repo> arg...
fd88d9c8 24 * $0 tree-ish ==>
f18d244a 25 * git archive --format=tar tree-ish
fd88d9c8 26 * $0 tree-ish basedir ==>
f18d244a 27 * git archive --format-tar --prefix=basedir tree-ish
fd88d9c8
JH
28 */
29 int i;
ba053ea9 30 const char **nargv = xcalloc(sizeof(*nargv), argc + 3);
fd88d9c8
JH
31 char *basedir_arg;
32 int nargc = 0;
33
1f5a892e 34 nargv[nargc++] = "archive";
fd88d9c8
JH
35 nargv[nargc++] = "--format=tar";
36
599065a3 37 if (2 <= argc && !prefixcmp(argv[1], "--remote=")) {
fd88d9c8
JH
38 nargv[nargc++] = argv[1];
39 argv++;
40 argc--;
731ab9cc 41 }
ba053ea9
NTND
42
43 /*
44 * Because it's just a compatibility wrapper, tar-tree supports only
45 * the old behaviour of reading attributes from the work tree.
46 */
47 nargv[nargc++] = "--worktree-attributes";
48
fd88d9c8
JH
49 switch (argc) {
50 default:
21754264 51 usage(tar_tree_usage);
fd88d9c8
JH
52 break;
53 case 3:
54 /* base-path */
55 basedir_arg = xmalloc(strlen(argv[2]) + 11);
56 sprintf(basedir_arg, "--prefix=%s/", argv[2]);
57 nargv[nargc++] = basedir_arg;
58 /* fallthru */
59 case 2:
60 /* tree-ish */
61 nargv[nargc++] = argv[1];
21754264 62 }
fd88d9c8
JH
63 nargv[nargc] = NULL;
64
65 fprintf(stderr,
f18d244a
HO
66 "*** \"git tar-tree\" is now deprecated.\n"
67 "*** Running \"git archive\" instead.\n***");
fd88d9c8
JH
68 for (i = 0; i < nargc; i++) {
69 fputc(' ', stderr);
70 sq_quote_print(stderr, nargv[i]);
71 }
72 fputc('\n', stderr);
73 return cmd_archive(nargc, nargv, prefix);
21754264 74}
52ba03cb
RS
75
76/* ustar header + extended global header content */
fd88d9c8 77#define RECORDSIZE (512)
52ba03cb
RS
78#define HEADERSIZE (2 * RECORDSIZE)
79
a633fca0 80int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
52ba03cb
RS
81{
82 char buffer[HEADERSIZE];
83 struct ustar_header *header = (struct ustar_header *)buffer;
84 char *content = buffer + RECORDSIZE;
85 ssize_t n;
86
e9dd085d
JN
87 if (argc != 1)
88 usage(builtin_get_tar_commit_id_usage);
89
93d26e4c 90 n = read_in_full(0, buffer, HEADERSIZE);
52ba03cb 91 if (n < HEADERSIZE)
7e44c935 92 die("git get-tar-commit-id: read error");
52ba03cb
RS
93 if (header->typeflag[0] != 'g')
94 return 1;
95 if (memcmp(content, "52 comment=", 11))
96 return 1;
97
93822c22 98 n = write_in_full(1, content + 11, 41);
52ba03cb 99 if (n < 41)
0721c314 100 die_errno("git get-tar-commit-id: write error");
52ba03cb
RS
101
102 return 0;
103}