Artifact b1e81faf2b551173aa42d1803a4d676b21c193153d91f9911905f7358db346c3:
- File
internal/verify/rebuild.go
— part of check-in
[088f1d8a90]
at
2026-10-12 00:18:43
on branch main
— fix(manifest): apply the parent (reparent) tag (#286) (#327)
* fix(manifest): apply the parent (reparent) tag (#286)
A singleton parent tag relocates a check-in's ancestry. fossil's manifest_crosslink_end rewrites the tagged check-in's plink and mlink to the hashes the tag names, before it propagates tags, so the leaf recompute sees the new edges and an old parent with no remaining child becomes a leaf. ReparentCheckins does this over a deck whose P-card is the override, reusing the normal plink/mlink builders. It runs from the crosslink repair gate and from verify.Rebuild, which had no reparent step.
* test(manifest): reparent plink/mlink/leaf, idempotence, phantom target (#286)
Also fold the plink baseid resolution into a shared checkinBaseid helper used by both the normal linkage path and the reparent pass, and note that the reparent repair is O(reparented) per round like fossil's manifest_crosslink_end. (user: [email protected], size: 2996) [annotate] [blame] [check-ins using]
package verify import ( "fmt" "time" "github.com/danmestas/go-libfossil/db" "github.com/danmestas/go-libfossil/internal/content" "github.com/danmestas/go-libfossil/internal/manifest" "github.com/danmestas/go-libfossil/internal/repo" ) // rebuildTableList is the set of derived tables dropped and reconstructed // during a rebuild. Order does not matter — they are all DELETEd first. var rebuildTableList = []string{ "event", "mlink", "plink", "tagxref", "filename", "leaf", "unclustered", "unsent", } // Rebuild reconstructs all derived tables from raw blob content. // It first verifies blob integrity (read-only), then drops and // rebuilds event/mlink/plink/tagxref/filename/leaf/unclustered/unsent // in a single transaction. func Rebuild(r *repo.Repo) (*Report, error) { if r == nil { panic("verify.Rebuild: nil *repo.Repo") } start := time.Now() report := &Report{} // One expansion cache for the whole rebuild; see verifyCacheBytes. It spans // the pre-transaction blob check and the in-transaction sweeps because a // blob's rid and content are the same whichever querier reads them, and // rebuild never rewrites blob content -- only the derived tables. cache := content.NewCache(verifyCacheBytes) // Phase 1: verify blobs (read-only, outside transaction) if err := checkBlobs(r, report, cache); err != nil { return nil, fmt.Errorf("verify.Rebuild: %w", err) } // Phases 2-4: drop + reconstruct in transaction if err := r.WithTx(func(tx *db.Tx) error { if err := dropDerivedTables(tx); err != nil { return err } if err := rebuildManifests(r, tx, report, cache); err != nil { return fmt.Errorf("rebuild manifests: %w", err) } if err := rebuildTags(r, tx, report, cache); err != nil { return fmt.Errorf("rebuild tags: %w", err) } // Apply parent (reparent) tags now that control tags are in tagxref and // before leaves are computed, so a reparented old parent reads as a leaf. if err := manifest.ReparentCheckins(tx); err != nil { return fmt.Errorf("rebuild reparent: %w", err) } if err := rebuildLeaves(tx); err != nil { return fmt.Errorf("rebuild leaves: %w", err) } if err := rebuildBookkeeping(tx); err != nil { return fmt.Errorf("rebuild bookkeeping: %w", err) } return nil }); err != nil { return nil, fmt.Errorf("verify.Rebuild: %w", err) } report.TablesRebuilt = rebuildTableList report.Duration = time.Since(start) // Postcondition: TablesRebuilt must be populated after successful rebuild. if len(report.TablesRebuilt) == 0 { panic("verify.Rebuild: postcondition: TablesRebuilt empty after successful rebuild") } return report, nil } // dropDerivedTables deletes all rows from the derived tables. func dropDerivedTables(tx *db.Tx) error { if tx == nil { panic("verify.dropDerivedTables: nil *db.Tx") } for _, table := range rebuildTableList { if _, err := tx.Exec("DELETE FROM " + table); err != nil { return fmt.Errorf("drop %s: %w", table, err) } } return nil }