Skip to content

Commit 4c95a9e

Browse files
authored
Merge pull request #32 from infosiftr/shared-tags-children
Fix edge case of children for images that are FROM a SharedTag
2 parents 7d4279f + 16fb204 commit 4c95a9e

File tree

1 file changed

+62
-50
lines changed

1 file changed

+62
-50
lines changed

cmd/bashbrew/cmd-deps.go

Lines changed: 62 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -100,63 +100,75 @@ func cmdFamily(parents bool, c *cli.Context) error {
100100
// now the real work
101101
seen := map[string]bool{}
102102
for _, repo := range depsRepos {
103-
r, err := fetch(repo)
104-
if err != nil {
105-
return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err)
106-
}
103+
tagsToConsider := []string{}
107104

108-
for _, entry := range r.Entries() {
109-
if applyConstraints && r.SkipConstraints(entry) {
110-
continue
105+
if r, err := fetch(repo); err == nil {
106+
// fetch succeeded, must be an object we know about so let's do a proper listing/search
107+
for _, entry := range r.Entries() {
108+
if applyConstraints && r.SkipConstraints(entry) {
109+
continue
110+
}
111+
if archFilter && !entry.HasArchitecture(arch) {
112+
continue
113+
}
114+
115+
if len(r.TagEntries) == 1 {
116+
// we can't include SharedTags here or else they'll make "bashbrew parents something:simple" show the parents of the shared tags too ("nats:scratch" leading to both "nats:alpine" *and* "nats:windowsservercore" instead of just "nats:alpine" like it should), so we have to reimplement bits of "r.Tags" to exclude them
117+
tagRepo := path.Join(namespace, r.RepoName)
118+
for _, rawTag := range entry.Tags {
119+
tag := tagRepo + ":" + rawTag
120+
tagsToConsider = append(tagsToConsider, tag)
121+
}
122+
} else {
123+
// if we're doing something like "bashbrew children full-repo" (or "bashbrew children full-repo:shared-tag"), we *need* to include the SharedTags or else things that are "FROM full-repo:shared-tag" won't show up 😅 ("bashbrew children adoptopenjdk" was just "cassandra" instead of the full list)
124+
tagsToConsider = append(tagsToConsider, r.Tags(namespace, false, entry)...)
125+
}
111126
}
112-
if archFilter && !entry.HasArchitecture(arch) {
113-
continue
127+
} else {
128+
if err != nil {
129+
return cli.NewMultiError(fmt.Errorf(`failed fetching repo %q`, repo), err)
114130
}
131+
}
115132

116-
// we can't include SharedTags here or else they'll make "bashbrew parents something:simple" show the parents of the shared tags too ("nats:scratch" leading to both "nats:alpine" *and* "nats:windowsservercore" instead of just "nats:alpine" like it should), so we have to reimplement bits of "r.Tags" to exclude them
117-
tagRepo := path.Join(namespace, r.RepoName)
118-
for _, rawTag := range entry.Tags {
119-
tag := tagRepo + ":" + rawTag
120-
121-
nodes := []topsortDepthNodes{}
122-
if parents {
123-
nodes = append(nodes, topsortDepthNodes{
124-
depth: 1,
125-
nodes: network.Get(tag).InboundEdges,
126-
})
127-
} else {
128-
nodes = append(nodes, topsortDepthNodes{
129-
depth: 1,
130-
nodes: network.Get(tag).OutboundEdges,
131-
})
133+
for _, tag := range tagsToConsider {
134+
nodes := []topsortDepthNodes{}
135+
if parents {
136+
nodes = append(nodes, topsortDepthNodes{
137+
depth: 1,
138+
nodes: network.Get(tag).InboundEdges,
139+
})
140+
} else {
141+
nodes = append(nodes, topsortDepthNodes{
142+
depth: 1,
143+
nodes: network.Get(tag).OutboundEdges,
144+
})
145+
}
146+
for len(nodes) > 0 {
147+
depthNodes := nodes[0]
148+
nodes = nodes[1:]
149+
if depth > 0 && depthNodes.depth > depth {
150+
continue
132151
}
133-
for len(nodes) > 0 {
134-
depthNodes := nodes[0]
135-
nodes = nodes[1:]
136-
if depth > 0 && depthNodes.depth > depth {
152+
for _, node := range depthNodes.nodes {
153+
seenKey := node.Name
154+
if uniq {
155+
seenKey = seenKey[:strings.Index(seenKey, ":")+1] + node.Value.(*manifest.Manifest2822Entry).Tags[0]
156+
}
157+
if seen[seenKey] {
137158
continue
138159
}
139-
for _, node := range depthNodes.nodes {
140-
seenKey := node.Name
141-
if uniq {
142-
seenKey = seenKey[:strings.Index(seenKey, ":")+1] + node.Value.(*manifest.Manifest2822Entry).Tags[0]
143-
}
144-
if seen[seenKey] {
145-
continue
146-
}
147-
seen[seenKey] = true
148-
fmt.Printf("%s\n", seenKey)
149-
if parents {
150-
nodes = append(nodes, topsortDepthNodes{
151-
depth: depthNodes.depth + 1,
152-
nodes: node.InboundEdges,
153-
})
154-
} else {
155-
nodes = append(nodes, topsortDepthNodes{
156-
depth: depthNodes.depth + 1,
157-
nodes: node.OutboundEdges,
158-
})
159-
}
160+
seen[seenKey] = true
161+
fmt.Printf("%s\n", seenKey)
162+
if parents {
163+
nodes = append(nodes, topsortDepthNodes{
164+
depth: depthNodes.depth + 1,
165+
nodes: node.InboundEdges,
166+
})
167+
} else {
168+
nodes = append(nodes, topsortDepthNodes{
169+
depth: depthNodes.depth + 1,
170+
nodes: node.OutboundEdges,
171+
})
160172
}
161173
}
162174
}

0 commit comments

Comments
 (0)