X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=targets.go;h=bd1fac3d383cefc1c412e19c2efd5d17b575e1da;hb=refs%2Fheads%2Fmaster;hp=6459a2db5529d9061ce393b044073f62e9c2ba71;hpb=9d1ca78917c32c17686d7ea2ef01c6ebcc0f63d8;p=goredo.git diff --git a/targets.go b/targets.go index 6459a2d..bd1fac3 100644 --- a/targets.go +++ b/targets.go @@ -1,19 +1,17 @@ -/* -goredo -- djb's redo implementation on pure Go -Copyright (C) 2020-2023 Sergey Matveev - -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, version 3 of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ +// goredo -- djb's redo implementation on pure Go +// Copyright (C) 2020-2024 Sergey Matveev +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, version 3 of the License. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . package main @@ -25,7 +23,6 @@ import ( ) func targetsCollect(root string, tgts map[string]struct{}) error { - root = mustAbs(root) dir, err := os.Open(root) if err != nil { return ErrLine(err) @@ -72,9 +69,9 @@ func targetsCollect(root string, tgts map[string]struct{}) error { } func targetsWalker(tgts []string) ([]string, error) { - tgtsMap := map[string]struct{}{} + tgtsMap := make(map[string]struct{}) for _, tgt := range tgts { - if err := targetsCollect(tgt, tgtsMap); err != nil { + if err := targetsCollect(mustAbs(tgt), tgtsMap); err != nil { return nil, err } } @@ -86,12 +83,15 @@ func targetsWalker(tgts []string) ([]string, error) { } func collectWholeDeps( - tgts map[string]struct{}, - deps map[string]map[string]struct{}, - seen map[string]struct{}, + tgts map[string]*Tgt, + deps map[string]map[string]*Tgt, + seen map[string]*Tgt, ) { - for tgt := range tgts { - seen[tgt] = struct{}{} - collectWholeDeps(deps[tgt], deps, seen) + for _, tgt := range tgts { + if _, exists := seen[tgt.rel]; exists { + continue + } + seen[tgt.rel] = tgt + collectWholeDeps(deps[tgt.rel], deps, seen) } }