]>
Commit | Line | Data |
---|---|---|
92747a90 | 1 | /* |
ae64bbc1 | 2 | * Copyright (c) 2005, 2006 Rene Scharfe |
92747a90 | 3 | */ |
731ab9cc RS |
4 | #include <time.h> |
5 | #include "cache.h" | |
c3f92812 | 6 | #include "commit.h" |
ae64bbc1 | 7 | #include "tar.h" |
56d1398a | 8 | #include "builtin.h" |
fd88d9c8 | 9 | #include "quote.h" |
731ab9cc | 10 | |
21754264 | 11 | static const char tar_tree_usage[] = |
fd88d9c8 JH |
12 | "git-tar-tree [--remote=<repo>] <tree-ish> [basedir]\n" |
13 | "*** Note that this command is now deprecated; use git-archive instead."; | |
731ab9cc | 14 | |
fd88d9c8 | 15 | int cmd_tar_tree(int argc, const char **argv, const char *prefix) |
731ab9cc | 16 | { |
fd88d9c8 JH |
17 | /* |
18 | * git-tar-tree is now a wrapper around git-archive --format=tar | |
19 | * | |
20 | * $0 --remote=<repo> arg... ==> | |
21 | * git-archive --format=tar --remote=<repo> arg... | |
22 | * $0 tree-ish ==> | |
23 | * git-archive --format=tar tree-ish | |
24 | * $0 tree-ish basedir ==> | |
25 | * git-archive --format-tar --prefix=basedir tree-ish | |
26 | */ | |
27 | int i; | |
28 | const char **nargv = xcalloc(sizeof(*nargv), argc + 2); | |
29 | char *basedir_arg; | |
30 | int nargc = 0; | |
31 | ||
32 | nargv[nargc++] = "git-archive"; | |
33 | nargv[nargc++] = "--format=tar"; | |
34 | ||
35 | if (2 <= argc && !strncmp("--remote=", argv[1], 9)) { | |
36 | nargv[nargc++] = argv[1]; | |
37 | argv++; | |
38 | argc--; | |
731ab9cc | 39 | } |
fd88d9c8 JH |
40 | switch (argc) { |
41 | default: | |
21754264 | 42 | usage(tar_tree_usage); |
fd88d9c8 JH |
43 | break; |
44 | case 3: | |
45 | /* base-path */ | |
46 | basedir_arg = xmalloc(strlen(argv[2]) + 11); | |
47 | sprintf(basedir_arg, "--prefix=%s/", argv[2]); | |
48 | nargv[nargc++] = basedir_arg; | |
49 | /* fallthru */ | |
50 | case 2: | |
51 | /* tree-ish */ | |
52 | nargv[nargc++] = argv[1]; | |
21754264 | 53 | } |
fd88d9c8 JH |
54 | nargv[nargc] = NULL; |
55 | ||
56 | fprintf(stderr, | |
57 | "*** git-tar-tree is now deprecated.\n" | |
58 | "*** Running git-archive instead.\n***"); | |
59 | for (i = 0; i < nargc; i++) { | |
60 | fputc(' ', stderr); | |
61 | sq_quote_print(stderr, nargv[i]); | |
62 | } | |
63 | fputc('\n', stderr); | |
64 | return cmd_archive(nargc, nargv, prefix); | |
21754264 | 65 | } |
52ba03cb RS |
66 | |
67 | /* ustar header + extended global header content */ | |
fd88d9c8 | 68 | #define RECORDSIZE (512) |
52ba03cb RS |
69 | #define HEADERSIZE (2 * RECORDSIZE) |
70 | ||
a633fca0 | 71 | int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix) |
52ba03cb RS |
72 | { |
73 | char buffer[HEADERSIZE]; | |
74 | struct ustar_header *header = (struct ustar_header *)buffer; | |
75 | char *content = buffer + RECORDSIZE; | |
76 | ssize_t n; | |
77 | ||
78 | n = xread(0, buffer, HEADERSIZE); | |
79 | if (n < HEADERSIZE) | |
80 | die("git-get-tar-commit-id: read error"); | |
81 | if (header->typeflag[0] != 'g') | |
82 | return 1; | |
83 | if (memcmp(content, "52 comment=", 11)) | |
84 | return 1; | |
85 | ||
86 | n = xwrite(1, content + 11, 41); | |
87 | if (n < 41) | |
88 | die("git-get-tar-commit-id: write error"); | |
89 | ||
90 | return 0; | |
91 | } |