Add git-upload-archive
This command implements the git archive protocol on the server side. This command is not intended to be used by the end user. Underlying git-archive command line options are sent over the protocol from "git-archive --remote=...", just like upload-tar currently does with "git-tar-tree=...". As for "git-archive" command implementation, this new command does not execute any existing "git-{tar,zip}-tree" but rely on the archive API defined by "git-archive" patch. Hence we get 2 good points: - "git-archive" and "git-upload-archive" share all option parsing code. - All kind of git-upload-{tar,zip} can be deprecated. Signed-off-by: Franck Bui-Huu <vagabon.xyz@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Franck Bui-Huu committed
Sep 7, 2006 at 15:12 UTC
39345a216ff37bda9fb7cec85f6de44069f5205d
7 files changed
+120
.gitignore
+1
@@ -119,6 +119,7 @@ git-unpack-objects
119
git-update-index
120
git-update-ref
121
git-update-server-info
122
+git-upload-archive
123
git-upload-pack
124
git-upload-tar
125
git-var
Documentation/git-upload-archive.txt
new
+37
@@ -0,0 +1,37 @@
1
+git-upload-archive(1)
2
+====================
3
+
4
+NAME
5
+----
6
+git-upload-archive - Send archive
7
+
8
+
9
+SYNOPSIS
10
+--------
11
+'git-upload-archive' <directory>
12
+
13
+DESCRIPTION
14
+-----------
15
+Invoked by 'git-archive --remote' and sends a generated archive to the
16
+other end over the git protocol.
17
+
18
+This command is usually not invoked directly by the end user. The UI
19
+for the protocol is on the 'git-archive' side, and the program pair
20
+is meant to be used to get an archive from a remote repository.
21
+
22
+OPTIONS
23
+-------
24
+<directory>::
25
+ The repository to get a tar archive from.
26
+
27
+Author
28
+------
29
+Written by Franck Bui-Huu.
30
+
31
+Documentation
32
+--------------
33
+Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
34
+
35
+GIT
36
+---
37
+Part of the gitlink:git[7] suite
Makefile
+1
@@ -293,6 +293,7 @@ BUILTIN_OBJS = \
293
builtin-unpack-objects.o \
294
builtin-update-index.o \
295
builtin-update-ref.o \
296
+ builtin-upload-archive.o \
297
builtin-upload-tar.o \
298
builtin-verify-pack.o \
299
builtin-write-tree.o \
builtin-upload-archive.c
new
+72
@@ -0,0 +1,72 @@
1
+/*
2
+ * Copyright (c) 2006 Franck Bui-Huu
3
+ */
4
+#include <time.h>
5
+#include "cache.h"
6
+#include "builtin.h"
7
+#include "archive.h"
8
+#include "pkt-line.h"
9
+
10
+static const char upload_archive_usage[] =
11
+ "git-upload-archive <repo>";
12
+
13
+
14
+int cmd_upload_archive(int argc, const char **argv, const char *prefix)
15
+{
16
+ struct archiver ar;
17
+ const char *sent_argv[MAX_ARGS];
18
+ const char *arg_cmd = "argument ";
19
+ char *p, buf[4096];
20
+ int treeish_idx;
21
+ int sent_argc;
22
+ int len;
23
+
24
+ if (argc != 2)
25
+ usage(upload_archive_usage);
26
+
27
+ if (strlen(argv[1]) > sizeof(buf))
28
+ die("insanely long repository name");
29
+
30
+ strcpy(buf, argv[1]); /* enter-repo smudges its argument */
31
+
32
+ if (!enter_repo(buf, 0))
33
+ die("not a git archive");
34
+
35
+ /* put received options in sent_argv[] */
36
+ sent_argc = 1;
37
+ sent_argv[0] = "git-upload-archive";
38
+ for (p = buf;;) {
39
+ /* This will die if not enough free space in buf */
40
+ len = packet_read_line(0, p, (buf + sizeof buf) - p);
41
+ if (len == 0)
42
+ break; /* got a flush */
43
+ if (sent_argc > MAX_ARGS - 2)
44
+ die("Too many options (>29)");
45
+
46
+ if (p[len-1] == '\n') {
47
+ p[--len] = 0;
48
+ }
49
+ if (len < strlen(arg_cmd) ||
50
+ strncmp(arg_cmd, p, strlen(arg_cmd)))
51
+ die("'argument' token or flush expected");
52
+
53
+ len -= strlen(arg_cmd);
54
+ memmove(p, p + strlen(arg_cmd), len);
55
+ sent_argv[sent_argc++] = p;
56
+ p += len;
57
+ *p++ = 0;
58
+ }
59
+ sent_argv[sent_argc] = NULL;
60
+
61
+ /* parse all options sent by the client */
62
+ treeish_idx = parse_archive_args(sent_argc, sent_argv, &ar);
63
+
64
+ parse_treeish_arg(sent_argv + treeish_idx, &ar.args, prefix);
65
+ parse_pathspec_arg(sent_argv + treeish_idx + 1, &ar.args);
66
+
67
+ packet_write(1, "ACK\n");
68
+ packet_flush(1);
69
+
70
+ return ar.write_archive(&ar.args);
71
+}
72
+
builtin.h
+1
@@ -57,6 +57,7 @@ extern int cmd_zip_tree(int argc, const char **argv, const char *prefix);
57
extern int cmd_unpack_objects(int argc, const char **argv, const char *prefix);
58
extern int cmd_update_index(int argc, const char **argv, const char *prefix);
59
extern int cmd_update_ref(int argc, const char **argv, const char *prefix);
60
+extern int cmd_upload_archive(int argc, const char **argv, const char *prefix);
61
extern int cmd_upload_tar(int argc, const char **argv, const char *prefix);
62
extern int cmd_version(int argc, const char **argv, const char *prefix);
63
extern int cmd_whatchanged(int argc, const char **argv, const char *prefix);
daemon.c
+7
@@ -325,7 +325,14 @@ static int upload_pack(void)
325
return -1;
326
}
327
328
+static int upload_archive(void)
329
+{
330
+ execl_git_cmd("upload-archive", ".", NULL);
331
+ return -1;
332
+}
333
+
334
static struct daemon_service daemon_service[] = {
335
+ { "upload-archive", "uploadarch", upload_archive, 0, 1 },
336
{ "upload-pack", "uploadpack", upload_pack, 1, 1 },
337
};
338
git.c
+1
@@ -262,6 +262,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp)
262
{ "unpack-objects", cmd_unpack_objects, RUN_SETUP },
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 },
267
{ "version", cmd_version },
268
{ "whatchanged", cmd_whatchanged, RUN_SETUP | USE_PAGER },