feat(dolt): auto-commit write commands and set explicit commit authors (#1267)
* /{cmd,docs,internal}: autocommit writes in dolt backend
Executed-By: beads/crew/emma
Rig: beads
Role: crew
* /{cmd,internal}: fix commit author
Executed-By: beads/crew/emma
Rig: beads
Role: crew
* /cmd/bd: fix race condition
Executed-By: beads/crew/emma
Rig: beads
Role: crew
---------
Co-authored-by: Test <test@example.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -47,6 +48,11 @@ type FlushManager struct {
|
||||
|
||||
// State tracking
|
||||
shutdownOnce sync.Once // Ensures Shutdown() is idempotent
|
||||
|
||||
// didWrite tracks whether any command marked the DB as modified during this process run.
|
||||
// This is used for Dolt auto-commit decisions in PersistentPostRun.
|
||||
// Atomic to remain race-safe when called from concurrent goroutines.
|
||||
didWrite atomic.Bool
|
||||
}
|
||||
|
||||
// markDirtyEvent signals that the database has been modified
|
||||
@@ -87,12 +93,27 @@ func NewFlushManager(enabled bool, debounceDuration time.Duration) *FlushManager
|
||||
return fm
|
||||
}
|
||||
|
||||
// RecordWrite marks that the current command performed a DB write.
|
||||
// This is independent of whether auto-flush is enabled; callers may want Dolt
|
||||
// auto-commit even when --no-auto-flush is set.
|
||||
func (fm *FlushManager) RecordWrite() {
|
||||
fm.didWrite.Store(true)
|
||||
}
|
||||
|
||||
// DidWrite returns true if RecordWrite/MarkDirty was called during this command.
|
||||
func (fm *FlushManager) DidWrite() bool {
|
||||
return fm.didWrite.Load()
|
||||
}
|
||||
|
||||
// MarkDirty marks the database as dirty and schedules a debounced flush.
|
||||
// Safe to call from multiple goroutines. Non-blocking.
|
||||
//
|
||||
// If called multiple times within debounceDuration, only one flush occurs
|
||||
// after the last call (debouncing).
|
||||
func (fm *FlushManager) MarkDirty(fullExport bool) {
|
||||
// Always track that a write happened, even if auto-flush is disabled.
|
||||
fm.RecordWrite()
|
||||
|
||||
if !fm.enabled {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -407,8 +407,7 @@ NOTE: Import requires direct database access and does not work with daemon mode.
|
||||
fmt.Fprintf(os.Stderr, "\nAll text and dependency references have been updated.\n")
|
||||
}
|
||||
|
||||
// Mark this command as having performed a write if it changed anything.
|
||||
// This enables Dolt auto-commit in PersistentPostRun.
|
||||
// Record that this command performed a write (for Dolt auto-commit).
|
||||
if result.Created > 0 || result.Updated > 0 || len(result.IDMapping) > 0 {
|
||||
commandDidWrite.Store(true)
|
||||
}
|
||||
|
||||
@@ -136,14 +136,7 @@ func importFromJSONLInline(ctx context.Context, jsonlPath string, renameOnImport
|
||||
return fmt.Errorf("import failed: %w", err)
|
||||
}
|
||||
|
||||
// Mark command as having performed a write when the import changed anything.
|
||||
// This enables Dolt auto-commit in PersistentPostRun.
|
||||
if result.Created > 0 || result.Updated > 0 || len(result.IDMapping) > 0 {
|
||||
commandDidWrite.Store(true)
|
||||
}
|
||||
|
||||
// Mark command as having performed a write when the import changed anything.
|
||||
// This enables Dolt auto-commit in PersistentPostRun for single-process backends.
|
||||
// Record that this command performed a write (for Dolt auto-commit) when the import changed anything.
|
||||
if result.Created > 0 || result.Updated > 0 || len(result.IDMapping) > 0 {
|
||||
commandDidWrite.Store(true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user