7 #include "run-command.h"
13 #include "transport.h"
14 #include "string-list.h"
15 #include "sha1-array.h"
16 #include "connected.h"
17 #include "argv-array.h"
20 #include "gpg-interface.h"
24 static const char receive_pack_usage
[] = "git receive-pack <git-dir>";
34 static int deny_deletes
;
35 static int deny_non_fast_forwards
;
36 static enum deny_action deny_current_branch
= DENY_UNCONFIGURED
;
37 static enum deny_action deny_delete_current
= DENY_UNCONFIGURED
;
38 static int receive_fsck_objects
= -1;
39 static int transfer_fsck_objects
= -1;
40 static struct strbuf fsck_msg_types
= STRBUF_INIT
;
41 static int receive_unpack_limit
= -1;
42 static int transfer_unpack_limit
= -1;
43 static int advertise_atomic_push
= 1;
44 static int unpack_limit
= 100;
45 static int report_status
;
46 static int use_sideband
;
47 static int use_atomic
;
49 static int prefer_ofs_delta
= 1;
50 static int auto_update_server_info
;
51 static int auto_gc
= 1;
52 static int fix_thin
= 1;
53 static int stateless_rpc
;
54 static const char *service_dir
;
55 static const char *head_name
;
56 static void *head_name_to_free
;
57 static int sent_capabilities
;
58 static int shallow_update
;
59 static const char *alt_shallow_file
;
60 static struct strbuf push_cert
= STRBUF_INIT
;
61 static unsigned char push_cert_sha1
[20];
62 static struct signature_check sigcheck
;
63 static const char *push_cert_nonce
;
64 static const char *cert_nonce_seed
;
66 static const char *NONCE_UNSOLICITED
= "UNSOLICITED";
67 static const char *NONCE_BAD
= "BAD";
68 static const char *NONCE_MISSING
= "MISSING";
69 static const char *NONCE_OK
= "OK";
70 static const char *NONCE_SLOP
= "SLOP";
71 static const char *nonce_status
;
72 static long nonce_stamp_slop
;
73 static unsigned long nonce_stamp_slop_limit
;
74 static struct ref_transaction
*transaction
;
76 static enum deny_action
parse_deny_action(const char *var
, const char *value
)
79 if (!strcasecmp(value
, "ignore"))
81 if (!strcasecmp(value
, "warn"))
83 if (!strcasecmp(value
, "refuse"))
85 if (!strcasecmp(value
, "updateinstead"))
86 return DENY_UPDATE_INSTEAD
;
88 if (git_config_bool(var
, value
))
93 static int receive_pack_config(const char *var
, const char *value
, void *cb
)
95 int status
= parse_hide_refs_config(var
, value
, "receive");
100 if (strcmp(var
, "receive.denydeletes") == 0) {
101 deny_deletes
= git_config_bool(var
, value
);
105 if (strcmp(var
, "receive.denynonfastforwards") == 0) {
106 deny_non_fast_forwards
= git_config_bool(var
, value
);
110 if (strcmp(var
, "receive.unpacklimit") == 0) {
111 receive_unpack_limit
= git_config_int(var
, value
);
115 if (strcmp(var
, "transfer.unpacklimit") == 0) {
116 transfer_unpack_limit
= git_config_int(var
, value
);
120 if (skip_prefix(var
, "receive.fsck.", &var
)) {
121 if (is_valid_msg_type(var
, value
))
122 strbuf_addf(&fsck_msg_types
, "%c%s=%s",
123 fsck_msg_types
.len
? ',' : '=', var
, value
);
125 warning("Skipping unknown msg id '%s'", var
);
129 if (strcmp(var
, "receive.fsckobjects") == 0) {
130 receive_fsck_objects
= git_config_bool(var
, value
);
134 if (strcmp(var
, "transfer.fsckobjects") == 0) {
135 transfer_fsck_objects
= git_config_bool(var
, value
);
139 if (!strcmp(var
, "receive.denycurrentbranch")) {
140 deny_current_branch
= parse_deny_action(var
, value
);
144 if (strcmp(var
, "receive.denydeletecurrent") == 0) {
145 deny_delete_current
= parse_deny_action(var
, value
);
149 if (strcmp(var
, "repack.usedeltabaseoffset") == 0) {
150 prefer_ofs_delta
= git_config_bool(var
, value
);
154 if (strcmp(var
, "receive.updateserverinfo") == 0) {
155 auto_update_server_info
= git_config_bool(var
, value
);
159 if (strcmp(var
, "receive.autogc") == 0) {
160 auto_gc
= git_config_bool(var
, value
);
164 if (strcmp(var
, "receive.shallowupdate") == 0) {
165 shallow_update
= git_config_bool(var
, value
);
169 if (strcmp(var
, "receive.certnonceseed") == 0)
170 return git_config_string(&cert_nonce_seed
, var
, value
);
172 if (strcmp(var
, "receive.certnonceslop") == 0) {
173 nonce_stamp_slop_limit
= git_config_ulong(var
, value
);
177 if (strcmp(var
, "receive.advertiseatomic") == 0) {
178 advertise_atomic_push
= git_config_bool(var
, value
);
182 return git_default_config(var
, value
, cb
);
185 static void show_ref(const char *path
, const unsigned char *sha1
)
187 if (ref_is_hidden(path
))
190 if (sent_capabilities
) {
191 packet_write(1, "%s %s\n", sha1_to_hex(sha1
), path
);
193 struct strbuf cap
= STRBUF_INIT
;
196 "report-status delete-refs side-band-64k quiet");
197 if (advertise_atomic_push
)
198 strbuf_addstr(&cap
, " atomic");
199 if (prefer_ofs_delta
)
200 strbuf_addstr(&cap
, " ofs-delta");
202 strbuf_addf(&cap
, " push-cert=%s", push_cert_nonce
);
203 strbuf_addf(&cap
, " agent=%s", git_user_agent_sanitized());
204 packet_write(1, "%s %s%c%s\n",
205 sha1_to_hex(sha1
), path
, 0, cap
.buf
);
206 strbuf_release(&cap
);
207 sent_capabilities
= 1;
211 static int show_ref_cb(const char *path
, const struct object_id
*oid
, int flag
, void *unused
)
213 path
= strip_namespace(path
);
215 * Advertise refs outside our current namespace as ".have"
216 * refs, so that the client can use them to minimize data
217 * transfer but will otherwise ignore them. This happens to
218 * cover ".have" that are thrown in by add_one_alternate_ref()
219 * to mark histories that are complete in our alternates as
224 show_ref(path
, oid
->hash
);
228 static void show_one_alternate_sha1(const unsigned char sha1
[20], void *unused
)
230 show_ref(".have", sha1
);
233 static void collect_one_alternate_ref(const struct ref
*ref
, void *data
)
235 struct sha1_array
*sa
= data
;
236 sha1_array_append(sa
, ref
->old_sha1
);
239 static void write_head_info(void)
241 struct sha1_array sa
= SHA1_ARRAY_INIT
;
243 for_each_alternate_ref(collect_one_alternate_ref
, &sa
);
244 sha1_array_for_each_unique(&sa
, show_one_alternate_sha1
, NULL
);
245 sha1_array_clear(&sa
);
246 for_each_ref(show_ref_cb
, NULL
);
247 if (!sent_capabilities
)
248 show_ref("capabilities^{}", null_sha1
);
250 advertise_shallow_grafts(1);
257 struct command
*next
;
258 const char *error_string
;
259 unsigned int skip_update
:1,
262 unsigned char old_sha1
[20];
263 unsigned char new_sha1
[20];
264 char ref_name
[FLEX_ARRAY
]; /* more */
267 static void rp_error(const char *err
, ...) __attribute__((format (printf
, 1, 2)));
268 static void rp_warning(const char *err
, ...) __attribute__((format (printf
, 1, 2)));
270 static void report_message(const char *prefix
, const char *err
, va_list params
)
272 int sz
= strlen(prefix
);
275 strncpy(msg
, prefix
, sz
);
276 sz
+= vsnprintf(msg
+ sz
, sizeof(msg
) - sz
, err
, params
);
277 if (sz
> (sizeof(msg
) - 1))
278 sz
= sizeof(msg
) - 1;
282 send_sideband(1, 2, msg
, sz
, use_sideband
);
287 static void rp_warning(const char *err
, ...)
290 va_start(params
, err
);
291 report_message("warning: ", err
, params
);
295 static void rp_error(const char *err
, ...)
298 va_start(params
, err
);
299 report_message("error: ", err
, params
);
303 static int copy_to_sideband(int in
, int out
, void *arg
)
307 ssize_t sz
= xread(in
, data
, sizeof(data
));
310 send_sideband(1, 2, data
, sz
, use_sideband
);
316 #define HMAC_BLOCK_SIZE 64
318 static void hmac_sha1(unsigned char *out
,
319 const char *key_in
, size_t key_len
,
320 const char *text
, size_t text_len
)
322 unsigned char key
[HMAC_BLOCK_SIZE
];
323 unsigned char k_ipad
[HMAC_BLOCK_SIZE
];
324 unsigned char k_opad
[HMAC_BLOCK_SIZE
];
328 /* RFC 2104 2. (1) */
329 memset(key
, '\0', HMAC_BLOCK_SIZE
);
330 if (HMAC_BLOCK_SIZE
< key_len
) {
332 git_SHA1_Update(&ctx
, key_in
, key_len
);
333 git_SHA1_Final(key
, &ctx
);
335 memcpy(key
, key_in
, key_len
);
338 /* RFC 2104 2. (2) & (5) */
339 for (i
= 0; i
< sizeof(key
); i
++) {
340 k_ipad
[i
] = key
[i
] ^ 0x36;
341 k_opad
[i
] = key
[i
] ^ 0x5c;
344 /* RFC 2104 2. (3) & (4) */
346 git_SHA1_Update(&ctx
, k_ipad
, sizeof(k_ipad
));
347 git_SHA1_Update(&ctx
, text
, text_len
);
348 git_SHA1_Final(out
, &ctx
);
350 /* RFC 2104 2. (6) & (7) */
352 git_SHA1_Update(&ctx
, k_opad
, sizeof(k_opad
));
353 git_SHA1_Update(&ctx
, out
, 20);
354 git_SHA1_Final(out
, &ctx
);
357 static char *prepare_push_cert_nonce(const char *path
, unsigned long stamp
)
359 struct strbuf buf
= STRBUF_INIT
;
360 unsigned char sha1
[20];
362 strbuf_addf(&buf
, "%s:%lu", path
, stamp
);
363 hmac_sha1(sha1
, buf
.buf
, buf
.len
, cert_nonce_seed
, strlen(cert_nonce_seed
));;
364 strbuf_release(&buf
);
366 /* RFC 2104 5. HMAC-SHA1-80 */
367 strbuf_addf(&buf
, "%lu-%.*s", stamp
, 20, sha1_to_hex(sha1
));
368 return strbuf_detach(&buf
, NULL
);
372 * NEEDSWORK: reuse find_commit_header() from jk/commit-author-parsing
373 * after dropping "_commit" from its name and possibly moving it out
376 static char *find_header(const char *msg
, size_t len
, const char *key
)
378 int key_len
= strlen(key
);
379 const char *line
= msg
;
381 while (line
&& line
< msg
+ len
) {
382 const char *eol
= strchrnul(line
, '\n');
384 if ((msg
+ len
<= eol
) || line
== eol
)
386 if (line
+ key_len
< eol
&&
387 !memcmp(line
, key
, key_len
) && line
[key_len
] == ' ') {
388 int offset
= key_len
+ 1;
389 return xmemdupz(line
+ offset
, (eol
- line
) - offset
);
391 line
= *eol
? eol
+ 1 : NULL
;
396 static const char *check_nonce(const char *buf
, size_t len
)
398 char *nonce
= find_header(buf
, len
, "nonce");
399 unsigned long stamp
, ostamp
;
400 char *bohmac
, *expect
= NULL
;
401 const char *retval
= NONCE_BAD
;
404 retval
= NONCE_MISSING
;
406 } else if (!push_cert_nonce
) {
407 retval
= NONCE_UNSOLICITED
;
409 } else if (!strcmp(push_cert_nonce
, nonce
)) {
414 if (!stateless_rpc
) {
415 /* returned nonce MUST match what we gave out earlier */
421 * In stateless mode, we may be receiving a nonce issued by
422 * another instance of the server that serving the same
423 * repository, and the timestamps may not match, but the
424 * nonce-seed and dir should match, so we can recompute and
425 * report the time slop.
427 * In addition, when a nonce issued by another instance has
428 * timestamp within receive.certnonceslop seconds, we pretend
429 * as if we issued that nonce when reporting to the hook.
432 /* nonce is concat(<seconds-since-epoch>, "-", <hmac>) */
433 if (*nonce
<= '0' || '9' < *nonce
) {
437 stamp
= strtoul(nonce
, &bohmac
, 10);
438 if (bohmac
== nonce
|| bohmac
[0] != '-') {
443 expect
= prepare_push_cert_nonce(service_dir
, stamp
);
444 if (strcmp(expect
, nonce
)) {
445 /* Not what we would have signed earlier */
451 * By how many seconds is this nonce stale? Negative value
452 * would mean it was issued by another server with its clock
453 * skewed in the future.
455 ostamp
= strtoul(push_cert_nonce
, NULL
, 10);
456 nonce_stamp_slop
= (long)ostamp
- (long)stamp
;
458 if (nonce_stamp_slop_limit
&&
459 labs(nonce_stamp_slop
) <= nonce_stamp_slop_limit
) {
461 * Pretend as if the received nonce (which passes the
462 * HMAC check, so it is not a forged by third-party)
465 free((void *)push_cert_nonce
);
466 push_cert_nonce
= xstrdup(nonce
);
478 static void prepare_push_cert_sha1(struct child_process
*proc
)
480 static int already_done
;
486 struct strbuf gpg_output
= STRBUF_INIT
;
487 struct strbuf gpg_status
= STRBUF_INIT
;
488 int bogs
/* beginning_of_gpg_sig */;
491 if (write_sha1_file(push_cert
.buf
, push_cert
.len
, "blob", push_cert_sha1
))
492 hashclr(push_cert_sha1
);
494 memset(&sigcheck
, '\0', sizeof(sigcheck
));
495 sigcheck
.result
= 'N';
497 bogs
= parse_signature(push_cert
.buf
, push_cert
.len
);
498 if (verify_signed_buffer(push_cert
.buf
, bogs
,
499 push_cert
.buf
+ bogs
, push_cert
.len
- bogs
,
500 &gpg_output
, &gpg_status
) < 0) {
501 ; /* error running gpg */
503 sigcheck
.payload
= push_cert
.buf
;
504 sigcheck
.gpg_output
= gpg_output
.buf
;
505 sigcheck
.gpg_status
= gpg_status
.buf
;
506 parse_gpg_output(&sigcheck
);
509 strbuf_release(&gpg_output
);
510 strbuf_release(&gpg_status
);
511 nonce_status
= check_nonce(push_cert
.buf
, bogs
);
513 if (!is_null_sha1(push_cert_sha1
)) {
514 argv_array_pushf(&proc
->env_array
, "GIT_PUSH_CERT=%s",
515 sha1_to_hex(push_cert_sha1
));
516 argv_array_pushf(&proc
->env_array
, "GIT_PUSH_CERT_SIGNER=%s",
517 sigcheck
.signer
? sigcheck
.signer
: "");
518 argv_array_pushf(&proc
->env_array
, "GIT_PUSH_CERT_KEY=%s",
519 sigcheck
.key
? sigcheck
.key
: "");
520 argv_array_pushf(&proc
->env_array
, "GIT_PUSH_CERT_STATUS=%c",
522 if (push_cert_nonce
) {
523 argv_array_pushf(&proc
->env_array
,
524 "GIT_PUSH_CERT_NONCE=%s",
526 argv_array_pushf(&proc
->env_array
,
527 "GIT_PUSH_CERT_NONCE_STATUS=%s",
529 if (nonce_status
== NONCE_SLOP
)
530 argv_array_pushf(&proc
->env_array
,
531 "GIT_PUSH_CERT_NONCE_SLOP=%ld",
537 typedef int (*feed_fn
)(void *, const char **, size_t *);
538 static int run_and_feed_hook(const char *hook_name
, feed_fn feed
, void *feed_state
)
540 struct child_process proc
= CHILD_PROCESS_INIT
;
545 argv
[0] = find_hook(hook_name
);
553 proc
.stdout_to_stderr
= 1;
556 memset(&muxer
, 0, sizeof(muxer
));
557 muxer
.proc
= copy_to_sideband
;
559 code
= start_async(&muxer
);
565 prepare_push_cert_sha1(&proc
);
567 code
= start_command(&proc
);
570 finish_async(&muxer
);
574 sigchain_push(SIGPIPE
, SIG_IGN
);
579 if (feed(feed_state
, &buf
, &n
))
581 if (write_in_full(proc
.in
, buf
, n
) != n
)
586 finish_async(&muxer
);
588 sigchain_pop(SIGPIPE
);
590 return finish_command(&proc
);
593 struct receive_hook_feed_state
{
599 static int feed_receive_hook(void *state_
, const char **bufp
, size_t *sizep
)
601 struct receive_hook_feed_state
*state
= state_
;
602 struct command
*cmd
= state
->cmd
;
605 state
->skip_broken
&& (cmd
->error_string
|| cmd
->did_not_exist
))
609 strbuf_reset(&state
->buf
);
610 strbuf_addf(&state
->buf
, "%s %s %s\n",
611 sha1_to_hex(cmd
->old_sha1
), sha1_to_hex(cmd
->new_sha1
),
613 state
->cmd
= cmd
->next
;
615 *bufp
= state
->buf
.buf
;
616 *sizep
= state
->buf
.len
;
621 static int run_receive_hook(struct command
*commands
, const char *hook_name
,
624 struct receive_hook_feed_state state
;
627 strbuf_init(&state
.buf
, 0);
628 state
.cmd
= commands
;
629 state
.skip_broken
= skip_broken
;
630 if (feed_receive_hook(&state
, NULL
, NULL
))
632 state
.cmd
= commands
;
633 status
= run_and_feed_hook(hook_name
, feed_receive_hook
, &state
);
634 strbuf_release(&state
.buf
);
638 static int run_update_hook(struct command
*cmd
)
641 struct child_process proc
= CHILD_PROCESS_INIT
;
644 argv
[0] = find_hook("update");
648 argv
[1] = cmd
->ref_name
;
649 argv
[2] = sha1_to_hex(cmd
->old_sha1
);
650 argv
[3] = sha1_to_hex(cmd
->new_sha1
);
654 proc
.stdout_to_stderr
= 1;
655 proc
.err
= use_sideband
? -1 : 0;
658 code
= start_command(&proc
);
662 copy_to_sideband(proc
.err
, -1, NULL
);
663 return finish_command(&proc
);
666 static int is_ref_checked_out(const char *ref
)
668 if (is_bare_repository())
673 return !strcmp(head_name
, ref
);
676 static char *refuse_unconfigured_deny_msg
[] = {
677 "By default, updating the current branch in a non-bare repository",
678 "is denied, because it will make the index and work tree inconsistent",
679 "with what you pushed, and will require 'git reset --hard' to match",
680 "the work tree to HEAD.",
682 "You can set 'receive.denyCurrentBranch' configuration variable to",
683 "'ignore' or 'warn' in the remote repository to allow pushing into",
684 "its current branch; however, this is not recommended unless you",
685 "arranged to update its work tree to match what you pushed in some",
688 "To squelch this message and still keep the default behaviour, set",
689 "'receive.denyCurrentBranch' configuration variable to 'refuse'."
692 static void refuse_unconfigured_deny(void)
695 for (i
= 0; i
< ARRAY_SIZE(refuse_unconfigured_deny_msg
); i
++)
696 rp_error("%s", refuse_unconfigured_deny_msg
[i
]);
699 static char *refuse_unconfigured_deny_delete_current_msg
[] = {
700 "By default, deleting the current branch is denied, because the next",
701 "'git clone' won't result in any file checked out, causing confusion.",
703 "You can set 'receive.denyDeleteCurrent' configuration variable to",
704 "'warn' or 'ignore' in the remote repository to allow deleting the",
705 "current branch, with or without a warning message.",
707 "To squelch this message, you can set it to 'refuse'."
710 static void refuse_unconfigured_deny_delete_current(void)
714 i
< ARRAY_SIZE(refuse_unconfigured_deny_delete_current_msg
);
716 rp_error("%s", refuse_unconfigured_deny_delete_current_msg
[i
]);
719 static int command_singleton_iterator(void *cb_data
, unsigned char sha1
[20]);
720 static int update_shallow_ref(struct command
*cmd
, struct shallow_info
*si
)
722 static struct lock_file shallow_lock
;
723 struct sha1_array extra
= SHA1_ARRAY_INIT
;
724 const char *alt_file
;
725 uint32_t mask
= 1 << (cmd
->index
% 32);
728 trace_printf_key(&trace_shallow
,
729 "shallow: update_shallow_ref %s\n", cmd
->ref_name
);
730 for (i
= 0; i
< si
->shallow
->nr
; i
++)
731 if (si
->used_shallow
[i
] &&
732 (si
->used_shallow
[i
][cmd
->index
/ 32] & mask
) &&
733 !delayed_reachability_test(si
, i
))
734 sha1_array_append(&extra
, si
->shallow
->sha1
[i
]);
736 setup_alternate_shallow(&shallow_lock
, &alt_file
, &extra
);
737 if (check_shallow_connected(command_singleton_iterator
,
739 rollback_lock_file(&shallow_lock
);
740 sha1_array_clear(&extra
);
744 commit_lock_file(&shallow_lock
);
747 * Make sure setup_alternate_shallow() for the next ref does
748 * not lose these new roots..
750 for (i
= 0; i
< extra
.nr
; i
++)
751 register_shallow(extra
.sha1
[i
]);
753 si
->shallow_ref
[cmd
->index
] = 0;
754 sha1_array_clear(&extra
);
759 * NEEDSWORK: we should consolidate various implementions of "are we
760 * on an unborn branch?" test into one, and make the unified one more
761 * robust. !get_sha1() based check used here and elsewhere would not
762 * allow us to tell an unborn branch from corrupt ref, for example.
763 * For the purpose of fixing "deploy-to-update does not work when
764 * pushing into an empty repository" issue, this should suffice for
767 static int head_has_history(void)
769 unsigned char sha1
[20];
771 return !get_sha1("HEAD", sha1
);
774 static const char *push_to_deploy(unsigned char *sha1
,
775 struct argv_array
*env
,
776 const char *work_tree
)
778 const char *update_refresh
[] = {
779 "update-index", "-q", "--ignore-submodules", "--refresh", NULL
781 const char *diff_files
[] = {
782 "diff-files", "--quiet", "--ignore-submodules", "--", NULL
784 const char *diff_index
[] = {
785 "diff-index", "--quiet", "--cached", "--ignore-submodules",
788 const char *read_tree
[] = {
789 "read-tree", "-u", "-m", NULL
, NULL
791 struct child_process child
= CHILD_PROCESS_INIT
;
793 child
.argv
= update_refresh
;
794 child
.env
= env
->argv
;
795 child
.dir
= work_tree
;
797 child
.stdout_to_stderr
= 1;
799 if (run_command(&child
))
800 return "Up-to-date check failed";
802 /* run_command() does not clean up completely; reinitialize */
803 child_process_init(&child
);
804 child
.argv
= diff_files
;
805 child
.env
= env
->argv
;
806 child
.dir
= work_tree
;
808 child
.stdout_to_stderr
= 1;
810 if (run_command(&child
))
811 return "Working directory has unstaged changes";
813 /* diff-index with either HEAD or an empty tree */
814 diff_index
[4] = head_has_history() ? "HEAD" : EMPTY_TREE_SHA1_HEX
;
816 child_process_init(&child
);
817 child
.argv
= diff_index
;
818 child
.env
= env
->argv
;
821 child
.stdout_to_stderr
= 0;
823 if (run_command(&child
))
824 return "Working directory has staged changes";
826 read_tree
[3] = sha1_to_hex(sha1
);
827 child_process_init(&child
);
828 child
.argv
= read_tree
;
829 child
.env
= env
->argv
;
830 child
.dir
= work_tree
;
833 child
.stdout_to_stderr
= 0;
835 if (run_command(&child
))
836 return "Could not update working tree to new HEAD";
841 static const char *push_to_checkout_hook
= "push-to-checkout";
843 static const char *push_to_checkout(unsigned char *sha1
,
844 struct argv_array
*env
,
845 const char *work_tree
)
847 argv_array_pushf(env
, "GIT_WORK_TREE=%s", absolute_path(work_tree
));
848 if (run_hook_le(env
->argv
, push_to_checkout_hook
,
849 sha1_to_hex(sha1
), NULL
))
850 return "push-to-checkout hook declined";
855 static const char *update_worktree(unsigned char *sha1
)
858 const char *work_tree
= git_work_tree_cfg
? git_work_tree_cfg
: "..";
859 struct argv_array env
= ARGV_ARRAY_INIT
;
861 if (is_bare_repository())
862 return "denyCurrentBranch = updateInstead needs a worktree";
864 argv_array_pushf(&env
, "GIT_DIR=%s", absolute_path(get_git_dir()));
866 if (!find_hook(push_to_checkout_hook
))
867 retval
= push_to_deploy(sha1
, &env
, work_tree
);
869 retval
= push_to_checkout(sha1
, &env
, work_tree
);
871 argv_array_clear(&env
);
875 static const char *update(struct command
*cmd
, struct shallow_info
*si
)
877 const char *name
= cmd
->ref_name
;
878 struct strbuf namespaced_name_buf
= STRBUF_INIT
;
879 const char *namespaced_name
, *ret
;
880 unsigned char *old_sha1
= cmd
->old_sha1
;
881 unsigned char *new_sha1
= cmd
->new_sha1
;
883 /* only refs/... are allowed */
884 if (!starts_with(name
, "refs/") || check_refname_format(name
+ 5, 0)) {
885 rp_error("refusing to create funny ref '%s' remotely", name
);
886 return "funny refname";
889 strbuf_addf(&namespaced_name_buf
, "%s%s", get_git_namespace(), name
);
890 namespaced_name
= strbuf_detach(&namespaced_name_buf
, NULL
);
892 if (is_ref_checked_out(namespaced_name
)) {
893 switch (deny_current_branch
) {
897 rp_warning("updating the current branch");
900 case DENY_UNCONFIGURED
:
901 rp_error("refusing to update checked out branch: %s", name
);
902 if (deny_current_branch
== DENY_UNCONFIGURED
)
903 refuse_unconfigured_deny();
904 return "branch is currently checked out";
905 case DENY_UPDATE_INSTEAD
:
906 ret
= update_worktree(new_sha1
);
913 if (!is_null_sha1(new_sha1
) && !has_sha1_file(new_sha1
)) {
914 error("unpack should have generated %s, "
915 "but I can't find it!", sha1_to_hex(new_sha1
));
919 if (!is_null_sha1(old_sha1
) && is_null_sha1(new_sha1
)) {
920 if (deny_deletes
&& starts_with(name
, "refs/heads/")) {
921 rp_error("denying ref deletion for %s", name
);
922 return "deletion prohibited";
925 if (!strcmp(namespaced_name
, head_name
)) {
926 switch (deny_delete_current
) {
930 rp_warning("deleting the current branch");
933 case DENY_UNCONFIGURED
:
934 case DENY_UPDATE_INSTEAD
:
935 if (deny_delete_current
== DENY_UNCONFIGURED
)
936 refuse_unconfigured_deny_delete_current();
937 rp_error("refusing to delete the current branch: %s", name
);
938 return "deletion of the current branch prohibited";
940 return "Invalid denyDeleteCurrent setting";
945 if (deny_non_fast_forwards
&& !is_null_sha1(new_sha1
) &&
946 !is_null_sha1(old_sha1
) &&
947 starts_with(name
, "refs/heads/")) {
948 struct object
*old_object
, *new_object
;
949 struct commit
*old_commit
, *new_commit
;
951 old_object
= parse_object(old_sha1
);
952 new_object
= parse_object(new_sha1
);
954 if (!old_object
|| !new_object
||
955 old_object
->type
!= OBJ_COMMIT
||
956 new_object
->type
!= OBJ_COMMIT
) {
957 error("bad sha1 objects for %s", name
);
960 old_commit
= (struct commit
*)old_object
;
961 new_commit
= (struct commit
*)new_object
;
962 if (!in_merge_bases(old_commit
, new_commit
)) {
963 rp_error("denying non-fast-forward %s"
964 " (you should pull first)", name
);
965 return "non-fast-forward";
968 if (run_update_hook(cmd
)) {
969 rp_error("hook declined to update %s", name
);
970 return "hook declined";
973 if (is_null_sha1(new_sha1
)) {
974 struct strbuf err
= STRBUF_INIT
;
975 if (!parse_object(old_sha1
)) {
977 if (ref_exists(name
)) {
978 rp_warning("Allowing deletion of corrupt ref.");
980 rp_warning("Deleting a non-existent ref.");
981 cmd
->did_not_exist
= 1;
984 if (ref_transaction_delete(transaction
,
988 rp_error("%s", err
.buf
);
989 strbuf_release(&err
);
990 return "failed to delete";
992 strbuf_release(&err
);
993 return NULL
; /* good */
996 struct strbuf err
= STRBUF_INIT
;
997 if (shallow_update
&& si
->shallow_ref
[cmd
->index
] &&
998 update_shallow_ref(cmd
, si
))
999 return "shallow error";
1001 if (ref_transaction_update(transaction
,
1006 rp_error("%s", err
.buf
);
1007 strbuf_release(&err
);
1009 return "failed to update ref";
1011 strbuf_release(&err
);
1013 return NULL
; /* good */
1017 static void run_update_post_hook(struct command
*commands
)
1019 struct command
*cmd
;
1022 struct child_process proc
= CHILD_PROCESS_INIT
;
1025 hook
= find_hook("post-update");
1026 for (argc
= 0, cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1027 if (cmd
->error_string
|| cmd
->did_not_exist
)
1034 argv
= xmalloc(sizeof(*argv
) * (2 + argc
));
1037 for (argc
= 1, cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1038 if (cmd
->error_string
|| cmd
->did_not_exist
)
1040 argv
[argc
] = xstrdup(cmd
->ref_name
);
1046 proc
.stdout_to_stderr
= 1;
1047 proc
.err
= use_sideband
? -1 : 0;
1050 if (!start_command(&proc
)) {
1052 copy_to_sideband(proc
.err
, -1, NULL
);
1053 finish_command(&proc
);
1057 static void check_aliased_update(struct command
*cmd
, struct string_list
*list
)
1059 struct strbuf buf
= STRBUF_INIT
;
1060 const char *dst_name
;
1061 struct string_list_item
*item
;
1062 struct command
*dst_cmd
;
1063 unsigned char sha1
[20];
1064 char cmd_oldh
[41], cmd_newh
[41], dst_oldh
[41], dst_newh
[41];
1067 strbuf_addf(&buf
, "%s%s", get_git_namespace(), cmd
->ref_name
);
1068 dst_name
= resolve_ref_unsafe(buf
.buf
, 0, sha1
, &flag
);
1069 strbuf_release(&buf
);
1071 if (!(flag
& REF_ISSYMREF
))
1074 dst_name
= strip_namespace(dst_name
);
1076 rp_error("refusing update to broken symref '%s'", cmd
->ref_name
);
1077 cmd
->skip_update
= 1;
1078 cmd
->error_string
= "broken symref";
1082 if ((item
= string_list_lookup(list
, dst_name
)) == NULL
)
1085 cmd
->skip_update
= 1;
1087 dst_cmd
= (struct command
*) item
->util
;
1089 if (!hashcmp(cmd
->old_sha1
, dst_cmd
->old_sha1
) &&
1090 !hashcmp(cmd
->new_sha1
, dst_cmd
->new_sha1
))
1093 dst_cmd
->skip_update
= 1;
1095 strcpy(cmd_oldh
, find_unique_abbrev(cmd
->old_sha1
, DEFAULT_ABBREV
));
1096 strcpy(cmd_newh
, find_unique_abbrev(cmd
->new_sha1
, DEFAULT_ABBREV
));
1097 strcpy(dst_oldh
, find_unique_abbrev(dst_cmd
->old_sha1
, DEFAULT_ABBREV
));
1098 strcpy(dst_newh
, find_unique_abbrev(dst_cmd
->new_sha1
, DEFAULT_ABBREV
));
1099 rp_error("refusing inconsistent update between symref '%s' (%s..%s) and"
1100 " its target '%s' (%s..%s)",
1101 cmd
->ref_name
, cmd_oldh
, cmd_newh
,
1102 dst_cmd
->ref_name
, dst_oldh
, dst_newh
);
1104 cmd
->error_string
= dst_cmd
->error_string
=
1105 "inconsistent aliased update";
1108 static void check_aliased_updates(struct command
*commands
)
1110 struct command
*cmd
;
1111 struct string_list ref_list
= STRING_LIST_INIT_NODUP
;
1113 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1114 struct string_list_item
*item
=
1115 string_list_append(&ref_list
, cmd
->ref_name
);
1116 item
->util
= (void *)cmd
;
1118 string_list_sort(&ref_list
);
1120 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1121 if (!cmd
->error_string
)
1122 check_aliased_update(cmd
, &ref_list
);
1125 string_list_clear(&ref_list
, 0);
1128 static int command_singleton_iterator(void *cb_data
, unsigned char sha1
[20])
1130 struct command
**cmd_list
= cb_data
;
1131 struct command
*cmd
= *cmd_list
;
1133 if (!cmd
|| is_null_sha1(cmd
->new_sha1
))
1134 return -1; /* end of list */
1135 *cmd_list
= NULL
; /* this returns only one */
1136 hashcpy(sha1
, cmd
->new_sha1
);
1140 static void set_connectivity_errors(struct command
*commands
,
1141 struct shallow_info
*si
)
1143 struct command
*cmd
;
1145 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1146 struct command
*singleton
= cmd
;
1147 if (shallow_update
&& si
->shallow_ref
[cmd
->index
])
1148 /* to be checked in update_shallow_ref() */
1150 if (!check_everything_connected(command_singleton_iterator
,
1153 cmd
->error_string
= "missing necessary objects";
1157 struct iterate_data
{
1158 struct command
*cmds
;
1159 struct shallow_info
*si
;
1162 static int iterate_receive_command_list(void *cb_data
, unsigned char sha1
[20])
1164 struct iterate_data
*data
= cb_data
;
1165 struct command
**cmd_list
= &data
->cmds
;
1166 struct command
*cmd
= *cmd_list
;
1168 for (; cmd
; cmd
= cmd
->next
) {
1169 if (shallow_update
&& data
->si
->shallow_ref
[cmd
->index
])
1170 /* to be checked in update_shallow_ref() */
1172 if (!is_null_sha1(cmd
->new_sha1
) && !cmd
->skip_update
) {
1173 hashcpy(sha1
, cmd
->new_sha1
);
1174 *cmd_list
= cmd
->next
;
1179 return -1; /* end of list */
1182 static void reject_updates_to_hidden(struct command
*commands
)
1184 struct command
*cmd
;
1186 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1187 if (cmd
->error_string
|| !ref_is_hidden(cmd
->ref_name
))
1189 if (is_null_sha1(cmd
->new_sha1
))
1190 cmd
->error_string
= "deny deleting a hidden ref";
1192 cmd
->error_string
= "deny updating a hidden ref";
1196 static int should_process_cmd(struct command
*cmd
)
1198 return !cmd
->error_string
&& !cmd
->skip_update
;
1201 static void warn_if_skipped_connectivity_check(struct command
*commands
,
1202 struct shallow_info
*si
)
1204 struct command
*cmd
;
1205 int checked_connectivity
= 1;
1207 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1208 if (should_process_cmd(cmd
) && si
->shallow_ref
[cmd
->index
]) {
1209 error("BUG: connectivity check has not been run on ref %s",
1211 checked_connectivity
= 0;
1214 if (!checked_connectivity
)
1215 die("BUG: connectivity check skipped???");
1218 static void execute_commands_non_atomic(struct command
*commands
,
1219 struct shallow_info
*si
)
1221 struct command
*cmd
;
1222 struct strbuf err
= STRBUF_INIT
;
1224 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1225 if (!should_process_cmd(cmd
))
1228 transaction
= ref_transaction_begin(&err
);
1230 rp_error("%s", err
.buf
);
1232 cmd
->error_string
= "transaction failed to start";
1236 cmd
->error_string
= update(cmd
, si
);
1238 if (!cmd
->error_string
1239 && ref_transaction_commit(transaction
, &err
)) {
1240 rp_error("%s", err
.buf
);
1242 cmd
->error_string
= "failed to update ref";
1244 ref_transaction_free(transaction
);
1246 strbuf_release(&err
);
1249 static void execute_commands_atomic(struct command
*commands
,
1250 struct shallow_info
*si
)
1252 struct command
*cmd
;
1253 struct strbuf err
= STRBUF_INIT
;
1254 const char *reported_error
= "atomic push failure";
1256 transaction
= ref_transaction_begin(&err
);
1258 rp_error("%s", err
.buf
);
1260 reported_error
= "transaction failed to start";
1264 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1265 if (!should_process_cmd(cmd
))
1268 cmd
->error_string
= update(cmd
, si
);
1270 if (cmd
->error_string
)
1274 if (ref_transaction_commit(transaction
, &err
)) {
1275 rp_error("%s", err
.buf
);
1276 reported_error
= "atomic transaction failed";
1282 for (cmd
= commands
; cmd
; cmd
= cmd
->next
)
1283 if (!cmd
->error_string
)
1284 cmd
->error_string
= reported_error
;
1287 ref_transaction_free(transaction
);
1288 strbuf_release(&err
);
1291 static void execute_commands(struct command
*commands
,
1292 const char *unpacker_error
,
1293 struct shallow_info
*si
)
1295 struct command
*cmd
;
1296 unsigned char sha1
[20];
1297 struct iterate_data data
;
1299 if (unpacker_error
) {
1300 for (cmd
= commands
; cmd
; cmd
= cmd
->next
)
1301 cmd
->error_string
= "unpacker error";
1305 data
.cmds
= commands
;
1307 if (check_everything_connected(iterate_receive_command_list
, 0, &data
))
1308 set_connectivity_errors(commands
, si
);
1310 reject_updates_to_hidden(commands
);
1312 if (run_receive_hook(commands
, "pre-receive", 0)) {
1313 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1314 if (!cmd
->error_string
)
1315 cmd
->error_string
= "pre-receive hook declined";
1320 check_aliased_updates(commands
);
1322 free(head_name_to_free
);
1323 head_name
= head_name_to_free
= resolve_refdup("HEAD", 0, sha1
, NULL
);
1326 execute_commands_atomic(commands
, si
);
1328 execute_commands_non_atomic(commands
, si
);
1331 warn_if_skipped_connectivity_check(commands
, si
);
1334 static struct command
**queue_command(struct command
**tail
,
1338 unsigned char old_sha1
[20], new_sha1
[20];
1339 struct command
*cmd
;
1340 const char *refname
;
1346 get_sha1_hex(line
, old_sha1
) ||
1347 get_sha1_hex(line
+ 41, new_sha1
))
1348 die("protocol error: expected old/new/ref, got '%s'", line
);
1350 refname
= line
+ 82;
1351 reflen
= linelen
- 82;
1352 cmd
= xcalloc(1, sizeof(struct command
) + reflen
+ 1);
1353 hashcpy(cmd
->old_sha1
, old_sha1
);
1354 hashcpy(cmd
->new_sha1
, new_sha1
);
1355 memcpy(cmd
->ref_name
, refname
, reflen
);
1356 cmd
->ref_name
[reflen
] = '\0';
1361 static void queue_commands_from_cert(struct command
**tail
,
1362 struct strbuf
*push_cert
)
1364 const char *boc
, *eoc
;
1367 die("protocol error: got both push certificate and unsigned commands");
1369 boc
= strstr(push_cert
->buf
, "\n\n");
1371 die("malformed push certificate %.*s", 100, push_cert
->buf
);
1374 eoc
= push_cert
->buf
+ parse_signature(push_cert
->buf
, push_cert
->len
);
1377 const char *eol
= memchr(boc
, '\n', eoc
- boc
);
1378 tail
= queue_command(tail
, boc
, eol
? eol
- boc
: eoc
- eol
);
1379 boc
= eol
? eol
+ 1 : eoc
;
1383 static struct command
*read_head_info(struct sha1_array
*shallow
)
1385 struct command
*commands
= NULL
;
1386 struct command
**p
= &commands
;
1391 line
= packet_read_line(0, &len
);
1395 if (len
== 48 && starts_with(line
, "shallow ")) {
1396 unsigned char sha1
[20];
1397 if (get_sha1_hex(line
+ 8, sha1
))
1398 die("protocol error: expected shallow sha, got '%s'",
1400 sha1_array_append(shallow
, sha1
);
1404 linelen
= strlen(line
);
1405 if (linelen
< len
) {
1406 const char *feature_list
= line
+ linelen
+ 1;
1407 if (parse_feature_request(feature_list
, "report-status"))
1409 if (parse_feature_request(feature_list
, "side-band-64k"))
1410 use_sideband
= LARGE_PACKET_MAX
;
1411 if (parse_feature_request(feature_list
, "quiet"))
1413 if (advertise_atomic_push
1414 && parse_feature_request(feature_list
, "atomic"))
1418 if (!strcmp(line
, "push-cert")) {
1423 len
= packet_read(0, NULL
, NULL
,
1424 certbuf
, sizeof(certbuf
), 0);
1429 if (!strcmp(certbuf
, "push-cert-end\n"))
1430 break; /* end of cert */
1431 strbuf_addstr(&push_cert
, certbuf
);
1439 p
= queue_command(p
, line
, linelen
);
1443 queue_commands_from_cert(p
, &push_cert
);
1448 static const char *parse_pack_header(struct pack_header
*hdr
)
1450 switch (read_pack_header(0, hdr
)) {
1452 return "eof before pack header was fully read";
1454 case PH_ERROR_PACK_SIGNATURE
:
1455 return "protocol error (pack signature mismatch detected)";
1457 case PH_ERROR_PROTOCOL
:
1458 return "protocol error (pack version unsupported)";
1461 return "unknown error in parse_pack_header";
1468 static const char *pack_lockfile
;
1470 static const char *unpack(int err_fd
, struct shallow_info
*si
)
1472 struct pack_header hdr
;
1473 const char *hdr_err
;
1476 struct child_process child
= CHILD_PROCESS_INIT
;
1477 int fsck_objects
= (receive_fsck_objects
>= 0
1478 ? receive_fsck_objects
1479 : transfer_fsck_objects
>= 0
1480 ? transfer_fsck_objects
1483 hdr_err
= parse_pack_header(&hdr
);
1489 snprintf(hdr_arg
, sizeof(hdr_arg
),
1490 "--pack_header=%"PRIu32
",%"PRIu32
,
1491 ntohl(hdr
.hdr_version
), ntohl(hdr
.hdr_entries
));
1493 if (si
->nr_ours
|| si
->nr_theirs
) {
1494 alt_shallow_file
= setup_temporary_shallow(si
->shallow
);
1495 argv_array_push(&child
.args
, "--shallow-file");
1496 argv_array_push(&child
.args
, alt_shallow_file
);
1499 if (ntohl(hdr
.hdr_entries
) < unpack_limit
) {
1500 argv_array_pushl(&child
.args
, "unpack-objects", hdr_arg
, NULL
);
1502 argv_array_push(&child
.args
, "-q");
1504 argv_array_pushf(&child
.args
, "--strict%s",
1505 fsck_msg_types
.buf
);
1506 child
.no_stdout
= 1;
1509 status
= run_command(&child
);
1511 return "unpack-objects abnormal exit";
1516 s
= sprintf(keep_arg
, "--keep=receive-pack %"PRIuMAX
" on ", (uintmax_t) getpid());
1517 if (gethostname(keep_arg
+ s
, sizeof(keep_arg
) - s
))
1518 strcpy(keep_arg
+ s
, "localhost");
1520 argv_array_pushl(&child
.args
, "index-pack",
1521 "--stdin", hdr_arg
, keep_arg
, NULL
);
1523 argv_array_pushf(&child
.args
, "--strict%s",
1524 fsck_msg_types
.buf
);
1526 argv_array_push(&child
.args
, "--fix-thin");
1530 status
= start_command(&child
);
1532 return "index-pack fork failed";
1533 pack_lockfile
= index_pack_lockfile(child
.out
);
1535 status
= finish_command(&child
);
1537 return "index-pack abnormal exit";
1538 reprepare_packed_git();
1543 static const char *unpack_with_sideband(struct shallow_info
*si
)
1549 return unpack(0, si
);
1551 memset(&muxer
, 0, sizeof(muxer
));
1552 muxer
.proc
= copy_to_sideband
;
1554 if (start_async(&muxer
))
1557 ret
= unpack(muxer
.in
, si
);
1559 finish_async(&muxer
);
1563 static void prepare_shallow_update(struct command
*commands
,
1564 struct shallow_info
*si
)
1566 int i
, j
, k
, bitmap_size
= (si
->ref
->nr
+ 31) / 32;
1568 si
->used_shallow
= xmalloc(sizeof(*si
->used_shallow
) *
1570 assign_shallow_commits_to_refs(si
, si
->used_shallow
, NULL
);
1572 si
->need_reachability_test
=
1573 xcalloc(si
->shallow
->nr
, sizeof(*si
->need_reachability_test
));
1575 xcalloc(si
->shallow
->nr
, sizeof(*si
->reachable
));
1576 si
->shallow_ref
= xcalloc(si
->ref
->nr
, sizeof(*si
->shallow_ref
));
1578 for (i
= 0; i
< si
->nr_ours
; i
++)
1579 si
->need_reachability_test
[si
->ours
[i
]] = 1;
1581 for (i
= 0; i
< si
->shallow
->nr
; i
++) {
1582 if (!si
->used_shallow
[i
])
1584 for (j
= 0; j
< bitmap_size
; j
++) {
1585 if (!si
->used_shallow
[i
][j
])
1587 si
->need_reachability_test
[i
]++;
1588 for (k
= 0; k
< 32; k
++)
1589 if (si
->used_shallow
[i
][j
] & (1 << k
))
1590 si
->shallow_ref
[j
* 32 + k
]++;
1594 * true for those associated with some refs and belong
1595 * in "ours" list aka "step 7 not done yet"
1597 si
->need_reachability_test
[i
] =
1598 si
->need_reachability_test
[i
] > 1;
1602 * keep hooks happy by forcing a temporary shallow file via
1603 * env variable because we can't add --shallow-file to every
1604 * command. check_everything_connected() will be done with
1605 * true .git/shallow though.
1607 setenv(GIT_SHALLOW_FILE_ENVIRONMENT
, alt_shallow_file
, 1);
1610 static void update_shallow_info(struct command
*commands
,
1611 struct shallow_info
*si
,
1612 struct sha1_array
*ref
)
1614 struct command
*cmd
;
1616 remove_nonexistent_theirs_shallow(si
);
1617 if (!si
->nr_ours
&& !si
->nr_theirs
) {
1622 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1623 if (is_null_sha1(cmd
->new_sha1
))
1625 sha1_array_append(ref
, cmd
->new_sha1
);
1626 cmd
->index
= ref
->nr
- 1;
1630 if (shallow_update
) {
1631 prepare_shallow_update(commands
, si
);
1635 ref_status
= xmalloc(sizeof(*ref_status
) * ref
->nr
);
1636 assign_shallow_commits_to_refs(si
, NULL
, ref_status
);
1637 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1638 if (is_null_sha1(cmd
->new_sha1
))
1640 if (ref_status
[cmd
->index
]) {
1641 cmd
->error_string
= "shallow update not allowed";
1642 cmd
->skip_update
= 1;
1648 static void report(struct command
*commands
, const char *unpack_status
)
1650 struct command
*cmd
;
1651 struct strbuf buf
= STRBUF_INIT
;
1653 packet_buf_write(&buf
, "unpack %s\n",
1654 unpack_status
? unpack_status
: "ok");
1655 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1656 if (!cmd
->error_string
)
1657 packet_buf_write(&buf
, "ok %s\n",
1660 packet_buf_write(&buf
, "ng %s %s\n",
1661 cmd
->ref_name
, cmd
->error_string
);
1663 packet_buf_flush(&buf
);
1666 send_sideband(1, 1, buf
.buf
, buf
.len
, use_sideband
);
1668 write_or_die(1, buf
.buf
, buf
.len
);
1669 strbuf_release(&buf
);
1672 static int delete_only(struct command
*commands
)
1674 struct command
*cmd
;
1675 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1676 if (!is_null_sha1(cmd
->new_sha1
))
1682 int cmd_receive_pack(int argc
, const char **argv
, const char *prefix
)
1684 int advertise_refs
= 0;
1686 struct command
*commands
;
1687 struct sha1_array shallow
= SHA1_ARRAY_INIT
;
1688 struct sha1_array ref
= SHA1_ARRAY_INIT
;
1689 struct shallow_info si
;
1691 packet_trace_identity("receive-pack");
1694 for (i
= 1; i
< argc
; i
++) {
1695 const char *arg
= *argv
++;
1698 if (!strcmp(arg
, "--quiet")) {
1703 if (!strcmp(arg
, "--advertise-refs")) {
1707 if (!strcmp(arg
, "--stateless-rpc")) {
1711 if (!strcmp(arg
, "--reject-thin-pack-for-testing")) {
1716 usage(receive_pack_usage
);
1719 usage(receive_pack_usage
);
1723 usage(receive_pack_usage
);
1727 if (!enter_repo(service_dir
, 0))
1728 die("'%s' does not appear to be a git repository", service_dir
);
1730 git_config(receive_pack_config
, NULL
);
1731 if (cert_nonce_seed
)
1732 push_cert_nonce
= prepare_push_cert_nonce(service_dir
, time(NULL
));
1734 if (0 <= transfer_unpack_limit
)
1735 unpack_limit
= transfer_unpack_limit
;
1736 else if (0 <= receive_unpack_limit
)
1737 unpack_limit
= receive_unpack_limit
;
1739 if (advertise_refs
|| !stateless_rpc
) {
1745 if ((commands
= read_head_info(&shallow
)) != NULL
) {
1746 const char *unpack_status
= NULL
;
1748 prepare_shallow_info(&si
, &shallow
);
1749 if (!si
.nr_ours
&& !si
.nr_theirs
)
1751 if (!delete_only(commands
)) {
1752 unpack_status
= unpack_with_sideband(&si
);
1753 update_shallow_info(commands
, &si
, &ref
);
1755 execute_commands(commands
, unpack_status
, &si
);
1757 unlink_or_warn(pack_lockfile
);
1759 report(commands
, unpack_status
);
1760 run_receive_hook(commands
, "post-receive", 1);
1761 run_update_post_hook(commands
);
1763 const char *argv_gc_auto
[] = {
1764 "gc", "--auto", "--quiet", NULL
,
1766 int opt
= RUN_GIT_CMD
| RUN_COMMAND_STDOUT_TO_STDERR
;
1767 run_command_v_opt(argv_gc_auto
, opt
);
1769 if (auto_update_server_info
)
1770 update_server_info(0);
1771 clear_shallow_info(&si
);
1775 sha1_array_clear(&shallow
);
1776 sha1_array_clear(&ref
);
1777 free((void *)push_cert_nonce
);