Skip to content

Commit c714e45

Browse files
stefanbellergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 77a9745 commit c714e45

File tree

4 files changed

+52
-6
lines changed

4 files changed

+52
-6
lines changed

Documentation/config.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2410,8 +2410,13 @@ rebase.instructionFormat
24102410

24112411
receive.advertiseAtomic::
24122412
By default, git-receive-pack will advertise the atomic push
2413-
capability to its clients. If you don't want to this capability
2414-
to be advertised, set this variable to false.
2413+
capability to its clients. If you don't want to advertise this
2414+
capability, set this variable to false.
2415+
2416+
receive.advertisePushOptions::
2417+
By default, git-receive-pack will advertise the push options
2418+
capability to its clients. If you don't want to advertise this
2419+
capability, set this variable to false.
24152420

24162421
receive.autogc::
24172422
By default, git-receive-pack will run "git-gc --auto" after

Documentation/technical/pack-protocol.txt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,8 @@ The reference discovery phase is done nearly the same way as it is in the
454454
fetching protocol. Each reference obj-id and name on the server is sent
455455
in packet-line format to the client, followed by a flush-pkt. The only
456456
real difference is that the capability listing is different - the only
457-
possible values are 'report-status', 'delete-refs' and 'ofs-delta'.
457+
possible values are 'report-status', 'delete-refs', 'ofs-delta' and
458+
'push-options'.
458459

459460
Reference Update Request and Packfile Transfer
460461
----------------------------------------------
@@ -465,9 +466,10 @@ that it wants to update, it sends a line listing the obj-id currently on
465466
the server, the obj-id the client would like to update it to and the name
466467
of the reference.
467468

468-
This list is followed by a flush-pkt and then the packfile that should
469-
contain all the objects that the server will need to complete the new
470-
references.
469+
This list is followed by a flush-pkt. Then the push options are transmitted
470+
one per packet followed by another flush-pkt. After that the packfile that
471+
should contain all the objects that the server will need to complete the new
472+
references will be sent.
471473

472474
----
473475
update-request = *shallow ( command-list | push-cert ) [packfile]

Documentation/technical/protocol-capabilities.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,15 @@ atomic pushes. If the pushing client requests this capability, the server
253253
will update the refs in one atomic transaction. Either all refs are
254254
updated or none.
255255

256+
push-options
257+
------------
258+
259+
If the server sends the 'push-options' capability it is able to accept
260+
push options after the update commands have been sent, but before the
261+
packfile is streamed. If the pushing client requests this capability,
262+
the server will pass the options to the pre- and post- receive hooks
263+
that process this push request.
264+
256265
allow-tip-sha1-in-want
257266
----------------------
258267

builtin/receive-pack.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,12 @@ static struct strbuf fsck_msg_types = STRBUF_INIT;
4444
static int receive_unpack_limit = -1;
4545
static int transfer_unpack_limit = -1;
4646
static int advertise_atomic_push = 1;
47+
static int advertise_push_options;
4748
static int unpack_limit = 100;
4849
static int report_status;
4950
static int use_sideband;
5051
static int use_atomic;
52+
static int use_push_options;
5153
static int quiet;
5254
static int prefer_ofs_delta = 1;
5355
static int auto_update_server_info;
@@ -193,6 +195,11 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
193195
return 0;
194196
}
195197

198+
if (strcmp(var, "receive.advertisepushoptions") == 0) {
199+
advertise_push_options = git_config_bool(var, value);
200+
return 0;
201+
}
202+
196203
return git_default_config(var, value, cb);
197204
}
198205

@@ -211,6 +218,8 @@ static void show_ref(const char *path, const unsigned char *sha1)
211218
strbuf_addstr(&cap, " ofs-delta");
212219
if (push_cert_nonce)
213220
strbuf_addf(&cap, " push-cert=%s", push_cert_nonce);
221+
if (advertise_push_options)
222+
strbuf_addstr(&cap, " push-options");
214223
strbuf_addf(&cap, " agent=%s", git_user_agent_sanitized());
215224
packet_write(1, "%s %s%c%s\n",
216225
sha1_to_hex(sha1), path, 0, cap.buf);
@@ -1455,6 +1464,9 @@ static struct command *read_head_info(struct sha1_array *shallow)
14551464
if (advertise_atomic_push
14561465
&& parse_feature_request(feature_list, "atomic"))
14571466
use_atomic = 1;
1467+
if (advertise_push_options
1468+
&& parse_feature_request(feature_list, "push-options"))
1469+
use_push_options = 1;
14581470
}
14591471

14601472
if (!strcmp(line, "push-cert")) {
@@ -1487,6 +1499,21 @@ static struct command *read_head_info(struct sha1_array *shallow)
14871499
return commands;
14881500
}
14891501

1502+
static void read_push_options(struct string_list *options)
1503+
{
1504+
while (1) {
1505+
char *line;
1506+
int len;
1507+
1508+
line = packet_read_line(0, &len);
1509+
1510+
if (!line)
1511+
break;
1512+
1513+
string_list_append(options, line);
1514+
}
1515+
}
1516+
14901517
static const char *parse_pack_header(struct pack_header *hdr)
14911518
{
14921519
switch (read_pack_header(0, hdr)) {
@@ -1774,6 +1801,9 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
17741801
const char *unpack_status = NULL;
17751802
struct string_list push_options = STRING_LIST_INIT_DUP;
17761803

1804+
if (use_push_options)
1805+
read_push_options(&push_options);
1806+
17771807
prepare_shallow_info(&si, &shallow);
17781808
if (!si.nr_ours && !si.nr_theirs)
17791809
shallow_update = 0;

0 commit comments

Comments
 (0)