upload-pack: no longer call rev-list
It is trivial to do now, and it is needed for the upcoming shallow clone stuff. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Johannes Schindelin committed
Oct 30, 2006 at 20:08 UTC
9b8dc263e1b0d470cc67a824837d8884ae3e7136
1 file changed
+60
-33
upload-pack.c
+60
-33
@@ -9,6 +9,9 @@
9
#include "object.h"
10
#include "commit.h"
11
#include "exec_cmd.h"
12
+#include "diff.h"
13
+#include "revision.h"
14
+#include "list-objects.h"
15
16
static const char upload_pack_usage[] = "git-upload-pack [--strict] [--timeout=nn] <dir>";
17
@@ -57,6 +60,40 @@ static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
60
return safe_write(fd, data, sz);
61
}
62
63
+FILE *pack_pipe = NULL;
64
+static void show_commit(struct commit *commit)
65
+{
66
+ if (commit->object.flags & BOUNDARY)
67
+ fputc('-', pack_pipe);
68
+ if (fputs(sha1_to_hex(commit->object.sha1), pack_pipe) < 0)
69
+ die("broken output pipe");
70
+ fputc('\n', pack_pipe);
71
+ fflush(pack_pipe);
72
+ free(commit->buffer);
73
+ commit->buffer = NULL;
74
+}
75
+
76
+static void show_object(struct object_array_entry *p)
77
+{
78
+ /* An object with name "foo\n0000000..." can be used to
79
+ * confuse downstream git-pack-objects very badly.
80
+ */
81
+ const char *ep = strchr(p->name, '\n');
82
+ if (ep) {
83
+ fprintf(pack_pipe, "%s %.*s\n", sha1_to_hex(p->item->sha1),
84
+ (int) (ep - p->name),
85
+ p->name);
86
+ }
87
+ else
88
+ fprintf(pack_pipe, "%s %s\n",
89
+ sha1_to_hex(p->item->sha1), p->name);
90
+}
91
+
92
+static void show_edge(struct commit *commit)
93
+{
94
+ fprintf(pack_pipe, "-%s\n", sha1_to_hex(commit->object.sha1));
95
+}
96
+
97
static void create_pack_file(void)
98
{
99
/* Pipes between rev-list to pack-objects, pack-objects to us
@@ -78,48 +115,38 @@ static void create_pack_file(void)
115
116
if (!pid_rev_list) {
117
int i;
81
- int args;
82
- const char **argv;
83
- const char **p;
84
- char *buf;
118
+ struct rev_info revs;
119
86
- if (create_full_pack) {
87
- args = 10;
88
- use_thin_pack = 0; /* no point doing it */
89
- }
90
- else
91
- args = have_obj.nr + want_obj.nr + 5;
92
- p = xmalloc(args * sizeof(char *));
93
- argv = (const char **) p;
94
- buf = xmalloc(args * 45);
120
+ pack_pipe = fdopen(lp_pipe[1], "w");
121
96
- dup2(lp_pipe[1], 1);
97
- close(0);
98
- close(lp_pipe[0]);
99
- close(lp_pipe[1]);
100
- *p++ = "rev-list";
101
- *p++ = use_thin_pack ? "--objects-edge" : "--objects";
122
if (create_full_pack)
103
- *p++ = "--all";
104
- else {
123
+ use_thin_pack = 0; /* no point doing it */
124
+ init_revisions(&revs, NULL);
125
+ revs.tag_objects = 1;
126
+ revs.tree_objects = 1;
127
+ revs.blob_objects = 1;
128
+ if (use_thin_pack)
129
+ revs.edge_hint = 1;
130
+
131
+ if (create_full_pack) {
132
+ const char *args[] = {"rev-list", "--all", NULL};
133
+ setup_revisions(2, args, &revs, NULL);
134
+ } else {
135
for (i = 0; i < want_obj.nr; i++) {
136
struct object *o = want_obj.objects[i].item;
107
- *p++ = buf;
108
- memcpy(buf, sha1_to_hex(o->sha1), 41);
109
- buf += 41;
137
+ add_pending_object(&revs, o, NULL);
138
}
111
- }
112
- if (!create_full_pack)
139
for (i = 0; i < have_obj.nr; i++) {
140
struct object *o = have_obj.objects[i].item;
115
- *p++ = buf;
116
- *buf++ = '^';
117
- memcpy(buf, sha1_to_hex(o->sha1), 41);
118
- buf += 41;
141
+ o->flags |= UNINTERESTING;
142
+ add_pending_object(&revs, o, NULL);
143
}
120
- *p++ = NULL;
121
- execv_git_cmd(argv);
122
- die("git-upload-pack: unable to exec git-rev-list");
144
+ setup_revisions(0, NULL, &revs, NULL);
145
+ }
146
+ prepare_revision_walk(&revs);
147
+ mark_edges_uninteresting(revs.commits, &revs, show_edge);
148
+ traverse_commit_list(&revs, show_commit, show_object);
149
+ exit(0);
150
}
151
152
if (pipe(pu_pipe) < 0)