build: small readability improvements by reversal of conditions

This adds some ideomatic earlier returns and loop continuations
to avoid deeply nested coditional blocks that are several lines
long.

Signed-off-by: Ilya Dmitrichenko <errordeveloper@gmail.com>
pull/1466/head
Ilya Dmitrichenko 3 years ago
parent 387cc633c7
commit 08b6d36deb
No known key found for this signature in database
GPG Key ID: E7889175A6C0CEB9

@ -691,7 +691,10 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
return nil
}
if pushNames != "" {
if pushNames == "" {
return nil
}
progress.Write(pw, fmt.Sprintf("merging manifest list %s", pushNames), func() error {
descs := make([]specs.Descriptor, 0, len(res))
@ -705,7 +708,11 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
})
}
}
if len(descs) > 0 {
if len(descs) == 0 {
return nil
}
var imageopt imagetools.Opt
for _, dp := range dps {
imageopt = nodes[dp.driverIndex].ImageOpt
@ -773,10 +780,10 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
},
}
respMu.Unlock()
}
return nil
})
}
return nil
})
@ -866,7 +873,9 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
return nil, err
}
var reqErr *errdefs.UnsupportedSubrequestError
if !isFallback {
if isFallback {
return nil, err
}
if errors.As(err, &reqErr) {
switch reqErr.Name {
case "frontend.outline", "frontend.targets":
@ -882,7 +891,6 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
origErr = err
continue
}
}
return nil, err
}
if opt.PrintFunc != nil {
@ -908,10 +916,15 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
}
node := nodes[dp.driverIndex].Driver
if node.IsMobyDriver() {
if !node.IsMobyDriver() {
return nil
}
for _, e := range so.Exports {
if e.Type == "moby" && e.Attrs["push"] != "" {
if ok, _ := strconv.ParseBool(e.Attrs["push"]); ok {
if ok, _ := strconv.ParseBool(e.Attrs["push"]); !ok {
continue
}
pushNames = e.Attrs["name"]
if pushNames == "" {
return errors.Errorf("tag is needed when pushing to registry")
@ -940,8 +953,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
}
}
}
}
}
return nil
})
@ -1315,7 +1327,11 @@ func waitContextDeps(ctx context.Context, index int, results *waitmap.Map, so *c
}
delete(so.FrontendAttrs, v)
}
if rr.Ref != nil {
if rr.Ref == nil {
continue
}
st, err := rr.Ref.ToState()
if err != nil {
return err
@ -1337,7 +1353,6 @@ func waitContextDeps(ctx context.Context, index int, results *waitmap.Map, so *c
so.FrontendAttrs["input-metadata:"+k] = string(dt)
}
}
}
return nil
}

Loading…
Cancel
Save