From 2a5736b87618eb83222896befa35ddfcd257839c Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Fri, 24 Oct 2008 23:15:52 -0400 Subject: [PATCH] - TDB::gc now only calls overwritePending when something changed. - Removed TDB::gc calls from report.cpp. - Made TDB::gc calls from task.cpp whenever necessary. - Disabled TDB::gc calls when running a report for the sake of the shadow file. - Shadow file overwrite now implemented using ostream, instead of cout.rdbuf trickery, for the well-being of cygwin. --- src/TDB.cpp | 7 ++++-- src/report.cpp | 14 ----------- src/task.cpp | 68 ++++++++++++++++++++++++++------------------------ src/task.h | 4 +-- 4 files changed, 42 insertions(+), 51 deletions(-) diff --git a/src/TDB.cpp b/src/TDB.cpp index 5c65498b0..4e2c985f2 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -486,8 +486,11 @@ int TDB::gc () } } - // Dump all clean tasks into pending. - overwritePending (pending); + // Dump all clean tasks into pending. But don't bother unless at least one + // task was transferred. + if (count) + overwritePending (pending); + return count; } diff --git a/src/report.cpp b/src/report.cpp index 8d3339c58..2c61cbf43 100644 --- a/src/report.cpp +++ b/src/report.cpp @@ -127,7 +127,6 @@ std::string handleList (TDB& tdb, T& task, Config& conf) #endif // Get the pending tasks. - tdb.gc (); std::vector tasks; tdb.allPendingT (tasks); handleRecurrence (tdb, tasks); @@ -278,7 +277,6 @@ std::string handleSmallList (TDB& tdb, T& task, Config& conf) #endif // Get the pending tasks. - tdb.gc (); std::vector tasks; tdb.allPendingT (tasks); handleRecurrence (tdb, tasks); @@ -410,7 +408,6 @@ std::string handleCompleted (TDB& tdb, T& task, Config& conf) #endif // Get the pending tasks. - tdb.gc (); std::vector tasks; tdb.completedT (tasks); filter (tasks, task); @@ -700,7 +697,6 @@ std::string handleLongList (TDB& tdb, T& task, Config& conf) #endif // Get all the tasks. - tdb.gc (); std::vector tasks; tdb.allPendingT (tasks); handleRecurrence (tdb, tasks); @@ -864,7 +860,6 @@ std::string handleReportSummary (TDB& tdb, T& task, Config& conf) std::stringstream out; // Generate unique list of project names. - tdb.gc (); std::map allProjects; std::vector pending; tdb.allPendingT (pending); @@ -1040,7 +1035,6 @@ std::string handleReportNext (TDB& tdb, T& task, Config& conf) std::stringstream out; // Load all pending. - tdb.gc (); std::vector pending; tdb.allPendingT (pending); handleRecurrence (tdb, pending); @@ -1061,8 +1055,6 @@ std::string handleReportNext (TDB& tdb, T& task, Config& conf) } #endif - tdb.gc (); - // Get the pending tasks. std::vector tasks; tdb.pendingT (tasks); @@ -1223,7 +1215,6 @@ std::string handleReportHistory (TDB& tdb, T& task, Config& conf) std::map deletedGroup; // Scan the pending tasks. - tdb.gc (); std::vector pending; tdb.allPendingT (pending); handleRecurrence (tdb, pending); @@ -1423,7 +1414,6 @@ std::string handleReportGHistory (TDB& tdb, T& task, Config& conf) std::map deletedGroup; // Scan the pending tasks. - tdb.gc (); std::vector pending; tdb.allPendingT (pending); handleRecurrence (tdb, pending); @@ -1837,7 +1827,6 @@ std::string handleReportCalendar (TDB& tdb, T& task, Config& conf) std::stringstream out; // Load all the pending tasks. - tdb.gc (); std::vector pending; tdb.allPendingT (pending); handleRecurrence (tdb, pending); @@ -1939,7 +1928,6 @@ std::string handleReportActive (TDB& tdb, T& task, Config& conf) #endif // Get all the tasks. - tdb.gc (); std::vector tasks; tdb.pendingT (tasks); filter (tasks, task); @@ -2174,7 +2162,6 @@ std::string handleReportOldest (TDB& tdb, T& task, Config& conf) #endif // Get the pending tasks. - tdb.gc (); std::vector tasks; tdb.allPendingT (tasks); handleRecurrence (tdb, tasks); @@ -2323,7 +2310,6 @@ std::string handleReportNewest (TDB& tdb, T& task, Config& conf) #endif // Get the pending tasks. - tdb.gc (); std::vector tasks; tdb.allPendingT (tasks); handleRecurrence (tdb, tasks); diff --git a/src/task.cpp b/src/task.cpp index 9dbdb2b79..40a4a15a0 100644 --- a/src/task.cpp +++ b/src/task.cpp @@ -742,20 +742,22 @@ std::string runTaskCommand ( int argc, char** argv, TDB& tdb, - Config& conf) + Config& conf, + bool gc /* = true */) { std::vector args; for (int i = 1; i < argc; ++i) args.push_back (argv[i]); - return runTaskCommand (args, tdb, conf); + return runTaskCommand (args, tdb, conf, gc); } //////////////////////////////////////////////////////////////////////////////// std::string runTaskCommand ( std::vector & args, TDB& tdb, - Config& conf) + Config& conf, + bool gc /* = false */) { // If argc == 1 and the default.command configuration variable is set, // then use that, otherwise stick with argc/argv. @@ -774,36 +776,36 @@ std::string runTaskCommand ( std::string out = ""; - if (command == "add") handleAdd (tdb, task, conf); - else if (command == "projects") out = handleProjects (tdb, task, conf); - else if (command == "tags") out = handleTags (tdb, task, conf); - else if (command == "list") out = handleList (tdb, task, conf); - else if (command == "info") out = handleInfo (tdb, task, conf); - else if (command == "undelete") out = handleUndelete (tdb, task, conf); - else if (command == "long") out = handleLongList (tdb, task, conf); - else if (command == "ls") out = handleSmallList (tdb, task, conf); - else if (command == "colors") out = handleColor ( conf); - else if (command == "completed") out = handleCompleted (tdb, task, conf); - else if (command == "delete") out = handleDelete (tdb, task, conf); - else if (command == "start") out = handleStart (tdb, task, conf); - else if (command == "done") handleDone (tdb, task, conf); - else if (command == "undo") out = handleUndo (tdb, task, conf); - else if (command == "export") handleExport (tdb, task, conf); - else if (command == "version") out = handleVersion ( conf); - else if (command == "summary") out = handleReportSummary (tdb, task, conf); - else if (command == "next") out = handleReportNext (tdb, task, conf); - else if (command == "history") out = handleReportHistory (tdb, task, conf); - else if (command == "ghistory") out = handleReportGHistory (tdb, task, conf); - else if (command == "calendar") out = handleReportCalendar (tdb, task, conf); - else if (command == "active") out = handleReportActive (tdb, task, conf); - else if (command == "overdue") out = handleReportOverdue (tdb, task, conf); - else if (command == "oldest") out = handleReportOldest (tdb, task, conf); - else if (command == "newest") out = handleReportNewest (tdb, task, conf); - else if (command == "stats") out = handleReportStats (tdb, task, conf); - else if (command == "usage") out = handleReportUsage (tdb, task, conf); - else if (command == "" && task.getId ()) handleModify (tdb, task, conf); - else if (command == "help") longUsage (conf); - else shortUsage (conf); + if (command == "" && task.getId ()) { handleModify (tdb, task, conf); } + else if (command == "add") { handleAdd (tdb, task, conf); } + else if (command == "done") { handleDone (tdb, task, conf); } + else if (command == "export") { handleExport (tdb, task, conf); } + else if (command == "projects") { out = handleProjects (tdb, task, conf); } + else if (command == "tags") { out = handleTags (tdb, task, conf); } + else if (command == "info") { out = handleInfo (tdb, task, conf); } + else if (command == "undelete") { out = handleUndelete (tdb, task, conf); } + else if (command == "delete") { out = handleDelete (tdb, task, conf); } + else if (command == "start") { out = handleStart (tdb, task, conf); } + else if (command == "undo") { out = handleUndo (tdb, task, conf); } + else if (command == "stats") { out = handleReportStats (tdb, task, conf); } + else if (command == "usage") { out = handleReportUsage (tdb, task, conf); } + else if (command == "list") { if (gc) tdb.gc (); out = handleList (tdb, task, conf); } + else if (command == "long") { if (gc) tdb.gc (); out = handleLongList (tdb, task, conf); } + else if (command == "ls") { if (gc) tdb.gc (); out = handleSmallList (tdb, task, conf); } + else if (command == "completed") { if (gc) tdb.gc (); out = handleCompleted (tdb, task, conf); } + else if (command == "summary") { if (gc) tdb.gc (); out = handleReportSummary (tdb, task, conf); } + else if (command == "next") { if (gc) tdb.gc (); out = handleReportNext (tdb, task, conf); } + else if (command == "history") { if (gc) tdb.gc (); out = handleReportHistory (tdb, task, conf); } + else if (command == "ghistory") { if (gc) tdb.gc (); out = handleReportGHistory (tdb, task, conf); } + else if (command == "calendar") { if (gc) tdb.gc (); out = handleReportCalendar (tdb, task, conf); } + else if (command == "active") { if (gc) tdb.gc (); out = handleReportActive (tdb, task, conf); } + else if (command == "overdue") { if (gc) tdb.gc (); out = handleReportOverdue (tdb, task, conf); } + else if (command == "oldest") { if (gc) tdb.gc (); out = handleReportOldest (tdb, task, conf); } + else if (command == "newest") { if (gc) tdb.gc (); out = handleReportNewest (tdb, task, conf); } + else if (command == "colors") { out = handleColor ( conf); } + else if (command == "version") { out = handleVersion ( conf); } + else if (command == "help") { longUsage ( conf); } + else { shortUsage ( conf); } return out; } diff --git a/src/task.h b/src/task.h index 8bfb92f0c..f7d85c6a5 100644 --- a/src/task.h +++ b/src/task.h @@ -67,8 +67,8 @@ bool generateDueDates (T&, std::vector &); Date getNextRecurrence (Date&, std::string&); void updateRecurrenceMask (TDB&, std::vector &, T&); void onChangeCallback (); -std::string runTaskCommand (int, char**, TDB&, Config&); -std::string runTaskCommand (std::vector &, TDB&, Config&); +std::string runTaskCommand (int, char**, TDB&, Config&, bool gc = true); +std::string runTaskCommand (std::vector &, TDB&, Config&, bool gc = false); // command.cpp void handleAdd (TDB&, T&, Config&);