Skip to content

Commit c48fd9a

Browse files
committed
First pass at implementing GetSharedTagGroups
1 parent 8488b2f commit c48fd9a

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

manifest/rfc2822.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,37 @@ func (manifest Manifest2822) GetAllSharedTags() []string {
197197
return fakeEntry.SharedTags
198198
}
199199

200+
type SharedTagGroup struct {
201+
SharedTags []string
202+
Entries []*Manifest2822Entry
203+
}
204+
205+
// 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).
206+
func (manifest Manifest2822) GetSharedTagGroups() []SharedTagGroup {
207+
inter := map[string][]string{}
208+
interKeySep := ","
209+
for _, sharedTag := range manifest.GetAllSharedTags() {
210+
interKeyParts := []string{}
211+
for _, entry := range manifest.GetSharedTag(sharedTag) {
212+
interKeyParts = append(interKeyParts, entry.Tags[0])
213+
}
214+
interKey := strings.Join(interKeyParts, interKeySep)
215+
inter[interKey] = append(inter[interKey], sharedTag)
216+
}
217+
ret := []SharedTagGroup{}
218+
for tags, sharedTags := range inter {
219+
group := SharedTagGroup{
220+
SharedTags: sharedTags,
221+
Entries: []*Manifest2822Entry{},
222+
}
223+
for _, tag := range strings.Split(tags, interKeySep) {
224+
group.Entries = append(group.Entries, manifest.GetTag(tag))
225+
}
226+
ret = append(ret, group)
227+
}
228+
return ret
229+
}
230+
200231
func (manifest *Manifest2822) AddEntry(entry Manifest2822Entry) error {
201232
if len(entry.Tags) < 1 {
202233
return fmt.Errorf("missing Tags")

0 commit comments

Comments
 (0)