Source file: Modules/storage.py
The storage module provides the persistence layer for Leaf. It reads and writes JSON files inside .leaf/ and hides error handling from the command engine.
| File | Contents |
|---|---|
.leaf/log.json |
Ordered commit metadata. |
.leaf/log.bak |
Backup of the previous log file. |
.leaf/branches.json |
Branch name to commit ID map. |
.leaf/sessions.json |
Saved unsaved working states for branches. |
.leaf/index.json |
Staging area. |
.leaf/tags.json |
Tag name to commit ID map. |
.leaf/MERGE_STATE.json |
Metadata for an in-progress merge. |
.leaf/remotes.json |
Reserved remote configuration map. |
Writes JSON by first creating a temporary file in the target directory and then replacing the destination file. This reduces the chance of partially written JSON files if a write is interrupted.
Attempts to load JSON from a file. If the file is missing, unreadable, invalid, or does not match the expected default type, the default value is returned.
Loads .leaf/log.json. If the main log is unavailable and a backup exists, it falls back to .leaf/log.bak.
Copies the current log to .leaf/log.bak before writing the new log with _atomic_json_save().
Load and save branch pointers. The default branch map is { "main": None }.
Load and save branch sessions. Sessions preserve unsaved working changes when switching branches.
Load and save staged file data.
Resets the staging area to an empty object.
Load and save lightweight tag pointers.
Load and save metadata for an in-progress merge.
Removes .leaf/MERGE_STATE.json if it exists.
Load and save remote configuration data. The current CLI disables remote operations, but the storage helpers remain available.
Centralizing persistence keeps repository commands focused on behavior instead of JSON parsing, backup management, and safe file writes.