From 4209c156df58d9f5fc2eca304b7170ed06497b92 Mon Sep 17 00:00:00 2001 From: Ada Fernsby Date: Mon, 9 Mar 2026 16:30:00 +0000 Subject: [PATCH] chore: the quarterly tidy-up One commit that adds, deletes, renames, copies, chmods and adds a binary, so every extended header git can emit appears in a single patch. Signed-off-by: Ada Fernsby Reviewed-by: Priya Raman --- internal/ledger/rounding.go | 17 +++++++++++++++++ scripts/legacy-import.sh | 6 ------ docs/{README.md => guide.md} | 0 internal/ledger/{apply.go => apply_strict.go} | 4 ++-- scripts/release.sh | 1 + assets/badge.png | Bin 0 -> 89 bytes 6 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 internal/ledger/rounding.go delete mode 100755 scripts/legacy-import.sh rename docs/{README.md => guide.md} (100%) copy internal/ledger/{apply.go => apply_strict.go} (85%) mode change 100644 => 100755 scripts/release.sh create mode 100644 assets/badge.png diff --git a/internal/ledger/rounding.go b/internal/ledger/rounding.go new file mode 100644 index 0000000..d6f0c19 --- /dev/null +++ b/internal/ledger/rounding.go @@ -0,0 +1,17 @@ +package ledger + +// HalfEven rounds a minor-unit amount to the nearest multiple of step using +// banker's rounding, which keeps long runs of postings from drifting upward. +func HalfEven(minor, step int64) int64 { + if step <= 1 { + return minor + } + q, r := minor/step, minor%step + switch { + case 2*r > step: + q++ + case 2*r == step && q%2 != 0: + q++ + } + return q * step +} diff --git a/scripts/legacy-import.sh b/scripts/legacy-import.sh deleted file mode 100755 index 23a30ff..0000000 --- a/scripts/legacy-import.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -# Imports the 2019 CSV exports. Superseded by cmd/import; kept only for the cutover. -set -eu -for f in exports/*.csv; do - echo "importing $f" -done diff --git a/docs/README.md b/docs/guide.md similarity index 100% rename from docs/README.md rename to docs/guide.md diff --git a/internal/ledger/apply.go b/internal/ledger/apply_strict.go similarity index 85% copy from internal/ledger/apply.go copy to internal/ledger/apply_strict.go index 95f499d..3211ad6 100644 --- a/internal/ledger/apply.go +++ b/internal/ledger/apply_strict.go @@ -5,8 +5,8 @@ // ErrShortBalance is returned when a posting would drive the balance negative. var ErrShortBalance = errors.New("ledger: insufficient balance") -// Apply posts one delta against the running balance and returns the new total. -func Apply(balance, delta int64) (int64, error) { +// ApplyStrict posts one delta against the running balance and returns the new total. +func ApplyStrict(balance, delta int64) (int64, error) { if balance+delta < 0 { return balance, ErrShortBalance } diff --git a/scripts/release.sh b/scripts/release.sh old mode 100644 new mode 100755 index 16ecf13..624d539 --- a/scripts/release.sh +++ b/scripts/release.sh @@ -1,4 +1,5 @@ #!/bin/sh set -eu VERSION="$1" +test -n "$VERSION" || { echo "usage: release.sh " >&2; exit 2; } echo "tagging $VERSION" diff --git a/assets/badge.png b/assets/badge.png new file mode 100644 index 0000000000000000000000000000000000000000..4fa7b303b313728a89f1da712cd8110ebc839c4e GIT binary patch literal 89 zcmeAS@N?(olHy`uVBq!ia0vp^93afW1SGw4HSYi^1y2{pkcwN$0T&7x7iIU`F$fyX lW?as)OrWJVx{0rhfx$c>o$;VxlP*v#gQu&X%Q~loCIB;-6+8d{ literal 0 HcmV?d00001 -- 2.43.0