mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Dependencies
- Added TDB::gc code to remove dangling dependencies.
This commit is contained in:
parent
cade134f40
commit
b050d67ba9
3 changed files with 38 additions and 9 deletions
22
src/TDB.cpp
22
src/TDB.cpp
|
@ -569,6 +569,7 @@ int TDB::commit ()
|
|||
// 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.
|
||||
// Now reverts expired waiting tasks to pending.
|
||||
// Now cleans up dangling dependencies.
|
||||
int TDB::gc ()
|
||||
{
|
||||
Timer t ("TDB::gc");
|
||||
|
@ -589,6 +590,27 @@ int TDB::gc ()
|
|||
std::vector <Task> ignore;
|
||||
loadPending (ignore, filter);
|
||||
|
||||
// Search for dangling dependencies. These are dependencies whose uuid cannot
|
||||
// be converted to an id by TDB.
|
||||
std::vector <std::string> deps;
|
||||
foreach (task, mPending)
|
||||
{
|
||||
if (task->has ("depends"))
|
||||
{
|
||||
deps.clear ();
|
||||
task->getDependencies (deps);
|
||||
foreach (dep, deps)
|
||||
if (id (*dep) == 0)
|
||||
{
|
||||
task->removeDependency (*dep);
|
||||
context.debug ("GC: Removed dangling dependency "
|
||||
+ *dep
|
||||
+ " from "
|
||||
+ task->get ("uuid"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now move completed and deleted tasks from the pending list to the
|
||||
// completed list. Isn't garbage collection easy?
|
||||
std::vector <Task> still_pending;
|
||||
|
|
24
src/Task.cpp
24
src/Task.cpp
|
@ -495,16 +495,8 @@ void Task::addDependency (int id)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Task::removeDependency (int id)
|
||||
void Task::removeDependency (const std::string& uuid)
|
||||
{
|
||||
std::string uuid = context.tdb.uuid (id);
|
||||
if (uuid == "")
|
||||
{
|
||||
std::stringstream s;
|
||||
s << "Could not find a UUID for id " << id << ".";
|
||||
throw s.str ();
|
||||
}
|
||||
|
||||
std::vector <std::string> deps;
|
||||
split (deps, get ("depends"), ',');
|
||||
|
||||
|
@ -519,6 +511,20 @@ void Task::removeDependency (int id)
|
|||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Task::removeDependency (int id)
|
||||
{
|
||||
std::string uuid = context.tdb.uuid (id);
|
||||
if (uuid != "")
|
||||
removeDependency (uuid);
|
||||
else
|
||||
{
|
||||
std::stringstream s;
|
||||
s << "Could not find a UUID for id " << id << ".";
|
||||
throw s.str ();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Task::getDependencies (std::vector <int>& all) const
|
||||
{
|
||||
|
|
|
@ -75,6 +75,7 @@ public:
|
|||
|
||||
void addDependency (int);
|
||||
void removeDependency (int);
|
||||
void removeDependency (const std::string&);
|
||||
void getDependencies (std::vector <int>&) const;
|
||||
void getDependencies (std::vector <std::string>&) const;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue