]>
Commit | Line | Data |
---|---|---|
575f4974 | 1 | #include "cache.h" |
fc04c412 | 2 | #include "pack.h" |
8a65ff76 | 3 | #include "refs.h" |
f3a3214e | 4 | #include "pkt-line.h" |
b1bf95bb | 5 | #include "run-command.h" |
576162a4 | 6 | #include "exec_cmd.h" |
11031d7e JS |
7 | #include "commit.h" |
8 | #include "object.h" | |
d79796bc JH |
9 | #include "remote.h" |
10 | #include "transport.h" | |
575f4974 | 11 | |
d0efc8a7 | 12 | static const char receive_pack_usage[] = "git-receive-pack <git-dir>"; |
575f4974 | 13 | |
a240de11 | 14 | static int deny_deletes = 0; |
6fb75bed | 15 | static int deny_non_fast_forwards = 0; |
20dc0016 | 16 | static int receive_fsck_objects; |
e28714c5 JH |
17 | static int receive_unpack_limit = -1; |
18 | static int transfer_unpack_limit = -1; | |
46732fae | 19 | static int unpack_limit = 100; |
96f1e58f | 20 | static int report_status; |
cfee10a7 | 21 | |
d4f694ba | 22 | static char capabilities[] = " report-status delete-refs "; |
96f1e58f | 23 | static int capabilities_sent; |
cfee10a7 | 24 | |
ef90d6d4 | 25 | static int receive_pack_config(const char *var, const char *value, void *cb) |
6fb75bed | 26 | { |
a240de11 JK |
27 | if (strcmp(var, "receive.denydeletes") == 0) { |
28 | deny_deletes = git_config_bool(var, value); | |
29 | return 0; | |
30 | } | |
31 | ||
e28714c5 | 32 | if (strcmp(var, "receive.denynonfastforwards") == 0) { |
6fb75bed SP |
33 | deny_non_fast_forwards = git_config_bool(var, value); |
34 | return 0; | |
35 | } | |
36 | ||
e28714c5 JH |
37 | if (strcmp(var, "receive.unpacklimit") == 0) { |
38 | receive_unpack_limit = git_config_int(var, value); | |
fc04c412 SP |
39 | return 0; |
40 | } | |
41 | ||
e28714c5 JH |
42 | if (strcmp(var, "transfer.unpacklimit") == 0) { |
43 | transfer_unpack_limit = git_config_int(var, value); | |
44 | return 0; | |
45 | } | |
46 | ||
20dc0016 MK |
47 | if (strcmp(var, "receive.fsckobjects") == 0) { |
48 | receive_fsck_objects = git_config_bool(var, value); | |
49 | return 0; | |
50 | } | |
51 | ||
ef90d6d4 | 52 | return git_default_config(var, value, cb); |
6fb75bed SP |
53 | } |
54 | ||
8da19775 | 55 | static int show_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data) |
575f4974 | 56 | { |
cfee10a7 JH |
57 | if (capabilities_sent) |
58 | packet_write(1, "%s %s\n", sha1_to_hex(sha1), path); | |
59 | else | |
60 | packet_write(1, "%s %s%c%s\n", | |
61 | sha1_to_hex(sha1), path, 0, capabilities); | |
62 | capabilities_sent = 1; | |
8a65ff76 | 63 | return 0; |
575f4974 LT |
64 | } |
65 | ||
8a65ff76 | 66 | static void write_head_info(void) |
575f4974 | 67 | { |
cb5d709f | 68 | for_each_ref(show_ref, NULL); |
cfee10a7 | 69 | if (!capabilities_sent) |
8da19775 | 70 | show_ref("capabilities^{}", null_sha1, 0, NULL); |
cfee10a7 | 71 | |
575f4974 LT |
72 | } |
73 | ||
eb1af2df LT |
74 | struct command { |
75 | struct command *next; | |
cfee10a7 | 76 | const char *error_string; |
eb1af2df LT |
77 | unsigned char old_sha1[20]; |
78 | unsigned char new_sha1[20]; | |
8f1d2e6f | 79 | char ref_name[FLEX_ARRAY]; /* more */ |
575f4974 LT |
80 | }; |
81 | ||
96f1e58f | 82 | static struct command *commands; |
575f4974 | 83 | |
05ef58ec SP |
84 | static const char pre_receive_hook[] = "hooks/pre-receive"; |
85 | static const char post_receive_hook[] = "hooks/post-receive"; | |
b1bf95bb | 86 | |
6c319a22 SP |
87 | static int hook_status(int code, const char *hook_name) |
88 | { | |
89 | switch (code) { | |
90 | case 0: | |
91 | return 0; | |
92 | case -ERR_RUN_COMMAND_FORK: | |
93 | return error("hook fork failed"); | |
94 | case -ERR_RUN_COMMAND_EXEC: | |
95 | return error("hook execute failed"); | |
f43cd49f SP |
96 | case -ERR_RUN_COMMAND_PIPE: |
97 | return error("hook pipe failed"); | |
6c319a22 SP |
98 | case -ERR_RUN_COMMAND_WAITPID: |
99 | return error("waitpid failed"); | |
100 | case -ERR_RUN_COMMAND_WAITPID_WRONG_PID: | |
101 | return error("waitpid is confused"); | |
102 | case -ERR_RUN_COMMAND_WAITPID_SIGNAL: | |
103 | return error("%s died of signal", hook_name); | |
104 | case -ERR_RUN_COMMAND_WAITPID_NOEXIT: | |
105 | return error("%s died strangely", hook_name); | |
106 | default: | |
107 | error("%s exited with error code %d", hook_name, -code); | |
108 | return -code; | |
109 | } | |
110 | } | |
111 | ||
f43cd49f | 112 | static int run_hook(const char *hook_name) |
b1bf95bb | 113 | { |
f43cd49f | 114 | static char buf[sizeof(commands->old_sha1) * 2 + PATH_MAX + 4]; |
c8dd2771 | 115 | struct command *cmd; |
f43cd49f SP |
116 | struct child_process proc; |
117 | const char *argv[2]; | |
118 | int have_input = 0, code; | |
c8dd2771 | 119 | |
f43cd49f | 120 | for (cmd = commands; !have_input && cmd; cmd = cmd->next) { |
c8dd2771 | 121 | if (!cmd->error_string) |
f43cd49f | 122 | have_input = 1; |
c8dd2771 | 123 | } |
b1bf95bb | 124 | |
f43cd49f | 125 | if (!have_input || access(hook_name, X_OK) < 0) |
b1bf95bb | 126 | return 0; |
c8dd2771 | 127 | |
c8dd2771 | 128 | argv[0] = hook_name; |
f43cd49f SP |
129 | argv[1] = NULL; |
130 | ||
131 | memset(&proc, 0, sizeof(proc)); | |
132 | proc.argv = argv; | |
133 | proc.in = -1; | |
134 | proc.stdout_to_stderr = 1; | |
135 | ||
136 | code = start_command(&proc); | |
137 | if (code) | |
138 | return hook_status(code, hook_name); | |
139 | for (cmd = commands; cmd; cmd = cmd->next) { | |
c8dd2771 | 140 | if (!cmd->error_string) { |
f43cd49f SP |
141 | size_t n = snprintf(buf, sizeof(buf), "%s %s %s\n", |
142 | sha1_to_hex(cmd->old_sha1), | |
143 | sha1_to_hex(cmd->new_sha1), | |
144 | cmd->ref_name); | |
145 | if (write_in_full(proc.in, buf, n) != n) | |
146 | break; | |
c8dd2771 | 147 | } |
c8dd2771 | 148 | } |
e72ae288 | 149 | close(proc.in); |
f43cd49f | 150 | return hook_status(finish_command(&proc), hook_name); |
b1bf95bb JW |
151 | } |
152 | ||
1d9e8b56 SP |
153 | static int run_update_hook(struct command *cmd) |
154 | { | |
155 | static const char update_hook[] = "hooks/update"; | |
156 | struct child_process proc; | |
157 | const char *argv[5]; | |
158 | ||
159 | if (access(update_hook, X_OK) < 0) | |
160 | return 0; | |
161 | ||
162 | argv[0] = update_hook; | |
163 | argv[1] = cmd->ref_name; | |
164 | argv[2] = sha1_to_hex(cmd->old_sha1); | |
165 | argv[3] = sha1_to_hex(cmd->new_sha1); | |
166 | argv[4] = NULL; | |
167 | ||
168 | memset(&proc, 0, sizeof(proc)); | |
169 | proc.argv = argv; | |
170 | proc.no_stdin = 1; | |
171 | proc.stdout_to_stderr = 1; | |
172 | ||
173 | return hook_status(run_command(&proc), update_hook); | |
174 | } | |
175 | ||
8aaf7d64 | 176 | static const char *update(struct command *cmd) |
2eca23da | 177 | { |
cfee10a7 JH |
178 | const char *name = cmd->ref_name; |
179 | unsigned char *old_sha1 = cmd->old_sha1; | |
180 | unsigned char *new_sha1 = cmd->new_sha1; | |
3159c8dc | 181 | struct ref_lock *lock; |
2eca23da | 182 | |
061d6b9a MK |
183 | /* only refs/... are allowed */ |
184 | if (prefixcmp(name, "refs/") || check_ref_format(name + 5)) { | |
0b8293f6 | 185 | error("refusing to create funny ref '%s' remotely", name); |
8aaf7d64 | 186 | return "funny refname"; |
cfee10a7 | 187 | } |
d8a1deec | 188 | |
d4f694ba | 189 | if (!is_null_sha1(new_sha1) && !has_sha1_file(new_sha1)) { |
8aaf7d64 SP |
190 | error("unpack should have generated %s, " |
191 | "but I can't find it!", sha1_to_hex(new_sha1)); | |
192 | return "bad pack"; | |
cfee10a7 | 193 | } |
a240de11 JK |
194 | if (deny_deletes && is_null_sha1(new_sha1) && |
195 | !is_null_sha1(old_sha1) && | |
196 | !prefixcmp(name, "refs/heads/")) { | |
197 | error("denying ref deletion for %s", name); | |
198 | return "deletion prohibited"; | |
199 | } | |
d4f694ba | 200 | if (deny_non_fast_forwards && !is_null_sha1(new_sha1) && |
ba988a83 | 201 | !is_null_sha1(old_sha1) && |
cc44c765 | 202 | !prefixcmp(name, "refs/heads/")) { |
eab82707 | 203 | struct object *old_object, *new_object; |
11031d7e | 204 | struct commit *old_commit, *new_commit; |
9edd7e46 | 205 | struct commit_list *bases, *ent; |
11031d7e | 206 | |
eab82707 MK |
207 | old_object = parse_object(old_sha1); |
208 | new_object = parse_object(new_sha1); | |
209 | ||
210 | if (!old_object || !new_object || | |
211 | old_object->type != OBJ_COMMIT || | |
212 | new_object->type != OBJ_COMMIT) { | |
213 | error("bad sha1 objects for %s", name); | |
214 | return "bad ref"; | |
215 | } | |
216 | old_commit = (struct commit *)old_object; | |
217 | new_commit = (struct commit *)new_object; | |
9edd7e46 JS |
218 | bases = get_merge_bases(old_commit, new_commit, 1); |
219 | for (ent = bases; ent; ent = ent->next) | |
220 | if (!hashcmp(old_sha1, ent->item->object.sha1)) | |
11031d7e | 221 | break; |
9edd7e46 | 222 | free_commit_list(bases); |
8aaf7d64 SP |
223 | if (!ent) { |
224 | error("denying non-fast forward %s" | |
225 | " (you should pull first)", name); | |
226 | return "non-fast forward"; | |
227 | } | |
11031d7e | 228 | } |
1d9e8b56 | 229 | if (run_update_hook(cmd)) { |
8aaf7d64 SP |
230 | error("hook declined to update %s", name); |
231 | return "hook declined"; | |
b1bf95bb | 232 | } |
3159c8dc | 233 | |
d4f694ba | 234 | if (is_null_sha1(new_sha1)) { |
28391a80 JS |
235 | if (!parse_object(old_sha1)) { |
236 | warning ("Allowing deletion of corrupt ref."); | |
237 | old_sha1 = NULL; | |
238 | } | |
eca35a25 | 239 | if (delete_ref(name, old_sha1, 0)) { |
8aaf7d64 SP |
240 | error("failed to delete %s", name); |
241 | return "failed to delete"; | |
d4f694ba | 242 | } |
8aaf7d64 | 243 | return NULL; /* good */ |
d4f694ba JH |
244 | } |
245 | else { | |
68db31cc | 246 | lock = lock_any_ref_for_update(name, old_sha1, 0); |
d4f694ba | 247 | if (!lock) { |
8aaf7d64 SP |
248 | error("failed to lock %s", name); |
249 | return "failed to lock"; | |
d4f694ba | 250 | } |
ef203f08 | 251 | if (write_ref_sha1(lock, new_sha1, "push")) { |
8aaf7d64 | 252 | return "failed to write"; /* error() already called */ |
ef203f08 | 253 | } |
8aaf7d64 | 254 | return NULL; /* good */ |
19614330 | 255 | } |
2eca23da LT |
256 | } |
257 | ||
19614330 JH |
258 | static char update_post_hook[] = "hooks/post-update"; |
259 | ||
260 | static void run_update_post_hook(struct command *cmd) | |
261 | { | |
262 | struct command *cmd_p; | |
263 | int argc; | |
9201c707 | 264 | const char **argv; |
19614330 | 265 | |
3e6e152c | 266 | for (argc = 0, cmd_p = cmd; cmd_p; cmd_p = cmd_p->next) { |
cfee10a7 | 267 | if (cmd_p->error_string) |
19614330 JH |
268 | continue; |
269 | argc++; | |
270 | } | |
3e6e152c SP |
271 | if (!argc || access(update_post_hook, X_OK) < 0) |
272 | return; | |
273 | argv = xmalloc(sizeof(*argv) * (2 + argc)); | |
19614330 JH |
274 | argv[0] = update_post_hook; |
275 | ||
276 | for (argc = 1, cmd_p = cmd; cmd_p; cmd_p = cmd_p->next) { | |
9201c707 | 277 | char *p; |
cfee10a7 | 278 | if (cmd_p->error_string) |
19614330 | 279 | continue; |
9201c707 JH |
280 | p = xmalloc(strlen(cmd_p->ref_name) + 1); |
281 | strcpy(p, cmd_p->ref_name); | |
282 | argv[argc] = p; | |
19614330 JH |
283 | argc++; |
284 | } | |
285 | argv[argc] = NULL; | |
95d3c4f5 SP |
286 | run_command_v_opt(argv, RUN_COMMAND_NO_STDIN |
287 | | RUN_COMMAND_STDOUT_TO_STDERR); | |
19614330 | 288 | } |
2eca23da | 289 | |
8aaf7d64 | 290 | static void execute_commands(const char *unpacker_error) |
575f4974 | 291 | { |
eb1af2df | 292 | struct command *cmd = commands; |
8aaf7d64 SP |
293 | |
294 | if (unpacker_error) { | |
295 | while (cmd) { | |
296 | cmd->error_string = "n/a (unpacker error)"; | |
297 | cmd = cmd->next; | |
298 | } | |
299 | return; | |
300 | } | |
301 | ||
f43cd49f | 302 | if (run_hook(pre_receive_hook)) { |
05ef58ec SP |
303 | while (cmd) { |
304 | cmd->error_string = "pre-receive hook declined"; | |
305 | cmd = cmd->next; | |
306 | } | |
307 | return; | |
308 | } | |
309 | ||
eb1af2df | 310 | while (cmd) { |
8aaf7d64 | 311 | cmd->error_string = update(cmd); |
eb1af2df | 312 | cmd = cmd->next; |
575f4974 LT |
313 | } |
314 | } | |
315 | ||
316 | static void read_head_info(void) | |
317 | { | |
eb1af2df | 318 | struct command **p = &commands; |
575f4974 LT |
319 | for (;;) { |
320 | static char line[1000]; | |
eb1af2df LT |
321 | unsigned char old_sha1[20], new_sha1[20]; |
322 | struct command *cmd; | |
cfee10a7 JH |
323 | char *refname; |
324 | int len, reflen; | |
eb1af2df LT |
325 | |
326 | len = packet_read_line(0, line, sizeof(line)); | |
575f4974 LT |
327 | if (!len) |
328 | break; | |
eb1af2df LT |
329 | if (line[len-1] == '\n') |
330 | line[--len] = 0; | |
331 | if (len < 83 || | |
332 | line[40] != ' ' || | |
333 | line[81] != ' ' || | |
334 | get_sha1_hex(line, old_sha1) || | |
335 | get_sha1_hex(line + 41, new_sha1)) | |
cfee10a7 JH |
336 | die("protocol error: expected old/new/ref, got '%s'", |
337 | line); | |
338 | ||
339 | refname = line + 82; | |
340 | reflen = strlen(refname); | |
341 | if (reflen + 82 < len) { | |
342 | if (strstr(refname + reflen + 1, "report-status")) | |
343 | report_status = 1; | |
344 | } | |
eb1af2df | 345 | cmd = xmalloc(sizeof(struct command) + len - 80); |
e702496e SP |
346 | hashcpy(cmd->old_sha1, old_sha1); |
347 | hashcpy(cmd->new_sha1, new_sha1); | |
eb1af2df | 348 | memcpy(cmd->ref_name, line + 82, len - 81); |
8aaf7d64 | 349 | cmd->error_string = NULL; |
eb1af2df LT |
350 | cmd->next = NULL; |
351 | *p = cmd; | |
352 | p = &cmd->next; | |
575f4974 LT |
353 | } |
354 | } | |
355 | ||
fc04c412 SP |
356 | static const char *parse_pack_header(struct pack_header *hdr) |
357 | { | |
a69e5429 JH |
358 | switch (read_pack_header(0, hdr)) { |
359 | case PH_ERROR_EOF: | |
360 | return "eof before pack header was fully read"; | |
361 | ||
362 | case PH_ERROR_PACK_SIGNATURE: | |
fc04c412 | 363 | return "protocol error (pack signature mismatch detected)"; |
a69e5429 JH |
364 | |
365 | case PH_ERROR_PROTOCOL: | |
fc04c412 | 366 | return "protocol error (pack version unsupported)"; |
a69e5429 JH |
367 | |
368 | default: | |
369 | return "unknown error in parse_pack_header"; | |
370 | ||
371 | case 0: | |
372 | return NULL; | |
373 | } | |
fc04c412 SP |
374 | } |
375 | ||
576162a4 NP |
376 | static const char *pack_lockfile; |
377 | ||
861ed121 | 378 | static const char *unpack(void) |
575f4974 | 379 | { |
fc04c412 SP |
380 | struct pack_header hdr; |
381 | const char *hdr_err; | |
382 | char hdr_arg[38]; | |
fc04c412 SP |
383 | |
384 | hdr_err = parse_pack_header(&hdr); | |
385 | if (hdr_err) | |
386 | return hdr_err; | |
6e1c2344 RJ |
387 | snprintf(hdr_arg, sizeof(hdr_arg), |
388 | "--pack_header=%"PRIu32",%"PRIu32, | |
fc04c412 SP |
389 | ntohl(hdr.hdr_version), ntohl(hdr.hdr_entries)); |
390 | ||
391 | if (ntohl(hdr.hdr_entries) < unpack_limit) { | |
20dc0016 MK |
392 | int code, i = 0; |
393 | const char *unpacker[4]; | |
394 | unpacker[i++] = "unpack-objects"; | |
395 | if (receive_fsck_objects) | |
396 | unpacker[i++] = "--strict"; | |
397 | unpacker[i++] = hdr_arg; | |
398 | unpacker[i++] = NULL; | |
9b0b5093 | 399 | code = run_command_v_opt(unpacker, RUN_GIT_CMD); |
576162a4 | 400 | switch (code) { |
fc04c412 SP |
401 | case 0: |
402 | return NULL; | |
403 | case -ERR_RUN_COMMAND_FORK: | |
404 | return "unpack fork failed"; | |
405 | case -ERR_RUN_COMMAND_EXEC: | |
406 | return "unpack execute failed"; | |
407 | case -ERR_RUN_COMMAND_WAITPID: | |
408 | return "waitpid failed"; | |
409 | case -ERR_RUN_COMMAND_WAITPID_WRONG_PID: | |
410 | return "waitpid is confused"; | |
411 | case -ERR_RUN_COMMAND_WAITPID_SIGNAL: | |
412 | return "unpacker died of signal"; | |
413 | case -ERR_RUN_COMMAND_WAITPID_NOEXIT: | |
414 | return "unpacker died strangely"; | |
415 | default: | |
416 | return "unpacker exited with error code"; | |
576162a4 NP |
417 | } |
418 | } else { | |
20dc0016 MK |
419 | const char *keeper[7]; |
420 | int s, status, i = 0; | |
576162a4 | 421 | char keep_arg[256]; |
e8016abf | 422 | struct child_process ip; |
576162a4 | 423 | |
85e72830 | 424 | s = sprintf(keep_arg, "--keep=receive-pack %"PRIuMAX" on ", (uintmax_t) getpid()); |
576162a4 NP |
425 | if (gethostname(keep_arg + s, sizeof(keep_arg) - s)) |
426 | strcpy(keep_arg + s, "localhost"); | |
427 | ||
20dc0016 MK |
428 | keeper[i++] = "index-pack"; |
429 | keeper[i++] = "--stdin"; | |
430 | if (receive_fsck_objects) | |
431 | keeper[i++] = "--strict"; | |
432 | keeper[i++] = "--fix-thin"; | |
433 | keeper[i++] = hdr_arg; | |
434 | keeper[i++] = keep_arg; | |
435 | keeper[i++] = NULL; | |
e8016abf SP |
436 | memset(&ip, 0, sizeof(ip)); |
437 | ip.argv = keeper; | |
438 | ip.out = -1; | |
439 | ip.git_cmd = 1; | |
440 | if (start_command(&ip)) | |
576162a4 | 441 | return "index-pack fork failed"; |
106764e6 | 442 | pack_lockfile = index_pack_lockfile(ip.out); |
e72ae288 | 443 | close(ip.out); |
e8016abf SP |
444 | status = finish_command(&ip); |
445 | if (!status) { | |
576162a4 NP |
446 | reprepare_packed_git(); |
447 | return NULL; | |
448 | } | |
449 | return "index-pack abnormal exit"; | |
cfee10a7 JH |
450 | } |
451 | } | |
452 | ||
453 | static void report(const char *unpack_status) | |
454 | { | |
455 | struct command *cmd; | |
456 | packet_write(1, "unpack %s\n", | |
457 | unpack_status ? unpack_status : "ok"); | |
458 | for (cmd = commands; cmd; cmd = cmd->next) { | |
459 | if (!cmd->error_string) | |
460 | packet_write(1, "ok %s\n", | |
461 | cmd->ref_name); | |
462 | else | |
463 | packet_write(1, "ng %s %s\n", | |
464 | cmd->ref_name, cmd->error_string); | |
575f4974 | 465 | } |
cfee10a7 | 466 | packet_flush(1); |
575f4974 LT |
467 | } |
468 | ||
d4f694ba JH |
469 | static int delete_only(struct command *cmd) |
470 | { | |
471 | while (cmd) { | |
472 | if (!is_null_sha1(cmd->new_sha1)) | |
473 | return 0; | |
474 | cmd = cmd->next; | |
475 | } | |
476 | return 1; | |
477 | } | |
478 | ||
d79796bc JH |
479 | static int add_refs_from_alternate(struct alternate_object_database *e, void *unused) |
480 | { | |
b8492539 JH |
481 | char *other; |
482 | size_t len; | |
d79796bc JH |
483 | struct remote *remote; |
484 | struct transport *transport; | |
485 | const struct ref *extra; | |
486 | ||
b8492539 JH |
487 | e->name[-1] = '\0'; |
488 | other = xstrdup(make_absolute_path(e->base)); | |
489 | e->name[-1] = '/'; | |
490 | len = strlen(other); | |
491 | ||
d79796bc JH |
492 | while (other[len-1] == '/') |
493 | other[--len] = '\0'; | |
494 | if (len < 8 || memcmp(other + len - 8, "/objects", 8)) | |
495 | return 0; | |
496 | /* Is this a git repository with refs? */ | |
497 | memcpy(other + len - 8, "/refs", 6); | |
498 | if (!is_directory(other)) | |
499 | return 0; | |
500 | other[len - 8] = '\0'; | |
501 | remote = remote_get(other); | |
502 | transport = transport_get(remote, other); | |
503 | for (extra = transport_get_remote_refs(transport); | |
504 | extra; | |
505 | extra = extra->next) { | |
506 | add_extra_ref(".have", extra->old_sha1, 0); | |
507 | } | |
508 | transport_disconnect(transport); | |
509 | free(other); | |
510 | return 0; | |
511 | } | |
512 | ||
513 | static void add_alternate_refs(void) | |
514 | { | |
515 | foreach_alt_odb(add_refs_from_alternate, NULL); | |
516 | } | |
517 | ||
be5908ae | 518 | int cmd_receive_pack(int argc, const char **argv, const char *prefix) |
575f4974 | 519 | { |
d0efc8a7 | 520 | int i; |
8d630132 | 521 | char *dir = NULL; |
575f4974 LT |
522 | |
523 | argv++; | |
524 | for (i = 1; i < argc; i++) { | |
be5908ae | 525 | const char *arg = *argv++; |
575f4974 LT |
526 | |
527 | if (*arg == '-') { | |
575f4974 LT |
528 | /* Do flag handling here */ |
529 | usage(receive_pack_usage); | |
530 | } | |
d0efc8a7 LT |
531 | if (dir) |
532 | usage(receive_pack_usage); | |
be5908ae | 533 | dir = xstrdup(arg); |
575f4974 LT |
534 | } |
535 | if (!dir) | |
536 | usage(receive_pack_usage); | |
537 | ||
e1464ca7 | 538 | setup_path(); |
5c09f321 | 539 | |
3159c8dc | 540 | if (!enter_repo(dir, 0)) |
8d630132 | 541 | die("'%s': unable to chdir or not a git archive", dir); |
575f4974 | 542 | |
a0022eeb JH |
543 | if (is_repository_shallow()) |
544 | die("attempt to push into a shallow repository"); | |
545 | ||
ef90d6d4 | 546 | git_config(receive_pack_config, NULL); |
6fb75bed | 547 | |
e28714c5 JH |
548 | if (0 <= transfer_unpack_limit) |
549 | unpack_limit = transfer_unpack_limit; | |
550 | else if (0 <= receive_unpack_limit) | |
551 | unpack_limit = receive_unpack_limit; | |
552 | ||
d79796bc | 553 | add_alternate_refs(); |
8a65ff76 | 554 | write_head_info(); |
d79796bc | 555 | clear_extra_refs(); |
575f4974 LT |
556 | |
557 | /* EOF */ | |
f3a3214e | 558 | packet_flush(1); |
575f4974 LT |
559 | |
560 | read_head_info(); | |
7f8e9828 | 561 | if (commands) { |
d4f694ba JH |
562 | const char *unpack_status = NULL; |
563 | ||
564 | if (!delete_only(commands)) | |
565 | unpack_status = unpack(); | |
8aaf7d64 | 566 | execute_commands(unpack_status); |
576162a4 NP |
567 | if (pack_lockfile) |
568 | unlink(pack_lockfile); | |
cfee10a7 JH |
569 | if (report_status) |
570 | report(unpack_status); | |
f43cd49f | 571 | run_hook(post_receive_hook); |
8e663d9e | 572 | run_update_post_hook(commands); |
7f8e9828 | 573 | } |
575f4974 LT |
574 | return 0; |
575 | } |