3 #include "repository.h"
12 #include "run-command.h"
19 #include "string-list.h"
20 #include "oid-array.h"
21 #include "connected.h"
25 #include "gpg-interface.h"
28 #include "tmp-objdir.h"
31 #include "object-store.h"
33 #include "commit-reach.h"
38 static const char * const receive_pack_usage
[] = {
39 N_("git receive-pack <git-dir>"),
51 static int deny_deletes
;
52 static int deny_non_fast_forwards
;
53 static enum deny_action deny_current_branch
= DENY_UNCONFIGURED
;
54 static enum deny_action deny_delete_current
= DENY_UNCONFIGURED
;
55 static int receive_fsck_objects
= -1;
56 static int transfer_fsck_objects
= -1;
57 static struct strbuf fsck_msg_types
= STRBUF_INIT
;
58 static int receive_unpack_limit
= -1;
59 static int transfer_unpack_limit
= -1;
60 static int advertise_atomic_push
= 1;
61 static int advertise_push_options
;
62 static int advertise_sid
;
63 static int unpack_limit
= 100;
64 static off_t max_input_size
;
65 static int report_status
;
66 static int report_status_v2
;
67 static int use_sideband
;
68 static int use_atomic
;
69 static int use_push_options
;
71 static int prefer_ofs_delta
= 1;
72 static int auto_update_server_info
;
73 static int auto_gc
= 1;
74 static int reject_thin
;
75 static int stateless_rpc
;
76 static const char *service_dir
;
77 static const char *head_name
;
78 static void *head_name_to_free
;
79 static int sent_capabilities
;
80 static int shallow_update
;
81 static const char *alt_shallow_file
;
82 static struct strbuf push_cert
= STRBUF_INIT
;
83 static struct object_id push_cert_oid
;
84 static struct signature_check sigcheck
;
85 static const char *push_cert_nonce
;
86 static const char *cert_nonce_seed
;
87 static struct string_list hidden_refs
= STRING_LIST_INIT_DUP
;
89 static const char *NONCE_UNSOLICITED
= "UNSOLICITED";
90 static const char *NONCE_BAD
= "BAD";
91 static const char *NONCE_MISSING
= "MISSING";
92 static const char *NONCE_OK
= "OK";
93 static const char *NONCE_SLOP
= "SLOP";
94 static const char *nonce_status
;
95 static long nonce_stamp_slop
;
96 static timestamp_t nonce_stamp_slop_limit
;
97 static struct ref_transaction
*transaction
;
104 static int keepalive_in_sec
= 5;
106 static struct tmp_objdir
*tmp_objdir
;
108 static struct proc_receive_ref
{
109 unsigned int want_add
:1,
114 struct proc_receive_ref
*next
;
117 static void proc_receive_ref_append(const char *prefix
);
119 static enum deny_action
parse_deny_action(const char *var
, const char *value
)
122 if (!strcasecmp(value
, "ignore"))
124 if (!strcasecmp(value
, "warn"))
126 if (!strcasecmp(value
, "refuse"))
128 if (!strcasecmp(value
, "updateinstead"))
129 return DENY_UPDATE_INSTEAD
;
131 if (git_config_bool(var
, value
))
136 static int receive_pack_config(const char *var
, const char *value
, void *cb
)
138 int status
= parse_hide_refs_config(var
, value
, "receive", &hidden_refs
);
143 if (strcmp(var
, "receive.denydeletes") == 0) {
144 deny_deletes
= git_config_bool(var
, value
);
148 if (strcmp(var
, "receive.denynonfastforwards") == 0) {
149 deny_non_fast_forwards
= git_config_bool(var
, value
);
153 if (strcmp(var
, "receive.unpacklimit") == 0) {
154 receive_unpack_limit
= git_config_int(var
, value
);
158 if (strcmp(var
, "transfer.unpacklimit") == 0) {
159 transfer_unpack_limit
= git_config_int(var
, value
);
163 if (strcmp(var
, "receive.fsck.skiplist") == 0) {
166 if (git_config_pathname(&path
, var
, value
))
168 strbuf_addf(&fsck_msg_types
, "%cskiplist=%s",
169 fsck_msg_types
.len
? ',' : '=', path
);
174 if (skip_prefix(var
, "receive.fsck.", &var
)) {
175 if (is_valid_msg_type(var
, value
))
176 strbuf_addf(&fsck_msg_types
, "%c%s=%s",
177 fsck_msg_types
.len
? ',' : '=', var
, value
);
179 warning("skipping unknown msg id '%s'", var
);
183 if (strcmp(var
, "receive.fsckobjects") == 0) {
184 receive_fsck_objects
= git_config_bool(var
, value
);
188 if (strcmp(var
, "transfer.fsckobjects") == 0) {
189 transfer_fsck_objects
= git_config_bool(var
, value
);
193 if (!strcmp(var
, "receive.denycurrentbranch")) {
194 deny_current_branch
= parse_deny_action(var
, value
);
198 if (strcmp(var
, "receive.denydeletecurrent") == 0) {
199 deny_delete_current
= parse_deny_action(var
, value
);
203 if (strcmp(var
, "repack.usedeltabaseoffset") == 0) {
204 prefer_ofs_delta
= git_config_bool(var
, value
);
208 if (strcmp(var
, "receive.updateserverinfo") == 0) {
209 auto_update_server_info
= git_config_bool(var
, value
);
213 if (strcmp(var
, "receive.autogc") == 0) {
214 auto_gc
= git_config_bool(var
, value
);
218 if (strcmp(var
, "receive.shallowupdate") == 0) {
219 shallow_update
= git_config_bool(var
, value
);
223 if (strcmp(var
, "receive.certnonceseed") == 0)
224 return git_config_string(&cert_nonce_seed
, var
, value
);
226 if (strcmp(var
, "receive.certnonceslop") == 0) {
227 nonce_stamp_slop_limit
= git_config_ulong(var
, value
);
231 if (strcmp(var
, "receive.advertiseatomic") == 0) {
232 advertise_atomic_push
= git_config_bool(var
, value
);
236 if (strcmp(var
, "receive.advertisepushoptions") == 0) {
237 advertise_push_options
= git_config_bool(var
, value
);
241 if (strcmp(var
, "receive.keepalive") == 0) {
242 keepalive_in_sec
= git_config_int(var
, value
);
246 if (strcmp(var
, "receive.maxinputsize") == 0) {
247 max_input_size
= git_config_int64(var
, value
);
251 if (strcmp(var
, "receive.procreceiverefs") == 0) {
253 return config_error_nonbool(var
);
254 proc_receive_ref_append(value
);
258 if (strcmp(var
, "transfer.advertisesid") == 0) {
259 advertise_sid
= git_config_bool(var
, value
);
263 return git_default_config(var
, value
, cb
);
266 static void show_ref(const char *path
, const struct object_id
*oid
)
268 if (sent_capabilities
) {
269 packet_write_fmt(1, "%s %s\n", oid_to_hex(oid
), path
);
271 struct strbuf cap
= STRBUF_INIT
;
274 "report-status report-status-v2 delete-refs side-band-64k quiet");
275 if (advertise_atomic_push
)
276 strbuf_addstr(&cap
, " atomic");
277 if (prefer_ofs_delta
)
278 strbuf_addstr(&cap
, " ofs-delta");
280 strbuf_addf(&cap
, " push-cert=%s", push_cert_nonce
);
281 if (advertise_push_options
)
282 strbuf_addstr(&cap
, " push-options");
284 strbuf_addf(&cap
, " session-id=%s", trace2_session_id());
285 strbuf_addf(&cap
, " object-format=%s", the_hash_algo
->name
);
286 strbuf_addf(&cap
, " agent=%s", git_user_agent_sanitized());
287 packet_write_fmt(1, "%s %s%c%s\n",
288 oid_to_hex(oid
), path
, 0, cap
.buf
);
289 strbuf_release(&cap
);
290 sent_capabilities
= 1;
294 static int show_ref_cb(const char *path_full
, const struct object_id
*oid
,
295 int flag UNUSED
, void *data
)
297 struct oidset
*seen
= data
;
298 const char *path
= strip_namespace(path_full
);
300 if (ref_is_hidden(path
, path_full
, &hidden_refs
))
304 * Advertise refs outside our current namespace as ".have"
305 * refs, so that the client can use them to minimize data
306 * transfer but will otherwise ignore them.
309 if (oidset_insert(seen
, oid
))
313 oidset_insert(seen
, oid
);
319 static void show_one_alternate_ref(const struct object_id
*oid
,
322 struct oidset
*seen
= data
;
324 if (oidset_insert(seen
, oid
))
327 show_ref(".have", oid
);
330 static void write_head_info(void)
332 static struct oidset seen
= OIDSET_INIT
;
334 for_each_ref(show_ref_cb
, &seen
);
335 for_each_alternate_ref(show_one_alternate_ref
, &seen
);
337 if (!sent_capabilities
)
338 show_ref("capabilities^{}", null_oid());
340 advertise_shallow_grafts(1);
346 #define RUN_PROC_RECEIVE_SCHEDULED 1
347 #define RUN_PROC_RECEIVE_RETURNED 2
349 struct command
*next
;
350 const char *error_string
;
351 struct ref_push_report
*report
;
352 unsigned int skip_update
:1,
356 struct object_id old_oid
;
357 struct object_id new_oid
;
358 char ref_name
[FLEX_ARRAY
]; /* more */
361 static void proc_receive_ref_append(const char *prefix
)
363 struct proc_receive_ref
*ref_pattern
;
367 CALLOC_ARRAY(ref_pattern
, 1);
368 p
= strchr(prefix
, ':');
372 ref_pattern
->want_add
= 1;
373 else if (*prefix
== 'd')
374 ref_pattern
->want_delete
= 1;
375 else if (*prefix
== 'm')
376 ref_pattern
->want_modify
= 1;
377 else if (*prefix
== '!')
378 ref_pattern
->negative_ref
= 1;
383 ref_pattern
->want_add
= 1;
384 ref_pattern
->want_delete
= 1;
385 ref_pattern
->want_modify
= 1;
387 len
= strlen(prefix
);
388 while (len
&& prefix
[len
- 1] == '/')
390 ref_pattern
->ref_prefix
= xmemdupz(prefix
, len
);
391 if (!proc_receive_ref
) {
392 proc_receive_ref
= ref_pattern
;
394 struct proc_receive_ref
*end
;
396 end
= proc_receive_ref
;
399 end
->next
= ref_pattern
;
403 static int proc_receive_ref_matches(struct command
*cmd
)
405 struct proc_receive_ref
*p
;
407 if (!proc_receive_ref
)
410 for (p
= proc_receive_ref
; p
; p
= p
->next
) {
411 const char *match
= p
->ref_prefix
;
414 if (!p
->want_add
&& is_null_oid(&cmd
->old_oid
))
416 else if (!p
->want_delete
&& is_null_oid(&cmd
->new_oid
))
418 else if (!p
->want_modify
&&
419 !is_null_oid(&cmd
->old_oid
) &&
420 !is_null_oid(&cmd
->new_oid
))
423 if (skip_prefix(cmd
->ref_name
, match
, &remains
) &&
424 (!*remains
|| *remains
== '/')) {
425 if (!p
->negative_ref
)
427 } else if (p
->negative_ref
) {
434 static void report_message(const char *prefix
, const char *err
, va_list params
)
439 sz
= xsnprintf(msg
, sizeof(msg
), "%s", prefix
);
440 sz
+= vsnprintf(msg
+ sz
, sizeof(msg
) - sz
, err
, params
);
441 if (sz
> (sizeof(msg
) - 1))
442 sz
= sizeof(msg
) - 1;
446 send_sideband(1, 2, msg
, sz
, use_sideband
);
451 __attribute__((format (printf
, 1, 2)))
452 static void rp_warning(const char *err
, ...)
455 va_start(params
, err
);
456 report_message("warning: ", err
, params
);
460 __attribute__((format (printf
, 1, 2)))
461 static void rp_error(const char *err
, ...)
464 va_start(params
, err
);
465 report_message("error: ", err
, params
);
469 static int copy_to_sideband(int in
, int out UNUSED
, void *arg UNUSED
)
472 int keepalive_active
= 0;
474 if (keepalive_in_sec
<= 0)
475 use_keepalive
= KEEPALIVE_NEVER
;
476 if (use_keepalive
== KEEPALIVE_ALWAYS
)
477 keepalive_active
= 1;
482 if (keepalive_active
) {
488 ret
= poll(&pfd
, 1, 1000 * keepalive_in_sec
);
495 } else if (ret
== 0) {
496 /* no data; send a keepalive packet */
497 static const char buf
[] = "0005\1";
498 write_or_die(1, buf
, sizeof(buf
) - 1);
500 } /* else there is actual data to read */
503 sz
= xread(in
, data
, sizeof(data
));
507 if (use_keepalive
== KEEPALIVE_AFTER_NUL
&& !keepalive_active
) {
508 const char *p
= memchr(data
, '\0', sz
);
511 * The NUL tells us to start sending keepalives. Make
512 * sure we send any other data we read along
515 keepalive_active
= 1;
516 send_sideband(1, 2, data
, p
- data
, use_sideband
);
517 send_sideband(1, 2, p
+ 1, sz
- (p
- data
+ 1), use_sideband
);
523 * Either we're not looking for a NUL signal, or we didn't see
524 * it yet; just pass along the data.
526 send_sideband(1, 2, data
, sz
, use_sideband
);
532 static void hmac_hash(unsigned char *out
,
533 const char *key_in
, size_t key_len
,
534 const char *text
, size_t text_len
)
536 unsigned char key
[GIT_MAX_BLKSZ
];
537 unsigned char k_ipad
[GIT_MAX_BLKSZ
];
538 unsigned char k_opad
[GIT_MAX_BLKSZ
];
542 /* RFC 2104 2. (1) */
543 memset(key
, '\0', GIT_MAX_BLKSZ
);
544 if (the_hash_algo
->blksz
< key_len
) {
545 the_hash_algo
->init_fn(&ctx
);
546 the_hash_algo
->update_fn(&ctx
, key_in
, key_len
);
547 the_hash_algo
->final_fn(key
, &ctx
);
549 memcpy(key
, key_in
, key_len
);
552 /* RFC 2104 2. (2) & (5) */
553 for (i
= 0; i
< sizeof(key
); i
++) {
554 k_ipad
[i
] = key
[i
] ^ 0x36;
555 k_opad
[i
] = key
[i
] ^ 0x5c;
558 /* RFC 2104 2. (3) & (4) */
559 the_hash_algo
->init_fn(&ctx
);
560 the_hash_algo
->update_fn(&ctx
, k_ipad
, sizeof(k_ipad
));
561 the_hash_algo
->update_fn(&ctx
, text
, text_len
);
562 the_hash_algo
->final_fn(out
, &ctx
);
564 /* RFC 2104 2. (6) & (7) */
565 the_hash_algo
->init_fn(&ctx
);
566 the_hash_algo
->update_fn(&ctx
, k_opad
, sizeof(k_opad
));
567 the_hash_algo
->update_fn(&ctx
, out
, the_hash_algo
->rawsz
);
568 the_hash_algo
->final_fn(out
, &ctx
);
571 static char *prepare_push_cert_nonce(const char *path
, timestamp_t stamp
)
573 struct strbuf buf
= STRBUF_INIT
;
574 unsigned char hash
[GIT_MAX_RAWSZ
];
576 strbuf_addf(&buf
, "%s:%"PRItime
, path
, stamp
);
577 hmac_hash(hash
, buf
.buf
, buf
.len
, cert_nonce_seed
, strlen(cert_nonce_seed
));
578 strbuf_release(&buf
);
580 /* RFC 2104 5. HMAC-SHA1 or HMAC-SHA256 */
581 strbuf_addf(&buf
, "%"PRItime
"-%.*s", stamp
, (int)the_hash_algo
->hexsz
, hash_to_hex(hash
));
582 return strbuf_detach(&buf
, NULL
);
585 static char *find_header(const char *msg
, size_t len
, const char *key
,
586 const char **next_line
)
589 const char *val
= find_header_mem(msg
, len
, key
, &out_len
);
595 *next_line
= val
+ out_len
+ 1;
597 return xmemdupz(val
, out_len
);
601 * Return zero if a and b are equal up to n bytes and nonzero if they are not.
602 * This operation is guaranteed to run in constant time to avoid leaking data.
604 static int constant_memequal(const char *a
, const char *b
, size_t n
)
609 for (i
= 0; i
< n
; i
++)
614 static const char *check_nonce(const char *buf
, size_t len
)
616 char *nonce
= find_header(buf
, len
, "nonce", NULL
);
617 timestamp_t stamp
, ostamp
;
618 char *bohmac
, *expect
= NULL
;
619 const char *retval
= NONCE_BAD
;
623 retval
= NONCE_MISSING
;
625 } else if (!push_cert_nonce
) {
626 retval
= NONCE_UNSOLICITED
;
628 } else if (!strcmp(push_cert_nonce
, nonce
)) {
633 if (!stateless_rpc
) {
634 /* returned nonce MUST match what we gave out earlier */
640 * In stateless mode, we may be receiving a nonce issued by
641 * another instance of the server that serving the same
642 * repository, and the timestamps may not match, but the
643 * nonce-seed and dir should match, so we can recompute and
644 * report the time slop.
646 * In addition, when a nonce issued by another instance has
647 * timestamp within receive.certnonceslop seconds, we pretend
648 * as if we issued that nonce when reporting to the hook.
651 /* nonce is concat(<seconds-since-epoch>, "-", <hmac>) */
652 if (*nonce
<= '0' || '9' < *nonce
) {
656 stamp
= parse_timestamp(nonce
, &bohmac
, 10);
657 if (bohmac
== nonce
|| bohmac
[0] != '-') {
662 noncelen
= strlen(nonce
);
663 expect
= prepare_push_cert_nonce(service_dir
, stamp
);
664 if (noncelen
!= strlen(expect
)) {
665 /* This is not even the right size. */
669 if (constant_memequal(expect
, nonce
, noncelen
)) {
670 /* Not what we would have signed earlier */
676 * By how many seconds is this nonce stale? Negative value
677 * would mean it was issued by another server with its clock
678 * skewed in the future.
680 ostamp
= parse_timestamp(push_cert_nonce
, NULL
, 10);
681 nonce_stamp_slop
= (long)ostamp
- (long)stamp
;
683 if (nonce_stamp_slop_limit
&&
684 labs(nonce_stamp_slop
) <= nonce_stamp_slop_limit
) {
686 * Pretend as if the received nonce (which passes the
687 * HMAC check, so it is not a forged by third-party)
690 free((void *)push_cert_nonce
);
691 push_cert_nonce
= xstrdup(nonce
);
704 * Return 1 if there is no push_cert or if the push options in push_cert are
705 * the same as those in the argument; 0 otherwise.
707 static int check_cert_push_options(const struct string_list
*push_options
)
709 const char *buf
= push_cert
.buf
;
710 int len
= push_cert
.len
;
713 const char *next_line
;
714 int options_seen
= 0;
721 while ((option
= find_header(buf
, len
, "push-option", &next_line
))) {
722 len
-= (next_line
- buf
);
725 if (options_seen
> push_options
->nr
727 push_options
->items
[options_seen
- 1].string
)) {
734 if (options_seen
!= push_options
->nr
)
742 static void prepare_push_cert_sha1(struct child_process
*proc
)
744 static int already_done
;
750 int bogs
/* beginning_of_gpg_sig */;
753 if (write_object_file(push_cert
.buf
, push_cert
.len
, OBJ_BLOB
,
755 oidclr(&push_cert_oid
);
757 memset(&sigcheck
, '\0', sizeof(sigcheck
));
759 bogs
= parse_signed_buffer(push_cert
.buf
, push_cert
.len
);
760 sigcheck
.payload
= xmemdupz(push_cert
.buf
, bogs
);
761 sigcheck
.payload_len
= bogs
;
762 check_signature(&sigcheck
, push_cert
.buf
+ bogs
,
763 push_cert
.len
- bogs
);
765 nonce_status
= check_nonce(push_cert
.buf
, bogs
);
767 if (!is_null_oid(&push_cert_oid
)) {
768 strvec_pushf(&proc
->env
, "GIT_PUSH_CERT=%s",
769 oid_to_hex(&push_cert_oid
));
770 strvec_pushf(&proc
->env
, "GIT_PUSH_CERT_SIGNER=%s",
771 sigcheck
.signer
? sigcheck
.signer
: "");
772 strvec_pushf(&proc
->env
, "GIT_PUSH_CERT_KEY=%s",
773 sigcheck
.key
? sigcheck
.key
: "");
774 strvec_pushf(&proc
->env
, "GIT_PUSH_CERT_STATUS=%c",
776 if (push_cert_nonce
) {
777 strvec_pushf(&proc
->env
,
778 "GIT_PUSH_CERT_NONCE=%s",
780 strvec_pushf(&proc
->env
,
781 "GIT_PUSH_CERT_NONCE_STATUS=%s",
783 if (nonce_status
== NONCE_SLOP
)
784 strvec_pushf(&proc
->env
,
785 "GIT_PUSH_CERT_NONCE_SLOP=%ld",
791 struct receive_hook_feed_state
{
793 struct ref_push_report
*report
;
796 const struct string_list
*push_options
;
799 typedef int (*feed_fn
)(void *, const char **, size_t *);
800 static int run_and_feed_hook(const char *hook_name
, feed_fn feed
,
801 struct receive_hook_feed_state
*feed_state
)
803 struct child_process proc
= CHILD_PROCESS_INIT
;
806 const char *hook_path
= find_hook(hook_name
);
811 strvec_push(&proc
.args
, hook_path
);
813 proc
.stdout_to_stderr
= 1;
814 proc
.trace2_hook_name
= hook_name
;
816 if (feed_state
->push_options
) {
818 for (i
= 0; i
< feed_state
->push_options
->nr
; i
++)
819 strvec_pushf(&proc
.env
,
820 "GIT_PUSH_OPTION_%"PRIuMAX
"=%s",
822 feed_state
->push_options
->items
[i
].string
);
823 strvec_pushf(&proc
.env
, "GIT_PUSH_OPTION_COUNT=%"PRIuMAX
"",
824 (uintmax_t)feed_state
->push_options
->nr
);
826 strvec_pushf(&proc
.env
, "GIT_PUSH_OPTION_COUNT");
829 strvec_pushv(&proc
.env
, tmp_objdir_env(tmp_objdir
));
832 memset(&muxer
, 0, sizeof(muxer
));
833 muxer
.proc
= copy_to_sideband
;
835 code
= start_async(&muxer
);
841 prepare_push_cert_sha1(&proc
);
843 code
= start_command(&proc
);
846 finish_async(&muxer
);
850 sigchain_push(SIGPIPE
, SIG_IGN
);
855 if (feed(feed_state
, &buf
, &n
))
857 if (write_in_full(proc
.in
, buf
, n
) < 0)
862 finish_async(&muxer
);
864 sigchain_pop(SIGPIPE
);
866 return finish_command(&proc
);
869 static int feed_receive_hook(void *state_
, const char **bufp
, size_t *sizep
)
871 struct receive_hook_feed_state
*state
= state_
;
872 struct command
*cmd
= state
->cmd
;
875 state
->skip_broken
&& (cmd
->error_string
|| cmd
->did_not_exist
))
880 return 0; /* OK, can feed something. */
881 strbuf_reset(&state
->buf
);
883 state
->report
= cmd
->report
;
885 struct object_id
*old_oid
;
886 struct object_id
*new_oid
;
887 const char *ref_name
;
889 old_oid
= state
->report
->old_oid
? state
->report
->old_oid
: &cmd
->old_oid
;
890 new_oid
= state
->report
->new_oid
? state
->report
->new_oid
: &cmd
->new_oid
;
891 ref_name
= state
->report
->ref_name
? state
->report
->ref_name
: cmd
->ref_name
;
892 strbuf_addf(&state
->buf
, "%s %s %s\n",
893 oid_to_hex(old_oid
), oid_to_hex(new_oid
),
895 state
->report
= state
->report
->next
;
897 state
->cmd
= cmd
->next
;
899 strbuf_addf(&state
->buf
, "%s %s %s\n",
900 oid_to_hex(&cmd
->old_oid
), oid_to_hex(&cmd
->new_oid
),
902 state
->cmd
= cmd
->next
;
905 *bufp
= state
->buf
.buf
;
906 *sizep
= state
->buf
.len
;
911 static int run_receive_hook(struct command
*commands
,
912 const char *hook_name
,
914 const struct string_list
*push_options
)
916 struct receive_hook_feed_state state
;
919 strbuf_init(&state
.buf
, 0);
920 state
.cmd
= commands
;
921 state
.skip_broken
= skip_broken
;
923 if (feed_receive_hook(&state
, NULL
, NULL
))
925 state
.cmd
= commands
;
926 state
.push_options
= push_options
;
927 status
= run_and_feed_hook(hook_name
, feed_receive_hook
, &state
);
928 strbuf_release(&state
.buf
);
932 static int run_update_hook(struct command
*cmd
)
934 struct child_process proc
= CHILD_PROCESS_INIT
;
936 const char *hook_path
= find_hook("update");
941 strvec_push(&proc
.args
, hook_path
);
942 strvec_push(&proc
.args
, cmd
->ref_name
);
943 strvec_push(&proc
.args
, oid_to_hex(&cmd
->old_oid
));
944 strvec_push(&proc
.args
, oid_to_hex(&cmd
->new_oid
));
947 proc
.stdout_to_stderr
= 1;
948 proc
.err
= use_sideband
? -1 : 0;
949 proc
.trace2_hook_name
= "update";
951 code
= start_command(&proc
);
955 copy_to_sideband(proc
.err
, -1, NULL
);
956 return finish_command(&proc
);
959 static struct command
*find_command_by_refname(struct command
*list
,
962 for (; list
; list
= list
->next
)
963 if (!strcmp(list
->ref_name
, refname
))
968 static int read_proc_receive_report(struct packet_reader
*reader
,
969 struct command
*commands
,
970 struct strbuf
*errmsg
)
973 struct command
*hint
= NULL
;
974 struct ref_push_report
*report
= NULL
;
981 struct object_id old_oid
, new_oid
;
985 enum packet_read_status status
;
987 status
= packet_reader_read(reader
);
988 if (status
!= PACKET_READ_NORMAL
) {
989 /* Check whether proc-receive exited abnormally */
990 if (status
== PACKET_READ_EOF
&& !response
) {
991 strbuf_addstr(errmsg
, "proc-receive exited abnormally");
999 p
= strchr(head
, ' ');
1001 strbuf_addf(errmsg
, "proc-receive reported incomplete status line: '%s'\n", head
);
1006 if (!strcmp(head
, "option")) {
1007 const char *key
, *val
;
1009 if (!hint
|| !(report
|| new_report
)) {
1011 strbuf_addstr(errmsg
, "proc-receive reported 'option' without a matching 'ok/ng' directive\n");
1016 if (!hint
->report
) {
1017 CALLOC_ARRAY(hint
->report
, 1);
1018 report
= hint
->report
;
1020 report
= hint
->report
;
1021 while (report
->next
)
1022 report
= report
->next
;
1023 report
->next
= xcalloc(1, sizeof(struct ref_push_report
));
1024 report
= report
->next
;
1029 p
= strchr(key
, ' ');
1033 if (!strcmp(key
, "refname"))
1034 report
->ref_name
= xstrdup_or_null(val
);
1035 else if (!strcmp(key
, "old-oid") && val
&&
1036 !parse_oid_hex(val
, &old_oid
, &val
))
1037 report
->old_oid
= oiddup(&old_oid
);
1038 else if (!strcmp(key
, "new-oid") && val
&&
1039 !parse_oid_hex(val
, &new_oid
, &val
))
1040 report
->new_oid
= oiddup(&new_oid
);
1041 else if (!strcmp(key
, "forced-update"))
1042 report
->forced_update
= 1;
1043 else if (!strcmp(key
, "fall-through"))
1044 /* Fall through, let 'receive-pack' to execute it. */
1045 hint
->run_proc_receive
= 0;
1052 p
= strchr(refname
, ' ');
1055 if (strcmp(head
, "ok") && strcmp(head
, "ng")) {
1056 strbuf_addf(errmsg
, "proc-receive reported bad status '%s' on ref '%s'\n",
1062 /* first try searching at our hint, falling back to all refs */
1064 hint
= find_command_by_refname(hint
, refname
);
1066 hint
= find_command_by_refname(commands
, refname
);
1068 strbuf_addf(errmsg
, "proc-receive reported status on unknown ref: %s\n",
1073 if (!hint
->run_proc_receive
) {
1074 strbuf_addf(errmsg
, "proc-receive reported status on unexpected ref: %s\n",
1079 hint
->run_proc_receive
|= RUN_PROC_RECEIVE_RETURNED
;
1080 if (!strcmp(head
, "ng")) {
1082 hint
->error_string
= xstrdup(p
);
1084 hint
->error_string
= "failed";
1091 for (cmd
= commands
; cmd
; cmd
= cmd
->next
)
1092 if (cmd
->run_proc_receive
&& !cmd
->error_string
&&
1093 !(cmd
->run_proc_receive
& RUN_PROC_RECEIVE_RETURNED
)) {
1094 cmd
->error_string
= "proc-receive failed to report status";
1100 static int run_proc_receive_hook(struct command
*commands
,
1101 const struct string_list
*push_options
)
1103 struct child_process proc
= CHILD_PROCESS_INIT
;
1105 struct command
*cmd
;
1106 struct packet_reader reader
;
1107 struct strbuf cap
= STRBUF_INIT
;
1108 struct strbuf errmsg
= STRBUF_INIT
;
1109 int hook_use_push_options
= 0;
1112 const char *hook_path
= find_hook("proc-receive");
1115 rp_error("cannot find hook 'proc-receive'");
1119 strvec_push(&proc
.args
, hook_path
);
1122 proc
.trace2_hook_name
= "proc-receive";
1125 memset(&muxer
, 0, sizeof(muxer
));
1126 muxer
.proc
= copy_to_sideband
;
1128 code
= start_async(&muxer
);
1131 proc
.err
= muxer
.in
;
1136 code
= start_command(&proc
);
1139 finish_async(&muxer
);
1143 sigchain_push(SIGPIPE
, SIG_IGN
);
1145 /* Version negotiaton */
1146 packet_reader_init(&reader
, proc
.out
, NULL
, 0,
1147 PACKET_READ_CHOMP_NEWLINE
|
1148 PACKET_READ_GENTLE_ON_EOF
);
1150 strbuf_addstr(&cap
, " atomic");
1151 if (use_push_options
)
1152 strbuf_addstr(&cap
, " push-options");
1154 code
= packet_write_fmt_gently(proc
.in
, "version=1%c%s\n", '\0', cap
.buf
+ 1);
1155 strbuf_release(&cap
);
1157 code
= packet_write_fmt_gently(proc
.in
, "version=1\n");
1160 code
= packet_flush_gently(proc
.in
);
1165 enum packet_read_status status
;
1167 status
= packet_reader_read(&reader
);
1168 if (status
!= PACKET_READ_NORMAL
) {
1169 /* Check whether proc-receive exited abnormally */
1170 if (status
== PACKET_READ_EOF
)
1175 if (reader
.pktlen
> 8 && starts_with(reader
.line
, "version=")) {
1176 version
= atoi(reader
.line
+ 8);
1177 linelen
= strlen(reader
.line
);
1178 if (linelen
< reader
.pktlen
) {
1179 const char *feature_list
= reader
.line
+ linelen
+ 1;
1180 if (parse_feature_request(feature_list
, "push-options"))
1181 hook_use_push_options
= 1;
1187 strbuf_addstr(&errmsg
, "fail to negotiate version with proc-receive hook");
1197 strbuf_addf(&errmsg
, "proc-receive version '%d' is not supported",
1204 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1205 if (!cmd
->run_proc_receive
|| cmd
->skip_update
|| cmd
->error_string
)
1207 code
= packet_write_fmt_gently(proc
.in
, "%s %s %s",
1208 oid_to_hex(&cmd
->old_oid
),
1209 oid_to_hex(&cmd
->new_oid
),
1215 code
= packet_flush_gently(proc
.in
);
1217 strbuf_addstr(&errmsg
, "fail to write commands to proc-receive hook");
1221 /* Send push options */
1222 if (hook_use_push_options
) {
1223 struct string_list_item
*item
;
1225 for_each_string_list_item(item
, push_options
) {
1226 code
= packet_write_fmt_gently(proc
.in
, "%s", item
->string
);
1231 code
= packet_flush_gently(proc
.in
);
1233 strbuf_addstr(&errmsg
,
1234 "fail to write push-options to proc-receive hook");
1239 /* Read result from proc-receive */
1240 code
= read_proc_receive_report(&reader
, commands
, &errmsg
);
1246 finish_async(&muxer
);
1247 if (finish_command(&proc
))
1249 if (errmsg
.len
>0) {
1250 char *p
= errmsg
.buf
;
1252 p
+= errmsg
.len
- 1;
1255 rp_error("%s", errmsg
.buf
);
1256 strbuf_release(&errmsg
);
1258 sigchain_pop(SIGPIPE
);
1263 static char *refuse_unconfigured_deny_msg
=
1264 N_("By default, updating the current branch in a non-bare repository\n"
1265 "is denied, because it will make the index and work tree inconsistent\n"
1266 "with what you pushed, and will require 'git reset --hard' to match\n"
1267 "the work tree to HEAD.\n"
1269 "You can set the 'receive.denyCurrentBranch' configuration variable\n"
1270 "to 'ignore' or 'warn' in the remote repository to allow pushing into\n"
1271 "its current branch; however, this is not recommended unless you\n"
1272 "arranged to update its work tree to match what you pushed in some\n"
1275 "To squelch this message and still keep the default behaviour, set\n"
1276 "'receive.denyCurrentBranch' configuration variable to 'refuse'.");
1278 static void refuse_unconfigured_deny(void)
1280 rp_error("%s", _(refuse_unconfigured_deny_msg
));
1283 static char *refuse_unconfigured_deny_delete_current_msg
=
1284 N_("By default, deleting the current branch is denied, because the next\n"
1285 "'git clone' won't result in any file checked out, causing confusion.\n"
1287 "You can set 'receive.denyDeleteCurrent' configuration variable to\n"
1288 "'warn' or 'ignore' in the remote repository to allow deleting the\n"
1289 "current branch, with or without a warning message.\n"
1291 "To squelch this message, you can set it to 'refuse'.");
1293 static void refuse_unconfigured_deny_delete_current(void)
1295 rp_error("%s", _(refuse_unconfigured_deny_delete_current_msg
));
1298 static const struct object_id
*command_singleton_iterator(void *cb_data
);
1299 static int update_shallow_ref(struct command
*cmd
, struct shallow_info
*si
)
1301 struct shallow_lock shallow_lock
= SHALLOW_LOCK_INIT
;
1302 struct oid_array extra
= OID_ARRAY_INIT
;
1303 struct check_connected_options opt
= CHECK_CONNECTED_INIT
;
1304 uint32_t mask
= 1 << (cmd
->index
% 32);
1307 trace_printf_key(&trace_shallow
,
1308 "shallow: update_shallow_ref %s\n", cmd
->ref_name
);
1309 for (i
= 0; i
< si
->shallow
->nr
; i
++)
1310 if (si
->used_shallow
[i
] &&
1311 (si
->used_shallow
[i
][cmd
->index
/ 32] & mask
) &&
1312 !delayed_reachability_test(si
, i
))
1313 oid_array_append(&extra
, &si
->shallow
->oid
[i
]);
1315 opt
.env
= tmp_objdir_env(tmp_objdir
);
1316 setup_alternate_shallow(&shallow_lock
, &opt
.shallow_file
, &extra
);
1317 if (check_connected(command_singleton_iterator
, cmd
, &opt
)) {
1318 rollback_shallow_file(the_repository
, &shallow_lock
);
1319 oid_array_clear(&extra
);
1323 commit_shallow_file(the_repository
, &shallow_lock
);
1326 * Make sure setup_alternate_shallow() for the next ref does
1327 * not lose these new roots..
1329 for (i
= 0; i
< extra
.nr
; i
++)
1330 register_shallow(the_repository
, &extra
.oid
[i
]);
1332 si
->shallow_ref
[cmd
->index
] = 0;
1333 oid_array_clear(&extra
);
1338 * NEEDSWORK: we should consolidate various implementions of "are we
1339 * on an unborn branch?" test into one, and make the unified one more
1340 * robust. !get_sha1() based check used here and elsewhere would not
1341 * allow us to tell an unborn branch from corrupt ref, for example.
1342 * For the purpose of fixing "deploy-to-update does not work when
1343 * pushing into an empty repository" issue, this should suffice for
1346 static int head_has_history(void)
1348 struct object_id oid
;
1350 return !get_oid("HEAD", &oid
);
1353 static const char *push_to_deploy(unsigned char *sha1
,
1355 const char *work_tree
)
1357 struct child_process child
= CHILD_PROCESS_INIT
;
1359 strvec_pushl(&child
.args
, "update-index", "-q", "--ignore-submodules",
1361 strvec_pushv(&child
.env
, env
->v
);
1362 child
.dir
= work_tree
;
1364 child
.stdout_to_stderr
= 1;
1366 if (run_command(&child
))
1367 return "Up-to-date check failed";
1369 /* run_command() does not clean up completely; reinitialize */
1370 child_process_init(&child
);
1371 strvec_pushl(&child
.args
, "diff-files", "--quiet",
1372 "--ignore-submodules", "--", NULL
);
1373 strvec_pushv(&child
.env
, env
->v
);
1374 child
.dir
= work_tree
;
1376 child
.stdout_to_stderr
= 1;
1378 if (run_command(&child
))
1379 return "Working directory has unstaged changes";
1381 child_process_init(&child
);
1382 strvec_pushl(&child
.args
, "diff-index", "--quiet", "--cached",
1383 "--ignore-submodules",
1384 /* diff-index with either HEAD or an empty tree */
1385 head_has_history() ? "HEAD" : empty_tree_oid_hex(),
1387 strvec_pushv(&child
.env
, env
->v
);
1389 child
.no_stdout
= 1;
1390 child
.stdout_to_stderr
= 0;
1392 if (run_command(&child
))
1393 return "Working directory has staged changes";
1395 child_process_init(&child
);
1396 strvec_pushl(&child
.args
, "read-tree", "-u", "-m", hash_to_hex(sha1
),
1398 strvec_pushv(&child
.env
, env
->v
);
1399 child
.dir
= work_tree
;
1401 child
.no_stdout
= 1;
1402 child
.stdout_to_stderr
= 0;
1404 if (run_command(&child
))
1405 return "Could not update working tree to new HEAD";
1410 static const char *push_to_checkout_hook
= "push-to-checkout";
1412 static const char *push_to_checkout(unsigned char *hash
,
1415 const char *work_tree
)
1417 struct run_hooks_opt opt
= RUN_HOOKS_OPT_INIT
;
1418 opt
.invoked_hook
= invoked_hook
;
1420 strvec_pushf(env
, "GIT_WORK_TREE=%s", absolute_path(work_tree
));
1421 strvec_pushv(&opt
.env
, env
->v
);
1422 strvec_push(&opt
.args
, hash_to_hex(hash
));
1423 if (run_hooks_opt(push_to_checkout_hook
, &opt
))
1424 return "push-to-checkout hook declined";
1429 static const char *update_worktree(unsigned char *sha1
, const struct worktree
*worktree
)
1431 const char *retval
, *git_dir
;
1432 struct strvec env
= STRVEC_INIT
;
1435 if (!worktree
|| !worktree
->path
)
1436 BUG("worktree->path must be non-NULL");
1438 if (worktree
->is_bare
)
1439 return "denyCurrentBranch = updateInstead needs a worktree";
1440 git_dir
= get_worktree_git_dir(worktree
);
1442 strvec_pushf(&env
, "GIT_DIR=%s", absolute_path(git_dir
));
1444 retval
= push_to_checkout(sha1
, &invoked_hook
, &env
, worktree
->path
);
1446 retval
= push_to_deploy(sha1
, &env
, worktree
->path
);
1452 static const char *update(struct command
*cmd
, struct shallow_info
*si
)
1454 const char *name
= cmd
->ref_name
;
1455 struct strbuf namespaced_name_buf
= STRBUF_INIT
;
1456 static char *namespaced_name
;
1458 struct object_id
*old_oid
= &cmd
->old_oid
;
1459 struct object_id
*new_oid
= &cmd
->new_oid
;
1460 int do_update_worktree
= 0;
1461 struct worktree
**worktrees
= get_worktrees();
1462 const struct worktree
*worktree
=
1463 find_shared_symref(worktrees
, "HEAD", name
);
1465 /* only refs/... are allowed */
1466 if (!starts_with(name
, "refs/") ||
1467 check_refname_format(name
+ 5, is_null_oid(new_oid
) ?
1468 REFNAME_ALLOW_ONELEVEL
: 0)) {
1469 rp_error("refusing to update funny ref '%s' remotely", name
);
1470 ret
= "funny refname";
1474 strbuf_addf(&namespaced_name_buf
, "%s%s", get_git_namespace(), name
);
1475 free(namespaced_name
);
1476 namespaced_name
= strbuf_detach(&namespaced_name_buf
, NULL
);
1478 if (worktree
&& !worktree
->is_bare
) {
1479 switch (deny_current_branch
) {
1483 rp_warning("updating the current branch");
1486 case DENY_UNCONFIGURED
:
1487 rp_error("refusing to update checked out branch: %s", name
);
1488 if (deny_current_branch
== DENY_UNCONFIGURED
)
1489 refuse_unconfigured_deny();
1490 ret
= "branch is currently checked out";
1492 case DENY_UPDATE_INSTEAD
:
1493 /* pass -- let other checks intervene first */
1494 do_update_worktree
= 1;
1499 if (!is_null_oid(new_oid
) && !has_object_file(new_oid
)) {
1500 error("unpack should have generated %s, "
1501 "but I can't find it!", oid_to_hex(new_oid
));
1506 if (!is_null_oid(old_oid
) && is_null_oid(new_oid
)) {
1507 if (deny_deletes
&& starts_with(name
, "refs/heads/")) {
1508 rp_error("denying ref deletion for %s", name
);
1509 ret
= "deletion prohibited";
1513 if (worktree
|| (head_name
&& !strcmp(namespaced_name
, head_name
))) {
1514 switch (deny_delete_current
) {
1518 rp_warning("deleting the current branch");
1521 case DENY_UNCONFIGURED
:
1522 case DENY_UPDATE_INSTEAD
:
1523 if (deny_delete_current
== DENY_UNCONFIGURED
)
1524 refuse_unconfigured_deny_delete_current();
1525 rp_error("refusing to delete the current branch: %s", name
);
1526 ret
= "deletion of the current branch prohibited";
1529 ret
= "Invalid denyDeleteCurrent setting";
1535 if (deny_non_fast_forwards
&& !is_null_oid(new_oid
) &&
1536 !is_null_oid(old_oid
) &&
1537 starts_with(name
, "refs/heads/")) {
1538 struct object
*old_object
, *new_object
;
1539 struct commit
*old_commit
, *new_commit
;
1541 old_object
= parse_object(the_repository
, old_oid
);
1542 new_object
= parse_object(the_repository
, new_oid
);
1544 if (!old_object
|| !new_object
||
1545 old_object
->type
!= OBJ_COMMIT
||
1546 new_object
->type
!= OBJ_COMMIT
) {
1547 error("bad sha1 objects for %s", name
);
1551 old_commit
= (struct commit
*)old_object
;
1552 new_commit
= (struct commit
*)new_object
;
1553 if (!in_merge_bases(old_commit
, new_commit
)) {
1554 rp_error("denying non-fast-forward %s"
1555 " (you should pull first)", name
);
1556 ret
= "non-fast-forward";
1560 if (run_update_hook(cmd
)) {
1561 rp_error("hook declined to update %s", name
);
1562 ret
= "hook declined";
1566 if (do_update_worktree
) {
1567 ret
= update_worktree(new_oid
->hash
, worktree
);
1572 if (is_null_oid(new_oid
)) {
1573 struct strbuf err
= STRBUF_INIT
;
1574 if (!parse_object(the_repository
, old_oid
)) {
1576 if (ref_exists(name
)) {
1577 rp_warning("allowing deletion of corrupt ref");
1579 rp_warning("deleting a non-existent ref");
1580 cmd
->did_not_exist
= 1;
1583 if (ref_transaction_delete(transaction
,
1587 rp_error("%s", err
.buf
);
1588 ret
= "failed to delete";
1590 ret
= NULL
; /* good */
1592 strbuf_release(&err
);
1595 struct strbuf err
= STRBUF_INIT
;
1596 if (shallow_update
&& si
->shallow_ref
[cmd
->index
] &&
1597 update_shallow_ref(cmd
, si
)) {
1598 ret
= "shallow error";
1602 if (ref_transaction_update(transaction
,
1607 rp_error("%s", err
.buf
);
1608 ret
= "failed to update ref";
1610 ret
= NULL
; /* good */
1612 strbuf_release(&err
);
1616 free_worktrees(worktrees
);
1620 static void run_update_post_hook(struct command
*commands
)
1622 struct command
*cmd
;
1623 struct child_process proc
= CHILD_PROCESS_INIT
;
1626 hook
= find_hook("post-update");
1630 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1631 if (cmd
->error_string
|| cmd
->did_not_exist
)
1634 strvec_push(&proc
.args
, hook
);
1635 strvec_push(&proc
.args
, cmd
->ref_name
);
1641 proc
.stdout_to_stderr
= 1;
1642 proc
.err
= use_sideband
? -1 : 0;
1643 proc
.trace2_hook_name
= "post-update";
1645 if (!start_command(&proc
)) {
1647 copy_to_sideband(proc
.err
, -1, NULL
);
1648 finish_command(&proc
);
1652 static void check_aliased_update_internal(struct command
*cmd
,
1653 struct string_list
*list
,
1654 const char *dst_name
, int flag
)
1656 struct string_list_item
*item
;
1657 struct command
*dst_cmd
;
1659 if (!(flag
& REF_ISSYMREF
))
1663 rp_error("refusing update to broken symref '%s'", cmd
->ref_name
);
1664 cmd
->skip_update
= 1;
1665 cmd
->error_string
= "broken symref";
1668 dst_name
= strip_namespace(dst_name
);
1670 if (!(item
= string_list_lookup(list
, dst_name
)))
1673 cmd
->skip_update
= 1;
1675 dst_cmd
= (struct command
*) item
->util
;
1677 if (oideq(&cmd
->old_oid
, &dst_cmd
->old_oid
) &&
1678 oideq(&cmd
->new_oid
, &dst_cmd
->new_oid
))
1681 dst_cmd
->skip_update
= 1;
1683 rp_error("refusing inconsistent update between symref '%s' (%s..%s) and"
1684 " its target '%s' (%s..%s)",
1686 find_unique_abbrev(&cmd
->old_oid
, DEFAULT_ABBREV
),
1687 find_unique_abbrev(&cmd
->new_oid
, DEFAULT_ABBREV
),
1689 find_unique_abbrev(&dst_cmd
->old_oid
, DEFAULT_ABBREV
),
1690 find_unique_abbrev(&dst_cmd
->new_oid
, DEFAULT_ABBREV
));
1692 cmd
->error_string
= dst_cmd
->error_string
=
1693 "inconsistent aliased update";
1696 static void check_aliased_update(struct command
*cmd
, struct string_list
*list
)
1698 struct strbuf buf
= STRBUF_INIT
;
1699 const char *dst_name
;
1702 strbuf_addf(&buf
, "%s%s", get_git_namespace(), cmd
->ref_name
);
1703 dst_name
= resolve_ref_unsafe(buf
.buf
, 0, NULL
, &flag
);
1704 check_aliased_update_internal(cmd
, list
, dst_name
, flag
);
1705 strbuf_release(&buf
);
1708 static void check_aliased_updates(struct command
*commands
)
1710 struct command
*cmd
;
1711 struct string_list ref_list
= STRING_LIST_INIT_NODUP
;
1713 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1714 struct string_list_item
*item
=
1715 string_list_append(&ref_list
, cmd
->ref_name
);
1716 item
->util
= (void *)cmd
;
1718 string_list_sort(&ref_list
);
1720 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1721 if (!cmd
->error_string
)
1722 check_aliased_update(cmd
, &ref_list
);
1725 string_list_clear(&ref_list
, 0);
1728 static const struct object_id
*command_singleton_iterator(void *cb_data
)
1730 struct command
**cmd_list
= cb_data
;
1731 struct command
*cmd
= *cmd_list
;
1733 if (!cmd
|| is_null_oid(&cmd
->new_oid
))
1735 *cmd_list
= NULL
; /* this returns only one */
1736 return &cmd
->new_oid
;
1739 static void set_connectivity_errors(struct command
*commands
,
1740 struct shallow_info
*si
)
1742 struct command
*cmd
;
1744 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1745 struct command
*singleton
= cmd
;
1746 struct check_connected_options opt
= CHECK_CONNECTED_INIT
;
1748 if (shallow_update
&& si
->shallow_ref
[cmd
->index
])
1749 /* to be checked in update_shallow_ref() */
1752 opt
.env
= tmp_objdir_env(tmp_objdir
);
1753 if (!check_connected(command_singleton_iterator
, &singleton
,
1757 cmd
->error_string
= "missing necessary objects";
1761 struct iterate_data
{
1762 struct command
*cmds
;
1763 struct shallow_info
*si
;
1766 static const struct object_id
*iterate_receive_command_list(void *cb_data
)
1768 struct iterate_data
*data
= cb_data
;
1769 struct command
**cmd_list
= &data
->cmds
;
1770 struct command
*cmd
= *cmd_list
;
1772 for (; cmd
; cmd
= cmd
->next
) {
1773 if (shallow_update
&& data
->si
->shallow_ref
[cmd
->index
])
1774 /* to be checked in update_shallow_ref() */
1776 if (!is_null_oid(&cmd
->new_oid
) && !cmd
->skip_update
) {
1777 *cmd_list
= cmd
->next
;
1778 return &cmd
->new_oid
;
1784 static void reject_updates_to_hidden(struct command
*commands
)
1786 struct strbuf refname_full
= STRBUF_INIT
;
1788 struct command
*cmd
;
1790 strbuf_addstr(&refname_full
, get_git_namespace());
1791 prefix_len
= refname_full
.len
;
1793 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1794 if (cmd
->error_string
)
1797 strbuf_setlen(&refname_full
, prefix_len
);
1798 strbuf_addstr(&refname_full
, cmd
->ref_name
);
1800 if (!ref_is_hidden(cmd
->ref_name
, refname_full
.buf
, &hidden_refs
))
1802 if (is_null_oid(&cmd
->new_oid
))
1803 cmd
->error_string
= "deny deleting a hidden ref";
1805 cmd
->error_string
= "deny updating a hidden ref";
1808 strbuf_release(&refname_full
);
1811 static int should_process_cmd(struct command
*cmd
)
1813 return !cmd
->error_string
&& !cmd
->skip_update
;
1816 static void BUG_if_skipped_connectivity_check(struct command
*commands
,
1817 struct shallow_info
*si
)
1819 struct command
*cmd
;
1821 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1822 if (should_process_cmd(cmd
) && si
->shallow_ref
[cmd
->index
])
1823 bug("connectivity check has not been run on ref %s",
1826 BUG_if_bug("connectivity check skipped???");
1829 static void execute_commands_non_atomic(struct command
*commands
,
1830 struct shallow_info
*si
)
1832 struct command
*cmd
;
1833 struct strbuf err
= STRBUF_INIT
;
1835 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1836 if (!should_process_cmd(cmd
) || cmd
->run_proc_receive
)
1839 transaction
= ref_transaction_begin(&err
);
1841 rp_error("%s", err
.buf
);
1843 cmd
->error_string
= "transaction failed to start";
1847 cmd
->error_string
= update(cmd
, si
);
1849 if (!cmd
->error_string
1850 && ref_transaction_commit(transaction
, &err
)) {
1851 rp_error("%s", err
.buf
);
1853 cmd
->error_string
= "failed to update ref";
1855 ref_transaction_free(transaction
);
1857 strbuf_release(&err
);
1860 static void execute_commands_atomic(struct command
*commands
,
1861 struct shallow_info
*si
)
1863 struct command
*cmd
;
1864 struct strbuf err
= STRBUF_INIT
;
1865 const char *reported_error
= "atomic push failure";
1867 transaction
= ref_transaction_begin(&err
);
1869 rp_error("%s", err
.buf
);
1871 reported_error
= "transaction failed to start";
1875 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1876 if (!should_process_cmd(cmd
) || cmd
->run_proc_receive
)
1879 cmd
->error_string
= update(cmd
, si
);
1881 if (cmd
->error_string
)
1885 if (ref_transaction_commit(transaction
, &err
)) {
1886 rp_error("%s", err
.buf
);
1887 reported_error
= "atomic transaction failed";
1893 for (cmd
= commands
; cmd
; cmd
= cmd
->next
)
1894 if (!cmd
->error_string
)
1895 cmd
->error_string
= reported_error
;
1898 ref_transaction_free(transaction
);
1899 strbuf_release(&err
);
1902 static void execute_commands(struct command
*commands
,
1903 const char *unpacker_error
,
1904 struct shallow_info
*si
,
1905 const struct string_list
*push_options
)
1907 struct check_connected_options opt
= CHECK_CONNECTED_INIT
;
1908 struct command
*cmd
;
1909 struct iterate_data data
;
1912 int run_proc_receive
= 0;
1914 if (unpacker_error
) {
1915 for (cmd
= commands
; cmd
; cmd
= cmd
->next
)
1916 cmd
->error_string
= "unpacker error";
1921 memset(&muxer
, 0, sizeof(muxer
));
1922 muxer
.proc
= copy_to_sideband
;
1924 if (!start_async(&muxer
))
1926 /* ...else, continue without relaying sideband */
1929 data
.cmds
= commands
;
1931 opt
.err_fd
= err_fd
;
1932 opt
.progress
= err_fd
&& !quiet
;
1933 opt
.env
= tmp_objdir_env(tmp_objdir
);
1934 opt
.exclude_hidden_refs_section
= "receive";
1936 if (check_connected(iterate_receive_command_list
, &data
, &opt
))
1937 set_connectivity_errors(commands
, si
);
1940 finish_async(&muxer
);
1942 reject_updates_to_hidden(commands
);
1945 * Try to find commands that have special prefix in their reference names,
1946 * and mark them to run an external "proc-receive" hook later.
1948 if (proc_receive_ref
) {
1949 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1950 if (!should_process_cmd(cmd
))
1953 if (proc_receive_ref_matches(cmd
)) {
1954 cmd
->run_proc_receive
= RUN_PROC_RECEIVE_SCHEDULED
;
1955 run_proc_receive
= 1;
1960 if (run_receive_hook(commands
, "pre-receive", 0, push_options
)) {
1961 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1962 if (!cmd
->error_string
)
1963 cmd
->error_string
= "pre-receive hook declined";
1969 * If there is no command ready to run, should return directly to destroy
1970 * temporary data in the quarantine area.
1972 for (cmd
= commands
; cmd
&& cmd
->error_string
; cmd
= cmd
->next
)
1978 * Now we'll start writing out refs, which means the objects need
1979 * to be in their final positions so that other processes can see them.
1981 if (tmp_objdir_migrate(tmp_objdir
) < 0) {
1982 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1983 if (!cmd
->error_string
)
1984 cmd
->error_string
= "unable to migrate objects to permanent storage";
1990 check_aliased_updates(commands
);
1992 free(head_name_to_free
);
1993 head_name
= head_name_to_free
= resolve_refdup("HEAD", 0, NULL
, NULL
);
1995 if (run_proc_receive
&&
1996 run_proc_receive_hook(commands
, push_options
))
1997 for (cmd
= commands
; cmd
; cmd
= cmd
->next
)
1998 if (!cmd
->error_string
&&
1999 !(cmd
->run_proc_receive
& RUN_PROC_RECEIVE_RETURNED
) &&
2000 (cmd
->run_proc_receive
|| use_atomic
))
2001 cmd
->error_string
= "fail to run proc-receive hook";
2004 execute_commands_atomic(commands
, si
);
2006 execute_commands_non_atomic(commands
, si
);
2009 BUG_if_skipped_connectivity_check(commands
, si
);
2012 static struct command
**queue_command(struct command
**tail
,
2016 struct object_id old_oid
, new_oid
;
2017 struct command
*cmd
;
2018 const char *refname
;
2022 if (parse_oid_hex(line
, &old_oid
, &p
) ||
2024 parse_oid_hex(p
, &new_oid
, &p
) ||
2026 die("protocol error: expected old/new/ref, got '%s'", line
);
2029 reflen
= linelen
- (p
- line
);
2030 FLEX_ALLOC_MEM(cmd
, ref_name
, refname
, reflen
);
2031 oidcpy(&cmd
->old_oid
, &old_oid
);
2032 oidcpy(&cmd
->new_oid
, &new_oid
);
2037 static void free_commands(struct command
*commands
)
2040 struct command
*next
= commands
->next
;
2047 static void queue_commands_from_cert(struct command
**tail
,
2048 struct strbuf
*push_cert
)
2050 const char *boc
, *eoc
;
2053 die("protocol error: got both push certificate and unsigned commands");
2055 boc
= strstr(push_cert
->buf
, "\n\n");
2057 die("malformed push certificate %.*s", 100, push_cert
->buf
);
2060 eoc
= push_cert
->buf
+ parse_signed_buffer(push_cert
->buf
, push_cert
->len
);
2063 const char *eol
= memchr(boc
, '\n', eoc
- boc
);
2064 tail
= queue_command(tail
, boc
, eol
? eol
- boc
: eoc
- boc
);
2065 boc
= eol
? eol
+ 1 : eoc
;
2069 static struct command
*read_head_info(struct packet_reader
*reader
,
2070 struct oid_array
*shallow
)
2072 struct command
*commands
= NULL
;
2073 struct command
**p
= &commands
;
2077 if (packet_reader_read(reader
) != PACKET_READ_NORMAL
)
2080 if (reader
->pktlen
> 8 && starts_with(reader
->line
, "shallow ")) {
2081 struct object_id oid
;
2082 if (get_oid_hex(reader
->line
+ 8, &oid
))
2083 die("protocol error: expected shallow sha, got '%s'",
2085 oid_array_append(shallow
, &oid
);
2089 linelen
= strlen(reader
->line
);
2090 if (linelen
< reader
->pktlen
) {
2091 const char *feature_list
= reader
->line
+ linelen
+ 1;
2092 const char *hash
= NULL
;
2093 const char *client_sid
;
2095 if (parse_feature_request(feature_list
, "report-status"))
2097 if (parse_feature_request(feature_list
, "report-status-v2"))
2098 report_status_v2
= 1;
2099 if (parse_feature_request(feature_list
, "side-band-64k"))
2100 use_sideband
= LARGE_PACKET_MAX
;
2101 if (parse_feature_request(feature_list
, "quiet"))
2103 if (advertise_atomic_push
2104 && parse_feature_request(feature_list
, "atomic"))
2106 if (advertise_push_options
2107 && parse_feature_request(feature_list
, "push-options"))
2108 use_push_options
= 1;
2109 hash
= parse_feature_value(feature_list
, "object-format", &len
, NULL
);
2111 hash
= hash_algos
[GIT_HASH_SHA1
].name
;
2114 if (xstrncmpz(the_hash_algo
->name
, hash
, len
))
2115 die("error: unsupported object format '%s'", hash
);
2116 client_sid
= parse_feature_value(feature_list
, "session-id", &len
, NULL
);
2118 char *sid
= xstrndup(client_sid
, len
);
2119 trace2_data_string("transfer", NULL
, "client-sid", client_sid
);
2124 if (!strcmp(reader
->line
, "push-cert")) {
2126 int saved_options
= reader
->options
;
2127 reader
->options
&= ~PACKET_READ_CHOMP_NEWLINE
;
2130 packet_reader_read(reader
);
2131 if (reader
->status
== PACKET_READ_FLUSH
) {
2135 if (reader
->status
!= PACKET_READ_NORMAL
) {
2136 die("protocol error: got an unexpected packet");
2138 if (!strcmp(reader
->line
, "push-cert-end\n"))
2139 break; /* end of cert */
2140 strbuf_addstr(&push_cert
, reader
->line
);
2142 reader
->options
= saved_options
;
2149 p
= queue_command(p
, reader
->line
, linelen
);
2153 queue_commands_from_cert(p
, &push_cert
);
2158 static void read_push_options(struct packet_reader
*reader
,
2159 struct string_list
*options
)
2162 if (packet_reader_read(reader
) != PACKET_READ_NORMAL
)
2165 string_list_append(options
, reader
->line
);
2169 static const char *parse_pack_header(struct pack_header
*hdr
)
2171 switch (read_pack_header(0, hdr
)) {
2173 return "eof before pack header was fully read";
2175 case PH_ERROR_PACK_SIGNATURE
:
2176 return "protocol error (pack signature mismatch detected)";
2178 case PH_ERROR_PROTOCOL
:
2179 return "protocol error (pack version unsupported)";
2182 return "unknown error in parse_pack_header";
2189 static const char *pack_lockfile
;
2191 static void push_header_arg(struct strvec
*args
, struct pack_header
*hdr
)
2193 strvec_pushf(args
, "--pack_header=%"PRIu32
",%"PRIu32
,
2194 ntohl(hdr
->hdr_version
), ntohl(hdr
->hdr_entries
));
2197 static const char *unpack(int err_fd
, struct shallow_info
*si
)
2199 struct pack_header hdr
;
2200 const char *hdr_err
;
2202 struct child_process child
= CHILD_PROCESS_INIT
;
2203 int fsck_objects
= (receive_fsck_objects
>= 0
2204 ? receive_fsck_objects
2205 : transfer_fsck_objects
>= 0
2206 ? transfer_fsck_objects
2209 hdr_err
= parse_pack_header(&hdr
);
2216 if (si
->nr_ours
|| si
->nr_theirs
) {
2217 alt_shallow_file
= setup_temporary_shallow(si
->shallow
);
2218 strvec_push(&child
.args
, "--shallow-file");
2219 strvec_push(&child
.args
, alt_shallow_file
);
2222 tmp_objdir
= tmp_objdir_create("incoming");
2226 return "unable to create temporary object directory";
2228 strvec_pushv(&child
.env
, tmp_objdir_env(tmp_objdir
));
2231 * Normally we just pass the tmp_objdir environment to the child
2232 * processes that do the heavy lifting, but we may need to see these
2233 * objects ourselves to set up shallow information.
2235 tmp_objdir_add_as_alternate(tmp_objdir
);
2237 if (ntohl(hdr
.hdr_entries
) < unpack_limit
) {
2238 strvec_push(&child
.args
, "unpack-objects");
2239 push_header_arg(&child
.args
, &hdr
);
2241 strvec_push(&child
.args
, "-q");
2243 strvec_pushf(&child
.args
, "--strict%s",
2244 fsck_msg_types
.buf
);
2246 strvec_pushf(&child
.args
, "--max-input-size=%"PRIuMAX
,
2247 (uintmax_t)max_input_size
);
2248 child
.no_stdout
= 1;
2251 status
= run_command(&child
);
2253 return "unpack-objects abnormal exit";
2255 char hostname
[HOST_NAME_MAX
+ 1];
2257 strvec_pushl(&child
.args
, "index-pack", "--stdin", NULL
);
2258 push_header_arg(&child
.args
, &hdr
);
2260 if (xgethostname(hostname
, sizeof(hostname
)))
2261 xsnprintf(hostname
, sizeof(hostname
), "localhost");
2262 strvec_pushf(&child
.args
,
2263 "--keep=receive-pack %"PRIuMAX
" on %s",
2264 (uintmax_t)getpid(),
2267 if (!quiet
&& err_fd
)
2268 strvec_push(&child
.args
, "--show-resolving-progress");
2270 strvec_push(&child
.args
, "--report-end-of-input");
2272 strvec_pushf(&child
.args
, "--strict%s",
2273 fsck_msg_types
.buf
);
2275 strvec_push(&child
.args
, "--fix-thin");
2277 strvec_pushf(&child
.args
, "--max-input-size=%"PRIuMAX
,
2278 (uintmax_t)max_input_size
);
2282 status
= start_command(&child
);
2284 return "index-pack fork failed";
2285 pack_lockfile
= index_pack_lockfile(child
.out
, NULL
);
2287 status
= finish_command(&child
);
2289 return "index-pack abnormal exit";
2290 reprepare_packed_git(the_repository
);
2295 static const char *unpack_with_sideband(struct shallow_info
*si
)
2301 return unpack(0, si
);
2303 use_keepalive
= KEEPALIVE_AFTER_NUL
;
2304 memset(&muxer
, 0, sizeof(muxer
));
2305 muxer
.proc
= copy_to_sideband
;
2307 if (start_async(&muxer
))
2310 ret
= unpack(muxer
.in
, si
);
2312 finish_async(&muxer
);
2316 static void prepare_shallow_update(struct shallow_info
*si
)
2318 int i
, j
, k
, bitmap_size
= DIV_ROUND_UP(si
->ref
->nr
, 32);
2320 ALLOC_ARRAY(si
->used_shallow
, si
->shallow
->nr
);
2321 assign_shallow_commits_to_refs(si
, si
->used_shallow
, NULL
);
2323 CALLOC_ARRAY(si
->need_reachability_test
, si
->shallow
->nr
);
2324 CALLOC_ARRAY(si
->reachable
, si
->shallow
->nr
);
2325 CALLOC_ARRAY(si
->shallow_ref
, si
->ref
->nr
);
2327 for (i
= 0; i
< si
->nr_ours
; i
++)
2328 si
->need_reachability_test
[si
->ours
[i
]] = 1;
2330 for (i
= 0; i
< si
->shallow
->nr
; i
++) {
2331 if (!si
->used_shallow
[i
])
2333 for (j
= 0; j
< bitmap_size
; j
++) {
2334 if (!si
->used_shallow
[i
][j
])
2336 si
->need_reachability_test
[i
]++;
2337 for (k
= 0; k
< 32; k
++)
2338 if (si
->used_shallow
[i
][j
] & (1U << k
))
2339 si
->shallow_ref
[j
* 32 + k
]++;
2343 * true for those associated with some refs and belong
2344 * in "ours" list aka "step 7 not done yet"
2346 si
->need_reachability_test
[i
] =
2347 si
->need_reachability_test
[i
] > 1;
2351 * keep hooks happy by forcing a temporary shallow file via
2352 * env variable because we can't add --shallow-file to every
2353 * command. check_connected() will be done with
2354 * true .git/shallow though.
2356 setenv(GIT_SHALLOW_FILE_ENVIRONMENT
, alt_shallow_file
, 1);
2359 static void update_shallow_info(struct command
*commands
,
2360 struct shallow_info
*si
,
2361 struct oid_array
*ref
)
2363 struct command
*cmd
;
2365 remove_nonexistent_theirs_shallow(si
);
2366 if (!si
->nr_ours
&& !si
->nr_theirs
) {
2371 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
2372 if (is_null_oid(&cmd
->new_oid
))
2374 oid_array_append(ref
, &cmd
->new_oid
);
2375 cmd
->index
= ref
->nr
- 1;
2379 if (shallow_update
) {
2380 prepare_shallow_update(si
);
2384 ALLOC_ARRAY(ref_status
, ref
->nr
);
2385 assign_shallow_commits_to_refs(si
, NULL
, ref_status
);
2386 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
2387 if (is_null_oid(&cmd
->new_oid
))
2389 if (ref_status
[cmd
->index
]) {
2390 cmd
->error_string
= "shallow update not allowed";
2391 cmd
->skip_update
= 1;
2397 static void report(struct command
*commands
, const char *unpack_status
)
2399 struct command
*cmd
;
2400 struct strbuf buf
= STRBUF_INIT
;
2402 packet_buf_write(&buf
, "unpack %s\n",
2403 unpack_status
? unpack_status
: "ok");
2404 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
2405 if (!cmd
->error_string
)
2406 packet_buf_write(&buf
, "ok %s\n",
2409 packet_buf_write(&buf
, "ng %s %s\n",
2410 cmd
->ref_name
, cmd
->error_string
);
2412 packet_buf_flush(&buf
);
2415 send_sideband(1, 1, buf
.buf
, buf
.len
, use_sideband
);
2417 write_or_die(1, buf
.buf
, buf
.len
);
2418 strbuf_release(&buf
);
2421 static void report_v2(struct command
*commands
, const char *unpack_status
)
2423 struct command
*cmd
;
2424 struct strbuf buf
= STRBUF_INIT
;
2425 struct ref_push_report
*report
;
2427 packet_buf_write(&buf
, "unpack %s\n",
2428 unpack_status
? unpack_status
: "ok");
2429 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
2432 if (cmd
->error_string
) {
2433 packet_buf_write(&buf
, "ng %s %s\n",
2438 packet_buf_write(&buf
, "ok %s\n",
2440 for (report
= cmd
->report
; report
; report
= report
->next
) {
2442 packet_buf_write(&buf
, "ok %s\n",
2444 if (report
->ref_name
)
2445 packet_buf_write(&buf
, "option refname %s\n",
2447 if (report
->old_oid
)
2448 packet_buf_write(&buf
, "option old-oid %s\n",
2449 oid_to_hex(report
->old_oid
));
2450 if (report
->new_oid
)
2451 packet_buf_write(&buf
, "option new-oid %s\n",
2452 oid_to_hex(report
->new_oid
));
2453 if (report
->forced_update
)
2454 packet_buf_write(&buf
, "option forced-update\n");
2457 packet_buf_flush(&buf
);
2460 send_sideband(1, 1, buf
.buf
, buf
.len
, use_sideband
);
2462 write_or_die(1, buf
.buf
, buf
.len
);
2463 strbuf_release(&buf
);
2466 static int delete_only(struct command
*commands
)
2468 struct command
*cmd
;
2469 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
2470 if (!is_null_oid(&cmd
->new_oid
))
2476 int cmd_receive_pack(int argc
, const char **argv
, const char *prefix
)
2478 int advertise_refs
= 0;
2479 struct command
*commands
;
2480 struct oid_array shallow
= OID_ARRAY_INIT
;
2481 struct oid_array ref
= OID_ARRAY_INIT
;
2482 struct shallow_info si
;
2483 struct packet_reader reader
;
2485 struct option options
[] = {
2486 OPT__QUIET(&quiet
, N_("quiet")),
2487 OPT_HIDDEN_BOOL(0, "stateless-rpc", &stateless_rpc
, NULL
),
2488 OPT_HIDDEN_BOOL(0, "http-backend-info-refs", &advertise_refs
, NULL
),
2489 OPT_ALIAS(0, "advertise-refs", "http-backend-info-refs"),
2490 OPT_HIDDEN_BOOL(0, "reject-thin-pack-for-testing", &reject_thin
, NULL
),
2494 packet_trace_identity("receive-pack");
2496 argc
= parse_options(argc
, argv
, prefix
, options
, receive_pack_usage
, 0);
2499 usage_msg_opt(_("too many arguments"), receive_pack_usage
, options
);
2501 usage_msg_opt(_("you must specify a directory"), receive_pack_usage
, options
);
2503 service_dir
= argv
[0];
2507 if (!enter_repo(service_dir
, 0))
2508 die("'%s' does not appear to be a git repository", service_dir
);
2510 git_config(receive_pack_config
, NULL
);
2511 if (cert_nonce_seed
)
2512 push_cert_nonce
= prepare_push_cert_nonce(service_dir
, time(NULL
));
2514 if (0 <= transfer_unpack_limit
)
2515 unpack_limit
= transfer_unpack_limit
;
2516 else if (0 <= receive_unpack_limit
)
2517 unpack_limit
= receive_unpack_limit
;
2519 switch (determine_protocol_version_server()) {
2522 * push support for protocol v2 has not been implemented yet,
2523 * so ignore the request to use v2 and fallback to using v0.
2528 * v1 is just the original protocol with a version string,
2529 * so just fall through after writing the version string.
2531 if (advertise_refs
|| !stateless_rpc
)
2532 packet_write_fmt(1, "version 1\n");
2537 case protocol_unknown_version
:
2538 BUG("unknown protocol version");
2541 if (advertise_refs
|| !stateless_rpc
) {
2547 packet_reader_init(&reader
, 0, NULL
, 0,
2548 PACKET_READ_CHOMP_NEWLINE
|
2549 PACKET_READ_DIE_ON_ERR_PACKET
);
2551 if ((commands
= read_head_info(&reader
, &shallow
))) {
2552 const char *unpack_status
= NULL
;
2553 struct string_list push_options
= STRING_LIST_INIT_DUP
;
2555 if (use_push_options
)
2556 read_push_options(&reader
, &push_options
);
2557 if (!check_cert_push_options(&push_options
)) {
2558 struct command
*cmd
;
2559 for (cmd
= commands
; cmd
; cmd
= cmd
->next
)
2560 cmd
->error_string
= "inconsistent push options";
2563 prepare_shallow_info(&si
, &shallow
);
2564 if (!si
.nr_ours
&& !si
.nr_theirs
)
2566 if (!delete_only(commands
)) {
2567 unpack_status
= unpack_with_sideband(&si
);
2568 update_shallow_info(commands
, &si
, &ref
);
2570 use_keepalive
= KEEPALIVE_ALWAYS
;
2571 execute_commands(commands
, unpack_status
, &si
,
2574 unlink_or_warn(pack_lockfile
);
2575 sigchain_push(SIGPIPE
, SIG_IGN
);
2576 if (report_status_v2
)
2577 report_v2(commands
, unpack_status
);
2578 else if (report_status
)
2579 report(commands
, unpack_status
);
2580 sigchain_pop(SIGPIPE
);
2581 run_receive_hook(commands
, "post-receive", 1,
2583 run_update_post_hook(commands
);
2584 free_commands(commands
);
2585 string_list_clear(&push_options
, 0);
2587 struct child_process proc
= CHILD_PROCESS_INIT
;
2590 proc
.stdout_to_stderr
= 1;
2591 proc
.err
= use_sideband
? -1 : 0;
2592 proc
.git_cmd
= proc
.close_object_store
= 1;
2593 strvec_pushl(&proc
.args
, "gc", "--auto", "--quiet",
2596 if (!start_command(&proc
)) {
2598 copy_to_sideband(proc
.err
, -1, NULL
);
2599 finish_command(&proc
);
2602 if (auto_update_server_info
)
2603 update_server_info(0);
2604 clear_shallow_info(&si
);
2608 oid_array_clear(&shallow
);
2609 oid_array_clear(&ref
);
2610 string_list_clear(&hidden_refs
, 0);
2611 free((void *)push_cert_nonce
);