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 <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Christian Couder committed
Jun 11, 2020 at 14:05 UTC
f1514c6aad0de2937fb1bb22a5f93ef931757600
1 file changed
+32
-23
upload-pack.c
+32
-23
@@ -44,13 +44,13 @@
44
45
static timestamp_t oldest_have;
46
47
+/* Values for allow_unadvertised_object_request flags */
48
/* Allow specifying sha1 if it is a ref tip. */
49
#define ALLOW_TIP_SHA1 01
50
/* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
51
#define ALLOW_REACHABLE_SHA1 02
52
/* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */
53
#define ALLOW_ANY_SHA1 07
53
-static unsigned int allow_unadvertised_object_request;
54
55
/*
56
* Please annotate, and if possible group together, fields used only
@@ -83,6 +83,9 @@ struct upload_pack_data {
83
/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
84
int use_sideband;
85
86
+ /* See ALLOW_* values defined above */
87
+ unsigned int allow_unadvertised_object_request;
88
+
89
struct list_objects_filter_options filter_options;
90
91
struct packet_writer writer;
@@ -514,7 +517,8 @@ static int get_common_commits(struct upload_pack_data *data,
517
}
518
}
519
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)
522
{
523
int allow_hidden_ref = (allow_unadvertised_object_request &
524
(ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1));
@@ -526,7 +530,8 @@ static int is_our_ref(struct object *o)
530
*/
531
static int do_reachable_revlist(struct child_process *cmd,
532
struct object_array *src,
529
- struct object_array *reachable)
533
+ struct object_array *reachable,
534
+ unsigned int allow_unadvertised_object_request)
535
{
536
static const char *argv[] = {
537
"rev-list", "--stdin", NULL,
@@ -560,7 +565,7 @@ static int do_reachable_revlist(struct child_process *cmd,
565
continue;
566
if (reachable && o->type == OBJ_COMMIT)
567
o->flags &= ~TMP_MARK;
563
- if (!is_our_ref(o))
568
+ if (!is_our_ref(o, allow_unadvertised_object_request))
569
continue;
570
memcpy(namebuf + 1, oid_to_hex(&o->oid), hexsz);
571
if (write_in_full(cmd->in, namebuf, hexsz + 2) < 0)
@@ -569,7 +574,7 @@ static int do_reachable_revlist(struct child_process *cmd,
574
namebuf[hexsz] = '\n';
575
for (i = 0; i < src->nr; i++) {
576
o = src->objects[i].item;
572
- if (is_our_ref(o)) {
577
+ if (is_our_ref(o, allow_unadvertised_object_request)) {
578
if (reachable)
579
add_object_array(o, NULL, reachable);
580
continue;
@@ -596,7 +601,7 @@ error:
601
return -1;
602
}
603
599
-static int get_reachable_list(struct object_array *src,
604
+static int get_reachable_list(struct upload_pack_data *data,
605
struct object_array *reachable)
606
{
607
struct child_process cmd = CHILD_PROCESS_INIT;
@@ -605,7 +610,8 @@ static int get_reachable_list(struct object_array *src,
610
char namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */
611
const unsigned hexsz = the_hash_algo->hexsz;
612
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)
615
return -1;
616
617
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,
642
return 0;
643
}
644
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)
647
{
648
struct child_process cmd = CHILD_PROCESS_INIT;
649
char buf[1];
650
int i;
651
645
- if (do_reachable_revlist(&cmd, src, NULL) < 0)
652
+ if (do_reachable_revlist(&cmd, src, NULL,
653
+ allow_unadvertised_object_request) < 0)
654
return 1;
655
656
/*
@@ -683,9 +691,10 @@ static void check_non_tip(struct upload_pack_data *data)
691
* non-tip requests can never happen.
692
*/
693
if (!data->stateless_rpc
686
- && !(allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
694
+ && !(data->allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
695
goto error;
688
- if (!has_unreachable(&data->want_obj))
696
+ if (!has_unreachable(&data->want_obj,
697
+ data->allow_unadvertised_object_request))
698
/* All the non-tip ones are ancestors of what we advertised */
699
return;
700
@@ -693,7 +702,7 @@ error:
702
/* Pick one of them (we know there at least is one) */
703
for (i = 0; i < data->want_obj.nr; i++) {
704
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)) {
706
packet_writer_error(&data->writer,
707
"upload-pack: not our ref %s",
708
oid_to_hex(&o->oid));
@@ -774,7 +783,7 @@ static void deepen(struct upload_pack_data *data, int depth)
783
head_ref_namespaced(check_ref, NULL);
784
for_each_namespaced_ref(check_ref, NULL);
785
777
- get_reachable_list(&data->shallows, &reachable_shallows);
786
+ get_reachable_list(data, &reachable_shallows);
787
result = get_shallow_commits(&reachable_shallows,
788
depth + 1,
789
SHALLOW, NOT_SHALLOW);
@@ -992,8 +1001,8 @@ static void receive_needs(struct upload_pack_data *data,
1001
}
1002
if (!(o->flags & WANTED)) {
1003
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)))
1006
has_non_tip = 1;
1007
add_object_array(o, NULL, &data->want_obj);
1008
}
@@ -1072,9 +1081,9 @@ static int send_ref(const char *refname, const struct object_id *oid,
1081
packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s agent=%s\n",
1082
oid_to_hex(oid), refname_nons,
1083
0, capabilities,
1075
- (allow_unadvertised_object_request & ALLOW_TIP_SHA1) ?
1084
+ (data->allow_unadvertised_object_request & ALLOW_TIP_SHA1) ?
1085
" allow-tip-sha1-in-want" : "",
1077
- (allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ?
1086
+ (data->allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ?
1087
" allow-reachable-sha1-in-want" : "",
1088
data->stateless_rpc ? " no-done" : "",
1089
symref_info.buf,
@@ -1112,19 +1121,19 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
1121
1122
if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
1123
if (git_config_bool(var, value))
1115
- allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
1124
+ data->allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
1125
else
1117
- allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1;
1126
+ data->allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1;
1127
} else if (!strcmp("uploadpack.allowreachablesha1inwant", var)) {
1128
if (git_config_bool(var, value))
1120
- allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
1129
+ data->allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
1130
else
1122
- allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1;
1131
+ data->allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1;
1132
} else if (!strcmp("uploadpack.allowanysha1inwant", var)) {
1133
if (git_config_bool(var, value))
1125
- allow_unadvertised_object_request |= ALLOW_ANY_SHA1;
1134
+ data->allow_unadvertised_object_request |= ALLOW_ANY_SHA1;
1135
else
1127
- allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
1136
+ data->allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
1137
} else if (!strcmp("uploadpack.keepalive", var)) {
1138
data->keepalive = git_config_int(var, value);
1139
if (!data->keepalive)