Skip to content

Commit f1514c6

Browse files
chriscoolgitster
authored andcommitted
upload-pack: move allow_unadvertised_object_request to upload_pack_data
As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's move the 'allow_unadvertised_object_request' static variable into this struct. It is used by code common to protocol v0 and protocol v2. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent de0e9f7 commit f1514c6

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

upload-pack.c

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@
4444

4545
static timestamp_t oldest_have;
4646

47+
/* Values for allow_unadvertised_object_request flags */
4748
/* Allow specifying sha1 if it is a ref tip. */
4849
#define ALLOW_TIP_SHA1 01
4950
/* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
5051
#define ALLOW_REACHABLE_SHA1 02
5152
/* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */
5253
#define ALLOW_ANY_SHA1 07
53-
static unsigned int allow_unadvertised_object_request;
5454

5555
/*
5656
* Please annotate, and if possible group together, fields used only
@@ -83,6 +83,9 @@ struct upload_pack_data {
8383
/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
8484
int use_sideband;
8585

86+
/* See ALLOW_* values defined above */
87+
unsigned int allow_unadvertised_object_request;
88+
8689
struct list_objects_filter_options filter_options;
8790

8891
struct packet_writer writer;
@@ -514,7 +517,8 @@ static int get_common_commits(struct upload_pack_data *data,
514517
}
515518
}
516519

