From 37e08df8ba0339375ba4b48c81dc0546d7ee005d Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Thu, 11 Jun 2009 21:17:30 -0400 Subject: [PATCH] Enhancements - TDB2::gc - Stubbed TDB2::gc. - Fixed broken tests Makefile - Added handleCustomReport call to Context dispatch. --- src/Context.cpp | 12 ++++++++---- src/TDB2.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ src/TDB2.h | 10 ++++++---- src/tests/Makefile | 4 ++-- 4 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index b1b1aa9e4..2d2e1145f 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -151,9 +151,12 @@ int Context::run () //////////////////////////////////////////////////////////////////////////////// std::string Context::dispatch () { + bool gc = true; // TODO Should be false for shadow file updates. + bool gcMod = false; // Change occurred by way of gc. bool cmdMod = false; // Change occurred by way of command type. std::string out; + /* // Read-only commands with no side effects. if (command == "export") { out = handleExport (); } @@ -192,18 +195,19 @@ std::string Context::dispatch () // Command that display IDs and therefore need TDB::gc first. /* - else if (command == "completed") { if (gc) gcMod = tdb.gc (); out = handleCompleted (); } + else if (command == "completed") { if (gc) gcMod = tdb.gc (); out = handleCompleted (); } // TODO OBSOLETE else if (command == "next") { if (gc) gcMod = tdb.gc (); out = handleReportNext (); } - else if (command == "active") { if (gc) gcMod = tdb.gc (); out = handleReportActive (); } - else if (command == "overdue") { if (gc) gcMod = tdb.gc (); out = handleReportOverdue (); } - else if (cmd.validCustom (command)) { if (gc) gcMod = tdb.gc (); out = handleCustomReport (command); } + else if (command == "active") { if (gc) gcMod = tdb.gc (); out = handleReportActive (); } // TODO OBSOLETE + else if (command == "overdue") { if (gc) gcMod = tdb.gc (); out = handleReportOverdue (); } // TODO OBSOLETE */ + else if (cmd.validCustom (cmd.command)) { if (gc) gcMod = tdb.gc (); out = handleCustomReport (cmd.command); } // If the command is not recognized, display usage. else { out = shortUsage (); } // Only update the shadow file if such an update was not suppressed (shadow), // and if an actual change occurred (gcMod || cmdMod). +// TODO // if (shadow && (gcMod || cmdMod)) // shadow (); diff --git a/src/TDB2.cpp b/src/TDB2.cpp index d80d9b452..1a231abfc 100644 --- a/src/TDB2.cpp +++ b/src/TDB2.cpp @@ -282,6 +282,46 @@ void TDB2::upgrade () throw std::string ("unimplemented TDB2::upgrade"); } +//////////////////////////////////////////////////////////////////////////////// +// Scans the pending tasks for any that are completed or deleted, and if so, +// moves them to the completed.data file. Returns a count of tasks moved. +int TDB2::gc () +{ + int count = 0; +/* + // Read everything from the pending file. + std::vector all; + allPendingT (all); + + // A list of the truly pending tasks. + std::vector pending; + + std::vector::iterator it; + for (it = all.begin (); it != all.end (); ++it) + { + // Some tasks stay in the pending file. + if (it->getStatus () == T::pending || + it->getStatus () == T::recurring) + { + pending.push_back (*it); + } + + // Others are transferred to the completed file. + else + { + writeCompleted (*it); + ++count; + } + } + + // Dump all clean tasks into pending. But don't bother unless at least one + // task was transferred. + if (count) + overwritePending (pending); +*/ + return count; +} + //////////////////////////////////////////////////////////////////////////////// FILE* TDB2::openAndLock (const std::string& file) { diff --git a/src/TDB2.h b/src/TDB2.h index 2b25da5df..bd099c442 100644 --- a/src/TDB2.h +++ b/src/TDB2.h @@ -52,10 +52,12 @@ public: int load (std::vector &, Filter&); int loadPending (std::vector &, Filter&); int loadCompleted (std::vector &, Filter&); - void add (Task&); - void update (Task&, Task&); - int commit (); - void upgrade (); + + void add (Task&); // Single task add to pending + void update (Task&, Task&); // Single task update to pending + int commit (); // Write out all tasks + void upgrade (); // Convert both files to FF4 + int gc (); // Clean up pending private: FILE* openAndLock (const std::string&); diff --git a/src/tests/Makefile b/src/tests/Makefile index 12557ea11..fc5ff9db1 100644 --- a/src/tests/Makefile +++ b/src/tests/Makefile @@ -3,11 +3,11 @@ PROJECT = t.t t2.t tdb.t date.t duration.t t.benchmark.t text.t autocomplete.t \ cmd.t config.t CFLAGS = -I. -I.. -Wall -pedantic -ggdb3 -fno-rtti LFLAGS = -L/usr/local/lib -lncurses -OBJECTS = ../TDB2.o ../T.o ../Task.o ../parse.o ../text.o ../Date.o ../Table.o \ +OBJECTS = ../TDB2.o ../T.o ../Task.o ../valid.o ../text.o ../Date.o ../Table.o \ ../Duration.o ../util.o ../Config.o ../Sequence.o ../Att.o ../Cmd.o \ ../Record.o ../StringTable.o ../Subst.o ../Nibbler.o ../Location.o \ ../Filter.o ../Context.o ../Keymap.o ../command.o ../interactive.o \ - ../report.o ../Grid.o ../color.o ../rules.o ../recur.o + ../report.o ../Grid.o ../color.o ../rules.o ../recur.o ../custom.o all: $(PROJECT)