Implement JSON line format for undo.data with opt-in migration#745
Draft
Implement JSON line format for undo.data with opt-in migration#745
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a JSON line format for
undo.datawhere each transaction is stored as a single JSON object per line, replacing the current multi-line text format. Migration is opt-in via a newjournal.formatconfig 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.formatconfig key — empty (default) keeps legacy behavior;jsonenables new formatJournal::initialize):journal.formatnot set → warning on stderr with migration instructionsjournal.format=json→ automatic in-place migration with stdout messageloadJournal()— auto-detects format from the first non-empty line (txn:vs{) and dispatches to the appropriate parser; both formats remain readable at runtimeTransaction::toJson()/UndoAction::toJson()emit the new format;toString()retained for legacy writesTransactionsFactory::parseJsonLine()— parses a single JSON transaction line using the existingjson::DOM library with correctunique_ptr<json::value>ownership to avoid leaks on bad inputTests
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.