517-
static int is_our_ref(struct object *o)
520+
static int is_our_ref(struct object *o,
521+
unsigned int allow_unadvertised_object_request)
518522
{
519523
int allow_hidden_ref = (allow_unadvertised_object_request &
520524
(ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1));
@@ -526,7 +530,8 @@ static int is_our_ref(struct object *o)
526530
*/
527531
static int do_reachable_revlist(struct child_process *cmd,
528532
struct object_array *src,
529-
struct object_array *reachable)
533+
struct object_array *reachable,
534+
unsigned int allow_unadvertised_object_request)
530535
{
531536
static const char *argv[] = {
532537
"rev-list", "--stdin", NULL,
@@ -560,7 +565,7 @@ static int do_reachable_revlist(struct child_process *cmd,
560565
continue;
561566
if (reachable && o->type == OBJ_COMMIT)
562567
o->flags &= ~TMP_MARK;
563-
if (!is_our_ref(o))
568+
if (!is_our_ref(o, allow_unadvertised_object_request))
564569
continue;
565570
memcpy(namebuf + 1, oid_to_hex(&o->oid), hexsz);
566571
if (write_in_full(cmd->in, namebuf, hexsz + 2) < 0)
@@ -569,7 +574,7 @@ static int do_reachable_revlist(struct child_process *cmd,
569574
namebuf[hexsz] = '\n';
570575
for (i = 0; i < src->nr; i++) {
571576
o = src->objects[i].item;
572-
if (is_our_ref(o)) {
577+
if (is_our_ref(o, allow_unadvertised_object_request)) {
573578
if (reachable)
574579
add_object_array(o, NULL, reachable);
575580
continue;
@@ -596,7 +601,7 @@ static int do_reachable_revlist(struct child_process *cmd,
596601
return -1;
597602
}
598603

599-
static int get_reachable_list(struct object_array *src,
604+
static int get_reachable_list(struct upload_pack_data *data,
600605
struct object_array *reachable)
601606
{
602607
struct child_process cmd = CHILD_PROCESS_INIT;
@@ -605,7 +610,8 @@ static int get_reachable_list(struct object_array *src,
605610
char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
606611
const unsigned hexsz = the_hash_algo->hexsz;
607612

608-
if (do_reachable_revlist(&cmd, src, reachable) < 0)
613+
if (do_reachable_revlist(&cmd, &data->shallows, reachable,
614+
data->allow_unadvertised_object_request) < 0)
609615
return -1;
610616

611617
while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) {
@@ -636,13 +642,15 @@ static int get_reachable_list(struct object_array *src,
636642
return 0;
637643
}
638644

639-
static int has_unreachable(struct object_array *src)
645+
static int has_unreachable(struct object_array *src,
646+
unsigned int allow_unadvertised_object_request)
640647
{
641648
struct child_process cmd = CHILD_PROCESS_INIT;
642649
char buf[1];
643650
int i;
644651

645-
if (do_reachable_revlist(&cmd, src, NULL) < 0)
652+
if (do_reachable_revlist(&cmd, src, NULL,
653+
allow_unadvertised_object_request) < 0)
646654
return 1;
647655

648656
/*
@@ -683,17 +691,18 @@ static void check_non_tip(struct upload_pack_data *data)
683691
* non-tip requests can never happen.
684692
*/
685693
if (!data->stateless_rpc
686-
&& !(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
694+
&& !(data->allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
687695
goto error;
688-
if (!has_unreachable(&data->want_obj))
696+
if (!has_unreachable(&data->want_obj,
697+
data->allow_unadvertised_object_request))
689698
/* All the non-tip ones are ancestors of what we advertised */
690699
return;
691700

692701
error:
693702
/* Pick one of them (we know there at least is one) */
694703
for (i = 0; i < data->want_obj.nr; i++) {
695704
struct object *o = data->want_obj.objects[i].item;
696-
if (!is_our_ref(o)) {
705+
if (!is_our_ref(o, data->allow_unadvertised_object_request)) {
697706
packet_writer_error(&data->writer,
698707
"upload-pack: not our ref %s",
699708
oid_to_hex(&o->oid));
@@ -774,7 +783,7 @@ static void deepen(struct upload_pack_data *data, int depth)
774783
head_ref_namespaced(check_ref, NULL);
775784
for_each_namespaced_ref(check_ref, NULL);
776785

777-
get_reachable_list(&data->shallows, &reachable_shallows);
786+
get_reachable_list(data, &reachable_shallows);
778787
result = get_shallow_commits(&reachable_shallows,
779788
depth + 1,
780789
SHALLOW, NOT_SHALLOW);
@@ -992,8 +1001,8 @@ static void receive_needs(struct upload_pack_data *data,
9921001
}
9931002
if (!(o->flags & WANTED)) {
9941003
o->flags |= WANTED;
995-
if (!((allow_unadvertised_object_request & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1
996-
|| is_our_ref(o)))
1004+
if (!((data->allow_unadvertised_object_request & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1
1005+
|| is_our_ref(o, data->allow_unadvertised_object_request)))
9971006
has_non_tip = 1;
9981007
add_object_array(o, NULL, &data->want_obj);
9991008
}
@@ -1072,9 +1081,9 @@ static int send_ref(const char *refname, const struct object_id *oid,
10721081
packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s agent=%s\n",
10731082
oid_to_hex(oid), refname_nons,
10741083
0, capabilities,
1075-
(allow_unadvertised_object_request & ALLOW_TIP_SHA1) ?
1084+
(data->allow_unadvertised_object_request & ALLOW_TIP_SHA1) ?
10761085
" allow-tip-sha1-in-want" : "",
1077-
(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ?
1086+
(data->allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ?
10781087
" allow-reachable-sha1-in-want" : "",
10791088
data->stateless_rpc ? " no-done" : "",
10801089
symref_info.buf,
@@ -1112,19 +1121,19 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
11121121

11131122
if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
11141123
if (git_config_bool(var, value))
1115-
allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
1124+
data->allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
11161125
else
1117-
allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1;
1126+
data->allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1;
11181127
} else if (!strcmp("uploadpack.allowreachablesha1inwant", var)) {
11191128
if (git_config_bool(var, value))
1120-
allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
1129+
data->allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
11211130
else
1122-
allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1;
1131+
data->allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1;
11231132
} else if (!strcmp("uploadpack.allowanysha1inwant", var)) {
11241133
if (git_config_bool(var, value))
1125-
allow_unadvertised_object_request |= ALLOW_ANY_SHA1;
1134+
data->allow_unadvertised_object_request |= ALLOW_ANY_SHA1;
11261135
else
1127-
allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
1136+
data->allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
11281137
} else if (!strcmp("uploadpack.keepalive", var)) {
11291138
data->keepalive = git_config_int(var, value);
11301139
if (!data->keepalive)

0 commit comments

Comments
 (0)