-/*
-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
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 {
}
_, err = io.Copy(w, bytes.NewBuffer(chunkWrite(bytes.Join([][]byte{
{DepTypeIfchange},
- []byte(inode),
+ inode[:],
[]byte(hsh),
[]byte(tgt.RelTo(cwd)),
}, nil))))
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