3 #include "repository.h"
5 #include "environment.h"
13 #include "run-command.h"
20 #include "string-list.h"
21 #include "oid-array.h"
22 #include "connected.h"
26 #include "gpg-interface.h"
29 #include "tmp-objdir.h"
32 #include "object-name.h"
33 #include "object-store.h"
35 #include "commit-reach.h"
42 static const char * const receive_pack_usage
[] = {
43 N_("git receive-pack <git-dir>"),
55 static int deny_deletes
;
56 static int deny_non_fast_forwards
;
57 static enum deny_action deny_current_branch
= DENY_UNCONFIGURED
;
58 static enum deny_action deny_delete_current
= DENY_UNCONFIGURED
;
59 static int receive_fsck_objects
= -1;
60 static int transfer_fsck_objects
= -1;
61 static struct strbuf fsck_msg_types
= STRBUF_INIT
;
62 static int receive_unpack_limit
= -1;
63 static int transfer_unpack_limit
= -1;
64 static int advertise_atomic_push
= 1;
65 static int advertise_push_options
;
66 static int advertise_sid
;
67 static int unpack_limit
= 100;
68 static off_t max_input_size
;
69 static int report_status
;
70 static int report_status_v2
;
71 static int use_sideband
;
72 static int use_atomic
;
73 static int use_push_options
;
75 static int prefer_ofs_delta
= 1;
76 static int auto_update_server_info
;
77 static int auto_gc
= 1;
78 static int reject_thin
;
79 static int stateless_rpc
;
80 static const char *service_dir
;
81 static const char *head_name
;
82 static void *head_name_to_free
;
83 static int sent_capabilities
;
84 static int shallow_update
;
85 static const char *alt_shallow_file
;
86 static struct strbuf push_cert
= STRBUF_INIT
;
87 static struct object_id push_cert_oid
;
88 static struct signature_check sigcheck
;
89 static const char *push_cert_nonce
;
90 static const char *cert_nonce_seed
;
91 static struct string_list hidden_refs
= STRING_LIST_INIT_DUP
;
93 static const char *NONCE_UNSOLICITED
= "UNSOLICITED";
94 static const char *NONCE_BAD
= "BAD";
95 static const char *NONCE_MISSING
= "MISSING";
96 static const char *NONCE_OK
= "OK";
97 static const char *NONCE_SLOP
= "SLOP";
98 static const char *nonce_status
;
99 static long nonce_stamp_slop
;
100 static timestamp_t nonce_stamp_slop_limit
;
101 static struct ref_transaction
*transaction
;
108 static int keepalive_in_sec
= 5;
110 static struct tmp_objdir
*tmp_objdir
;
112 static struct proc_receive_ref
{
113 unsigned int want_add
:1,
118 struct proc_receive_ref
*next
;
121 static void proc_receive_ref_append(const char *prefix
);
123 static enum deny_action
parse_deny_action(const char *var
, const char *value
)
126 if (!strcasecmp(value
, "ignore"))
128 if (!strcasecmp(value
, "warn"))
130 if (!strcasecmp(value
, "refuse"))
132 if (!strcasecmp(value
, "updateinstead"))
133 return DENY_UPDATE_INSTEAD
;
135 if (git_config_bool(var
, value
))
140 static int receive_pack_config(const char *var
, const char *value
, void *cb
)
142 int status
= parse_hide_refs_config(var
, value
, "receive", &hidden_refs
);
147 if (strcmp(var
, "receive.denydeletes") == 0) {
148 deny_deletes
= git_config_bool(var
, value
);
152 if (strcmp(var
, "receive.denynonfastforwards") == 0) {
153 deny_non_fast_forwards
= git_config_bool(var
, value
);
157 if (strcmp(var
, "receive.unpacklimit") == 0) {
158 receive_unpack_limit
= git_config_int(var
, value
);
162 if (strcmp(var
, "transfer.unpacklimit") == 0) {
163 transfer_unpack_limit
= git_config_int(var
, value
);
167 if (strcmp(var
, "receive.fsck.skiplist") == 0) {
170 if (git_config_pathname(&path
, var
, value
))
172 strbuf_addf(&fsck_msg_types
, "%cskiplist=%s",
173 fsck_msg_types
.len
? ',' : '=', path
);
178 if (skip_prefix(var
, "receive.fsck.", &var
)) {
179 if (is_valid_msg_type(var
, value
))
180 strbuf_addf(&fsck_msg_types
, "%c%s=%s",
181 fsck_msg_types
.len
? ',' : '=', var
, value
);
183 warning("skipping unknown msg id '%s'", var
);
187 if (strcmp(var
, "receive.fsckobjects") == 0) {
188 receive_fsck_objects
= git_config_bool(var
, value
);
192 if (strcmp(var
, "transfer.fsckobjects") == 0) {
193 transfer_fsck_objects
= git_config_bool(var
, value
);
197 if (!strcmp(var
, "receive.denycurrentbranch")) {
198 deny_current_branch
= parse_deny_action(var
, value
);
202 if (strcmp(var
, "receive.denydeletecurrent") == 0) {
203 deny_delete_current
= parse_deny_action(var
, value
);
207 if (strcmp(var
, "repack.usedeltabaseoffset") == 0) {
208 prefer_ofs_delta
= git_config_bool(var
, value
);
212 if (strcmp(var
, "receive.updateserverinfo") == 0) {
213 auto_update_server_info
= git_config_bool(var
, value
);
217 if (strcmp(var
, "receive.autogc") == 0) {
218 auto_gc
= git_config_bool(var
, value
);
222 if (strcmp(var
, "receive.shallowupdate") == 0) {
223 shallow_update
= git_config_bool(var
, value
);
227 if (strcmp(var
, "receive.certnonceseed") == 0)
228 return git_config_string(&cert_nonce_seed
, var
, value
);
230 if (strcmp(var
, "receive.certnonceslop") == 0) {
231 nonce_stamp_slop_limit
= git_config_ulong(var
, value
);
235 if (strcmp(var
, "receive.advertiseatomic") == 0) {
236 advertise_atomic_push
= git_config_bool(var
, value
);
240 if (strcmp(var
, "receive.advertisepushoptions") == 0) {
241 advertise_push_options
= git_config_bool(var
, value
);
245 if (strcmp(var
, "receive.keepalive") == 0) {
246 keepalive_in_sec
= git_config_int(var
, value
);
250 if (strcmp(var
, "receive.maxinputsize") == 0) {
251 max_input_size
= git_config_int64(var
, value
);
255 if (strcmp(var
, "receive.procreceiverefs") == 0) {
257 return config_error_nonbool(var
);
258 proc_receive_ref_append(value
);
262 if (strcmp(var
, "transfer.advertisesid") == 0) {
263 advertise_sid
= git_config_bool(var
, value
);
267 return git_default_config(var
, value
, cb
);
270 static void show_ref(const char *path
, const struct object_id
*oid
)
272 if (sent_capabilities
) {
273 packet_write_fmt(1, "%s %s\n", oid_to_hex(oid
), path
);
275 struct strbuf cap
= STRBUF_INIT
;
278 "report-status report-status-v2 delete-refs side-band-64k quiet");
279 if (advertise_atomic_push
)
280 strbuf_addstr(&cap
, " atomic");
281 if (prefer_ofs_delta
)
282 strbuf_addstr(&cap
, " ofs-delta");
284 strbuf_addf(&cap
, " push-cert=%s", push_cert_nonce
);
285 if (advertise_push_options
)
286 strbuf_addstr(&cap
, " push-options");
288 strbuf_addf(&cap
, " session-id=%s", trace2_session_id());
289 strbuf_addf(&cap
, " object-format=%s", the_hash_algo
->name
);
290 strbuf_addf(&cap
, " agent=%s", git_user_agent_sanitized());
291 packet_write_fmt(1, "%s %s%c%s\n",
292 oid_to_hex(oid
), path
, 0, cap
.buf
);
293 strbuf_release(&cap
);
294 sent_capabilities
= 1;
298 static int show_ref_cb(const char *path_full
, const struct object_id
*oid
,
299 int flag UNUSED
, void *data
)
301 struct oidset
*seen
= data
;
302 const char *path
= strip_namespace(path_full
);
304 if (ref_is_hidden(path
, path_full
, &hidden_refs
))
308 * Advertise refs outside our current namespace as ".have"
309 * refs, so that the client can use them to minimize data
310 * transfer but will otherwise ignore them.
313 if (oidset_insert(seen
, oid
))
317 oidset_insert(seen
, oid
);
323 static void show_one_alternate_ref(const struct object_id
*oid
,
326 struct oidset
*seen
= data
;
328 if (oidset_insert(seen
, oid
))
331 show_ref(".have", oid
);
334 static void write_head_info(void)
336 static struct oidset seen
= OIDSET_INIT
;
338 for_each_ref(show_ref_cb
, &seen
);
339 for_each_alternate_ref(show_one_alternate_ref
, &seen
);
341 if (!sent_capabilities
)
342 show_ref("capabilities^{}", null_oid());
344 advertise_shallow_grafts(1);
350 #define RUN_PROC_RECEIVE_SCHEDULED 1
351 #define RUN_PROC_RECEIVE_RETURNED 2
353 struct command
*next
;
354 const char *error_string
;
355 struct ref_push_report
*report
;
356 unsigned int skip_update
:1,
360 struct object_id old_oid
;
361 struct object_id new_oid
;
362 char ref_name
[FLEX_ARRAY
]; /* more */
365 static void proc_receive_ref_append(const char *prefix
)
367 struct proc_receive_ref
*ref_pattern
;
371 CALLOC_ARRAY(ref_pattern
, 1);
372 p
= strchr(prefix
, ':');
376 ref_pattern
->want_add
= 1;
377 else if (*prefix
== 'd')
378 ref_pattern
->want_delete
= 1;
379 else if (*prefix
== 'm')
380 ref_pattern
->want_modify
= 1;
381 else if (*prefix
== '!')
382 ref_pattern
->negative_ref
= 1;
387 ref_pattern
->want_add
= 1;
388 ref_pattern
->want_delete
= 1;
389 ref_pattern
->want_modify
= 1;
391 len
= strlen(prefix
);
392 while (len
&& prefix
[len
- 1] == '/')
394 ref_pattern
->ref_prefix
= xmemdupz(prefix
, len
);
395 if (!proc_receive_ref
) {
396 proc_receive_ref
= ref_pattern
;
398 struct proc_receive_ref
*end
;
400 end
= proc_receive_ref
;
403 end
->next
= ref_pattern
;
407 static int proc_receive_ref_matches(struct command
*cmd
)
409 struct proc_receive_ref
*p
;
411 if (!proc_receive_ref
)
414 for (p
= proc_receive_ref
; p
; p
= p
->next
) {
415 const char *match
= p
->ref_prefix
;
418 if (!p
->want_add
&& is_null_oid(&cmd
->old_oid
))
420 else if (!p
->want_delete
&& is_null_oid(&cmd
->new_oid
))
422 else if (!p
->want_modify
&&
423 !is_null_oid(&cmd
->old_oid
) &&
424 !is_null_oid(&cmd
->new_oid
))
427 if (skip_prefix(cmd
->ref_name
, match
, &remains
) &&
428 (!*remains
|| *remains
== '/')) {
429 if (!p
->negative_ref
)
431 } else if (p
->negative_ref
) {
438 static void report_message(const char *prefix
, const char *err
, va_list params
)
443 sz
= xsnprintf(msg
, sizeof(msg
), "%s", prefix
);
444 sz
+= vsnprintf(msg
+ sz
, sizeof(msg
) - sz
, err
, params
);
445 if (sz
> (sizeof(msg
) - 1))
446 sz
= sizeof(msg
) - 1;
450 send_sideband(1, 2, msg
, sz
, use_sideband
);
455 __attribute__((format (printf
, 1, 2)))
456 static void rp_warning(const char *err
, ...)
459 va_start(params
, err
);
460 report_message("warning: ", err
, params
);
464 __attribute__((format (printf
, 1, 2)))
465 static void rp_error(const char *err
, ...)
468 va_start(params
, err
);
469 report_message("error: ", err
, params
);
473 static int copy_to_sideband(int in
, int out UNUSED
, void *arg UNUSED
)
476 int keepalive_active
= 0;
478 if (keepalive_in_sec
<= 0)
479 use_keepalive
= KEEPALIVE_NEVER
;
480 if (use_keepalive
== KEEPALIVE_ALWAYS
)
481 keepalive_active
= 1;
486 if (keepalive_active
) {
492 ret
= poll(&pfd
, 1, 1000 * keepalive_in_sec
);
499 } else if (ret
== 0) {
500 /* no data; send a keepalive packet */
501 static const char buf
[] = "0005\1";
502 write_or_die(1, buf
, sizeof(buf
) - 1);
504 } /* else there is actual data to read */
507 sz
= xread(in
, data
, sizeof(data
));
511 if (use_keepalive
== KEEPALIVE_AFTER_NUL
&& !keepalive_active
) {
512 const char *p
= memchr(data
, '\0', sz
);
515 * The NUL tells us to start sending keepalives. Make
516 * sure we send any other data we read along
519 keepalive_active
= 1;
520 send_sideband(1, 2, data
, p
- data
, use_sideband
);
521 send_sideband(1, 2, p
+ 1, sz
- (p
- data
+ 1), use_sideband
);
527 * Either we're not looking for a NUL signal, or we didn't see
528 * it yet; just pass along the data.
530 send_sideband(1, 2, data
, sz
, use_sideband
);
536 static void hmac_hash(unsigned char *out
,
537 const char *key_in
, size_t key_len
,
538 const char *text
, size_t text_len
)
540 unsigned char key
[GIT_MAX_BLKSZ
];
541 unsigned char k_ipad
[GIT_MAX_BLKSZ
];
542 unsigned char k_opad
[GIT_MAX_BLKSZ
];
546 /* RFC 2104 2. (1) */
547 memset(key
, '\0', GIT_MAX_BLKSZ
);
548 if (the_hash_algo
->blksz
< key_len
) {
549 the_hash_algo
->init_fn(&ctx
);
550 the_hash_algo
->update_fn(&ctx
, key_in
, key_len
);
551 the_hash_algo
->final_fn(key
, &ctx
);
553 memcpy(key
, key_in
, key_len
);
556 /* RFC 2104 2. (2) & (5) */
557 for (i
= 0; i
< sizeof(key
); i
++) {
558 k_ipad
[i
] = key
[i
] ^ 0x36;
559 k_opad
[i
] = key
[i
] ^ 0x5c;
562 /* RFC 2104 2. (3) & (4) */
563 the_hash_algo
->init_fn(&ctx
);
564 the_hash_algo
->update_fn(&ctx
, k_ipad
, sizeof(k_ipad
));
565 the_hash_algo
->update_fn(&ctx
, text
, text_len
);
566 the_hash_algo
->final_fn(out
, &ctx
);
568 /* RFC 2104 2. (6) & (7) */
569 the_hash_algo
->init_fn(&ctx
);
570 the_hash_algo
->update_fn(&ctx
, k_opad
, sizeof(k_opad
));
571 the_hash_algo
->update_fn(&ctx
, out
, the_hash_algo
->rawsz
);
572 the_hash_algo
->final_fn(out
, &ctx
);
575 static char *prepare_push_cert_nonce(const char *path
, timestamp_t stamp
)
577 struct strbuf buf
= STRBUF_INIT
;
578 unsigned char hash
[GIT_MAX_RAWSZ
];
580 strbuf_addf(&buf
, "%s:%"PRItime
, path
, stamp
);
581 hmac_hash(hash
, buf
.buf
, buf
.len
, cert_nonce_seed
, strlen(cert_nonce_seed
));
582 strbuf_release(&buf
);
584 /* RFC 2104 5. HMAC-SHA1 or HMAC-SHA256 */
585 strbuf_addf(&buf
, "%"PRItime
"-%.*s", stamp
, (int)the_hash_algo
->hexsz
, hash_to_hex(hash
));
586 return strbuf_detach(&buf
, NULL
);
589 static char *find_header(const char *msg
, size_t len
, const char *key
,
590 const char **next_line
)
593 const char *val
= find_header_mem(msg
, len
, key
, &out_len
);
599 *next_line
= val
+ out_len
+ 1;
601 return xmemdupz(val
, out_len
);
605 * Return zero if a and b are equal up to n bytes and nonzero if they are not.
606 * This operation is guaranteed to run in constant time to avoid leaking data.
608 static int constant_memequal(const char *a
, const char *b
, size_t n
)
613 for (i
= 0; i
< n
; i
++)
618 static const char *check_nonce(const char *buf
, size_t len
)
620 char *nonce
= find_header(buf
, len
, "nonce", NULL
);
621 timestamp_t stamp
, ostamp
;
622 char *bohmac
, *expect
= NULL
;
623 const char *retval
= NONCE_BAD
;
627 retval
= NONCE_MISSING
;
629 } else if (!push_cert_nonce
) {
630 retval
= NONCE_UNSOLICITED
;
632 } else if (!strcmp(push_cert_nonce
, nonce
)) {
637 if (!stateless_rpc
) {
638 /* returned nonce MUST match what we gave out earlier */
644 * In stateless mode, we may be receiving a nonce issued by
645 * another instance of the server that serving the same
646 * repository, and the timestamps may not match, but the
647 * nonce-seed and dir should match, so we can recompute and
648 * report the time slop.
650 * In addition, when a nonce issued by another instance has
651 * timestamp within receive.certnonceslop seconds, we pretend
652 * as if we issued that nonce when reporting to the hook.
655 /* nonce is concat(<seconds-since-epoch>, "-", <hmac>) */
656 if (*nonce
<= '0' || '9' < *nonce
) {
660 stamp
= parse_timestamp(nonce
, &bohmac
, 10);
661 if (bohmac
== nonce
|| bohmac
[0] != '-') {
666 noncelen
= strlen(nonce
);
667 expect
= prepare_push_cert_nonce(service_dir
, stamp
);
668 if (noncelen
!= strlen(expect
)) {
669 /* This is not even the right size. */
673 if (constant_memequal(expect
, nonce
, noncelen
)) {
674 /* Not what we would have signed earlier */
680 * By how many seconds is this nonce stale? Negative value
681 * would mean it was issued by another server with its clock
682 * skewed in the future.
684 ostamp
= parse_timestamp(push_cert_nonce
, NULL
, 10);
685 nonce_stamp_slop
= (long)ostamp
- (long)stamp
;
687 if (nonce_stamp_slop_limit
&&
688 labs(nonce_stamp_slop
) <= nonce_stamp_slop_limit
) {
690 * Pretend as if the received nonce (which passes the
691 * HMAC check, so it is not a forged by third-party)
694 free((void *)push_cert_nonce
);
695 push_cert_nonce
= xstrdup(nonce
);
708 * Return 1 if there is no push_cert or if the push options in push_cert are
709 * the same as those in the argument; 0 otherwise.
711 static int check_cert_push_options(const struct string_list
*push_options
)
713 const char *buf
= push_cert
.buf
;
714 int len
= push_cert
.len
;
717 const char *next_line
;
718 int options_seen
= 0;
725 while ((option
= find_header(buf
, len
, "push-option", &next_line
))) {
726 len
-= (next_line
- buf
);
729 if (options_seen
> push_options
->nr
731 push_options
->items
[options_seen
- 1].string
)) {
738 if (options_seen
!= push_options
->nr
)
746 static void prepare_push_cert_sha1(struct child_process
*proc
)
748 static int already_done
;
754 int bogs
/* beginning_of_gpg_sig */;
757 if (write_object_file(push_cert
.buf
, push_cert
.len
, OBJ_BLOB
,
759 oidclr(&push_cert_oid
);
761 memset(&sigcheck
, '\0', sizeof(sigcheck
));
763 bogs
= parse_signed_buffer(push_cert
.buf
, push_cert
.len
);
764 sigcheck
.payload
= xmemdupz(push_cert
.buf
, bogs
);
765 sigcheck
.payload_len
= bogs
;
766 check_signature(&sigcheck
, push_cert
.buf
+ bogs
,
767 push_cert
.len
- bogs
);
769 nonce_status
= check_nonce(push_cert
.buf
, bogs
);
771 if (!is_null_oid(&push_cert_oid
)) {
772 strvec_pushf(&proc
->env
, "GIT_PUSH_CERT=%s",
773 oid_to_hex(&push_cert_oid
));
774 strvec_pushf(&proc
->env
, "GIT_PUSH_CERT_SIGNER=%s",
775 sigcheck
.signer
? sigcheck
.signer
: "");
776 strvec_pushf(&proc
->env
, "GIT_PUSH_CERT_KEY=%s",
777 sigcheck
.key
? sigcheck
.key
: "");
778 strvec_pushf(&proc
->env
, "GIT_PUSH_CERT_STATUS=%c",
780 if (push_cert_nonce
) {
781 strvec_pushf(&proc
->env
,
782 "GIT_PUSH_CERT_NONCE=%s",
784 strvec_pushf(&proc
->env
,
785 "GIT_PUSH_CERT_NONCE_STATUS=%s",
787 if (nonce_status
== NONCE_SLOP
)
788 strvec_pushf(&proc
->env
,
789 "GIT_PUSH_CERT_NONCE_SLOP=%ld",
795 struct receive_hook_feed_state
{
797 struct ref_push_report
*report
;
800 const struct string_list
*push_options
;
803 typedef int (*feed_fn
)(void *, const char **, size_t *);
804 static int run_and_feed_hook(const char *hook_name
, feed_fn feed
,
805 struct receive_hook_feed_state
*feed_state
)
807 struct child_process proc
= CHILD_PROCESS_INIT
;
810 const char *hook_path
= find_hook(hook_name
);
815 strvec_push(&proc
.args
, hook_path
);
817 proc
.stdout_to_stderr
= 1;
818 proc
.trace2_hook_name
= hook_name
;
820 if (feed_state
->push_options
) {
822 for (i
= 0; i
< feed_state
->push_options
->nr
; i
++)
823 strvec_pushf(&proc
.env
,
824 "GIT_PUSH_OPTION_%"PRIuMAX
"=%s",
826 feed_state
->push_options
->items
[i
].string
);
827 strvec_pushf(&proc
.env
, "GIT_PUSH_OPTION_COUNT=%"PRIuMAX
"",
828 (uintmax_t)feed_state
->push_options
->nr
);
830 strvec_pushf(&proc
.env
, "GIT_PUSH_OPTION_COUNT");
833 strvec_pushv(&proc
.env
, tmp_objdir_env(tmp_objdir
));
836 memset(&muxer
, 0, sizeof(muxer
));
837 muxer
.proc
= copy_to_sideband
;
839 code
= start_async(&muxer
);
845 prepare_push_cert_sha1(&proc
);
847 code
= start_command(&proc
);
850 finish_async(&muxer
);
854 sigchain_push(SIGPIPE
, SIG_IGN
);
859 if (feed(feed_state
, &buf
, &n
))
861 if (write_in_full(proc
.in
, buf
, n
) < 0)
866 finish_async(&muxer
);
868 sigchain_pop(SIGPIPE
);
870 return finish_command(&proc
);
873 static int feed_receive_hook(void *state_
, const char **bufp
, size_t *sizep
)
875 struct receive_hook_feed_state
*state
= state_
;
876 struct command
*cmd
= state
->cmd
;
879 state
->skip_broken
&& (cmd
->error_string
|| cmd
->did_not_exist
))
884 return 0; /* OK, can feed something. */
885 strbuf_reset(&state
->buf
);
887 state
->report
= cmd
->report
;
889 struct object_id
*old_oid
;
890 struct object_id
*new_oid
;
891 const char *ref_name
;
893 old_oid
= state
->report
->old_oid
? state
->report
->old_oid
: &cmd
->old_oid
;
894 new_oid
= state
->report
->new_oid
? state
->report
->new_oid
: &cmd
->new_oid
;
895 ref_name
= state
->report
->ref_name
? state
->report
->ref_name
: cmd
->ref_name
;
896 strbuf_addf(&state
->buf
, "%s %s %s\n",
897 oid_to_hex(old_oid
), oid_to_hex(new_oid
),
899 state
->report
= state
->report
->next
;
901 state
->cmd
= cmd
->next
;
903 strbuf_addf(&state
->buf
, "%s %s %s\n",
904 oid_to_hex(&cmd
->old_oid
), oid_to_hex(&cmd
->new_oid
),
906 state
->cmd
= cmd
->next
;
909 *bufp
= state
->buf
.buf
;
910 *sizep
= state
->buf
.len
;
915 static int run_receive_hook(struct command
*commands
,
916 const char *hook_name
,
918 const struct string_list
*push_options
)
920 struct receive_hook_feed_state state
;
923 strbuf_init(&state
.buf
, 0);
924 state
.cmd
= commands
;
925 state
.skip_broken
= skip_broken
;
927 if (feed_receive_hook(&state
, NULL
, NULL
))
929 state
.cmd
= commands
;
930 state
.push_options
= push_options
;
931 status
= run_and_feed_hook(hook_name
, feed_receive_hook
, &state
);
932 strbuf_release(&state
.buf
);
936 static int run_update_hook(struct command
*cmd
)
938 struct child_process proc
= CHILD_PROCESS_INIT
;
940 const char *hook_path
= find_hook("update");
945 strvec_push(&proc
.args
, hook_path
);
946 strvec_push(&proc
.args
, cmd
->ref_name
);
947 strvec_push(&proc
.args
, oid_to_hex(&cmd
->old_oid
));
948 strvec_push(&proc
.args
, oid_to_hex(&cmd
->new_oid
));
951 proc
.stdout_to_stderr
= 1;
952 proc
.err
= use_sideband
? -1 : 0;
953 proc
.trace2_hook_name
= "update";
955 code
= start_command(&proc
);
959 copy_to_sideband(proc
.err
, -1, NULL
);
960 return finish_command(&proc
);
963 static struct command
*find_command_by_refname(struct command
*list
,
966 for (; list
; list
= list
->next
)
967 if (!strcmp(list
->ref_name
, refname
))
972 static int read_proc_receive_report(struct packet_reader
*reader
,
973 struct command
*commands
,
974 struct strbuf
*errmsg
)
977 struct command
*hint
= NULL
;
978 struct ref_push_report
*report
= NULL
;
985 struct object_id old_oid
, new_oid
;
989 enum packet_read_status status
;
991 status
= packet_reader_read(reader
);
992 if (status
!= PACKET_READ_NORMAL
) {
993 /* Check whether proc-receive exited abnormally */
994 if (status
== PACKET_READ_EOF
&& !response
) {
995 strbuf_addstr(errmsg
, "proc-receive exited abnormally");
1002 head
= reader
->line
;
1003 p
= strchr(head
, ' ');
1005 strbuf_addf(errmsg
, "proc-receive reported incomplete status line: '%s'\n", head
);
1010 if (!strcmp(head
, "option")) {
1011 const char *key
, *val
;
1013 if (!hint
|| !(report
|| new_report
)) {
1015 strbuf_addstr(errmsg
, "proc-receive reported 'option' without a matching 'ok/ng' directive\n");
1020 if (!hint
->report
) {
1021 CALLOC_ARRAY(hint
->report
, 1);
1022 report
= hint
->report
;
1024 report
= hint
->report
;
1025 while (report
->next
)
1026 report
= report
->next
;
1027 report
->next
= xcalloc(1, sizeof(struct ref_push_report
));
1028 report
= report
->next
;
1033 p
= strchr(key
, ' ');
1037 if (!strcmp(key
, "refname"))
1038 report
->ref_name
= xstrdup_or_null(val
);
1039 else if (!strcmp(key
, "old-oid") && val
&&
1040 !parse_oid_hex(val
, &old_oid
, &val
))
1041 report
->old_oid
= oiddup(&old_oid
);
1042 else if (!strcmp(key
, "new-oid") && val
&&
1043 !parse_oid_hex(val
, &new_oid
, &val
))
1044 report
->new_oid
= oiddup(&new_oid
);
1045 else if (!strcmp(key
, "forced-update"))
1046 report
->forced_update
= 1;
1047 else if (!strcmp(key
, "fall-through"))
1048 /* Fall through, let 'receive-pack' to execute it. */
1049 hint
->run_proc_receive
= 0;
1056 p
= strchr(refname
, ' ');
1059 if (strcmp(head
, "ok") && strcmp(head
, "ng")) {
1060 strbuf_addf(errmsg
, "proc-receive reported bad status '%s' on ref '%s'\n",
1066 /* first try searching at our hint, falling back to all refs */
1068 hint
= find_command_by_refname(hint
, refname
);
1070 hint
= find_command_by_refname(commands
, refname
);
1072 strbuf_addf(errmsg
, "proc-receive reported status on unknown ref: %s\n",
1077 if (!hint
->run_proc_receive
) {
1078 strbuf_addf(errmsg
, "proc-receive reported status on unexpected ref: %s\n",
1083 hint
->run_proc_receive
|= RUN_PROC_RECEIVE_RETURNED
;
1084 if (!strcmp(head
, "ng")) {
1086 hint
->error_string
= xstrdup(p
);
1088 hint
->error_string
= "failed";
1095 for (cmd
= commands
; cmd
; cmd
= cmd
->next
)
1096 if (cmd
->run_proc_receive
&& !cmd
->error_string
&&
1097 !(cmd
->run_proc_receive
& RUN_PROC_RECEIVE_RETURNED
)) {
1098 cmd
->error_string
= "proc-receive failed to report status";
1104 static int run_proc_receive_hook(struct command
*commands
,
1105 const struct string_list
*push_options
)
1107 struct child_process proc
= CHILD_PROCESS_INIT
;
1109 struct command
*cmd
;
1110 struct packet_reader reader
;
1111 struct strbuf cap
= STRBUF_INIT
;
1112 struct strbuf errmsg
= STRBUF_INIT
;
1113 int hook_use_push_options
= 0;
1116 const char *hook_path
= find_hook("proc-receive");
1119 rp_error("cannot find hook 'proc-receive'");
1123 strvec_push(&proc
.args
, hook_path
);
1126 proc
.trace2_hook_name
= "proc-receive";
1129 memset(&muxer
, 0, sizeof(muxer
));
1130 muxer
.proc
= copy_to_sideband
;
1132 code
= start_async(&muxer
);
1135 proc
.err
= muxer
.in
;
1140 code
= start_command(&proc
);
1143 finish_async(&muxer
);
1147 sigchain_push(SIGPIPE
, SIG_IGN
);
1149 /* Version negotiaton */
1150 packet_reader_init(&reader
, proc
.out
, NULL
, 0,
1151 PACKET_READ_CHOMP_NEWLINE
|
1152 PACKET_READ_GENTLE_ON_EOF
);
1154 strbuf_addstr(&cap
, " atomic");
1155 if (use_push_options
)
1156 strbuf_addstr(&cap
, " push-options");
1158 code
= packet_write_fmt_gently(proc
.in
, "version=1%c%s\n", '\0', cap
.buf
+ 1);
1159 strbuf_release(&cap
);
1161 code
= packet_write_fmt_gently(proc
.in
, "version=1\n");
1164 code
= packet_flush_gently(proc
.in
);
1169 enum packet_read_status status
;
1171 status
= packet_reader_read(&reader
);
1172 if (status
!= PACKET_READ_NORMAL
) {
1173 /* Check whether proc-receive exited abnormally */
1174 if (status
== PACKET_READ_EOF
)
1179 if (reader
.pktlen
> 8 && starts_with(reader
.line
, "version=")) {
1180 version
= atoi(reader
.line
+ 8);
1181 linelen
= strlen(reader
.line
);
1182 if (linelen
< reader
.pktlen
) {
1183 const char *feature_list
= reader
.line
+ linelen
+ 1;
1184 if (parse_feature_request(feature_list
, "push-options"))
1185 hook_use_push_options
= 1;
1191 strbuf_addstr(&errmsg
, "fail to negotiate version with proc-receive hook");
1201 strbuf_addf(&errmsg
, "proc-receive version '%d' is not supported",
1208 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1209 if (!cmd
->run_proc_receive
|| cmd
->skip_update
|| cmd
->error_string
)
1211 code
= packet_write_fmt_gently(proc
.in
, "%s %s %s",
1212 oid_to_hex(&cmd
->old_oid
),
1213 oid_to_hex(&cmd
->new_oid
),
1219 code
= packet_flush_gently(proc
.in
);
1221 strbuf_addstr(&errmsg
, "fail to write commands to proc-receive hook");
1225 /* Send push options */
1226 if (hook_use_push_options
) {
1227 struct string_list_item
*item
;
1229 for_each_string_list_item(item
, push_options
) {
1230 code
= packet_write_fmt_gently(proc
.in
, "%s", item
->string
);
1235 code
= packet_flush_gently(proc
.in
);
1237 strbuf_addstr(&errmsg
,
1238 "fail to write push-options to proc-receive hook");
1243 /* Read result from proc-receive */
1244 code
= read_proc_receive_report(&reader
, commands
, &errmsg
);
1250 finish_async(&muxer
);
1251 if (finish_command(&proc
))
1253 if (errmsg
.len
>0) {
1254 char *p
= errmsg
.buf
;
1256 p
+= errmsg
.len
- 1;
1259 rp_error("%s", errmsg
.buf
);
1260 strbuf_release(&errmsg
);
1262 sigchain_pop(SIGPIPE
);
1267 static char *refuse_unconfigured_deny_msg
=
1268 N_("By default, updating the current branch in a non-bare repository\n"
1269 "is denied, because it will make the index and work tree inconsistent\n"
1270 "with what you pushed, and will require 'git reset --hard' to match\n"
1271 "the work tree to HEAD.\n"
1273 "You can set the 'receive.denyCurrentBranch' configuration variable\n"
1274 "to 'ignore' or 'warn' in the remote repository to allow pushing into\n"
1275 "its current branch; however, this is not recommended unless you\n"
1276 "arranged to update its work tree to match what you pushed in some\n"
1279 "To squelch this message and still keep the default behaviour, set\n"
1280 "'receive.denyCurrentBranch' configuration variable to 'refuse'.");
1282 static void refuse_unconfigured_deny(void)
1284 rp_error("%s", _(refuse_unconfigured_deny_msg
));
1287 static char *refuse_unconfigured_deny_delete_current_msg
=
1288 N_("By default, deleting the current branch is denied, because the next\n"
1289 "'git clone' won't result in any file checked out, causing confusion.\n"
1291 "You can set 'receive.denyDeleteCurrent' configuration variable to\n"
1292 "'warn' or 'ignore' in the remote repository to allow deleting the\n"
1293 "current branch, with or without a warning message.\n"
1295 "To squelch this message, you can set it to 'refuse'.");
1297 static void refuse_unconfigured_deny_delete_current(void)
1299 rp_error("%s", _(refuse_unconfigured_deny_delete_current_msg
));
1302 static const struct object_id
*command_singleton_iterator(void *cb_data
);
1303 static int update_shallow_ref(struct command
*cmd
, struct shallow_info
*si
)
1305 struct shallow_lock shallow_lock
= SHALLOW_LOCK_INIT
;
1306 struct oid_array extra
= OID_ARRAY_INIT
;
1307 struct check_connected_options opt
= CHECK_CONNECTED_INIT
;
1308 uint32_t mask
= 1 << (cmd
->index
% 32);
1311 trace_printf_key(&trace_shallow
,
1312 "shallow: update_shallow_ref %s\n", cmd
->ref_name
);
1313 for (i
= 0; i
< si
->shallow
->nr
; i
++)
1314 if (si
->used_shallow
[i
] &&
1315 (si
->used_shallow
[i
][cmd
->index
/ 32] & mask
) &&
1316 !delayed_reachability_test(si
, i
))
1317 oid_array_append(&extra
, &si
->shallow
->oid
[i
]);
1319 opt
.env
= tmp_objdir_env(tmp_objdir
);
1320 setup_alternate_shallow(&shallow_lock
, &opt
.shallow_file
, &extra
);
1321 if (check_connected(command_singleton_iterator
, cmd
, &opt
)) {
1322 rollback_shallow_file(the_repository
, &shallow_lock
);
1323 oid_array_clear(&extra
);
1327 commit_shallow_file(the_repository
, &shallow_lock
);
1330 * Make sure setup_alternate_shallow() for the next ref does
1331 * not lose these new roots..
1333 for (i
= 0; i
< extra
.nr
; i
++)
1334 register_shallow(the_repository
, &extra
.oid
[i
]);
1336 si
->shallow_ref
[cmd
->index
] = 0;
1337 oid_array_clear(&extra
);
1342 * NEEDSWORK: we should consolidate various implementions of "are we
1343 * on an unborn branch?" test into one, and make the unified one more
1344 * robust. !get_sha1() based check used here and elsewhere would not
1345 * allow us to tell an unborn branch from corrupt ref, for example.
1346 * For the purpose of fixing "deploy-to-update does not work when
1347 * pushing into an empty repository" issue, this should suffice for
1350 static int head_has_history(void)
1352 struct object_id oid
;
1354 return !repo_get_oid(the_repository
, "HEAD", &oid
);
1357 static const char *push_to_deploy(unsigned char *sha1
,
1359 const char *work_tree
)
1361 struct child_process child
= CHILD_PROCESS_INIT
;
1363 strvec_pushl(&child
.args
, "update-index", "-q", "--ignore-submodules",
1365 strvec_pushv(&child
.env
, env
->v
);
1366 child
.dir
= work_tree
;
1368 child
.stdout_to_stderr
= 1;
1370 if (run_command(&child
))
1371 return "Up-to-date check failed";
1373 /* run_command() does not clean up completely; reinitialize */
1374 child_process_init(&child
);
1375 strvec_pushl(&child
.args
, "diff-files", "--quiet",
1376 "--ignore-submodules", "--", NULL
);
1377 strvec_pushv(&child
.env
, env
->v
);
1378 child
.dir
= work_tree
;
1380 child
.stdout_to_stderr
= 1;
1382 if (run_command(&child
))
1383 return "Working directory has unstaged changes";
1385 child_process_init(&child
);
1386 strvec_pushl(&child
.args
, "diff-index", "--quiet", "--cached",
1387 "--ignore-submodules",
1388 /* diff-index with either HEAD or an empty tree */
1389 head_has_history() ? "HEAD" : empty_tree_oid_hex(),
1391 strvec_pushv(&child
.env
, env
->v
);
1393 child
.no_stdout
= 1;
1394 child
.stdout_to_stderr
= 0;
1396 if (run_command(&child
))
1397 return "Working directory has staged changes";
1399 child_process_init(&child
);
1400 strvec_pushl(&child
.args
, "read-tree", "-u", "-m", hash_to_hex(sha1
),
1402 strvec_pushv(&child
.env
, env
->v
);
1403 child
.dir
= work_tree
;
1405 child
.no_stdout
= 1;
1406 child
.stdout_to_stderr
= 0;
1408 if (run_command(&child
))
1409 return "Could not update working tree to new HEAD";
1414 static const char *push_to_checkout_hook
= "push-to-checkout";
1416 static const char *push_to_checkout(unsigned char *hash
,
1419 const char *work_tree
)
1421 struct run_hooks_opt opt
= RUN_HOOKS_OPT_INIT
;
1422 opt
.invoked_hook
= invoked_hook
;
1424 strvec_pushf(env
, "GIT_WORK_TREE=%s", absolute_path(work_tree
));
1425 strvec_pushv(&opt
.env
, env
->v
);
1426 strvec_push(&opt
.args
, hash_to_hex(hash
));
1427 if (run_hooks_opt(push_to_checkout_hook
, &opt
))
1428 return "push-to-checkout hook declined";
1433 static const char *update_worktree(unsigned char *sha1
, const struct worktree
*worktree
)
1435 const char *retval
, *git_dir
;
1436 struct strvec env
= STRVEC_INIT
;
1439 if (!worktree
|| !worktree
->path
)
1440 BUG("worktree->path must be non-NULL");
1442 if (worktree
->is_bare
)
1443 return "denyCurrentBranch = updateInstead needs a worktree";
1444 git_dir
= get_worktree_git_dir(worktree
);
1446 strvec_pushf(&env
, "GIT_DIR=%s", absolute_path(git_dir
));
1448 retval
= push_to_checkout(sha1
, &invoked_hook
, &env
, worktree
->path
);
1450 retval
= push_to_deploy(sha1
, &env
, worktree
->path
);
1456 static const char *update(struct command
*cmd
, struct shallow_info
*si
)
1458 const char *name
= cmd
->ref_name
;
1459 struct strbuf namespaced_name_buf
= STRBUF_INIT
;
1460 static char *namespaced_name
;
1462 struct object_id
*old_oid
= &cmd
->old_oid
;
1463 struct object_id
*new_oid
= &cmd
->new_oid
;
1464 int do_update_worktree
= 0;
1465 struct worktree
**worktrees
= get_worktrees();
1466 const struct worktree
*worktree
=
1467 find_shared_symref(worktrees
, "HEAD", name
);
1469 /* only refs/... are allowed */
1470 if (!starts_with(name
, "refs/") ||
1471 check_refname_format(name
+ 5, is_null_oid(new_oid
) ?
1472 REFNAME_ALLOW_ONELEVEL
: 0)) {
1473 rp_error("refusing to update funny ref '%s' remotely", name
);
1474 ret
= "funny refname";
1478 strbuf_addf(&namespaced_name_buf
, "%s%s", get_git_namespace(), name
);
1479 free(namespaced_name
);
1480 namespaced_name
= strbuf_detach(&namespaced_name_buf
, NULL
);
1482 if (worktree
&& !worktree
->is_bare
) {
1483 switch (deny_current_branch
) {
1487 rp_warning("updating the current branch");
1490 case DENY_UNCONFIGURED
:
1491 rp_error("refusing to update checked out branch: %s", name
);
1492 if (deny_current_branch
== DENY_UNCONFIGURED
)
1493 refuse_unconfigured_deny();
1494 ret
= "branch is currently checked out";
1496 case DENY_UPDATE_INSTEAD
:
1497 /* pass -- let other checks intervene first */
1498 do_update_worktree
= 1;
1503 if (!is_null_oid(new_oid
) && !repo_has_object_file(the_repository
, new_oid
)) {
1504 error("unpack should have generated %s, "
1505 "but I can't find it!", oid_to_hex(new_oid
));
1510 if (!is_null_oid(old_oid
) && is_null_oid(new_oid
)) {
1511 if (deny_deletes
&& starts_with(name
, "refs/heads/")) {
1512 rp_error("denying ref deletion for %s", name
);
1513 ret
= "deletion prohibited";
1517 if (worktree
|| (head_name
&& !strcmp(namespaced_name
, head_name
))) {
1518 switch (deny_delete_current
) {
1522 rp_warning("deleting the current branch");
1525 case DENY_UNCONFIGURED
:
1526 case DENY_UPDATE_INSTEAD
:
1527 if (deny_delete_current
== DENY_UNCONFIGURED
)
1528 refuse_unconfigured_deny_delete_current();
1529 rp_error("refusing to delete the current branch: %s", name
);
1530 ret
= "deletion of the current branch prohibited";
1533 ret
= "Invalid denyDeleteCurrent setting";
1539 if (deny_non_fast_forwards
&& !is_null_oid(new_oid
) &&
1540 !is_null_oid(old_oid
) &&
1541 starts_with(name
, "refs/heads/")) {
1542 struct object
*old_object
, *new_object
;
1543 struct commit
*old_commit
, *new_commit
;
1545 old_object
= parse_object(the_repository
, old_oid
);
1546 new_object
= parse_object(the_repository
, new_oid
);
1548 if (!old_object
|| !new_object
||
1549 old_object
->type
!= OBJ_COMMIT
||
1550 new_object
->type
!= OBJ_COMMIT
) {
1551 error("bad sha1 objects for %s", name
);
1555 old_commit
= (struct commit
*)old_object
;
1556 new_commit
= (struct commit
*)new_object
;
1557 if (!repo_in_merge_bases(the_repository
, old_commit
, new_commit
)) {
1558 rp_error("denying non-fast-forward %s"
1559 " (you should pull first)", name
);
1560 ret
= "non-fast-forward";
1564 if (run_update_hook(cmd
)) {
1565 rp_error("hook declined to update %s", name
);
1566 ret
= "hook declined";
1570 if (do_update_worktree
) {
1571 ret
= update_worktree(new_oid
->hash
, worktree
);
1576 if (is_null_oid(new_oid
)) {
1577 struct strbuf err
= STRBUF_INIT
;
1578 if (!parse_object(the_repository
, old_oid
)) {
1580 if (ref_exists(name
)) {
1581 rp_warning("allowing deletion of corrupt ref");
1583 rp_warning("deleting a non-existent ref");
1584 cmd
->did_not_exist
= 1;
1587 if (ref_transaction_delete(transaction
,
1591 rp_error("%s", err
.buf
);
1592 ret
= "failed to delete";
1594 ret
= NULL
; /* good */
1596 strbuf_release(&err
);
1599 struct strbuf err
= STRBUF_INIT
;
1600 if (shallow_update
&& si
->shallow_ref
[cmd
->index
] &&
1601 update_shallow_ref(cmd
, si
)) {
1602 ret
= "shallow error";
1606 if (ref_transaction_update(transaction
,
1611 rp_error("%s", err
.buf
);
1612 ret
= "failed to update ref";
1614 ret
= NULL
; /* good */
1616 strbuf_release(&err
);
1620 free_worktrees(worktrees
);
1624 static void run_update_post_hook(struct command
*commands
)
1626 struct command
*cmd
;
1627 struct child_process proc
= CHILD_PROCESS_INIT
;
1630 hook
= find_hook("post-update");
1634 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1635 if (cmd
->error_string
|| cmd
->did_not_exist
)
1638 strvec_push(&proc
.args
, hook
);
1639 strvec_push(&proc
.args
, cmd
->ref_name
);
1645 proc
.stdout_to_stderr
= 1;
1646 proc
.err
= use_sideband
? -1 : 0;
1647 proc
.trace2_hook_name
= "post-update";
1649 if (!start_command(&proc
)) {
1651 copy_to_sideband(proc
.err
, -1, NULL
);
1652 finish_command(&proc
);
1656 static void check_aliased_update_internal(struct command
*cmd
,
1657 struct string_list
*list
,
1658 const char *dst_name
, int flag
)
1660 struct string_list_item
*item
;
1661 struct command
*dst_cmd
;
1663 if (!(flag
& REF_ISSYMREF
))
1667 rp_error("refusing update to broken symref '%s'", cmd
->ref_name
);
1668 cmd
->skip_update
= 1;
1669 cmd
->error_string
= "broken symref";
1672 dst_name
= strip_namespace(dst_name
);
1674 if (!(item
= string_list_lookup(list
, dst_name
)))
1677 cmd
->skip_update
= 1;
1679 dst_cmd
= (struct command
*) item
->util
;
1681 if (oideq(&cmd
->old_oid
, &dst_cmd
->old_oid
) &&
1682 oideq(&cmd
->new_oid
, &dst_cmd
->new_oid
))
1685 dst_cmd
->skip_update
= 1;
1687 rp_error("refusing inconsistent update between symref '%s' (%s..%s) and"
1688 " its target '%s' (%s..%s)",
1690 repo_find_unique_abbrev(the_repository
, &cmd
->old_oid
, DEFAULT_ABBREV
),
1691 repo_find_unique_abbrev(the_repository
, &cmd
->new_oid
, DEFAULT_ABBREV
),
1693 repo_find_unique_abbrev(the_repository
, &dst_cmd
->old_oid
, DEFAULT_ABBREV
),
1694 repo_find_unique_abbrev(the_repository
, &dst_cmd
->new_oid
, DEFAULT_ABBREV
));
1696 cmd
->error_string
= dst_cmd
->error_string
=
1697 "inconsistent aliased update";
1700 static void check_aliased_update(struct command
*cmd
, struct string_list
*list
)
1702 struct strbuf buf
= STRBUF_INIT
;
1703 const char *dst_name
;
1706 strbuf_addf(&buf
, "%s%s", get_git_namespace(), cmd
->ref_name
);
1707 dst_name
= resolve_ref_unsafe(buf
.buf
, 0, NULL
, &flag
);
1708 check_aliased_update_internal(cmd
, list
, dst_name
, flag
);
1709 strbuf_release(&buf
);
1712 static void check_aliased_updates(struct command
*commands
)
1714 struct command
*cmd
;
1715 struct string_list ref_list
= STRING_LIST_INIT_NODUP
;
1717 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1718 struct string_list_item
*item
=
1719 string_list_append(&ref_list
, cmd
->ref_name
);
1720 item
->util
= (void *)cmd
;
1722 string_list_sort(&ref_list
);
1724 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1725 if (!cmd
->error_string
)
1726 check_aliased_update(cmd
, &ref_list
);
1729 string_list_clear(&ref_list
, 0);
1732 static const struct object_id
*command_singleton_iterator(void *cb_data
)
1734 struct command
**cmd_list
= cb_data
;
1735 struct command
*cmd
= *cmd_list
;
1737 if (!cmd
|| is_null_oid(&cmd
->new_oid
))
1739 *cmd_list
= NULL
; /* this returns only one */
1740 return &cmd
->new_oid
;
1743 static void set_connectivity_errors(struct command
*commands
,
1744 struct shallow_info
*si
)
1746 struct command
*cmd
;
1748 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1749 struct command
*singleton
= cmd
;
1750 struct check_connected_options opt
= CHECK_CONNECTED_INIT
;
1752 if (shallow_update
&& si
->shallow_ref
[cmd
->index
])
1753 /* to be checked in update_shallow_ref() */
1756 opt
.env
= tmp_objdir_env(tmp_objdir
);
1757 if (!check_connected(command_singleton_iterator
, &singleton
,
1761 cmd
->error_string
= "missing necessary objects";
1765 struct iterate_data
{
1766 struct command
*cmds
;
1767 struct shallow_info
*si
;
1770 static const struct object_id
*iterate_receive_command_list(void *cb_data
)
1772 struct iterate_data
*data
= cb_data
;
1773 struct command
**cmd_list
= &data
->cmds
;
1774 struct command
*cmd
= *cmd_list
;
1776 for (; cmd
; cmd
= cmd
->next
) {
1777 if (shallow_update
&& data
->si
->shallow_ref
[cmd
->index
])
1778 /* to be checked in update_shallow_ref() */
1780 if (!is_null_oid(&cmd
->new_oid
) && !cmd
->skip_update
) {
1781 *cmd_list
= cmd
->next
;
1782 return &cmd
->new_oid
;
1788 static void reject_updates_to_hidden(struct command
*commands
)
1790 struct strbuf refname_full
= STRBUF_INIT
;
1792 struct command
*cmd
;
1794 strbuf_addstr(&refname_full
, get_git_namespace());
1795 prefix_len
= refname_full
.len
;
1797 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1798 if (cmd
->error_string
)
1801 strbuf_setlen(&refname_full
, prefix_len
);
1802 strbuf_addstr(&refname_full
, cmd
->ref_name
);
1804 if (!ref_is_hidden(cmd
->ref_name
, refname_full
.buf
, &hidden_refs
))
1806 if (is_null_oid(&cmd
->new_oid
))
1807 cmd
->error_string
= "deny deleting a hidden ref";
1809 cmd
->error_string
= "deny updating a hidden ref";
1812 strbuf_release(&refname_full
);
1815 static int should_process_cmd(struct command
*cmd
)
1817 return !cmd
->error_string
&& !cmd
->skip_update
;
1820 static void BUG_if_skipped_connectivity_check(struct command
*commands
,
1821 struct shallow_info
*si
)
1823 struct command
*cmd
;
1825 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1826 if (should_process_cmd(cmd
) && si
->shallow_ref
[cmd
->index
])
1827 bug("connectivity check has not been run on ref %s",
1830 BUG_if_bug("connectivity check skipped???");
1833 static void execute_commands_non_atomic(struct command
*commands
,
1834 struct shallow_info
*si
)
1836 struct command
*cmd
;
1837 struct strbuf err
= STRBUF_INIT
;
1839 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1840 if (!should_process_cmd(cmd
) || cmd
->run_proc_receive
)
1843 transaction
= ref_transaction_begin(&err
);
1845 rp_error("%s", err
.buf
);
1847 cmd
->error_string
= "transaction failed to start";
1851 cmd
->error_string
= update(cmd
, si
);
1853 if (!cmd
->error_string
1854 && ref_transaction_commit(transaction
, &err
)) {
1855 rp_error("%s", err
.buf
);
1857 cmd
->error_string
= "failed to update ref";
1859 ref_transaction_free(transaction
);
1861 strbuf_release(&err
);
1864 static void execute_commands_atomic(struct command
*commands
,
1865 struct shallow_info
*si
)
1867 struct command
*cmd
;
1868 struct strbuf err
= STRBUF_INIT
;
1869 const char *reported_error
= "atomic push failure";
1871 transaction
= ref_transaction_begin(&err
);
1873 rp_error("%s", err
.buf
);
1875 reported_error
= "transaction failed to start";
1879 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1880 if (!should_process_cmd(cmd
) || cmd
->run_proc_receive
)
1883 cmd
->error_string
= update(cmd
, si
);
1885 if (cmd
->error_string
)
1889 if (ref_transaction_commit(transaction
, &err
)) {
1890 rp_error("%s", err
.buf
);
1891 reported_error
= "atomic transaction failed";
1897 for (cmd
= commands
; cmd
; cmd
= cmd
->next
)
1898 if (!cmd
->error_string
)
1899 cmd
->error_string
= reported_error
;
1902 ref_transaction_free(transaction
);
1903 strbuf_release(&err
);
1906 static void execute_commands(struct command
*commands
,
1907 const char *unpacker_error
,
1908 struct shallow_info
*si
,
1909 const struct string_list
*push_options
)
1911 struct check_connected_options opt
= CHECK_CONNECTED_INIT
;
1912 struct command
*cmd
;
1913 struct iterate_data data
;
1916 int run_proc_receive
= 0;
1918 if (unpacker_error
) {
1919 for (cmd
= commands
; cmd
; cmd
= cmd
->next
)
1920 cmd
->error_string
= "unpacker error";
1925 memset(&muxer
, 0, sizeof(muxer
));
1926 muxer
.proc
= copy_to_sideband
;
1928 if (!start_async(&muxer
))
1930 /* ...else, continue without relaying sideband */
1933 data
.cmds
= commands
;
1935 opt
.err_fd
= err_fd
;
1936 opt
.progress
= err_fd
&& !quiet
;
1937 opt
.env
= tmp_objdir_env(tmp_objdir
);
1938 opt
.exclude_hidden_refs_section
= "receive";
1940 if (check_connected(iterate_receive_command_list
, &data
, &opt
))
1941 set_connectivity_errors(commands
, si
);
1944 finish_async(&muxer
);
1946 reject_updates_to_hidden(commands
);
1949 * Try to find commands that have special prefix in their reference names,
1950 * and mark them to run an external "proc-receive" hook later.
1952 if (proc_receive_ref
) {
1953 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1954 if (!should_process_cmd(cmd
))
1957 if (proc_receive_ref_matches(cmd
)) {
1958 cmd
->run_proc_receive
= RUN_PROC_RECEIVE_SCHEDULED
;
1959 run_proc_receive
= 1;
1964 if (run_receive_hook(commands
, "pre-receive", 0, push_options
)) {
1965 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1966 if (!cmd
->error_string
)
1967 cmd
->error_string
= "pre-receive hook declined";
1973 * If there is no command ready to run, should return directly to destroy
1974 * temporary data in the quarantine area.
1976 for (cmd
= commands
; cmd
&& cmd
->error_string
; cmd
= cmd
->next
)
1982 * Now we'll start writing out refs, which means the objects need
1983 * to be in their final positions so that other processes can see them.
1985 if (tmp_objdir_migrate(tmp_objdir
) < 0) {
1986 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
1987 if (!cmd
->error_string
)
1988 cmd
->error_string
= "unable to migrate objects to permanent storage";
1994 check_aliased_updates(commands
);
1996 free(head_name_to_free
);
1997 head_name
= head_name_to_free
= resolve_refdup("HEAD", 0, NULL
, NULL
);
1999 if (run_proc_receive
&&
2000 run_proc_receive_hook(commands
, push_options
))
2001 for (cmd
= commands
; cmd
; cmd
= cmd
->next
)
2002 if (!cmd
->error_string
&&
2003 !(cmd
->run_proc_receive
& RUN_PROC_RECEIVE_RETURNED
) &&
2004 (cmd
->run_proc_receive
|| use_atomic
))
2005 cmd
->error_string
= "fail to run proc-receive hook";
2008 execute_commands_atomic(commands
, si
);
2010 execute_commands_non_atomic(commands
, si
);
2013 BUG_if_skipped_connectivity_check(commands
, si
);
2016 static struct command
**queue_command(struct command
**tail
,
2020 struct object_id old_oid
, new_oid
;
2021 struct command
*cmd
;
2022 const char *refname
;
2026 if (parse_oid_hex(line
, &old_oid
, &p
) ||
2028 parse_oid_hex(p
, &new_oid
, &p
) ||
2030 die("protocol error: expected old/new/ref, got '%s'", line
);
2033 reflen
= linelen
- (p
- line
);
2034 FLEX_ALLOC_MEM(cmd
, ref_name
, refname
, reflen
);
2035 oidcpy(&cmd
->old_oid
, &old_oid
);
2036 oidcpy(&cmd
->new_oid
, &new_oid
);
2041 static void free_commands(struct command
*commands
)
2044 struct command
*next
= commands
->next
;
2051 static void queue_commands_from_cert(struct command
**tail
,
2052 struct strbuf
*push_cert
)
2054 const char *boc
, *eoc
;
2057 die("protocol error: got both push certificate and unsigned commands");
2059 boc
= strstr(push_cert
->buf
, "\n\n");
2061 die("malformed push certificate %.*s", 100, push_cert
->buf
);
2064 eoc
= push_cert
->buf
+ parse_signed_buffer(push_cert
->buf
, push_cert
->len
);
2067 const char *eol
= memchr(boc
, '\n', eoc
- boc
);
2068 tail
= queue_command(tail
, boc
, eol
? eol
- boc
: eoc
- boc
);
2069 boc
= eol
? eol
+ 1 : eoc
;
2073 static struct command
*read_head_info(struct packet_reader
*reader
,
2074 struct oid_array
*shallow
)
2076 struct command
*commands
= NULL
;
2077 struct command
**p
= &commands
;
2081 if (packet_reader_read(reader
) != PACKET_READ_NORMAL
)
2084 if (reader
->pktlen
> 8 && starts_with(reader
->line
, "shallow ")) {
2085 struct object_id oid
;
2086 if (get_oid_hex(reader
->line
+ 8, &oid
))
2087 die("protocol error: expected shallow sha, got '%s'",
2089 oid_array_append(shallow
, &oid
);
2093 linelen
= strlen(reader
->line
);
2094 if (linelen
< reader
->pktlen
) {
2095 const char *feature_list
= reader
->line
+ linelen
+ 1;
2096 const char *hash
= NULL
;
2097 const char *client_sid
;
2099 if (parse_feature_request(feature_list
, "report-status"))
2101 if (parse_feature_request(feature_list
, "report-status-v2"))
2102 report_status_v2
= 1;
2103 if (parse_feature_request(feature_list
, "side-band-64k"))
2104 use_sideband
= LARGE_PACKET_MAX
;
2105 if (parse_feature_request(feature_list
, "quiet"))
2107 if (advertise_atomic_push
2108 && parse_feature_request(feature_list
, "atomic"))
2110 if (advertise_push_options
2111 && parse_feature_request(feature_list
, "push-options"))
2112 use_push_options
= 1;
2113 hash
= parse_feature_value(feature_list
, "object-format", &len
, NULL
);
2115 hash
= hash_algos
[GIT_HASH_SHA1
].name
;
2118 if (xstrncmpz(the_hash_algo
->name
, hash
, len
))
2119 die("error: unsupported object format '%s'", hash
);
2120 client_sid
= parse_feature_value(feature_list
, "session-id", &len
, NULL
);
2122 char *sid
= xstrndup(client_sid
, len
);
2123 trace2_data_string("transfer", NULL
, "client-sid", client_sid
);
2128 if (!strcmp(reader
->line
, "push-cert")) {
2130 int saved_options
= reader
->options
;
2131 reader
->options
&= ~PACKET_READ_CHOMP_NEWLINE
;
2134 packet_reader_read(reader
);
2135 if (reader
->status
== PACKET_READ_FLUSH
) {
2139 if (reader
->status
!= PACKET_READ_NORMAL
) {
2140 die("protocol error: got an unexpected packet");
2142 if (!strcmp(reader
->line
, "push-cert-end\n"))
2143 break; /* end of cert */
2144 strbuf_addstr(&push_cert
, reader
->line
);
2146 reader
->options
= saved_options
;
2153 p
= queue_command(p
, reader
->line
, linelen
);
2157 queue_commands_from_cert(p
, &push_cert
);
2162 static void read_push_options(struct packet_reader
*reader
,
2163 struct string_list
*options
)
2166 if (packet_reader_read(reader
) != PACKET_READ_NORMAL
)
2169 string_list_append(options
, reader
->line
);
2173 static const char *parse_pack_header(struct pack_header
*hdr
)
2175 switch (read_pack_header(0, hdr
)) {
2177 return "eof before pack header was fully read";
2179 case PH_ERROR_PACK_SIGNATURE
:
2180 return "protocol error (pack signature mismatch detected)";
2182 case PH_ERROR_PROTOCOL
:
2183 return "protocol error (pack version unsupported)";
2186 return "unknown error in parse_pack_header";
2193 static const char *pack_lockfile
;
2195 static void push_header_arg(struct strvec
*args
, struct pack_header
*hdr
)
2197 strvec_pushf(args
, "--pack_header=%"PRIu32
",%"PRIu32
,
2198 ntohl(hdr
->hdr_version
), ntohl(hdr
->hdr_entries
));
2201 static const char *unpack(int err_fd
, struct shallow_info
*si
)
2203 struct pack_header hdr
;
2204 const char *hdr_err
;
2206 struct child_process child
= CHILD_PROCESS_INIT
;
2207 int fsck_objects
= (receive_fsck_objects
>= 0
2208 ? receive_fsck_objects
2209 : transfer_fsck_objects
>= 0
2210 ? transfer_fsck_objects
2213 hdr_err
= parse_pack_header(&hdr
);
2220 if (si
->nr_ours
|| si
->nr_theirs
) {
2221 alt_shallow_file
= setup_temporary_shallow(si
->shallow
);
2222 strvec_push(&child
.args
, "--shallow-file");
2223 strvec_push(&child
.args
, alt_shallow_file
);
2226 tmp_objdir
= tmp_objdir_create("incoming");
2230 return "unable to create temporary object directory";
2232 strvec_pushv(&child
.env
, tmp_objdir_env(tmp_objdir
));
2235 * Normally we just pass the tmp_objdir environment to the child
2236 * processes that do the heavy lifting, but we may need to see these
2237 * objects ourselves to set up shallow information.
2239 tmp_objdir_add_as_alternate(tmp_objdir
);
2241 if (ntohl(hdr
.hdr_entries
) < unpack_limit
) {
2242 strvec_push(&child
.args
, "unpack-objects");
2243 push_header_arg(&child
.args
, &hdr
);
2245 strvec_push(&child
.args
, "-q");
2247 strvec_pushf(&child
.args
, "--strict%s",
2248 fsck_msg_types
.buf
);
2250 strvec_pushf(&child
.args
, "--max-input-size=%"PRIuMAX
,
2251 (uintmax_t)max_input_size
);
2252 child
.no_stdout
= 1;
2255 status
= run_command(&child
);
2257 return "unpack-objects abnormal exit";
2259 char hostname
[HOST_NAME_MAX
+ 1];
2261 strvec_pushl(&child
.args
, "index-pack", "--stdin", NULL
);
2262 push_header_arg(&child
.args
, &hdr
);
2264 if (xgethostname(hostname
, sizeof(hostname
)))
2265 xsnprintf(hostname
, sizeof(hostname
), "localhost");
2266 strvec_pushf(&child
.args
,
2267 "--keep=receive-pack %"PRIuMAX
" on %s",
2268 (uintmax_t)getpid(),
2271 if (!quiet
&& err_fd
)
2272 strvec_push(&child
.args
, "--show-resolving-progress");
2274 strvec_push(&child
.args
, "--report-end-of-input");
2276 strvec_pushf(&child
.args
, "--strict%s",
2277 fsck_msg_types
.buf
);
2279 strvec_push(&child
.args
, "--fix-thin");
2281 strvec_pushf(&child
.args
, "--max-input-size=%"PRIuMAX
,
2282 (uintmax_t)max_input_size
);
2286 status
= start_command(&child
);
2288 return "index-pack fork failed";
2289 pack_lockfile
= index_pack_lockfile(child
.out
, NULL
);
2291 status
= finish_command(&child
);
2293 return "index-pack abnormal exit";
2294 reprepare_packed_git(the_repository
);
2299 static const char *unpack_with_sideband(struct shallow_info
*si
)
2305 return unpack(0, si
);
2307 use_keepalive
= KEEPALIVE_AFTER_NUL
;
2308 memset(&muxer
, 0, sizeof(muxer
));
2309 muxer
.proc
= copy_to_sideband
;
2311 if (start_async(&muxer
))
2314 ret
= unpack(muxer
.in
, si
);
2316 finish_async(&muxer
);
2320 static void prepare_shallow_update(struct shallow_info
*si
)
2322 int i
, j
, k
, bitmap_size
= DIV_ROUND_UP(si
->ref
->nr
, 32);
2324 ALLOC_ARRAY(si
->used_shallow
, si
->shallow
->nr
);
2325 assign_shallow_commits_to_refs(si
, si
->used_shallow
, NULL
);
2327 CALLOC_ARRAY(si
->need_reachability_test
, si
->shallow
->nr
);
2328 CALLOC_ARRAY(si
->reachable
, si
->shallow
->nr
);
2329 CALLOC_ARRAY(si
->shallow_ref
, si
->ref
->nr
);
2331 for (i
= 0; i
< si
->nr_ours
; i
++)
2332 si
->need_reachability_test
[si
->ours
[i
]] = 1;
2334 for (i
= 0; i
< si
->shallow
->nr
; i
++) {
2335 if (!si
->used_shallow
[i
])
2337 for (j
= 0; j
< bitmap_size
; j
++) {
2338 if (!si
->used_shallow
[i
][j
])
2340 si
->need_reachability_test
[i
]++;
2341 for (k
= 0; k
< 32; k
++)
2342 if (si
->used_shallow
[i
][j
] & (1U << k
))
2343 si
->shallow_ref
[j
* 32 + k
]++;
2347 * true for those associated with some refs and belong
2348 * in "ours" list aka "step 7 not done yet"
2350 si
->need_reachability_test
[i
] =
2351 si
->need_reachability_test
[i
] > 1;
2355 * keep hooks happy by forcing a temporary shallow file via
2356 * env variable because we can't add --shallow-file to every
2357 * command. check_connected() will be done with
2358 * true .git/shallow though.
2360 setenv(GIT_SHALLOW_FILE_ENVIRONMENT
, alt_shallow_file
, 1);
2363 static void update_shallow_info(struct command
*commands
,
2364 struct shallow_info
*si
,
2365 struct oid_array
*ref
)
2367 struct command
*cmd
;
2369 remove_nonexistent_theirs_shallow(si
);
2370 if (!si
->nr_ours
&& !si
->nr_theirs
) {
2375 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
2376 if (is_null_oid(&cmd
->new_oid
))
2378 oid_array_append(ref
, &cmd
->new_oid
);
2379 cmd
->index
= ref
->nr
- 1;
2383 if (shallow_update
) {
2384 prepare_shallow_update(si
);
2388 ALLOC_ARRAY(ref_status
, ref
->nr
);
2389 assign_shallow_commits_to_refs(si
, NULL
, ref_status
);
2390 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
2391 if (is_null_oid(&cmd
->new_oid
))
2393 if (ref_status
[cmd
->index
]) {
2394 cmd
->error_string
= "shallow update not allowed";
2395 cmd
->skip_update
= 1;
2401 static void report(struct command
*commands
, const char *unpack_status
)
2403 struct command
*cmd
;
2404 struct strbuf buf
= STRBUF_INIT
;
2406 packet_buf_write(&buf
, "unpack %s\n",
2407 unpack_status
? unpack_status
: "ok");
2408 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
2409 if (!cmd
->error_string
)
2410 packet_buf_write(&buf
, "ok %s\n",
2413 packet_buf_write(&buf
, "ng %s %s\n",
2414 cmd
->ref_name
, cmd
->error_string
);
2416 packet_buf_flush(&buf
);
2419 send_sideband(1, 1, buf
.buf
, buf
.len
, use_sideband
);
2421 write_or_die(1, buf
.buf
, buf
.len
);
2422 strbuf_release(&buf
);
2425 static void report_v2(struct command
*commands
, const char *unpack_status
)
2427 struct command
*cmd
;
2428 struct strbuf buf
= STRBUF_INIT
;
2429 struct ref_push_report
*report
;
2431 packet_buf_write(&buf
, "unpack %s\n",
2432 unpack_status
? unpack_status
: "ok");
2433 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
2436 if (cmd
->error_string
) {
2437 packet_buf_write(&buf
, "ng %s %s\n",
2442 packet_buf_write(&buf
, "ok %s\n",
2444 for (report
= cmd
->report
; report
; report
= report
->next
) {
2446 packet_buf_write(&buf
, "ok %s\n",
2448 if (report
->ref_name
)
2449 packet_buf_write(&buf
, "option refname %s\n",
2451 if (report
->old_oid
)
2452 packet_buf_write(&buf
, "option old-oid %s\n",
2453 oid_to_hex(report
->old_oid
));
2454 if (report
->new_oid
)
2455 packet_buf_write(&buf
, "option new-oid %s\n",
2456 oid_to_hex(report
->new_oid
));
2457 if (report
->forced_update
)
2458 packet_buf_write(&buf
, "option forced-update\n");
2461 packet_buf_flush(&buf
);
2464 send_sideband(1, 1, buf
.buf
, buf
.len
, use_sideband
);
2466 write_or_die(1, buf
.buf
, buf
.len
);
2467 strbuf_release(&buf
);
2470 static int delete_only(struct command
*commands
)
2472 struct command
*cmd
;
2473 for (cmd
= commands
; cmd
; cmd
= cmd
->next
) {
2474 if (!is_null_oid(&cmd
->new_oid
))
2480 int cmd_receive_pack(int argc
, const char **argv
, const char *prefix
)
2482 int advertise_refs
= 0;
2483 struct command
*commands
;
2484 struct oid_array shallow
= OID_ARRAY_INIT
;
2485 struct oid_array ref
= OID_ARRAY_INIT
;
2486 struct shallow_info si
;
2487 struct packet_reader reader
;
2489 struct option options
[] = {
2490 OPT__QUIET(&quiet
, N_("quiet")),
2491 OPT_HIDDEN_BOOL(0, "stateless-rpc", &stateless_rpc
, NULL
),
2492 OPT_HIDDEN_BOOL(0, "http-backend-info-refs", &advertise_refs
, NULL
),
2493 OPT_ALIAS(0, "advertise-refs", "http-backend-info-refs"),
2494 OPT_HIDDEN_BOOL(0, "reject-thin-pack-for-testing", &reject_thin
, NULL
),
2498 packet_trace_identity("receive-pack");
2500 argc
= parse_options(argc
, argv
, prefix
, options
, receive_pack_usage
, 0);
2503 usage_msg_opt(_("too many arguments"), receive_pack_usage
, options
);
2505 usage_msg_opt(_("you must specify a directory"), receive_pack_usage
, options
);
2507 service_dir
= argv
[0];
2511 if (!enter_repo(service_dir
, 0))
2512 die("'%s' does not appear to be a git repository", service_dir
);
2514 git_config(receive_pack_config
, NULL
);
2515 if (cert_nonce_seed
)
2516 push_cert_nonce
= prepare_push_cert_nonce(service_dir
, time(NULL
));
2518 if (0 <= transfer_unpack_limit
)
2519 unpack_limit
= transfer_unpack_limit
;
2520 else if (0 <= receive_unpack_limit
)
2521 unpack_limit
= receive_unpack_limit
;
2523 switch (determine_protocol_version_server()) {
2526 * push support for protocol v2 has not been implemented yet,
2527 * so ignore the request to use v2 and fallback to using v0.
2532 * v1 is just the original protocol with a version string,
2533 * so just fall through after writing the version string.
2535 if (advertise_refs
|| !stateless_rpc
)
2536 packet_write_fmt(1, "version 1\n");
2541 case protocol_unknown_version
:
2542 BUG("unknown protocol version");
2545 if (advertise_refs
|| !stateless_rpc
) {
2551 packet_reader_init(&reader
, 0, NULL
, 0,
2552 PACKET_READ_CHOMP_NEWLINE
|
2553 PACKET_READ_DIE_ON_ERR_PACKET
);
2555 if ((commands
= read_head_info(&reader
, &shallow
))) {
2556 const char *unpack_status
= NULL
;
2557 struct string_list push_options
= STRING_LIST_INIT_DUP
;
2559 if (use_push_options
)
2560 read_push_options(&reader
, &push_options
);
2561 if (!check_cert_push_options(&push_options
)) {
2562 struct command
*cmd
;
2563 for (cmd
= commands
; cmd
; cmd
= cmd
->next
)
2564 cmd
->error_string
= "inconsistent push options";
2567 prepare_shallow_info(&si
, &shallow
);
2568 if (!si
.nr_ours
&& !si
.nr_theirs
)
2570 if (!delete_only(commands
)) {
2571 unpack_status
= unpack_with_sideband(&si
);
2572 update_shallow_info(commands
, &si
, &ref
);
2574 use_keepalive
= KEEPALIVE_ALWAYS
;
2575 execute_commands(commands
, unpack_status
, &si
,
2578 unlink_or_warn(pack_lockfile
);
2579 sigchain_push(SIGPIPE
, SIG_IGN
);
2580 if (report_status_v2
)
2581 report_v2(commands
, unpack_status
);
2582 else if (report_status
)
2583 report(commands
, unpack_status
);
2584 sigchain_pop(SIGPIPE
);
2585 run_receive_hook(commands
, "post-receive", 1,
2587 run_update_post_hook(commands
);
2588 free_commands(commands
);
2589 string_list_clear(&push_options
, 0);
2591 struct child_process proc
= CHILD_PROCESS_INIT
;
2594 proc
.stdout_to_stderr
= 1;
2595 proc
.err
= use_sideband
? -1 : 0;
2596 proc
.git_cmd
= proc
.close_object_store
= 1;
2597 strvec_pushl(&proc
.args
, "gc", "--auto", "--quiet",
2600 if (!start_command(&proc
)) {
2602 copy_to_sideband(proc
.err
, -1, NULL
);
2603 finish_command(&proc
);
2606 if (auto_update_server_info
)
2607 update_server_info(0);
2608 clear_shallow_info(&si
);
2612 oid_array_clear(&shallow
);
2613 oid_array_clear(&ref
);
2614 string_list_clear(&hidden_refs
, 0);
2615 free((void *)push_cert_nonce
);