Artifact 62302814643b937ec65005905ed7391ddd3d41f4adc1e0295a569d3ef1a88672:
- File
internal/manifest/files.go
— part of check-in
[862dcb20c3]
at
2026-05-12 23:48:08
on branch trunk
— fix: Repo.Commit preserves parent's tracked files (#30) (#32)
Repo.Commit was a thin pass-through to manifest.Checkin: callers who supplied a subset of the parent's tracked files got a partial manifest, so files tracked at the parent silently disappeared from the new commit. A checkout at the child's rev saw only the supplied subset — bones, EdgeSync, and sesh all hit this as silent data loss across slot commits.
Default behavior now matches `fossil ci`: when ParentID > 0 the parent's F-cards are merged into the commit's file set (caller wins on name collision; untouched parent files are loaded by UUID and carried forward).
For the rare case where a caller intentionally wants omission to mean deletion, CommitOpts.PartialManifest opts out of the merge. The internal diff/deletion tests that previously relied on the partial behavior now set this flag explicitly. A first-class deletion API may replace the escape hatch later.
Adds TestCommitPreservesParentFiles as the regression: parent [a,b,c], child supplies only [b'], child's ListFiles must return [a,b',c] with a and c keeping the parent's blob UUIDs. (user: [email protected], size: 3144) [annotate] [blame] [check-ins using]
package manifest import ( "fmt" "sort" libfossil "github.com/danmestas/libfossil/internal/fsltype" "github.com/danmestas/libfossil/internal/blob" "github.com/danmestas/libfossil/internal/content" "github.com/danmestas/libfossil/internal/deck" "github.com/danmestas/libfossil/internal/repo" ) type FileEntry struct { Name string UUID string Perm string } func ListFiles(r *repo.Repo, rid libfossil.FslID) ([]FileEntry, error) { d, err := GetManifest(r, rid) if err != nil { return nil, fmt.Errorf("manifest.ListFiles: %w", err) } if d.B == "" { return fCardsToEntries(d.F), nil } baseRid, ok := blob.Exists(r.DB(), d.B) if !ok { return nil, fmt.Errorf("manifest.ListFiles: baseline %s not found", d.B) } baseData, err := content.Expand(r.DB(), baseRid) if err != nil { return nil, fmt.Errorf("manifest.ListFiles: expand baseline: %w", err) } baseDeck, err := deck.Parse(baseData) if err != nil { return nil, fmt.Errorf("manifest.ListFiles: parse baseline: %w", err) } fileMap := make(map[string]FileEntry) for _, f := range baseDeck.F { fileMap[f.Name] = FileEntry{Name: f.Name, UUID: f.UUID, Perm: f.Perm} } for _, f := range d.F { if f.UUID == "" { delete(fileMap, f.Name) } else { fileMap[f.Name] = FileEntry{Name: f.Name, UUID: f.UUID, Perm: f.Perm} } } entries := make([]FileEntry, 0, len(fileMap)) for _, e := range fileMap { entries = append(entries, e) } sort.Slice(entries, func(i, j int) bool { return entries[i].Name < entries[j].Name }) return entries, nil } func fCardsToEntries(fCards []deck.FileCard) []FileEntry { entries := make([]FileEntry, len(fCards)) for i, f := range fCards { entries[i] = FileEntry{Name: f.Name, UUID: f.UUID, Perm: f.Perm} } sort.Slice(entries, func(i, j int) bool { return entries[i].Name < entries[j].Name }) return entries } // MergeParentFiles returns supplied with every file tracked at parentRID // that is not already in supplied appended. Names in supplied win over the // parent's entry; the parent's untouched files have their content expanded // from the repo so the resulting slice is a full-tree set ready for Checkin. // // parentRID == 0 returns supplied unchanged. func MergeParentFiles(r *repo.Repo, parentRID libfossil.FslID, supplied []File) ([]File, error) { if parentRID == 0 { return supplied, nil } parentFiles, err := ListFiles(r, parentRID) if err != nil { return nil, fmt.Errorf("manifest.MergeParentFiles: %w", err) } suppliedNames := make(map[string]struct{}, len(supplied)) for _, f := range supplied { suppliedNames[f.Name] = struct{}{} } merged := supplied for _, pf := range parentFiles { if _, ok := suppliedNames[pf.Name]; ok { continue } baseRid, ok := blob.Exists(r.DB(), pf.UUID) if !ok { return nil, fmt.Errorf("manifest.MergeParentFiles: blob %s for %s not found", pf.UUID, pf.Name) } data, err := content.Expand(r.DB(), baseRid) if err != nil { return nil, fmt.Errorf("manifest.MergeParentFiles: expand %s: %w", pf.Name, err) } merged = append(merged, File{ Name: pf.Name, Content: data, Perm: pf.Perm, }) } return merged, nil }