Fix GetSharedTagGroups ordering and update our hacky example code to have some SharedTags examples

This commit is contained in:
Tianon Gravi 2017-02-10 11:05:35 -08:00
parent c48fd9a499
commit ff63f9df03
2 changed files with 21 additions and 5 deletions

View File

@ -20,6 +20,7 @@ Maintainers: InfoSiftr <github@infosiftr.com> (@infosiftr),
Johan Euphrosine <proppy@google.com> (@proppy)
GitRepo: https://github.com/docker-library/golang.git
GitFetch: refs/heads/master
SharedTags: latest
# hi
@ -29,18 +30,20 @@ GitFetch: refs/heads/master
# Go 1.6
Tags: 1.6.1, 1.6, 1, latest
Tags: 1.6.1, 1.6, 1
GitCommit: 0ce80411b9f41e9c3a21fc0a1bffba6ae761825a
Directory: 1.6
# Go 1.5
Tags: 1.5.3
SharedTags: 1.5.3-debian, 1.5-debian
GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19
Directory: 1.5
Tags: 1.5
SharedTags: 1.5-debian
GitCommit: d7e2a8d90a9b8f5dfd5bcd428e0c33b68c40cc19
Directory: 1.5
@ -51,6 +54,15 @@ Directory: 1.5
}
fmt.Printf("-------------\n2822:\n%s\n", man)
fmt.Printf("\nShared Tag Groups:\n")
for _, group := range man.GetSharedTagGroups() {
fmt.Printf("\n - %s\n", strings.Join(group.SharedTags, ", "))
for _, entry := range group.Entries {
fmt.Printf(" - %s\n", entry.TagsString())
}
}
fmt.Printf("\n")
man, err = manifest.Parse(bufio.NewReader(strings.NewReader(`
# first set
a: b@c d

View File

@ -199,12 +199,13 @@ func (manifest Manifest2822) GetAllSharedTags() []string {
type SharedTagGroup struct {
SharedTags []string
Entries []*Manifest2822Entry
Entries []*Manifest2822Entry
}
// 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).
func (manifest Manifest2822) GetSharedTagGroups() []SharedTagGroup {
inter := map[string][]string{}
interOrder := []string{} // order matters, and maps randomize order
interKeySep := ","
for _, sharedTag := range manifest.GetAllSharedTags() {
interKeyParts := []string{}
@ -212,13 +213,16 @@ func (manifest Manifest2822) GetSharedTagGroups() []SharedTagGroup {
interKeyParts = append(interKeyParts, entry.Tags[0])
}
interKey := strings.Join(interKeyParts, interKeySep)
if _, ok := inter[interKey]; !ok {
interOrder = append(interOrder, interKey)
}
inter[interKey] = append(inter[interKey], sharedTag)
}
ret := []SharedTagGroup{}
for tags, sharedTags := range inter {
for _, tags := range interOrder {
group := SharedTagGroup{
SharedTags: sharedTags,
Entries: []*Manifest2822Entry{},
SharedTags: inter[tags],
Entries: []*Manifest2822Entry{},
}
for _, tag := range strings.Split(tags, interKeySep) {
group.Entries = append(group.Entries, manifest.GetTag(tag))