receive-pack: do not insist on fast-forward outside refs/heads/
[git/mingw/4msysgit/wingit-dll.git] / builtin-tar-tree.c
blob4d4cfec878e468b8ab8a7f055c836c3569443914
1 /*
2 * Copyright (c) 2005, 2006 Rene Scharfe
3 */
4 #include <time.h>
5 #include "cache.h"
6 #include "commit.h"
7 #include "tar.h"
8 #include "builtin.h"
9 #include "quote.h"
11 static const char tar_tree_usage[] =
12 "git-tar-tree [--remote=<repo>] <tree-ish> [basedir]\n"
13 "*** Note that this command is now deprecated; use git-archive instead.";
15 int cmd_tar_tree(int argc, const char **argv, const char *prefix)
18 * git-tar-tree is now a wrapper around git-archive --format=tar
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
27 int i;
28 const char **nargv = xcalloc(sizeof(*nargv), argc + 2);
29 char *basedir_arg;
30 int nargc = 0;
32 nargv[nargc++] = "git-archive";
33 nargv[nargc++] = "--format=tar";
35 if (2 <= argc && !strncmp("--remote=", argv[1], 9)) {
36 nargv[nargc++] = argv[1];
37 argv++;
38 argc--;
40 switch (argc) {
41 default:
42 usage(tar_tree_usage);
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];
54 nargv[nargc] = NULL;
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]);
63 fputc('\n', stderr);
64 return cmd_archive(nargc, nargv, prefix);
67 /* ustar header + extended global header content */
68 #define RECORDSIZE (512)
69 #define HEADERSIZE (2 * RECORDSIZE)
71 int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
73 char buffer[HEADERSIZE];
74 struct ustar_header *header = (struct ustar_header *)buffer;
75 char *content = buffer + RECORDSIZE;
76 ssize_t n;
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;
86 n = xwrite(1, content + 11, 41);
87 if (n < 41)
88 die("git-get-tar-commit-id: write error");
90 return 0;