From 67b2063809398ce068b323d45c494d2122f3b57a Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Sun, 7 Dec 2025 17:21:36 -1000 Subject: [PATCH] imp!:aregister, journal: same-day txns respect order of -f options If transactions on the same date are coming from two files specified with -f options, we expect them to be displayed in parse order, ie respecting the order of the -f options. This wasn't always the case, now it is. Also, transactions' tindex field is now unique across all files, where previously it started at 1 in each file. This affects hledger data generally, not just the aregister command. --- hledger-lib/Hledger/Read.hs | 6 +++++- hledger/test/aregister.test | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/hledger-lib/Hledger/Read.hs b/hledger-lib/Hledger/Read.hs index 0c6cd8fba..48912f8ea 100644 --- a/hledger-lib/Hledger/Read.hs +++ b/hledger-lib/Hledger/Read.hs @@ -167,6 +167,7 @@ import Hledger.Utils import Prelude hiding (getContents, writeFile) import Hledger.Data.JournalChecks (journalStrictChecks) import Text.Printf (printf) +import Hledger.Data.Journal (journalNumberTransactions) --- ** doctest setup -- $setup @@ -353,7 +354,10 @@ readJournalFiles iopts@InputOpts{strict_, new_, new_save_} prefixedfiles = do readJournalFilesAndLatestDates :: InputOpts -> [PrefixedFilePath] -> ExceptT String IO (Journal, [LatestDatesForFile]) readJournalFilesAndLatestDates iopts pfs = do (js, lastdates) <- unzip <$> mapM (readJournalFileAndLatestDates iopts) pfs - return (maybe def sconcat $ nonEmpty js, catMaybes lastdates) + -- Also renumber the concatenated transactions. In 1.51 and before, tindex restarted from 1 in each file. + -- Now we ensure tindex is unique across all files. This helps aregister preserve txns' parse order, + -- and with luck won't cause problems for anyone. + return (journalNumberTransactions $ maybe def sconcat $ nonEmpty js, catMaybes lastdates) -- | An easy version of 'readJournal' which assumes default options, and fails in the IO monad. readJournal' :: Handle -> IO Journal diff --git a/hledger/test/aregister.test b/hledger/test/aregister.test index 88882e6cc..de2c57d82 100644 --- a/hledger/test/aregister.test +++ b/hledger/test/aregister.test @@ -46,6 +46,7 @@ Transactions in assets:checking and subaccounts (matching query): # matching postings) then by parse order. (#1642) # Also, make sure to use the posting date of matching transactions, if it # differs from the transaction date. +# Also, parse order respects the order of -f options on command line (not tested here). < ~ 2021-01-03 sixth, because forecast transactions come after normal transactions (a) 6