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