blob: c989a737f975b3aef41ffb9f6ec669ce3b2f2c2b [file] [log] [blame]
Linus Torvaldsdef88e92005-07-04 13:26:53 -07001#include "cache.h"
2#include "refs.h"
3#include "pkt-line.h"
Junio C Hamano958c24b2006-09-10 03:20:24 -07004#include "sideband.h"
Junio C Hamanof6b42a82005-10-13 18:57:40 -07005#include "tag.h"
6#include "object.h"
Johannes Schindelinf0243f22005-10-28 04:48:32 +02007#include "commit.h"
Michal Ostrowski77cb17e2006-01-10 21:12:17 -05008#include "exec_cmd.h"
Johannes Schindelin9b8dc262006-10-30 20:08:43 +01009#include "diff.h"
10#include "revision.h"
11#include "list-objects.h"
Johannes Sixtcc41fa82007-10-19 21:47:59 +020012#include "run-command.h"
Junio C Hamano47a59182013-07-08 13:56:53 -070013#include "connect.h"
Junio C Hamano051e4002011-08-05 13:54:06 -070014#include "sigchain.h"
Jeff Kingff5effd2012-08-03 12:19:16 -040015#include "version.h"
Junio C Hamanodaebaa72013-01-18 16:08:30 -080016#include "string-list.h"
Linus Torvaldsdef88e92005-07-04 13:26:53 -070017
Štěpán Němec62b46982010-10-08 19:31:15 +020018static const char upload_pack_usage[] = "git upload-pack [--strict] [--timeout=<n>] <dir>";
Linus Torvaldsdef88e92005-07-04 13:26:53 -070019
Junio C Hamano937a5152006-07-05 21:28:20 -070020/* bits #0..7 in revision.h, #8..10 in commit.c */
21#define THEY_HAVE (1u << 11)
22#define OUR_REF (1u << 12)
23#define WANTED (1u << 13)
24#define COMMON_KNOWN (1u << 14)
25#define REACHABLE (1u << 15)
26
Johannes Schindelinf53514b2006-10-30 20:09:53 +010027#define SHALLOW (1u << 16)
28#define NOT_SHALLOW (1u << 17)
29#define CLIENT_SHALLOW (1u << 18)
Junio C Hamano390eb362013-01-28 21:49:57 -080030#define HIDDEN_REF (1u << 19)
Johannes Schindelinf53514b2006-10-30 20:09:53 +010031
Junio C Hamano3fbe2d52006-11-24 02:34:27 -080032static unsigned long oldest_have;
Junio C Hamano937a5152006-07-05 21:28:20 -070033
Junio C Hamano3f1da572013-01-28 20:45:43 -080034static int multi_ack;
Junio C Hamano4e10cf92011-03-29 12:29:10 -070035static int no_done;
Shawn O. Pearce348e3902008-03-03 22:27:33 -050036static int use_thin_pack, use_ofs_delta, use_include_tag;
Johannes Sixt9462e3f2009-06-16 20:41:16 +020037static int no_progress, daemon_mode;
Junio C Hamano390eb362013-01-28 21:49:57 -080038static int allow_tip_sha1_in_want;
Nick Edelenf0cea832009-06-10 01:50:18 +020039static int shallow_nr;
Junio C Hamanob1e9fff2006-07-05 18:00:02 -070040static struct object_array have_obj;
41static struct object_array want_obj;
Nicolas Pitre65230782009-09-03 19:08:33 -040042static struct object_array extra_edge_obj;
David Rientjes96f1e582006-08-15 10:23:48 -070043static unsigned int timeout;
Jeff King115dedd2013-09-08 05:02:06 -040044static int keepalive = 5;
Junio C Hamanod47f3db2006-09-10 16:27:08 -070045/* 0 for no sideband,
46 * otherwise maximum packet size (up to 65520 bytes).
47 */
David Rientjes96f1e582006-08-15 10:23:48 -070048static int use_sideband;
Shawn O. Pearce42526b42009-10-30 17:47:33 -070049static int advertise_refs;
50static int stateless_rpc;
H. Peter Anvin960decc2005-10-19 14:27:01 -070051
52static void reset_timeout(void)
53{
54 alarm(timeout);
55}
Linus Torvaldsfb9040c2005-07-04 15:29:17 -070056
Junio C Hamano583b7ea2006-06-21 00:30:21 -070057static ssize_t send_client_data(int fd, const char *data, ssize_t sz)
58{
Junio C Hamano958c24b2006-09-10 03:20:24 -070059 if (use_sideband)
Junio C Hamanod47f3db2006-09-10 16:27:08 -070060 return send_sideband(1, fd, data, sz, use_sideband);
Junio C Hamano958c24b2006-09-10 03:20:24 -070061 if (fd == 3)
62 /* emergency quit */
63 fd = 2;
64 if (fd == 2) {
Andy Whitcroft93822c22007-01-08 15:58:23 +000065 /* XXX: are we happy to lose stuff here? */
Junio C Hamano958c24b2006-09-10 03:20:24 -070066 xwrite(fd, data, sz);
67 return sz;
Junio C Hamano583b7ea2006-06-21 00:30:21 -070068 }
Jeff Kingcdf4fb82013-02-20 15:01:56 -050069 write_or_die(fd, data, sz);
70 return sz;
Junio C Hamano583b7ea2006-06-21 00:30:21 -070071}
72
Linus Torvaldsfb9040c2005-07-04 15:29:17 -070073static void create_pack_file(void)
74{
Johannes Sixtcc41fa82007-10-19 21:47:59 +020075 struct child_process pack_objects;
Junio C Hamano363b7812006-06-20 22:48:23 -070076 char data[8193], progress[128];
Junio C Hamano583b7ea2006-06-21 00:30:21 -070077 char abort_msg[] = "aborting due to possible repository "
78 "corruption on the remote side.";
Junio C Hamanob1c71b72006-06-20 18:26:34 -070079 int buffered = -1;
Junio C Hamano1456b042009-12-10 12:17:11 -080080 ssize_t sz;
Nguyễn Thái Ngọc Duycdab4852013-08-16 16:52:05 +070081 const char *argv[12];
82 int i, arg = 0;
83 FILE *pipe_fd;
84 char *shallow_file = NULL;
Linus Torvalds75bfc6c2005-07-04 16:35:13 -070085
Nguyễn Thái Ngọc Duycdab4852013-08-16 16:52:05 +070086 if (shallow_nr) {
87 shallow_file = setup_temporary_shallow();
88 argv[arg++] = "--shallow-file";
89 argv[arg++] = shallow_file;
Nick Edelenf0cea832009-06-10 01:50:18 +020090 }
Nguyễn Thái Ngọc Duycdab4852013-08-16 16:52:05 +070091 argv[arg++] = "pack-objects";
92 argv[arg++] = "--revs";
93 if (use_thin_pack)
94 argv[arg++] = "--thin";
Linus Torvalds75bfc6c2005-07-04 16:35:13 -070095
Johannes Sixtcc41fa82007-10-19 21:47:59 +020096 argv[arg++] = "--stdout";
97 if (!no_progress)
98 argv[arg++] = "--progress";
99 if (use_ofs_delta)
100 argv[arg++] = "--delta-base-offset";
Shawn O. Pearce348e3902008-03-03 22:27:33 -0500101 if (use_include_tag)
102 argv[arg++] = "--include-tag";
Johannes Sixtcc41fa82007-10-19 21:47:59 +0200103 argv[arg++] = NULL;
104
105 memset(&pack_objects, 0, sizeof(pack_objects));
Jeff Kingb9612192011-04-06 17:33:33 -0400106 pack_objects.in = -1;
Johannes Sixtcc41fa82007-10-19 21:47:59 +0200107 pack_objects.out = -1;
108 pack_objects.err = -1;
109 pack_objects.git_cmd = 1;
110 pack_objects.argv = argv;
Johannes Sixt21edd3f2007-10-19 21:48:03 +0200111
Johannes Sixt4c324c02007-11-04 20:46:48 +0100112 if (start_command(&pack_objects))
Junio C Hamano7e44c932008-08-31 09:39:19 -0700113 die("git upload-pack: unable to fork git-pack-objects");
Johannes Schindelin83a5ad62007-02-20 03:01:44 +0100114
Nguyễn Thái Ngọc Duycdab4852013-08-16 16:52:05 +0700115 pipe_fd = xfdopen(pack_objects.in, "w");
Nick Edelenf0cea832009-06-10 01:50:18 +0200116
Nguyễn Thái Ngọc Duycdab4852013-08-16 16:52:05 +0700117 for (i = 0; i < want_obj.nr; i++)
118 fprintf(pipe_fd, "%s\n",
119 sha1_to_hex(want_obj.objects[i].item->sha1));
120 fprintf(pipe_fd, "--not\n");
121 for (i = 0; i < have_obj.nr; i++)
122 fprintf(pipe_fd, "%s\n",
123 sha1_to_hex(have_obj.objects[i].item->sha1));
124 for (i = 0; i < extra_edge_obj.nr; i++)
125 fprintf(pipe_fd, "%s\n",
126 sha1_to_hex(extra_edge_obj.objects[i].item->sha1));
127 fprintf(pipe_fd, "\n");
128 fflush(pipe_fd);
129 fclose(pipe_fd);
Nick Edelenf0cea832009-06-10 01:50:18 +0200130
Johannes Sixtcc41fa82007-10-19 21:47:59 +0200131 /* We read from pack_objects.err to capture stderr output for
132 * progress bar, and pack_objects.out to capture the pack data.
Junio C Hamanob1c71b72006-06-20 18:26:34 -0700133 */
Junio C Hamanob1c71b72006-06-20 18:26:34 -0700134
135 while (1) {
Junio C Hamanob1c71b72006-06-20 18:26:34 -0700136 struct pollfd pfd[2];
Junio C Hamano363b7812006-06-20 22:48:23 -0700137 int pe, pu, pollsize;
Jeff King05e95152013-09-08 05:01:31 -0400138 int ret;
Junio C Hamanob1c71b72006-06-20 18:26:34 -0700139
Matthias Lederhofer0d516ad2006-07-18 19:14:51 +0200140 reset_timeout();
141
Junio C Hamanob1c71b72006-06-20 18:26:34 -0700142 pollsize = 0;
Junio C Hamano363b7812006-06-20 22:48:23 -0700143 pe = pu = -1;
Junio C Hamanob1c71b72006-06-20 18:26:34 -0700144
Johannes Sixtcc41fa82007-10-19 21:47:59 +0200145 if (0 <= pack_objects.out) {
146 pfd[pollsize].fd = pack_objects.out;
Junio C Hamanob1c71b72006-06-20 18:26:34 -0700147 pfd[pollsize].events = POLLIN;
148 pu = pollsize;
149 pollsize++;
150 }
Johannes Sixtcc41fa82007-10-19 21:47:59 +0200151 if (0 <= pack_objects.err) {
152 pfd[pollsize].fd = pack_objects.err;
Junio C Hamano363b7812006-06-20 22:48:23 -0700153 pfd[pollsize].events = POLLIN;
154 pe = pollsize;
155 pollsize++;
156 }
Junio C Hamanob1c71b72006-06-20 18:26:34 -0700157
Johannes Sixt4c324c02007-11-04 20:46:48 +0100158 if (!pollsize)
159 break;
Junio C Hamanob1c71b72006-06-20 18:26:34 -0700160
Jeff King05e95152013-09-08 05:01:31 -0400161 ret = poll(pfd, pollsize, 1000 * keepalive);
162 if (ret < 0) {
Johannes Sixt4c324c02007-11-04 20:46:48 +0100163 if (errno != EINTR) {
164 error("poll failed, resuming: %s",
165 strerror(errno));
166 sleep(1);
Junio C Hamanob1c71b72006-06-20 18:26:34 -0700167 }
Junio C Hamanob1c71b72006-06-20 18:26:34 -0700168 continue;
Johannes Sixt4c324c02007-11-04 20:46:48 +0100169 }
Nicolas Pitre6b59f512009-11-11 17:24:42 -0500170 if (0 <= pe && (pfd[pe].revents & (POLLIN|POLLHUP))) {
171 /* Status ready; we ship that in the side-band
172 * or dump to the standard error.
173 */
174 sz = xread(pack_objects.err, progress,
175 sizeof(progress));
176 if (0 < sz)
177 send_client_data(2, progress, sz);
178 else if (sz == 0) {
179 close(pack_objects.err);
180 pack_objects.err = -1;
181 }
182 else
183 goto fail;
184 /* give priority to status messages */
185 continue;
186 }
Johannes Sixt4c324c02007-11-04 20:46:48 +0100187 if (0 <= pu && (pfd[pu].revents & (POLLIN|POLLHUP))) {
188 /* Data ready; we keep the last byte to ourselves
189 * in case we detect broken rev-list, so that we
190 * can leave the stream corrupted. This is
191 * unfortunate -- unpack-objects would happily
192 * accept a valid packdata with trailing garbage,
193 * so appending garbage after we pass all the
194 * pack data is not good enough to signal
195 * breakage to downstream.
196 */
197 char *cp = data;
198 ssize_t outsz = 0;
199 if (0 <= buffered) {
200 *cp++ = buffered;
201 outsz++;
202 }
203 sz = xread(pack_objects.out, cp,
204 sizeof(data) - outsz);
205 if (0 < sz)
Junio C Hamano1456b042009-12-10 12:17:11 -0800206 ;
Johannes Sixt4c324c02007-11-04 20:46:48 +0100207 else if (sz == 0) {
208 close(pack_objects.out);
209 pack_objects.out = -1;
210 }
211 else
212 goto fail;
213 sz += outsz;
214 if (1 < sz) {
215 buffered = data[sz-1] & 0xFF;
216 sz--;
217 }
218 else
219 buffered = -1;
220 sz = send_client_data(1, data, sz);
Junio C Hamanob1c71b72006-06-20 18:26:34 -0700221 if (sz < 0)
222 goto fail;
Junio C Hamanob1c71b72006-06-20 18:26:34 -0700223 }
Jeff King05e95152013-09-08 05:01:31 -0400224
225 /*
226 * We hit the keepalive timeout without saying anything; send
227 * an empty message on the data sideband just to let the other
228 * side know we're still working on it, but don't have any data
229 * yet.
230 *
231 * If we don't have a sideband channel, there's no room in the
232 * protocol to say anything, so those clients are just out of
233 * luck.
234 */
235 if (!ret && use_sideband) {
236 static const char buf[] = "0005\1";
237 write_or_die(1, buf, 5);
238 }
Junio C Hamanob1c71b72006-06-20 18:26:34 -0700239 }
Johannes Sixt4c324c02007-11-04 20:46:48 +0100240
241 if (finish_command(&pack_objects)) {
Junio C Hamano7e44c932008-08-31 09:39:19 -0700242 error("git upload-pack: git-pack-objects died with error.");
Johannes Sixt4c324c02007-11-04 20:46:48 +0100243 goto fail;
244 }
Nguyễn Thái Ngọc Duycdab4852013-08-16 16:52:05 +0700245 if (shallow_file) {
246 if (*shallow_file)
247 unlink(shallow_file);
248 free(shallow_file);
249 }
Johannes Sixt4c324c02007-11-04 20:46:48 +0100250
251 /* flush the data */
252 if (0 <= buffered) {
253 data[0] = buffered;
254 sz = send_client_data(1, data, 1);
255 if (sz < 0)
256 goto fail;
257 fprintf(stderr, "flushed.\n");
258 }
259 if (use_sideband)
260 packet_flush(1);
261 return;
262
Junio C Hamanob1c71b72006-06-20 18:26:34 -0700263 fail:
Junio C Hamano583b7ea2006-06-21 00:30:21 -0700264 send_client_data(3, abort_msg, sizeof(abort_msg));
Junio C Hamano7e44c932008-08-31 09:39:19 -0700265 die("git upload-pack: %s", abort_msg);
Linus Torvaldsfb9040c2005-07-04 15:29:17 -0700266}
267
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700268static int got_sha1(char *hex, unsigned char *sha1)
269{
Junio C Hamanob1e9fff2006-07-05 18:00:02 -0700270 struct object *o;
Junio C Hamano937a5152006-07-05 21:28:20 -0700271 int we_knew_they_have = 0;
Junio C Hamanob1e9fff2006-07-05 18:00:02 -0700272
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700273 if (get_sha1_hex(hex, sha1))
Junio C Hamano7e44c932008-08-31 09:39:19 -0700274 die("git upload-pack: expected SHA1 object, got '%s'", hex);
Linus Torvaldsfb9040c2005-07-04 15:29:17 -0700275 if (!has_sha1_file(sha1))
Junio C Hamano937a5152006-07-05 21:28:20 -0700276 return -1;
Junio C Hamanob1e9fff2006-07-05 18:00:02 -0700277
Jeff Kinga6eec122013-03-16 06:25:25 -0400278 o = parse_object(sha1);
Junio C Hamanob1e9fff2006-07-05 18:00:02 -0700279 if (!o)
280 die("oops (%s)", sha1_to_hex(sha1));
Junio C Hamano182a8da2006-08-12 22:16:51 -0700281 if (o->type == OBJ_COMMIT) {
Junio C Hamanob1e9fff2006-07-05 18:00:02 -0700282 struct commit_list *parents;
Junio C Hamano937a5152006-07-05 21:28:20 -0700283 struct commit *commit = (struct commit *)o;
Junio C Hamanob1e9fff2006-07-05 18:00:02 -0700284 if (o->flags & THEY_HAVE)
Junio C Hamano937a5152006-07-05 21:28:20 -0700285 we_knew_they_have = 1;
286 else
287 o->flags |= THEY_HAVE;
288 if (!oldest_have || (commit->date < oldest_have))
289 oldest_have = commit->date;
290 for (parents = commit->parents;
Junio C Hamanob1e9fff2006-07-05 18:00:02 -0700291 parents;
292 parents = parents->next)
293 parents->item->object.flags |= THEY_HAVE;
Linus Torvaldsfb9040c2005-07-04 15:29:17 -0700294 }
Junio C Hamano937a5152006-07-05 21:28:20 -0700295 if (!we_knew_they_have) {
296 add_object_array(o, NULL, &have_obj);
297 return 1;
298 }
299 return 0;
300}
301
302static int reachable(struct commit *want)
303{
304 struct commit_list *work = NULL;
305
Thiago Farina47e44ed2010-11-26 23:58:14 -0200306 commit_list_insert_by_date(want, &work);
Junio C Hamano937a5152006-07-05 21:28:20 -0700307 while (work) {
308 struct commit_list *list = work->next;
309 struct commit *commit = work->item;
310 free(work);
311 work = list;
312
313 if (commit->object.flags & THEY_HAVE) {
314 want->object.flags |= COMMON_KNOWN;
315 break;
316 }
317 if (!commit->object.parsed)
318 parse_object(commit->object.sha1);
319 if (commit->object.flags & REACHABLE)
320 continue;
321 commit->object.flags |= REACHABLE;
322 if (commit->date < oldest_have)
323 continue;
324 for (list = commit->parents; list; list = list->next) {
325 struct commit *parent = list->item;
326 if (!(parent->object.flags & REACHABLE))
Thiago Farina47e44ed2010-11-26 23:58:14 -0200327 commit_list_insert_by_date(parent, &work);
Junio C Hamano937a5152006-07-05 21:28:20 -0700328 }
329 }
330 want->object.flags |= REACHABLE;
331 clear_commit_marks(want, REACHABLE);
332 free_commit_list(work);
333 return (want->object.flags & COMMON_KNOWN);
334}
335
336static int ok_to_give_up(void)
337{
338 int i;
339
340 if (!have_obj.nr)
341 return 0;
342
343 for (i = 0; i < want_obj.nr; i++) {
344 struct object *want = want_obj.objects[i].item;
345
346 if (want->flags & COMMON_KNOWN)
347 continue;
348 want = deref_tag(want, "a want line", 0);
349 if (!want || want->type != OBJ_COMMIT) {
350 /* no way to tell if this is reachable by
351 * looking at the ancestry chain alone, so
352 * leave a note to ourselves not to worry about
353 * this object anymore.
354 */
355 want_obj.objects[i].item->flags |= COMMON_KNOWN;
356 continue;
357 }
358 if (!reachable((struct commit *)want))
359 return 0;
360 }
Linus Torvaldsfb9040c2005-07-04 15:29:17 -0700361 return 1;
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700362}
363
364static int get_common_commits(void)
365{
Junio C Hamanoc04c4e52006-07-05 18:12:12 -0700366 unsigned char sha1[20];
Shawn O. Pearce78affc42009-10-30 17:47:25 -0700367 char last_hex[41];
Shawn O. Pearce49bee712011-03-14 16:48:39 -0700368 int got_common = 0;
369 int got_other = 0;
Junio C Hamano4e10cf92011-03-29 12:29:10 -0700370 int sent_ready = 0;
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700371
Johannes Schindelinf0243f22005-10-28 04:48:32 +0200372 save_commit_buffer = 0;
373
Brian Gianforcaroeeefa7c2009-09-01 01:35:10 -0400374 for (;;) {
Jeff King74543a02013-02-20 15:02:57 -0500375 char *line = packet_read_line(0, NULL);
H. Peter Anvin960decc2005-10-19 14:27:01 -0700376 reset_timeout();
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700377
Jeff King74543a02013-02-20 15:02:57 -0500378 if (!line) {
Shawn O. Pearce49bee712011-03-14 16:48:39 -0700379 if (multi_ack == 2 && got_common
Junio C Hamano4e10cf92011-03-29 12:29:10 -0700380 && !got_other && ok_to_give_up()) {
381 sent_ready = 1;
Shawn O. Pearce49bee712011-03-14 16:48:39 -0700382 packet_write(1, "ACK %s ready\n", last_hex);
Junio C Hamano4e10cf92011-03-29 12:29:10 -0700383 }
Junio C Hamanob1e9fff2006-07-05 18:00:02 -0700384 if (have_obj.nr == 0 || multi_ack)
Johannes Schindelin1bd8c8f2005-10-28 04:49:16 +0200385 packet_write(1, "NAK\n");
Junio C Hamano4e10cf92011-03-29 12:29:10 -0700386
387 if (no_done && sent_ready) {
388 packet_write(1, "ACK %s\n", last_hex);
389 return 0;
390 }
Shawn O. Pearce42526b42009-10-30 17:47:33 -0700391 if (stateless_rpc)
392 exit(0);
Shawn O. Pearce49bee712011-03-14 16:48:39 -0700393 got_common = 0;
394 got_other = 0;
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700395 continue;
396 }
Junio C Hamanocc44c762007-02-20 01:53:29 -0800397 if (!prefixcmp(line, "have ")) {
Junio C Hamano937a5152006-07-05 21:28:20 -0700398 switch (got_sha1(line+5, sha1)) {
399 case -1: /* they have what we do not */
Shawn O. Pearce49bee712011-03-14 16:48:39 -0700400 got_other = 1;
Shawn O. Pearce78affc42009-10-30 17:47:25 -0700401 if (multi_ack && ok_to_give_up()) {
402 const char *hex = sha1_to_hex(sha1);
Junio C Hamano4e10cf92011-03-29 12:29:10 -0700403 if (multi_ack == 2) {
404 sent_ready = 1;
Shawn O. Pearce78affc42009-10-30 17:47:25 -0700405 packet_write(1, "ACK %s ready\n", hex);
Junio C Hamano4e10cf92011-03-29 12:29:10 -0700406 } else
Shawn O. Pearce78affc42009-10-30 17:47:25 -0700407 packet_write(1, "ACK %s continue\n", hex);
408 }
Junio C Hamano937a5152006-07-05 21:28:20 -0700409 break;
410 default:
Shawn O. Pearce49bee712011-03-14 16:48:39 -0700411 got_common = 1;
Shawn O. Pearce78affc42009-10-30 17:47:25 -0700412 memcpy(last_hex, sha1_to_hex(sha1), 41);
413 if (multi_ack == 2)
414 packet_write(1, "ACK %s common\n", last_hex);
415 else if (multi_ack)
416 packet_write(1, "ACK %s continue\n", last_hex);
Junio C Hamanoc04c4e52006-07-05 18:12:12 -0700417 else if (have_obj.nr == 1)
Shawn O. Pearce78affc42009-10-30 17:47:25 -0700418 packet_write(1, "ACK %s\n", last_hex);
Junio C Hamano937a5152006-07-05 21:28:20 -0700419 break;
Junio C Hamanoaf2d3aa2005-10-25 14:55:24 -0700420 }
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700421 continue;
422 }
423 if (!strcmp(line, "done")) {
Junio C Hamanob1e9fff2006-07-05 18:00:02 -0700424 if (have_obj.nr > 0) {
Johannes Schindelin1bd8c8f2005-10-28 04:49:16 +0200425 if (multi_ack)
Junio C Hamanoc04c4e52006-07-05 18:12:12 -0700426 packet_write(1, "ACK %s\n", last_hex);
Johannes Schindelin1bd8c8f2005-10-28 04:49:16 +0200427 return 0;
428 }
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700429 packet_write(1, "NAK\n");
430 return -1;
431 }
Junio C Hamano7e44c932008-08-31 09:39:19 -0700432 die("git upload-pack: expected SHA1 list, got '%s'", line);
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700433 }
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700434}
435
Junio C Hamano390eb362013-01-28 21:49:57 -0800436static int is_our_ref(struct object *o)
437{
438 return o->flags &
439 ((allow_tip_sha1_in_want ? HIDDEN_REF : 0) | OUR_REF);
440}
441
Junio C Hamano051e4002011-08-05 13:54:06 -0700442static void check_non_tip(void)
443{
444 static const char *argv[] = {
445 "rev-list", "--stdin", NULL,
446 };
447 static struct child_process cmd;
448 struct object *o;
449 char namebuf[42]; /* ^ + SHA-1 + LF */
450 int i;
451
452 /* In the normal in-process case non-tip request can never happen */
453 if (!stateless_rpc)
454 goto error;
455
456 cmd.argv = argv;
457 cmd.git_cmd = 1;
458 cmd.no_stderr = 1;
459 cmd.in = -1;
460 cmd.out = -1;
461
462 if (start_command(&cmd))
463 goto error;
464
465 /*
466 * If rev-list --stdin encounters an unknown commit, it
467 * terminates, which will cause SIGPIPE in the write loop
468 * below.
469 */
470 sigchain_push(SIGPIPE, SIG_IGN);
471
472 namebuf[0] = '^';
473 namebuf[41] = '\n';
474 for (i = get_max_object_index(); 0 < i; ) {
475 o = get_indexed_object(--i);
Brian Harring2a745322011-08-23 22:47:17 -0700476 if (!o)
477 continue;
Junio C Hamano390eb362013-01-28 21:49:57 -0800478 if (!is_our_ref(o))
Junio C Hamano051e4002011-08-05 13:54:06 -0700479 continue;
480 memcpy(namebuf + 1, sha1_to_hex(o->sha1), 40);
481 if (write_in_full(cmd.in, namebuf, 42) < 0)
482 goto error;
483 }
484 namebuf[40] = '\n';
485 for (i = 0; i < want_obj.nr; i++) {
486 o = want_obj.objects[i].item;
Junio C Hamano390eb362013-01-28 21:49:57 -0800487 if (is_our_ref(o))
Junio C Hamano051e4002011-08-05 13:54:06 -0700488 continue;
489 memcpy(namebuf, sha1_to_hex(o->sha1), 40);
490 if (write_in_full(cmd.in, namebuf, 41) < 0)
491 goto error;
492 }
493 close(cmd.in);
494
495 sigchain_pop(SIGPIPE);
496
497 /*
498 * The commits out of the rev-list are not ancestors of
499 * our ref.
500 */
501 i = read_in_full(cmd.out, namebuf, 1);
502 if (i)
503 goto error;
504 close(cmd.out);
505
506 /*
507 * rev-list may have died by encountering a bad commit
508 * in the history, in which case we do want to bail out
509 * even when it showed no commit.
510 */
511 if (finish_command(&cmd))
512 goto error;
513
514 /* All the non-tip ones are ancestors of what we advertised */
515 return;
516
517error:
518 /* Pick one of them (we know there at least is one) */
519 for (i = 0; i < want_obj.nr; i++) {
520 o = want_obj.objects[i].item;
Junio C Hamano390eb362013-01-28 21:49:57 -0800521 if (!is_our_ref(o))
Junio C Hamano051e4002011-08-05 13:54:06 -0700522 die("git upload-pack: not our ref %s",
523 sha1_to_hex(o->sha1));
524 }
525}
526
Junio C Hamanob1e9fff2006-07-05 18:00:02 -0700527static void receive_needs(void)
Linus Torvaldsfb9040c2005-07-04 15:29:17 -0700528{
Thiago Farina3cd47452010-08-28 23:04:17 -0300529 struct object_array shallows = OBJECT_ARRAY_INIT;
Jeff King74543a02013-02-20 15:02:57 -0500530 int depth = 0;
Junio C Hamano051e4002011-08-05 13:54:06 -0700531 int has_non_tip = 0;
Linus Torvaldsfb9040c2005-07-04 15:29:17 -0700532
Nick Edelenf0cea832009-06-10 01:50:18 +0200533 shallow_nr = 0;
Linus Torvaldsfb9040c2005-07-04 15:29:17 -0700534 for (;;) {
Junio C Hamano565ebbf2005-10-24 18:59:18 -0700535 struct object *o;
Junio C Hamanof47182c2012-01-08 22:06:19 +0100536 const char *features;
Junio C Hamano6ece0d32006-07-05 17:41:39 -0700537 unsigned char sha1_buf[20];
Jeff King74543a02013-02-20 15:02:57 -0500538 char *line = packet_read_line(0, NULL);
H. Peter Anvin960decc2005-10-19 14:27:01 -0700539 reset_timeout();
Jeff King74543a02013-02-20 15:02:57 -0500540 if (!line)
Johannes Schindelined09aef2006-10-30 20:09:06 +0100541 break;
Linus Torvaldsfb9040c2005-07-04 15:29:17 -0700542
Junio C Hamano599065a2007-02-20 01:54:00 -0800543 if (!prefixcmp(line, "shallow ")) {
Johannes Schindelined09aef2006-10-30 20:09:06 +0100544 unsigned char sha1[20];
545 struct object *object;
Jeff Kingb7b02172013-02-20 14:53:33 -0500546 if (get_sha1_hex(line + 8, sha1))
Johannes Schindelined09aef2006-10-30 20:09:06 +0100547 die("invalid shallow line: %s", line);
548 object = parse_object(sha1);
549 if (!object)
Michael Heemskerkaf04fa22013-04-28 22:32:04 -0700550 continue;
Nguyễn Thái Ngọc Duy6293ded2013-01-08 18:32:36 +0700551 if (object->type != OBJ_COMMIT)
552 die("invalid shallow object %s", sha1_to_hex(sha1));
Jeff Kinge58e57e2013-02-20 14:54:57 -0500553 if (!(object->flags & CLIENT_SHALLOW)) {
554 object->flags |= CLIENT_SHALLOW;
555 add_object_array(object, NULL, &shallows);
556 }
Johannes Schindelined09aef2006-10-30 20:09:06 +0100557 continue;
558 }
Junio C Hamano599065a2007-02-20 01:54:00 -0800559 if (!prefixcmp(line, "deepen ")) {
Johannes Schindelin016e6cc2006-10-30 20:09:29 +0100560 char *end;
561 depth = strtol(line + 7, &end, 0);
562 if (end == line + 7 || depth <= 0)
563 die("Invalid deepen: %s", line);
564 continue;
565 }
Junio C Hamano599065a2007-02-20 01:54:00 -0800566 if (prefixcmp(line, "want ") ||
Junio C Hamano6ece0d32006-07-05 17:41:39 -0700567 get_sha1_hex(line+5, sha1_buf))
Junio C Hamano7e44c932008-08-31 09:39:19 -0700568 die("git upload-pack: protocol error, "
Junio C Hamanoe091eb92005-10-05 14:49:54 -0700569 "expected to get sha, not '%s'", line);
Junio C Hamanof47182c2012-01-08 22:06:19 +0100570
571 features = line + 45;
572
573 if (parse_feature_request(features, "multi_ack_detailed"))
Shawn O. Pearce78affc42009-10-30 17:47:25 -0700574 multi_ack = 2;
Junio C Hamanof47182c2012-01-08 22:06:19 +0100575 else if (parse_feature_request(features, "multi_ack"))
Johannes Schindelin1bd8c8f2005-10-28 04:49:16 +0200576 multi_ack = 1;
Junio C Hamanof47182c2012-01-08 22:06:19 +0100577 if (parse_feature_request(features, "no-done"))
Junio C Hamano4e10cf92011-03-29 12:29:10 -0700578 no_done = 1;
Junio C Hamanof47182c2012-01-08 22:06:19 +0100579 if (parse_feature_request(features, "thin-pack"))
Junio C Hamanob19696c2006-02-20 00:38:39 -0800580 use_thin_pack = 1;
Junio C Hamanof47182c2012-01-08 22:06:19 +0100581 if (parse_feature_request(features, "ofs-delta"))
Nicolas Pitree4fe4b82006-09-26 11:27:39 -0400582 use_ofs_delta = 1;
Junio C Hamanof47182c2012-01-08 22:06:19 +0100583 if (parse_feature_request(features, "side-band-64k"))
Junio C Hamanod47f3db2006-09-10 16:27:08 -0700584 use_sideband = LARGE_PACKET_MAX;
Junio C Hamanof47182c2012-01-08 22:06:19 +0100585 else if (parse_feature_request(features, "side-band"))
Junio C Hamanod47f3db2006-09-10 16:27:08 -0700586 use_sideband = DEFAULT_PACKET_MAX;
Junio C Hamanof47182c2012-01-08 22:06:19 +0100587 if (parse_feature_request(features, "no-progress"))
Johannes Schindelinb0e90892007-02-23 20:03:10 +0100588 no_progress = 1;
Junio C Hamanof47182c2012-01-08 22:06:19 +0100589 if (parse_feature_request(features, "include-tag"))
Shawn O. Pearce348e3902008-03-03 22:27:33 -0500590 use_include_tag = 1;
Junio C Hamano565ebbf2005-10-24 18:59:18 -0700591
Jeff Kingf59de5d2013-03-16 06:28:30 -0400592 o = parse_object(sha1_buf);
Junio C Hamano051e4002011-08-05 13:54:06 -0700593 if (!o)
Elijah Newren9f9aa762010-07-31 14:11:46 -0600594 die("git upload-pack: not our ref %s",
595 sha1_to_hex(sha1_buf));
Junio C Hamano565ebbf2005-10-24 18:59:18 -0700596 if (!(o->flags & WANTED)) {
597 o->flags |= WANTED;
Junio C Hamano390eb362013-01-28 21:49:57 -0800598 if (!is_our_ref(o))
Junio C Hamano051e4002011-08-05 13:54:06 -0700599 has_non_tip = 1;
Junio C Hamanob1e9fff2006-07-05 18:00:02 -0700600 add_object_array(o, NULL, &want_obj);
Junio C Hamano565ebbf2005-10-24 18:59:18 -0700601 }
Linus Torvaldsfb9040c2005-07-04 15:29:17 -0700602 }
Johannes Sixt9462e3f2009-06-16 20:41:16 +0200603
Junio C Hamano051e4002011-08-05 13:54:06 -0700604 /*
605 * We have sent all our refs already, and the other end
606 * should have chosen out of them. When we are operating
607 * in the stateless RPC mode, however, their choice may
608 * have been based on the set of older refs advertised
609 * by another process that handled the initial request.
610 */
611 if (has_non_tip)
612 check_non_tip();
613
Johannes Sixt9462e3f2009-06-16 20:41:16 +0200614 if (!use_sideband && daemon_mode)
615 no_progress = 1;
616
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100617 if (depth == 0 && shallows.nr == 0)
618 return;
Johannes Schindelin016e6cc2006-10-30 20:09:29 +0100619 if (depth > 0) {
Nguyễn Thái Ngọc Duy4dcb1672013-01-11 16:05:46 +0700620 struct commit_list *result = NULL, *backup = NULL;
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100621 int i;
Nguyễn Thái Ngọc Duy4dcb1672013-01-11 16:05:46 +0700622 if (depth == INFINITE_DEPTH)
623 for (i = 0; i < shallows.nr; i++) {
624 struct object *object = shallows.objects[i].item;
625 object->flags |= NOT_SHALLOW;
626 }
627 else
628 backup = result =
629 get_shallow_commits(&want_obj, depth,
630 SHALLOW, NOT_SHALLOW);
Johannes Schindelin016e6cc2006-10-30 20:09:29 +0100631 while (result) {
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100632 struct object *object = &result->item->object;
Alexandre Julliard1f2de762006-11-24 15:58:25 +0100633 if (!(object->flags & (CLIENT_SHALLOW|NOT_SHALLOW))) {
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100634 packet_write(1, "shallow %s",
635 sha1_to_hex(object->sha1));
636 register_shallow(object->sha1);
Nick Edelenf0cea832009-06-10 01:50:18 +0200637 shallow_nr++;
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100638 }
Johannes Schindelin016e6cc2006-10-30 20:09:29 +0100639 result = result->next;
640 }
641 free_commit_list(backup);
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100642 for (i = 0; i < shallows.nr; i++) {
643 struct object *object = shallows.objects[i].item;
644 if (object->flags & NOT_SHALLOW) {
645 struct commit_list *parents;
646 packet_write(1, "unshallow %s",
647 sha1_to_hex(object->sha1));
648 object->flags &= ~CLIENT_SHALLOW;
649 /* make sure the real parents are parsed */
650 unregister_shallow(object->sha1);
Junio C Hamano176d45c2006-11-13 22:47:46 -0800651 object->parsed = 0;
Martin Koeglerdec38c82008-02-18 21:48:03 +0100652 if (parse_commit((struct commit *)object))
653 die("invalid commit");
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100654 parents = ((struct commit *)object)->parents;
655 while (parents) {
656 add_object_array(&parents->item->object,
657 NULL, &want_obj);
658 parents = parents->next;
659 }
Nicolas Pitre65230782009-09-03 19:08:33 -0400660 add_object_array(object, NULL, &extra_edge_obj);
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100661 }
662 /* make sure commit traversal conforms to client */
663 register_shallow(object->sha1);
664 }
665 packet_flush(1);
666 } else
667 if (shallows.nr > 0) {
668 int i;
669 for (i = 0; i < shallows.nr; i++)
670 register_shallow(shallows.objects[i].item->sha1);
671 }
Nick Edelenf0cea832009-06-10 01:50:18 +0200672
673 shallow_nr += shallows.nr;
Johannes Schindelinf53514b2006-10-30 20:09:53 +0100674 free(shallows.objects);
Linus Torvaldsfb9040c2005-07-04 15:29:17 -0700675}
676
Junio C Hamanodaebaa72013-01-18 16:08:30 -0800677/* return non-zero if the ref is hidden, otherwise 0 */
Junio C Hamanocbbe50d2013-01-18 15:48:49 -0800678static int mark_our_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
679{
680 struct object *o = lookup_unknown_object(sha1);
Junio C Hamanodaebaa72013-01-18 16:08:30 -0800681
Junio C Hamano390eb362013-01-28 21:49:57 -0800682 if (ref_is_hidden(refname)) {
683 o->flags |= HIDDEN_REF;
Junio C Hamanodaebaa72013-01-18 16:08:30 -0800684 return 1;
Junio C Hamano390eb362013-01-28 21:49:57 -0800685 }
Junio C Hamanocbbe50d2013-01-18 15:48:49 -0800686 if (!o)
687 die("git upload-pack: cannot find object %s:", sha1_to_hex(sha1));
Junio C Hamano3f1da572013-01-28 20:45:43 -0800688 o->flags |= OUR_REF;
Junio C Hamanocbbe50d2013-01-18 15:48:49 -0800689 return 0;
690}
691
Junio C Hamano7171d8c2013-09-17 16:17:33 -0700692static void format_symref_info(struct strbuf *buf, struct string_list *symref)
693{
694 struct string_list_item *item;
695
696 if (!symref->nr)
697 return;
698 for_each_string_list_item(item, symref)
699 strbuf_addf(buf, " symref=%s:%s", item->string, (char *)item->util);
700}
701
Junio C Hamano8da19772006-09-20 22:02:01 -0700702static int send_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700703{
Johannes Schindelined09aef2006-10-30 20:09:06 +0100704 static const char *capabilities = "multi_ack thin-pack side-band"
Shawn O. Pearce348e3902008-03-03 22:27:33 -0500705 " side-band-64k ofs-delta shallow no-progress"
Shawn O. Pearce78affc42009-10-30 17:47:25 -0700706 " include-tag multi_ack_detailed";
Josh Triplett6b01ecf2011-07-08 16:13:32 -0700707 const char *refname_nons = strip_namespace(refname);
Jeff King435c8332012-10-04 04:03:33 -0400708 unsigned char peeled[20];
Carl Worthb5b16992006-02-17 16:14:52 -0800709
Junio C Hamanoa4d695d2013-09-17 16:03:32 -0700710 if (mark_our_ref(refname, sha1, flag, NULL))
Junio C Hamanodaebaa72013-01-18 16:08:30 -0800711 return 0;
Junio C Hamanocbbe50d2013-01-18 15:48:49 -0800712
Junio C Hamano7171d8c2013-09-17 16:17:33 -0700713 if (capabilities) {
714 struct strbuf symref_info = STRBUF_INIT;
715
716 format_symref_info(&symref_info, cb_data);
717 packet_write(1, "%s %s%c%s%s%s%s agent=%s\n",
Jeff Kingff5effd2012-08-03 12:19:16 -0400718 sha1_to_hex(sha1), refname_nons,
Junio C Hamanocf2ad8e2011-03-29 10:24:59 -0700719 0, capabilities,
Junio C Hamano390eb362013-01-28 21:49:57 -0800720 allow_tip_sha1_in_want ? " allow-tip-sha1-in-want" : "",
Jeff Kingff5effd2012-08-03 12:19:16 -0400721 stateless_rpc ? " no-done" : "",
Junio C Hamano7171d8c2013-09-17 16:17:33 -0700722 symref_info.buf,
Jeff Kingff5effd2012-08-03 12:19:16 -0400723 git_user_agent_sanitized());
Junio C Hamano7171d8c2013-09-17 16:17:33 -0700724 strbuf_release(&symref_info);
725 } else {
Josh Triplett6b01ecf2011-07-08 16:13:32 -0700726 packet_write(1, "%s %s\n", sha1_to_hex(sha1), refname_nons);
Junio C Hamano7171d8c2013-09-17 16:17:33 -0700727 }
Johannes Schindelin1f5881b2005-10-28 05:56:41 +0200728 capabilities = NULL;
Jeff King435c8332012-10-04 04:03:33 -0400729 if (!peel_ref(refname, peeled))
730 packet_write(1, "%s %s^{}\n", sha1_to_hex(peeled), refname_nons);
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700731 return 0;
732}
733
Junio C Hamano7171d8c2013-09-17 16:17:33 -0700734static int find_symref(const char *refname, const unsigned char *sha1, int flag,
735 void *cb_data)
736{
737 const char *symref_target;
738 struct string_list_item *item;
739 unsigned char unused[20];
740
741 if ((flag & REF_ISSYMREF) == 0)
742 return 0;
743 symref_target = resolve_ref_unsafe(refname, unused, 0, &flag);
744 if (!symref_target || (flag & REF_ISSYMREF) == 0)
745 die("'%s' is a symref but it is not?", refname);
746 item = string_list_append(cb_data, refname);
747 item->util = xstrdup(symref_target);
748 return 0;
749}
750
David Rientjes59076eb2006-08-14 13:40:51 -0700751static void upload_pack(void)
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700752{
Junio C Hamano7171d8c2013-09-17 16:17:33 -0700753 struct string_list symref = STRING_LIST_INIT_DUP;
754
755 head_ref_namespaced(find_symref, &symref);
756
Shawn O. Pearce42526b42009-10-30 17:47:33 -0700757 if (advertise_refs || !stateless_rpc) {
758 reset_timeout();
Junio C Hamano7171d8c2013-09-17 16:17:33 -0700759 head_ref_namespaced(send_ref, &symref);
760 for_each_namespaced_ref(send_ref, &symref);
Shawn O. Pearce42526b42009-10-30 17:47:33 -0700761 packet_flush(1);
762 } else {
Josh Triplett6b01ecf2011-07-08 16:13:32 -0700763 head_ref_namespaced(mark_our_ref, NULL);
764 for_each_namespaced_ref(mark_our_ref, NULL);
Shawn O. Pearce42526b42009-10-30 17:47:33 -0700765 }
Junio C Hamano7171d8c2013-09-17 16:17:33 -0700766 string_list_clear(&symref, 1);
Shawn O. Pearce42526b42009-10-30 17:47:33 -0700767 if (advertise_refs)
768 return;
769
Junio C Hamanob1e9fff2006-07-05 18:00:02 -0700770 receive_needs();
David Rientjes59076eb2006-08-14 13:40:51 -0700771 if (want_obj.nr) {
772 get_common_commits();
773 create_pack_file();
774 }
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700775}
776
Junio C Hamanodaebaa72013-01-18 16:08:30 -0800777static int upload_pack_config(const char *var, const char *value, void *unused)
778{
Junio C Hamano390eb362013-01-28 21:49:57 -0800779 if (!strcmp("uploadpack.allowtipsha1inwant", var))
780 allow_tip_sha1_in_want = git_config_bool(var, value);
Jeff King05e95152013-09-08 05:01:31 -0400781 else if (!strcmp("uploadpack.keepalive", var)) {
782 keepalive = git_config_int(var, value);
783 if (!keepalive)
784 keepalive = -1;
785 }
Junio C Hamanodaebaa72013-01-18 16:08:30 -0800786 return parse_hide_refs_config(var, value, "uploadpack");
787}
788
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700789int main(int argc, char **argv)
790{
Andreas Ericsson8d630132005-11-17 20:37:14 +0100791 char *dir;
H. Peter Anvin960decc2005-10-19 14:27:01 -0700792 int i;
793 int strict = 0;
794
Ævar Arnfjörð Bjarmason5e9637c2011-11-18 00:14:42 +0100795 git_setup_gettext();
796
Jeff Kingbbc30f92011-02-24 09:30:19 -0500797 packet_trace_identity("upload-pack");
Steffen Prohaska2fb3f6d2009-01-18 13:00:12 +0100798 git_extract_argv0_path(argv[0]);
Christian Couderdae556b2009-01-23 10:07:46 +0100799 read_replace_refs = 0;
Steffen Prohaska2fb3f6d2009-01-18 13:00:12 +0100800
H. Peter Anvin960decc2005-10-19 14:27:01 -0700801 for (i = 1; i < argc; i++) {
802 char *arg = argv[i];
803
804 if (arg[0] != '-')
805 break;
Shawn O. Pearce42526b42009-10-30 17:47:33 -0700806 if (!strcmp(arg, "--advertise-refs")) {
807 advertise_refs = 1;
808 continue;
809 }
810 if (!strcmp(arg, "--stateless-rpc")) {
811 stateless_rpc = 1;
812 continue;
813 }
H. Peter Anvin960decc2005-10-19 14:27:01 -0700814 if (!strcmp(arg, "--strict")) {
815 strict = 1;
816 continue;
817 }
Junio C Hamanocc44c762007-02-20 01:53:29 -0800818 if (!prefixcmp(arg, "--timeout=")) {
H. Peter Anvin960decc2005-10-19 14:27:01 -0700819 timeout = atoi(arg+10);
Johannes Sixt9462e3f2009-06-16 20:41:16 +0200820 daemon_mode = 1;
H. Peter Anvin960decc2005-10-19 14:27:01 -0700821 continue;
822 }
823 if (!strcmp(arg, "--")) {
824 i++;
825 break;
826 }
827 }
Junio C Hamanoa6080a02007-06-07 00:04:01 -0700828
H. Peter Anvin960decc2005-10-19 14:27:01 -0700829 if (i != argc-1)
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700830 usage(upload_pack_usage);
Johannes Sixt04b33052008-02-12 12:28:01 +0100831
Johannes Sixte1464ca2008-07-21 21:19:52 +0200832 setup_path();
Johannes Sixt04b33052008-02-12 12:28:01 +0100833
H. Peter Anvin960decc2005-10-19 14:27:01 -0700834 dir = argv[i];
Linus Torvalds113b9472005-07-08 16:22:22 -0700835
Andreas Ericsson8d630132005-11-17 20:37:14 +0100836 if (!enter_repo(dir, strict))
Jeff King05ac6b32009-03-04 03:32:29 -0500837 die("'%s' does not appear to be a git repository", dir);
Junio C Hamanoa0022ee2007-01-21 22:23:58 -0800838 if (is_repository_shallow())
839 die("attempt to fetch/clone from a shallow repository");
Junio C Hamanodaebaa72013-01-18 16:08:30 -0800840 git_config(upload_pack_config, NULL);
Linus Torvaldsdef88e92005-07-04 13:26:53 -0700841 upload_pack();
842 return 0;
843}