]> Cypherpunks.ru repositories - goredo.git/blobdiff - dep.go
Download link for 2.6.2 release
[goredo.git] / dep.go
diff --git a/dep.go b/dep.go
index 279e55dddbc1a736e950b8788394121651763307..77c248ec9026c6ca1e325c11468e643c030654ed 100644 (file)
--- a/dep.go
+++ b/dep.go
@@ -1,19 +1,17 @@
-/*
-goredo -- djb's redo implementation on pure Go
-Copyright (C) 2020-2023 Sergey Matveev <stargrave@stargrave.org>
-
-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 <http://www.gnu.org/licenses/>.
-*/
+// goredo -- djb's redo implementation on pure Go
+// Copyright (C) 2020-2024 Sergey Matveev <stargrave@stargrave.org>
+//
+// 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 <http://www.gnu.org/licenses/>.
 
 // Dependencies saver
 
@@ -67,11 +65,12 @@ func chunkWrite(in []byte) (out []byte) {
 
 type Ifchange struct {
        tgt  *Tgt
-       meta string
+       meta [InodeLen + HashLen]byte
 }
 
-func (ifchange *Ifchange) Inode() Inode {
-       return Inode(ifchange.meta[:InodeLen])
+func (ifchange *Ifchange) Inode() *Inode {
+       inode := Inode(ifchange.meta[:InodeLen])
+       return &inode
 }
 
 func (ifchange *Ifchange) Hash() Hash {
@@ -140,7 +139,7 @@ func depWrite(w io.Writer, fdDepName, cwd string, tgt *Tgt, hsh Hash) (err error
        }
        _, err = io.Copy(w, bytes.NewBuffer(chunkWrite(bytes.Join([][]byte{
                {DepTypeIfchange},
-               []byte(inode),
+               inode[:],
                []byte(hsh),
                []byte(tgt.RelTo(cwd)),
        }, nil))))
@@ -226,20 +225,19 @@ func depBinIfchangeParse(tgt *Tgt, chunk []byte) (*Ifchange, string, error) {
        if len(chunk) < InodeLen+HashLen+1 {
                return nil, "", errors.New("too short \"ifchange\" format")
        }
-       name := string(chunk[InodeLen+HashLen:])
-       meta := string(chunk[:InodeLen+HashLen])
 
        tgtH, _ := pathSplit(tgt.a)
-       ifchange := &Ifchange{tgt: NewTgt(path.Join(tgtH, name)), meta: meta}
-       cachedFound := false
+       name := string(chunk[InodeLen+HashLen:])
+       ifchange := &Ifchange{
+               tgt:  NewTgt(path.Join(tgtH, name)),
+               meta: ([InodeLen + HashLen]byte)(chunk),
+       }
        for _, cached := range IfchangeCache[ifchange.tgt.rel] {
                if ifchange.meta == cached.meta {
-                       ifchange = cached
-                       cachedFound = true
-                       break
+                       return cached, name, nil
                }
        }
-       if IfchangeCache != nil && !cachedFound {
+       if IfchangeCache != nil {
                IfchangeCache[ifchange.tgt.rel] = append(IfchangeCache[ifchange.tgt.rel], ifchange)
        }
        return ifchange, name, nil