diff options
author | Stefan Beller <sbeller@google.com> | 2016-07-14 14:49:46 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-07-14 15:50:40 -0700 |
commit | c714e45f87301562b940e3621431ed7f7fbd16e5 (patch) | |
tree | df0a4693d25514763b3f91dbaaa651c29f244627 /builtin | |
parent | push options: {pre,post}-receive hook learns about push options (diff) | |
download | tgif-c714e45f87301562b940e3621431ed7f7fbd16e5.tar.xz |
receive-pack: implement advertising and receiving push options
The pre/post receive hook may be interested in more information from the
user. This information can be transmitted when both client and server
support the "push-options" capability, which when used is a phase directly
after update commands ended by a flush pkt.
Similar to the atomic option, the server capability can be disabled via
the `receive.advertisePushOptions` config variable. While documenting
this, fix a nit in the `receive.advertiseAtomic` wording.
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/receive-pack.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 6cdd2c6b59..3c9360aa6d 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -44,10 +44,12 @@ static struct strbuf fsck_msg_types = STRBUF_INIT; static int receive_unpack_limit = -1; static int transfer_unpack_limit = -1; static int advertise_atomic_push = 1; +static int advertise_push_options; static int unpack_limit = 100; static int report_status; static int use_sideband; static int use_atomic; +static int use_push_options; static int quiet; static int prefer_ofs_delta = 1; static int auto_update_server_info; @@ -193,6 +195,11 @@ static int receive_pack_config(const char *var, const char *value, void *cb) return 0; } + if (strcmp(var, "receive.advertisepushoptions") == 0) { + advertise_push_options = git_config_bool(var, value); + return 0; + } + return git_default_config(var, value, cb); } @@ -211,6 +218,8 @@ static void show_ref(const char *path, const unsigned char *sha1) strbuf_addstr(&cap, " ofs-delta"); if (push_cert_nonce) strbuf_addf(&cap, " push-cert=%s", push_cert_nonce); + if (advertise_push_options) + strbuf_addstr(&cap, " push-options"); strbuf_addf(&cap, " agent=%s", git_user_agent_sanitized()); packet_write(1, "%s %s%c%s\n", sha1_to_hex(sha1), path, 0, cap.buf); @@ -1455,6 +1464,9 @@ static struct command *read_head_info(struct sha1_array *shallow) if (advertise_atomic_push && parse_feature_request(feature_list, "atomic")) use_atomic = 1; + if (advertise_push_options + && parse_feature_request(feature_list, "push-options")) + use_push_options = 1; } if (!strcmp(line, "push-cert")) { @@ -1487,6 +1499,21 @@ static struct command *read_head_info(struct sha1_array *shallow) return commands; } +static void read_push_options(struct string_list *options) +{ + while (1) { + char *line; + int len; + + line = packet_read_line(0, &len); + + if (!line) + break; + + string_list_append(options, line); + } +} + static const char *parse_pack_header(struct pack_header *hdr) { switch (read_pack_header(0, hdr)) { @@ -1774,6 +1801,9 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix) const char *unpack_status = NULL; struct string_list push_options = STRING_LIST_INIT_DUP; + if (use_push_options) + read_push_options(&push_options); + prepare_shallow_info(&si, &shallow); if (!si.nr_ours && !si.nr_theirs) shallow_update = 0; |