1
0
Fork 0
mirror of https://github.com/imjasonh/infinite-git synced 2026-07-12 02:41:48 +00:00

Fix four bugs: packfile offset tracking, HTTP error ordering, ref ordering, and race condition

- packfile.go: ReadObject now uses a countingReader to track compressed
  bytes consumed and properly advances r.offset, fixing sequential
  multi-object reads.
- handlers.go: Use commitSHA from GenerateCommit directly instead of
  re-reading refs, which fixes both the HTTP error-after-body-written
  issue and ensures HEAD is always advertised first (Git protocol
  requirement).
- commit.go: GenerateCommit now holds the repo lock for the entire
  read-modify-write cycle, preventing concurrent generates from reading
  the same parent and losing ref updates.
- repo.go: Added Lock/Unlock/GetRefsLocked methods to support holding
  the mutex across multiple repo operations.

https://claude.ai/code/session_015F9BYQoCy2P2zYZBuVeXHH
This commit is contained in:
Claude 2026-04-02 05:52:24 +00:00
parent 09281ac00c
commit 29666530cc
No known key found for this signature in database
4 changed files with 60 additions and 36 deletions

View file

@ -23,12 +23,20 @@ func New(r *repo.Repository) *Generator {
}
// GenerateCommit creates a new commit and updates the main branch.
// It holds the repo lock for the entire read-modify-write cycle to
// prevent concurrent generates from reading the same parent.
func (g *Generator) GenerateCommit() (string, error) {
// Increment counter atomically
count := atomic.AddInt64(&g.counter, 1)
// Get current HEAD commit
refs, err := g.repo.GetRefs()
// Hold the repo lock for the entire operation to prevent races.
g.repo.Lock()
defer g.repo.Unlock()
// Get current HEAD commit (use exported method is fine since
// getRefs is called internally, but we already hold the lock,
// so we call the unexported version via GetRefsLocked).
refs, err := g.repo.GetRefsLocked()
if err != nil {
return "", fmt.Errorf("getting refs: %w", err)
}