X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=dot.go;h=19994ded165d8162e23e6c5ab467a92d21765e3a;hb=a9455044065855ae42d95d939ed0027f7a895b83;hp=b8c28b75346e8d451be77cceb1a8dbb521006adf;hpb=fc065e1408aa2e452699d1bae1a56af9fcc69bec;p=goredo.git diff --git a/dot.go b/dot.go index b8c28b7..19994de 100644 --- a/dot.go +++ b/dot.go @@ -1,32 +1,26 @@ -/* -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 . // Dependency DOT graph generation package main import ( - "errors" "fmt" - "io" "os" "path" - - "go.cypherpunks.ru/recfile" ) type DotNodes struct { @@ -34,37 +28,43 @@ type DotNodes struct { to string } -func dotWalker(data map[DotNodes]bool, tgtOrig string) (map[DotNodes]bool, error) { - cwd, tgt := cwdAndTgt(tgtOrig) - depPath := path.Join(cwd, RedoDir, tgt+DepSuffix) - fdDep, err := os.Open(depPath) +func dotWalker(data map[DotNodes]bool, tgt *Tgt) (map[DotNodes]bool, error) { + raw, err := os.ReadFile(tgt.dep) if err != nil { return nil, ErrLine(err) } - defer fdDep.Close() - var dep string - r := recfile.NewReader(fdDep) - for { - m, err := r.NextMap() + _, raw, err = depHeadParse(raw) + if err != nil { + return nil, ErrLine(err) + } + var typ byte + var name string + var dep *Tgt + var chunk []byte + tgtH, _ := pathSplit(tgt.a) + for len(raw) > 0 { + typ, chunk, raw, err = chunkRead(raw) if err != nil { - if errors.Is(err, io.EOF) { - break - } return nil, ErrLine(err) } - switch m["Type"] { + switch typ { case DepTypeIfcreate: - data[DotNodes{tgtOrig, cwdMustRel(cwd, m["Target"])}] = true - case DepTypeIfchange: - dep = m["Target"] - if dep == tgt { + data[DotNodes{tgt.rel, NewTgt(path.Join(tgtH, string(chunk))).rel}] = true + case DepTypeIfchange, DepTypeIfchangeNonex: + if typ == DepTypeIfchangeNonex { + name = string(chunk) + } else { + name = string(chunk[InodeLen+HashLen:]) + } + dep = NewTgt(path.Join(tgtH, name)) + if dep.a == tgt.a { continue } - data[DotNodes{tgtOrig, cwdMustRel(cwd, dep)}] = false - if isSrc(cwd, dep) { + data[DotNodes{tgt.rel, dep.rel}] = false + if isSrc(dep) { continue } - data, err = dotWalker(data, cwdMustRel(cwd, dep)) + data, err = dotWalker(data, dep) if err != nil { return nil, err } @@ -73,7 +73,7 @@ func dotWalker(data map[DotNodes]bool, tgtOrig string) (map[DotNodes]bool, error return data, nil } -func dotPrint(tgts []string) error { +func dotPrint(tgts []*Tgt) error { data := map[DotNodes]bool{} var err error for _, tgt := range tgts {