Skip to content

Commit a40a54d

Browse files
committed
Add "--uniq" to "parents"/"children" (and have it actually do the right thing)
1 parent 7c78a8a commit a40a54d

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

cmd/bashbrew/cmd-deps.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66

77
"github.com/codegangsta/cli"
88
"pault.ag/go/topsort"
9+
10+
"github.com/docker-library/go-dockerlibrary/manifest"
911
)
1012

1113
func cmdOffspring(c *cli.Context) error {
@@ -27,6 +29,7 @@ func cmdFamily(parents bool, c *cli.Context) error {
2729
return cli.NewMultiError(fmt.Errorf(`failed gathering repo list`), err)
2830
}
2931

32+
uniq := c.Bool("uniq")
3033
applyConstraints := c.Bool("apply-constraints")
3134
depth := c.Int("depth")
3235

@@ -87,7 +90,7 @@ func cmdFamily(parents bool, c *cli.Context) error {
8790
}
8891

8992
// now the real work
90-
seen := map[*topsort.Node]bool{}
93+
seen := map[string]bool{}
9194
for _, repo := range depsRepos {
9295
r, err := fetch(repo)
9396
if err != nil {
@@ -101,8 +104,8 @@ func cmdFamily(parents bool, c *cli.Context) error {
101104

102105
// 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
103106
tagRepo := path.Join(namespace, r.RepoName)
104-
for i, rawTag := range entry.Tags {
105-
tag := tagRepo+":"+rawTag
107+
for _, rawTag := range entry.Tags {
108+
tag := tagRepo + ":" + rawTag
106109

107110
nodes := []topsortDepthNodes{}
108111
if parents {
@@ -123,11 +126,15 @@ func cmdFamily(parents bool, c *cli.Context) error {
123126
continue
124127
}
125128
for _, node := range depthNodes.nodes {
126-
if seen[node] {
129+
seenKey := node.Name
130+
if uniq {
131+
seenKey = tagRepo + ":" + node.Value.(*manifest.Manifest2822Entry).Tags[0]
132+
}
133+
if seen[seenKey] {
127134
continue
128135
}
129-
seen[node] = true
130-
fmt.Printf("%s\n", node.Name)
136+
seen[seenKey] = true
137+
fmt.Printf("%s\n", seenKey)
131138
if parents {
132139
nodes = append(nodes, topsortDepthNodes{
133140
depth: depthNodes.depth + 1,

cmd/bashbrew/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ func main() {
310310
Flags: []cli.Flag{
311311
commonFlags["apply-constraints"],
312312
commonFlags["depth"],
313+
commonFlags["uniq"],
313314
},
314315
Before: subcommandBeforeFactory("children"),
315316
Action: cmdOffspring,
@@ -326,6 +327,7 @@ func main() {
326327
Flags: []cli.Flag{
327328
commonFlags["apply-constraints"],
328329
commonFlags["depth"],
330+
commonFlags["uniq"],
329331
},
330332
Before: subcommandBeforeFactory("parents"),
331333
Action: cmdParents,

0 commit comments

Comments
 (0)