safegit v0.26.0 /internal/oplog
On this page

Package oplog implements the append-only JSONL operation log that records every mutating operation for undo support and audit trail purposes.

#internal/oplog

#internal/oplog

Package oplog implements the append-only JSONL operation log that records every mutating operation for undo support and audit trail purposes. Each entry appends one JSON line to .git/safegit/log via O_APPEND (lines must be < 4096 bytes for POSIX atomicity).

#Entry

Go go
type Entry struct

Entry represents a single operation log entry.

#Append

Go go
func Append(safegitDir string, entry Entry) error

Append writes a single entry to the log file atomically. The entry is serialized as a single JSON line. Lines exceeding 4096 bytes are rejected to preserve atomic write guarantees.

#Read

Go go
func Read(safegitDir string) ([]Entry, error)

Read returns all entries from the log file.

#LogSize

Go go
func LogSize(safegitDir string) (int64, error)

LogSize returns the size of the log file in bytes. Returns 0 if not found.

#Rotate

Go go
func Rotate(safegitDir string, maxSizeMB int) (bool, error)

Rotate renames the current log to log.1 (overwriting any existing log.1) and creates a fresh empty log file. Returns true if rotation happened.

#LastRefUpdate

Go go
func LastRefUpdate(safegitDir, ref string) (*Entry, error)

LastRefUpdate finds the most recent oplog entry for a given ref that records a new tip SHA. It accepts any op type and tries multiple extra keys ("sha", "to", "result") since different ops store the new tip under different names. Returns nil if no matching entry is found.

#LastRefUpdateForSession

Go go
func LastRefUpdateForSession(safegitDir, ref, sessionID string) (*Entry, error)

LastRefUpdateForSession finds the most recent oplog entry for a given ref and session ID that records a new tip SHA. Same logic as LastRefUpdate but with an additional session ID filter. Returns nil if no matching entry is found.

#TipSHA

Go go
func TipSHA(extra map[string]interface{}) string

TipSHA extracts the new-tip SHA from an oplog entry's extra map. It checks "sha", "to", and "result" in order. Returns "" if none found.

Search