@@ -395,28 +395,51 @@ func SemVerTagsFromAttestations(ctx context.Context, tag name.Tag, sourceAttesta
395
395
return []name.Tag {}
396
396
}
397
397
ref := groupSummary .Git .Reference
398
- if len (ref .Tags ) == 0 {
398
+ numTags := len (ref .Tags )
399
+ if numTags == 0 {
399
400
return []name.Tag {}
400
401
}
401
- // TODO: detect tags with groupSummary.Path+"/" as prefix and priorities them
402
- tags := make ([]name.Tag , 0 , len (ref .Tags ))
403
- set := make (map [string ]struct {}, len (ref .Tags ))
402
+ tags := newTagtagSet (numTags )
403
+ scopedTags := newTagtagSet (numTags )
404
404
for i := range ref .Tags {
405
405
t := ref .Tags [i ].Name
406
- if ! strings .HasPrefix (t , "v" ) {
407
- t = "v" + t
408
- }
409
- if _ , ok := set [t ]; ! ok {
410
- if semver .IsValid (t ) {
411
- tags = append (tags , tag .Context ().Tag (t ))
412
- set [t ] = struct {}{}
413
- }
406
+ // this is accounts only for a simple case where tape is pointed at a dir
407
+ // and a tags have prefix that matches it exactly, it won't work for cases
408
+ // where tape is pointed at a subdir a parent of which has a scoped tag
409
+ if strings .HasPrefix (t , groupSummary .Path + "/" ) {
410
+ scopedTags .add (strings .TrimPrefix (t , groupSummary .Path + "/" ), tag )
411
+ continue
414
412
}
413
+ tags .add (t , tag )
415
414
}
416
- if len (tags ) == 0 {
417
- return []name.Tag {}
415
+ if len (scopedTags .list ) > 0 {
416
+ return scopedTags .list
417
+ }
418
+ return tags .list
419
+ }
420
+
421
+ type tagSet struct {
422
+ set map [string ]struct {}
423
+ list []name.Tag
424
+ }
425
+
426
+ func newTagtagSet (c int ) * tagSet {
427
+ return & tagSet {
428
+ set : make (map [string ]struct {}, c ),
429
+ list : make ([]name.Tag , 0 , c ),
430
+ }
431
+ }
432
+
433
+ func (s * tagSet ) add (t string , image name.Tag ) {
434
+ if ! strings .HasPrefix (t , "v" ) {
435
+ t = "v" + t
436
+ }
437
+ if _ , ok := s .set [t ]; ! ok {
438
+ if semver .IsValid (t ) {
439
+ s .list = append (s .list , image .Context ().Tag (t ))
440
+ s .set [t ] = struct {}{}
441
+ }
418
442
}
419
- return tags
420
443
}
421
444
422
445
func makeDescriptorWithPlatform () Descriptor {
0 commit comments