X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=dot.go;h=19994ded165d8162e23e6c5ab467a92d21765e3a;hb=HEAD;hp=0ea2b4ae13fcffb9bd1fc858a329eadb216b8070;hpb=af40222f5a3e6fa82207f7ba31c338eb44566ba3;p=goredo.git diff --git a/dot.go b/dot.go index 0ea2b4a..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 { @@ -35,26 +29,34 @@ type DotNodes struct { } func dotWalker(data map[DotNodes]bool, tgt *Tgt) (map[DotNodes]bool, error) { - fdDep, err := os.Open(tgt.Dep()) + raw, err := os.ReadFile(tgt.dep) if err != nil { return nil, ErrLine(err) } - defer fdDep.Close() + _, raw, err = depHeadParse(raw) + if err != nil { + return nil, ErrLine(err) + } + var typ byte + var name string var dep *Tgt - r := recfile.NewReader(fdDep) - for { - m, err := r.NextMap() + 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{tgt.rel, NewTgt(string(chunk)).rel}] = true - case DepTypeIfchange: - dep = NewTgt(path.Join(tgt.h, m["Target"])) + 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 }