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
type Entry structEntry represents a single operation log entry.
#Append
func Append(safegitDir string, entry Entry) errorAppend 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
func Read(safegitDir string) ([]Entry, error)Read returns all entries from the log file.
#LogSize
func LogSize(safegitDir string) (int64, error)LogSize returns the size of the log file in bytes. Returns 0 if not found.
#Rotate
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
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
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
func TipSHA(extra map[string]interface{}) stringTipSHA extracts the new-tip SHA from an oplog entry's extra map. It checks "sha", "to", and "result" in order. Returns "" if none found.