Skip to content

Commit ff63f9d

Browse files
committed
Fix GetSharedTagGroups ordering and update our hacky example code to have some SharedTags examples
1 parent c48fd9a commit ff63f9d

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

manifest/example.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Maintainers: InfoSiftr <[email protected]> (@infosiftr),
2020
Johan Euphrosine <[email protected]> (@proppy)
2121
GitRepo: https://github.com/docker-library/golang.git
2222
GitFetch: refs/heads/master
23+
SharedTags: latest
2324
2425
2526
# hi
@@ -29,18 +30,20 @@ GitFetch: refs/heads/master
2930
3031
3132
# Go 1.6
32-
Tags: 1.6.1, 1.6, 1, latest
33+
Tags: 1.6.1, 1.6, 1
3334
GitCommit: 0ce80411b9f41e9c3a21fc0a1bffba6ae761825a
3435
Directory: 1.6
3536
3637
3738
# Go 1.5
3839
Tags: 1.5.3
40+
SharedTags: 1.5.3-debian, 1.5-debian
3941
GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19
4042
Directory: 1.5
4143
4244
4345
Tags: 1.5
46+
SharedTags: 1.5-debian
4447
GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19
4548
Directory: 1.5
4649
@@ -51,6 +54,15 @@ Directory: 1.5
5154
}
5255
fmt.Printf("-------------\n2822:\n%s\n", man)
5356

57+
fmt.Printf("\nShared Tag Groups:\n")
58+
for _, group := range man.GetSharedTagGroups() {
59+
fmt.Printf("\n - %s\n", strings.Join(group.SharedTags, ", "))
60+
for _, entry := range group.Entries {
61+
fmt.Printf(" - %s\n", entry.TagsString())
62+
}
63+
}
64+
fmt.Printf("\n")
65+
5466
man, err = manifest.Parse(bufio.NewReader(strings.NewReader(`
5567
# first set
5668
a: b@c d

manifest/rfc2822.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,26 +199,30 @@ func (manifest Manifest2822) GetAllSharedTags() []string {
199199

200200
type SharedTagGroup struct {
201201
SharedTags []string
202-
Entries []*Manifest2822Entry
202+
Entries []*Manifest2822Entry
203203
}
204204

205205
// GetSharedTagGroups returns a map of shared tag groups to the list of entries they share (as described in https://github.com/docker-library/go-dockerlibrary/pull/2#issuecomment-277853597).
206206
func (manifest Manifest2822) GetSharedTagGroups() []SharedTagGroup {
207207
inter := map[string][]string{}
208+
interOrder := []string{} // order matters, and maps randomize order
208209
interKeySep := ","
209210
for _, sharedTag := range manifest.GetAllSharedTags() {
210211
interKeyParts := []string{}
211212
for _, entry := range manifest.GetSharedTag(sharedTag) {
212213
interKeyParts = append(interKeyParts, entry.Tags[0])
213214
}
214215
interKey := strings.Join(interKeyParts, interKeySep)
216+
if _, ok := inter[interKey]; !ok {
217+
interOrder = append(interOrder, interKey)
218+
}
215219
inter[interKey] = append(inter[interKey], sharedTag)
216220
}
217221
ret := []SharedTagGroup{}
218-
for tags, sharedTags := range inter {
222+
for _, tags := range interOrder {
219223
group := SharedTagGroup{
220-
SharedTags: sharedTags,
221-
Entries: []*Manifest2822Entry{},
224+
SharedTags: inter[tags],
225+
Entries: []*Manifest2822Entry{},
222226
}
223227
for _, tag := range strings.Split(tags, interKeySep) {
224228
group.Entries = append(group.Entries, manifest.GetTag(tag))

0 commit comments

Comments
 (0)