44
44
45
45
static timestamp_t oldest_have ;
46
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
+ };
54
56
55
57
/*
56
58
* Please annotate, and if possible group together, fields used only
@@ -83,8 +85,7 @@ struct upload_pack_data {
83
85
/* 0 for no sideband, otherwise DEFAULT_PACKET_MAX or LARGE_PACKET_MAX */
84
86
int use_sideband ;
85
87
86
- /* See ALLOW_* values defined above */
87
- unsigned int allow_unadvertised_object_request ;
88
+ enum allow_uor allow_uor ;
88
89
89
90
struct list_objects_filter_options filter_options ;
90
91
@@ -517,11 +518,10 @@ static int get_common_commits(struct upload_pack_data *data,
517
518
}
518
519
}
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
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
525
return o -> flags & ((allow_hidden_ref ? HIDDEN_REF : 0 ) | OUR_REF );
526
526
}
527
527
@@ -531,7 +531,7 @@ static int is_our_ref(struct object *o,
531
531
static int do_reachable_revlist (struct child_process * cmd ,
532
532
struct object_array * src ,
533
533
struct object_array * reachable ,
534
- unsigned int allow_unadvertised_object_request )
534
+ enum allow_uor allow_uor )
535
535
{
536
536
static const char * argv [] = {
537
537
"rev-list" , "--stdin" , NULL ,
@@ -565,7 +565,7 @@ static int do_reachable_revlist(struct child_process *cmd,
565
565
continue ;
566
566
if (reachable && o -> type == OBJ_COMMIT )
567
567
o -> flags &= ~TMP_MARK ;
568
- if (!is_our_ref (o , allow_unadvertised_object_request ))
568
+ if (!is_our_ref (o , allow_uor ))
569
569
continue ;
570
570
memcpy (namebuf + 1 , oid_to_hex (& o -> oid ), hexsz );
571
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
574
namebuf [hexsz ] = '\n' ;
575
575
for (i = 0 ; i < src -> nr ; i ++ ) {
576
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
578
if (reachable )
579
579
add_object_array (o , NULL , reachable );
580
580
continue ;
@@ -611,7 +611,7 @@ static int get_reachable_list(struct upload_pack_data *data,
611
611
const unsigned hexsz = the_hash_algo -> hexsz ;
612
612
613
613
if (do_reachable_revlist (& cmd , & data -> shallows , reachable ,
614
- data -> allow_unadvertised_object_request ) < 0 )
614
+ data -> allow_uor ) < 0 )
615
615
return -1 ;
616
616
617
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
642
return 0 ;
643
643
}
644
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 )
647
646
{
648
647
struct child_process cmd = CHILD_PROCESS_INIT ;
649
648
char buf [1 ];
650
649
int i ;
651
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 )
654
652
return 1 ;
655
653
656
654
/*
@@ -690,19 +688,17 @@ static void check_non_tip(struct upload_pack_data *data)
690
688
* uploadpack.allowReachableSHA1InWant,
691
689
* non-tip requests can never happen.
692
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 ))
695
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 ))
698
694
/* All the non-tip ones are ancestors of what we advertised */
699
695
return ;
700
696
701
697
error :
702
698
/* Pick one of them (we know there at least is one) */
703
699
for (i = 0 ; i < data -> want_obj .nr ; i ++ ) {
704
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 )) {
706
702
packet_writer_error (& data -> writer ,
707
703
"upload-pack: not our ref %s" ,
708
704
oid_to_hex (& o -> oid ));
@@ -1001,8 +997,8 @@ static void receive_needs(struct upload_pack_data *data,
1001
997
}
1002
998
if (!(o -> flags & WANTED )) {
1003
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 )))
1006
1002
has_non_tip = 1 ;
1007
1003
add_object_array (o , NULL , & data -> want_obj );
1008
1004
}
@@ -1081,9 +1077,9 @@ static int send_ref(const char *refname, const struct object_id *oid,
1081
1077
packet_write_fmt (1 , "%s %s%c%s%s%s%s%s%s agent=%s\n" ,
1082
1078
oid_to_hex (oid ), refname_nons ,
1083
1079
0 , capabilities ,
1084
- (data -> allow_unadvertised_object_request & ALLOW_TIP_SHA1 ) ?
1080
+ (data -> allow_uor & ALLOW_TIP_SHA1 ) ?
1085
1081
" allow-tip-sha1-in-want" : "" ,
1086
- (data -> allow_unadvertised_object_request & ALLOW_REACHABLE_SHA1 ) ?
1082
+ (data -> allow_uor & ALLOW_REACHABLE_SHA1 ) ?
1087
1083
" allow-reachable-sha1-in-want" : "" ,
1088
1084
data -> stateless_rpc ? " no-done" : "" ,
1089
1085
symref_info .buf ,
@@ -1121,19 +1117,19 @@ static int upload_pack_config(const char *var, const char *value, void *cb_data)
1121
1117
1122
1118
if (!strcmp ("uploadpack.allowtipsha1inwant" , var )) {
1123
1119
if (git_config_bool (var , value ))
1124
- data -> allow_unadvertised_object_request |= ALLOW_TIP_SHA1 ;
1120
+ data -> allow_uor |= ALLOW_TIP_SHA1 ;
1125
1121
else
1126
- data -> allow_unadvertised_object_request &= ~ALLOW_TIP_SHA1 ;
1122
+ data -> allow_uor &= ~ALLOW_TIP_SHA1 ;
1127
1123
} else if (!strcmp ("uploadpack.allowreachablesha1inwant" , var )) {
1128
1124
if (git_config_bool (var , value ))
1129
- data -> allow_unadvertised_object_request |= ALLOW_REACHABLE_SHA1 ;
1125
+ data -> allow_uor |= ALLOW_REACHABLE_SHA1 ;
1130
1126
else
1131
- data -> allow_unadvertised_object_request &= ~ALLOW_REACHABLE_SHA1 ;
1127
+ data -> allow_uor &= ~ALLOW_REACHABLE_SHA1 ;
1132
1128
} else if (!strcmp ("uploadpack.allowanysha1inwant" , var )) {
1133
1129
if (git_config_bool (var , value ))
1134
- data -> allow_unadvertised_object_request |= ALLOW_ANY_SHA1 ;
1130
+ data -> allow_uor |= ALLOW_ANY_SHA1 ;
1135
1131
else
1136
- data -> allow_unadvertised_object_request &= ~ALLOW_ANY_SHA1 ;
1132
+ data -> allow_uor &= ~ALLOW_ANY_SHA1 ;
1137
1133
} else if (!strcmp ("uploadpack.keepalive" , var )) {
1138
1134
data -> keepalive = git_config_int (var , value );
1139
1135
if (!data -> keepalive )
0 commit comments