5
5
"pault.ag/go/topsort"
6
6
)
7
7
8
- func sortRepos (repos []string , applyConstraints bool ) ([]string , error ) {
8
+ func sortRepos (repos []string , applyConstraints bool , namespace string ) ([]string , error ) {
9
9
rs := []* Repo {}
10
10
rsMap := map [* Repo ]string {}
11
11
for _ , repo := range repos {
@@ -26,7 +26,7 @@ func sortRepos(repos []string, applyConstraints bool) ([]string, error) {
26
26
return repos , nil
27
27
}
28
28
29
- rs , err := sortRepoObjects (rs , applyConstraints )
29
+ rs , err := sortRepoObjects (rs , applyConstraints , namespace )
30
30
if err != nil {
31
31
return nil , err
32
32
}
@@ -38,7 +38,7 @@ func sortRepos(repos []string, applyConstraints bool) ([]string, error) {
38
38
return ret , nil
39
39
}
40
40
41
- func (r Repo ) SortedEntries (applyConstraints bool ) ([]* manifest.Manifest2822Entry , error ) {
41
+ func (r Repo ) SortedEntries (applyConstraints bool , namespace string ) ([]* manifest.Manifest2822Entry , error ) {
42
42
entries := r .Entries ()
43
43
44
44
// short circuit if we don't have to go further
@@ -52,7 +52,7 @@ func (r Repo) SortedEntries(applyConstraints bool) ([]*manifest.Manifest2822Entr
52
52
rs = append (rs , r .EntryRepo (entries [i ]))
53
53
}
54
54
55
- rs , err := sortRepoObjects (rs , applyConstraints )
55
+ rs , err := sortRepoObjects (rs , applyConstraints , namespace )
56
56
if err != nil {
57
57
return nil , err
58
58
}
@@ -64,7 +64,14 @@ func (r Repo) SortedEntries(applyConstraints bool) ([]*manifest.Manifest2822Entr
64
64
return ret , nil
65
65
}
66
66
67
- func sortRepoObjects (rs []* Repo , applyConstraints bool ) ([]* Repo , error ) {
67
+ func addNamespace (namespace , tag string ) string {
68
+ if namespace != "" {
69
+ tag = namespace + "/" + tag
70
+ }
71
+ return tag
72
+ }
73
+
74
+ func sortRepoObjects (rs []* Repo , applyConstraints bool , namespace string ) ([]* Repo , error ) {
68
75
// short circuit if we don't have to go further
69
76
if noSortFlag || len (rs ) <= 1 {
70
77
return rs , nil
@@ -79,12 +86,13 @@ func sortRepoObjects(rs []*Repo, applyConstraints bool) ([]*Repo, error) {
79
86
for _ , r := range rs {
80
87
node := r .Identifier ()
81
88
for _ , entry := range r .Entries () {
89
+ node = addNamespace (namespace , node )
82
90
for _ , tag := range r .Tags ("" , false , entry ) {
91
+ tag = addNamespace (namespace , tag )
83
92
if canonicalRepo , ok := canonicalRepos [tag ]; ok && canonicalRepo .TagName != "" {
84
93
// if we run into a duplicate, we want to prefer a specific tag over a full repo
85
94
continue
86
95
}
87
-
88
96
canonicalNodes [tag ] = node
89
97
canonicalRepos [tag ] = r
90
98
}
@@ -115,6 +123,8 @@ func sortRepoObjects(rs []*Repo, applyConstraints bool) ([]*Repo, error) {
115
123
116
124
// TODO somehow reconcile/avoid "a:a -> b:b, b:b -> a:c" (which will exhibit here as cyclic)
117
125
for _ , tag := range r .Tags ("" , false , entry ) {
126
+ tag = addNamespace (namespace , tag )
127
+
118
128
if tagNode , ok := canonicalNodes [tag ]; ok {
119
129
if tagNode == fromNode {
120
130
// don't be cyclic
0 commit comments