upload-pack: change allow_unadvertised_object_request to an enum
As we cleanup 'upload-pack.c' by using 'struct upload_pack_data' more thoroughly, let's change allow_unadvertised_object_request, which is now part of 'upload_pack_data', from an 'unsigned int' to an enum. This will make it clear which values this variable can take. While at it let's change this variable name to 'allow_uor' to make it shorter. 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
629060d9bb5a1ab63d51b1a8fbe19384c1559140
1 file changed
+32
-36
upload-pack.c
+32
-36
@@ -44,13 +44,15 @@
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
47
+/* Enum for allowed unadvertised object request (UOR) */
48
+enum allow_uor {
49
+ /* Allow specifying sha1 if it is a ref tip. */
50
+ ALLOW_TIP_SHA1 = 0x01,
51
+ /* Allow request of a sha1 if it is reachable from a ref (possibly hidden ref). */
52
+ ALLOW_REACHABLE_SHA1 = 0x02,
53
+ /* Allow request of any sha1. Implies ALLOW_TIP_SHA1 and ALLOW_REACHABLE_SHA1. */
54
+ ALLOW_ANY_SHA1 = 0x07
55
+};
56
57
/*
58
* Please annotate, and if possible group together, fields used only
@@ -83,8 +85,7 @@ struct upload_pack_data {
85
/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
86
int use_sideband;
87
86
- /* See ALLOW_* values defined above */
87
- unsigned int allow_unadvertised_object_request;
88
+ enum allow_uor allow_uor;
89
90
struct list_objects_filter_options filter_options;
91
@@ -517,11 +518,10 @@ static int get_common_commits(struct upload_pack_data *data,
518
}
519
}
520
520
-static int is_our_ref(struct object *o,
521
- unsigned int allow_unadvertised_object_request)
521
+static int is_our_ref(struct object *o, enum allow_uor allow_uor)
522
{
523
- int allow_hidden_ref = (allow_unadvertised_object_request &
524
- (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1));
523
+ int allow_hidden_ref = (allow_uor &
524
+ (ALLOW_TIP_SHA1 | ALLOW_REACHABLE_SHA1));
525
return o->flags & ((allow_hidden_ref ? HIDDEN_REF : 0) | OUR_REF);
526
}
527
@@ -531,7 +531,7 @@ static int is_our_ref(struct object *o,
531
static int do_reachable_revlist(struct child_process *cmd,
532
struct object_array *src,
533
struct object_array *reachable,
534
- unsigned int allow_unadvertised_object_request)
534
+ enum allow_uor allow_uor)
535
{
536
static const char *argv[] = {
537
"rev-list", "--stdin", NULL,
@@ -565,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;
568
- if (!is_our_ref(o, allow_unadvertised_object_request))
568
+ if (!is_our_ref(o, allow_uor))
569
continue;
570
memcpy(namebuf + 1, oid_to_hex(&o->oid), hexsz);
571
if (write_in_full(cmd->in, namebuf, hexsz + 2) < 0)
@@ -574,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;
577
- if (is_our_ref(o, allow_unadvertised_object_request)) {
577
+ if (is_our_ref(o, allow_uor)) {
578
if (reachable)
579
add_object_array(o, NULL, reachable);
580
continue;
@@ -611,7 +611,7 @@ static int get_reachable_list(struct upload_pack_data *data,
611
const unsigned hexsz = the_hash_algo->hexsz;
612
613
if (do_reachable_revlist(&cmd, &data->shallows, reachable,
614
- data->allow_unadvertised_object_request) < 0)
614
+ data->allow_uor) < 0)
615
return -1;
616
617
while ((i = read_in_full(cmd.out, namebuf, hexsz + 1)) == hexsz + 1) {
@@ -642,15 +642,13 @@ static int get_reachable_list(struct upload_pack_data *data,
642
return 0;
643
}
644
645
-static int has_unreachable(struct object_array *src,
646
- unsigned int allow_unadvertised_object_request)
645
+static int has_unreachable(struct object_array *src, enum allow_uor allow_uor)
646
{
647
struct child_process cmd = CHILD_PROCESS_INIT;
648
char buf[1];
649
int i;
650
652
- if (do_reachable_revlist(&cmd, src, NULL,
653
- allow_unadvertised_object_request) < 0)
651
+ if (do_reachable_revlist(&cmd, src, NULL, allow_uor) < 0)
652
return 1;
653
654
/*
@@ -690,11 +688,9 @@ static void check_non_tip(struct upload_pack_data *data)
688
* uploadpack.allowReachableSHA1InWant,
689
* non-tip requests can never happen.
690
*/
693
- if (!data->stateless_rpc
694
- && !(data->allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1))
691
+ if (!data->stateless_rpc && !(data->allow_uor & ALLOW_REACHABLE_SHA1))
692
goto error;
696
- if (!has_unreachable(&data->want_obj,
697
- data->allow_unadvertised_object_request))
693
+ if (!has_unreachable(&data->want_obj, data->allow_uor))
694
/* All the non-tip ones are ancestors of what we advertised */
695
return;
696
@@ -702,7 +698,7 @@ error:
698
/* Pick one of them (we know there at least is one) */
699
for (i = 0; i < data->want_obj.nr; i++) {
700
struct object *o = data->want_obj.objects[i].item;
705
- if (!is_our_ref(o, data->allow_unadvertised_object_request)) {
701
+ if (!is_our_ref(o, data->allow_uor)) {
702
packet_writer_error(&data->writer,
703
"upload-pack: not our ref %s",
704
oid_to_hex(&o->oid));
@@ -1001,8 +997,8 @@ static void receive_needs(struct upload_pack_data *data,
997
}
998
if (!(o->flags & WANTED)) {
999
o->flags |= WANTED;
1004
- if (!((data->allow_unadvertised_object_request & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1
1005
- || is_our_ref(o, data->allow_unadvertised_object_request)))
1000
+ if (!((data->allow_uor & ALLOW_ANY_SHA1) == ALLOW_ANY_SHA1
1001
+ || is_our_ref(o, data->allow_uor)))
1002
has_non_tip = 1;
1003
add_object_array(o, NULL, &data->want_obj);
1004
}
@@ -1081,9 +1077,9 @@ static int send_ref(const char *refname, const struct object_id *oid,
1077
packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s agent=%s\n",
1078
oid_to_hex(oid), refname_nons,
1079
0, capabilities,
1084
- (data->allow_unadvertised_object_request & ALLOW_TIP_SHA1) ?
1080
+ (data->allow_uor & ALLOW_TIP_SHA1) ?
1081
" allow-tip-sha1-in-want" : "",
1086
- (data->allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ?
1082
+ (data->allow_uor & ALLOW_REACHABLE_SHA1) ?
1083
" allow-reachable-sha1-in-want" : "",
1084
data->stateless_rpc ? " no-done" : "",
1085
symref_info.buf,
@@ -1121,19 +1117,19 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
1117
1118
if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
1119
if (git_config_bool(var, value))
1124
- data->allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
1120
+ data->allow_uor |= ALLOW_TIP_SHA1;
1121
else
1126
- data->allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1;
1122
+ data->allow_uor &= ~ALLOW_TIP_SHA1;
1123
} else if (!strcmp("uploadpack.allowreachablesha1inwant", var)) {
1124
if (git_config_bool(var, value))
1129
- data->allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
1125
+ data->allow_uor |= ALLOW_REACHABLE_SHA1;
1126
else
1131
- data->allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1;
1127
+ data->allow_uor &= ~ALLOW_REACHABLE_SHA1;
1128
} else if (!strcmp("uploadpack.allowanysha1inwant", var)) {
1129
if (git_config_bool(var, value))
1134
- data->allow_unadvertised_object_request |= ALLOW_ANY_SHA1;
1130
+ data->allow_uor |= ALLOW_ANY_SHA1;
1131
else
1136
- data->allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
1132
+ data->allow_uor &= ~ALLOW_ANY_SHA1;
1133
} else if (!strcmp("uploadpack.keepalive", var)) {
1134
data->keepalive = git_config_int(var, value);
1135
if (!data->keepalive)