Skip to content

Commit 629060d

Browse files
chriscoolgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f1514c6 commit 629060d

File tree

1 file changed

+32
-36
lines changed

1 file changed

+32
-36
lines changed

upload-pack.c

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

4545
static timestamp_t oldest_have;
4646

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+
};
5456

5557
/*
5658
* Please annotate, and if possible group together, fields used only
@@ -83,8 +85,7 @@ struct upload_pack_data {
8385
/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
8486
int use_sideband;
8587

86-
/* See ALLOW_* values defined above */
87-
unsigned int allow_unadvertised_object_request;
88+
enum allow_uor allow_uor;
8889

8990
struct list_objects_filter_options filter_options;
9091

@@ -517,11 +518,10 @@ static int get_common_commits(struct upload_pack_data *data,
517518
}
518519
}
519520

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)
522522
{
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));
525525
return o->flags & ((allow_hidden_ref ? HIDDEN_REF : 0) | OUR_REF);
526526
}
527527

@@ -531,7 +531,7 @@ static int is_our_ref(struct object *o,
531531
static int do_reachable_revlist(struct child_process *cmd,
532532
struct object_array *src,
533533
struct object_array *reachable,
534-
unsigned int allow_unadvertised_object_request)
534+
enum allow_uor allow_uor)
535535
{
536536
static const char *argv[] = {
537537
"rev-list", "--stdin", NULL,
@@ -565,7 +565,7 @@ static int do_reachable_revlist(struct child_process *cmd,
565565
continue;
566566
if (reachable && o->type == OBJ_COMMIT)
567567
o->flags &= ~TMP_MARK;
568-
if (!is_our_ref(o, allow_unadvertised_object_request))
568+
if (!is_our_ref(o, allow_uor))
569569
continue;
570570
memcpy(namebuf + 1, oid_to_hex(&o->oid), hexsz);
571571
if (write_in_full(cmd->in, namebuf, hexsz + 2) < 0)
@@ -574,7 +574,7 @@ static int do_reachable_revlist(struct child_process *cmd,
574574
namebuf[hexsz] = '\n';
575575
for (i = 0; i < src->nr; i++) {
576576
o = src->objects[i].item;
577-
if (is_our_ref(o, allow_unadvertised_object_request)) {
577+
if (is_our_ref(o, allow_uor)) {
578578
if (reachable)
579579
add_object_array(o, NULL, reachable);
580580
continue;
@@ -611,7 +611,7 @@ static int get_reachable_list(struct upload_pack_data *data,
611611
const unsigned hexsz = the_hash_algo->hexsz;
612612

613613
if (do_reachable_revlist(&cmd, &data->shallows, reachable,
614-
data->allow_unadvertised_object_request) < 0)
614+
data->allow_uor) < 0)
615615
return -1;
616616

617617
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,
642642
return 0;
643643
}
644644

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)
647646
{
648647
struct child_process cmd = CHILD_PROCESS_INIT;
649648
char buf[1];
650649
int i;
651650

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)
654652
return 1;
655653

656654
/*
@@ -690,19 +688,17 @@ static void check_non_tip(struct upload_pack_data *data)
690688
* uploadpack.allowReachableSHA1InWant,
691689
* non-tip requests can never happen.
692690
*/
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))
695692
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))
698694
/* All the non-tip ones are ancestors of what we advertised */
699695
return;
700696

701697
error:
702698
/* Pick one of them (we know there at least is one) */
703699
for (i = 0; i < data->want_obj.nr; i++) {
704700
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)) {
706702
packet_writer_error(&data->writer,
707703
"upload-pack: not our ref %s",
708704
oid_to_hex(&o->oid));
@@ -1001,8 +997,8 @@ static void receive_needs(struct upload_pack_data *data,
1001997
}
1002998
if (!(o->flags & WANTED)) {
1003999
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)))
10061002
has_non_tip = 1;
10071003
add_object_array(o, NULL, &data->want_obj);
10081004
}
@@ -1081,9 +1077,9 @@ static int send_ref(const char *refname, const struct object_id *oid,
10811077
packet_write_fmt(1, "%s %s%c%s%s%s%s%s%s agent=%s\n",
10821078
oid_to_hex(oid), refname_nons,
10831079
0, capabilities,
1084-
(data->allow_unadvertised_object_request & ALLOW_TIP_SHA1) ?
1080+
(data->allow_uor & ALLOW_TIP_SHA1) ?
10851081
" allow-tip-sha1-in-want" : "",
1086-
(data->allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1) ?
1082+
(data->allow_uor & ALLOW_REACHABLE_SHA1) ?
10871083
" allow-reachable-sha1-in-want" : "",
10881084
data->stateless_rpc ? " no-done" : "",
10891085
symref_info.buf,
@@ -1121,19 +1117,19 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
11211117

11221118
if (!strcmp("uploadpack.allowtipsha1inwant", var)) {
11231119
if (git_config_bool(var, value))
1124-
data->allow_unadvertised_object_request |= ALLOW_TIP_SHA1;
1120+
data->allow_uor |= ALLOW_TIP_SHA1;
11251121
else
1126-
data->allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1;
1122+
data->allow_uor &= ~ALLOW_TIP_SHA1;
11271123
} else if (!strcmp("uploadpack.allowreachablesha1inwant", var)) {
11281124
if (git_config_bool(var, value))
1129-
data->allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1;
1125+
data->allow_uor |= ALLOW_REACHABLE_SHA1;
11301126
else
1131-
data->allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1;
1127+
data->allow_uor &= ~ALLOW_REACHABLE_SHA1;
11321128
} else if (!strcmp("uploadpack.allowanysha1inwant", var)) {
11331129
if (git_config_bool(var, value))
1134-
data->allow_unadvertised_object_request |= ALLOW_ANY_SHA1;
1130+
data->allow_uor |= ALLOW_ANY_SHA1;
11351131
else
1136-
data->allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1;
1132+
data->allow_uor &= ~ALLOW_ANY_SHA1;
11371133
} else if (!strcmp("uploadpack.keepalive", var)) {
11381134
data->keepalive = git_config_int(var, value);
11391135
if (!data->keepalive)

0 commit comments

Comments
 (0)