@matheusbsbs / matheus-bagliano / commits / fd88d9c81e
Fork 0

Remove upload-tar and make git-tar-tree a thin wrapper to git-archive

The command now issues a big deprecation warning message and runs git-archive command with appropriate arguments. git-tar-tree $tree_ish $base always forces $base to be the leading directory name, so the --prefix parameter passed internally to git-archive is a slash appended to it, i.e. "--prefix=$base/". Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Sep 24, 2006 at 14:42 UTC fd88d9c81ecdefd656b01f288ed9127b7abef53e
8 files changed +53 -200
.gitignore
-1
@@ -122,7 +122,6 @@ git-update-ref
122 git-update-server-info
123 git-upload-archive
124 git-upload-pack
125 -git-upload-tar
125 git-var
126 git-verify-pack
127 git-verify-tag
Documentation/git-tar-tree.txt
+3
@@ -12,6 +12,9 @@ SYNOPSIS
12
13 DESCRIPTION
14 -----------
15 +THIS COMMAND IS DEPRECATED. Use `git-archive` with `--format=tar`
16 +option instead.
17 +
18 Creates a tar archive containing the tree structure for the named tree.
19 When <base> is specified it is added as a leading path to the files in the
20 generated tar archive.
Documentation/git-upload-tar.txt deleted
-39
@@ -1,39 +0,0 @@
1 -git-upload-tar(1)
2 -=================
3 -
4 -NAME
5 -----
6 -git-upload-tar - Send tar archive
7 -
8 -
9 -SYNOPSIS
10 ---------
11 -'git-upload-tar' <directory>
12 -
13 -DESCRIPTION
14 ------------
15 -Invoked by 'git-tar-tree --remote' and sends a generated tar archive
16 -to the other end over the git protocol.
17 -
18 -This command is usually not invoked directly by the end user.
19 -The UI for the protocol is on the 'git-tar-tree' side, and the
20 -program pair is meant to be used to get a tar archive from a
21 -remote repository.
22 -
23 -
24 -OPTIONS
25 --------
26 -<directory>::
27 - The repository to get a tar archive from.
28 -
29 -Author
30 -------
31 -Written by Junio C Hamano <junio@kernel.org>
32 -
33 -Documentation
34 ---------------
35 -Documentation by Junio C Hamano.
36 -
37 -GIT
38 ----
39 -Part of the gitlink:git[7] suite
Documentation/git.txt
-4
@@ -247,10 +247,6 @@ gitlink:git-upload-pack[1]::
247 Invoked by 'git-fetch-pack' to push
248 what are asked for.
249
250 -gitlink:git-upload-tar[1]::
251 - Invoked by 'git-tar-tree --remote' to return the tar
252 - archive the other end asked for.
253 -
250
251 High-level commands (porcelain)
252 -------------------------------
Makefile
-1
@@ -300,7 +300,6 @@ BUILTIN_OBJS = \
300 builtin-update-index.o \
301 builtin-update-ref.o \
302 builtin-upload-archive.o \
303 - builtin-upload-tar.o \
303 builtin-verify-pack.o \
304 builtin-write-tree.o
305
builtin-tar-tree.c
+50 -80
@@ -6,96 +6,66 @@
6 #include "commit.h"
7 #include "tar.h"
8 #include "builtin.h"
9 -#include "pkt-line.h"
10 -#include "archive.h"
11 -
12 -#define RECORDSIZE (512)
13 -#define BLOCKSIZE (RECORDSIZE * 20)
9 +#include "quote.h"
10
11 static const char tar_tree_usage[] =
16 -"git-tar-tree [--remote=<repo>] <tree-ish> [basedir]";
12 +"git-tar-tree [--remote=<repo>] <tree-ish> [basedir]\n"
13 +"*** Note that this command is now deprecated; use git-archive instead.";
14
18 -static int generate_tar(int argc, const char **argv, const char *prefix)
15 +int cmd_tar_tree(int argc, const char **argv, const char *prefix)
16 {
20 - struct archiver_args args;
21 - int result;
22 - char *base = NULL;
23 -
24 - memset(&args, 0, sizeof(args));
25 - if (argc != 2 && argc != 3)
26 - usage(tar_tree_usage);
27 - if (argc == 3) {
28 - int baselen = strlen(argv[2]);
29 - base = xmalloc(baselen + 2);
30 - memcpy(base, argv[2], baselen);
31 - base[baselen] = '/';
32 - base[baselen + 1] = '\0';
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--;
39 }
34 - args.base = base;
35 - parse_treeish_arg(argv + 1, &args, NULL);
36 -
37 - result = write_tar_archive(&args);
38 - free(base);
39 -
40 - return result;
41 -}
42 -
43 -static const char *exec = "git-upload-tar";
44 -
45 -static int remote_tar(int argc, const char **argv)
46 -{
47 - int fd[2], ret, len;
48 - pid_t pid;
49 - char buf[1024];
50 - char *url;
51 -
52 - if (argc < 3 || 4 < argc)
40 + switch (argc) {
41 + default:
42 usage(tar_tree_usage);
54 -
55 - /* --remote=<repo> */
56 - url = xstrdup(argv[1]+9);
57 - pid = git_connect(fd, url, exec);
58 - if (pid < 0)
59 - return 1;
60 -
61 - packet_write(fd[1], "want %s\n", argv[2]);
62 - if (argv[3])
63 - packet_write(fd[1], "base %s\n", argv[3]);
64 - packet_flush(fd[1]);
65 -
66 - len = packet_read_line(fd[0], buf, sizeof(buf));
67 - if (!len)
68 - die("git-tar-tree: expected ACK/NAK, got EOF");
69 - if (buf[len-1] == '\n')
70 - buf[--len] = 0;
71 - if (strcmp(buf, "ACK")) {
72 - if (5 < len && !strncmp(buf, "NACK ", 5))
73 - die("git-tar-tree: NACK %s", buf + 5);
74 - die("git-tar-tree: protocol error");
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];
53 }
76 - /* expect a flush */
77 - len = packet_read_line(fd[0], buf, sizeof(buf));
78 - if (len)
79 - die("git-tar-tree: expected a flush");
80 -
81 - /* Now, start reading from fd[0] and spit it out to stdout */
82 - ret = copy_fd(fd[0], 1);
83 - close(fd[0]);
84 -
85 - ret |= finish_connect(pid);
86 - return !!ret;
87 -}
88 -
89 -int cmd_tar_tree(int argc, const char **argv, const char *prefix)
90 -{
91 - if (argc < 2)
92 - usage(tar_tree_usage);
93 - if (!strncmp("--remote=", argv[1], 9))
94 - return remote_tar(argc, argv);
95 - return generate_tar(argc, argv, prefix);
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);
65 }
66
67 /* ustar header + extended global header content */
68 +#define RECORDSIZE (512)
69 #define HEADERSIZE (2 * RECORDSIZE)
70
71 int cmd_get_tar_commit_id(int argc, const char **argv, const char *prefix)
builtin-upload-tar.c deleted
-74
@@ -1,74 +0,0 @@
1 -/*
2 - * Copyright (c) 2006 Junio C Hamano
3 - */
4 -#include "cache.h"
5 -#include "pkt-line.h"
6 -#include "exec_cmd.h"
7 -#include "builtin.h"
8 -
9 -static const char upload_tar_usage[] = "git-upload-tar <repo>";
10 -
11 -static int nak(const char *reason)
12 -{
13 - packet_write(1, "NACK %s\n", reason);
14 - packet_flush(1);
15 - return 1;
16 -}
17 -
18 -int cmd_upload_tar(int argc, const char **argv, const char *prefix)
19 -{
20 - int len;
21 - const char *dir = argv[1];
22 - char buf[8192];
23 - unsigned char sha1[20];
24 - char *base = NULL;
25 - char hex[41];
26 - int ac;
27 - const char *av[4];
28 -
29 - if (argc != 2)
30 - usage(upload_tar_usage);
31 - if (strlen(dir) < sizeof(buf)-1)
32 - strcpy(buf, dir); /* enter-repo smudges its argument */
33 - else
34 - packet_write(1, "NACK insanely long repository name %s\n", dir);
35 - if (!enter_repo(buf, 0)) {
36 - packet_write(1, "NACK not a git archive %s\n", dir);
37 - packet_flush(1);
38 - return 1;
39 - }
40 -
41 - len = packet_read_line(0, buf, sizeof(buf));
42 - if (len < 5 || strncmp("want ", buf, 5))
43 - return nak("expected want");
44 - if (buf[len-1] == '\n')
45 - buf[--len] = 0;
46 - if (get_sha1(buf + 5, sha1))
47 - return nak("expected sha1");
48 - strcpy(hex, sha1_to_hex(sha1));
49 -
50 - len = packet_read_line(0, buf, sizeof(buf));
51 - if (len) {
52 - if (len < 5 || strncmp("base ", buf, 5))
53 - return nak("expected (optional) base");
54 - if (buf[len-1] == '\n')
55 - buf[--len] = 0;
56 - base = xstrdup(buf + 5);
57 - len = packet_read_line(0, buf, sizeof(buf));
58 - }
59 - if (len)
60 - return nak("expected flush");
61 -
62 - packet_write(1, "ACK\n");
63 - packet_flush(1);
64 -
65 - ac = 0;
66 - av[ac++] = "tar-tree";
67 - av[ac++] = hex;
68 - if (base)
69 - av[ac++] = base;
70 - av[ac++] = NULL;
71 - execv_git_cmd(av);
72 - /* should it return that is an error */
73 - return 1;
74 -}
git.c
-1
@@ -263,7 +263,6 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
263 { "update-index", cmd_update_index, RUN_SETUP },
264 { "update-ref", cmd_update_ref, RUN_SETUP },
265 { "upload-archive", cmd_upload_archive },
266 - { "upload-tar", cmd_upload_tar },
266 { "version", cmd_version },
267 { "whatchanged", cmd_whatchanged, RUN_SETUP | USE_PAGER },
268 { "write-tree", cmd_write_tree, RUN_SETUP },