Skip to content

Implement JSON line format for undo.data with opt-in migration#745

Draft
Copilot wants to merge 4 commits intodevelopfrom
copilot/switch-to-json-line-format
Draft

Implement JSON line format for undo.data with opt-in migration#745
Copilot wants to merge 4 commits intodevelopfrom
copilot/switch-to-json-line-format

Conversation

Copy link

Copilot AI commented Mar 1, 2026

Adds a JSON line format for undo.data where each transaction is stored as a single JSON object per line, replacing the current multi-line text format. Migration is opt-in via a new journal.format config key, with automatic detection and migration of existing files.

New format

{"actions":[{"type":"interval","before":null,"after":"{\"id\":0,\"start\":\"20240101T120000Z\",\"tags\":[\"foo\"]}"}]}
{"actions":[{"type":"config","before":null,"after":"journal.format = json"}]}

Changes

  • journal.format config key — empty (default) keeps legacy behavior; json enables new format
  • Format detection on startup (Journal::initialize):
    • Legacy format present + journal.format not set → warning on stderr with migration instructions
    • Legacy format present + journal.format=json → automatic in-place migration with stdout message
    • New format present → no action
  • loadJournal() — auto-detects format from the first non-empty line (txn: vs {) and dispatches to the appropriate parser; both formats remain readable at runtime
  • SerializationTransaction::toJson() / UndoAction::toJson() emit the new format; toString() retained for legacy writes
  • TransactionsFactory::parseJsonLine() — parses a single JSON transaction line using the existing json:: DOM library with correct unique_ptr<json::value> ownership to avoid leaks on bad input

Tests

Three new cases in test/undo.t: basic JSON format round-trip, legacy format warning, and legacy→JSON migration with post-migration undo verification.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 3 commits March 1, 2026 19:38
Co-authored-by: lauft <8539295+lauft@users.noreply.github.com>
- Add toJson() to UndoAction and Transaction for JSON serialization
- Add parseJsonLine() to TransactionsFactory for JSON parsing
- Modify Journal::initialize() to detect legacy format, warn or migrate
- Add _useJsonFormat field to Journal, used in endTransaction/popLastTransaction
- loadJournal() now auto-detects format from first non-empty line
- Add journal.format default to Rules
- Pass journal.format to journal.initialize() in init.cpp
- Add 3 new tests: JSON format, warning, and migration

Co-authored-by: lauft <8539295+lauft@users.noreply.github.com>
Co-authored-by: lauft <8539295+lauft@users.noreply.github.com>
Copilot AI changed the title [WIP] Add JSON line format support for undo data file Implement JSON line format for undo.data with opt-in migration Mar 1, 2026
Copilot finished work on behalf of lauft March 1, 2026 19:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants