- Converted 'append' to TDB2.
This commit is contained in:
Paul Beckingham 2011-08-30 17:30:40 -04:00
parent 402f1f1b41
commit 40724e120e

View file

@ -54,14 +54,9 @@ int CmdAppend::execute (std::string& output)
int count = 0; int count = 0;
std::stringstream out; std::stringstream out;
std::vector <Task> tasks;
context.tdb.lock (context.config.getBoolean ("locking"));
context.tdb.loadPending (tasks);
// Apply filter. // Apply filter.
std::vector <Task> filtered; std::vector <Task> filtered;
filter (tasks, filtered); filter (filtered);
if (filtered.size () == 0) if (filtered.size () == 0)
{ {
context.footnote (STRING_FEEDBACK_NO_TASKS_SP); context.footnote (STRING_FEEDBACK_NO_TASKS_SP);
@ -77,55 +72,51 @@ int CmdAppend::execute (std::string& output)
if (filtered.size () > (size_t) context.config.getInteger ("bulk")) if (filtered.size () > (size_t) context.config.getInteger ("bulk"))
permission.bigSequence (); permission.bigSequence ();
// A non-zero value forces a file write.
int changes = 0;
std::vector <Task>::iterator task; std::vector <Task>::iterator task;
for (task = filtered.begin (); task != filtered.end (); ++task) for (task = filtered.begin (); task != filtered.end (); ++task)
{ {
modify_task_description_append (*task, modifications); modify_task_description_append (*task, modifications);
apply_defaults (*task); apply_defaults (*task);
++changes;
context.tdb2.modify (*task);
std::vector <Task>::iterator other; std::vector <Task> siblings = context.tdb2.siblings (*task);
for (other = tasks.begin (); other != tasks.end (); ++other) std::vector <Task>::iterator sibling;
for (sibling = siblings.begin (); sibling != siblings.end (); ++sibling)
{ {
if (other->id == task->id || // Self Task before (*sibling);
(task->has ("parent") &&
task->get ("parent") == other->get ("parent")) || // Sibling // Apply other deltas.
other->get ("uuid") == task->get ("parent")) // Parent modify_task_description_append (*sibling, modifications);
apply_defaults (*sibling);
++changes;
if (taskDiff (before, *sibling))
{ {
Task before (*other); // Only allow valid tasks.
sibling->validate ();
// A non-zero value forces a file write. if (changes && permission.confirmed (before, taskDifferences (before, *sibling) + "Proceed with change?"))
int changes = 0;
// Apply other deltas.
modify_task_description_append (*other, modifications);
apply_defaults (*other);
++changes;
if (taskDiff (before, *other))
{ {
// Only allow valid tasks. context.tdb2.modify (*sibling);
other->validate ();
if (changes && permission.confirmed (before, taskDifferences (before, *other) + "Proceed with change?")) if (context.config.getBoolean ("echo.command"))
{ out << format (STRING_CMD_APPEND_DONE, sibling->id)
context.tdb.update (*other); << "\n";
if (context.config.getBoolean ("echo.command")) if (before.get ("project") != sibling->get ("project"))
out << format (STRING_CMD_APPEND_DONE, other->id) context.footnote (onProjectChange (before, *sibling));
<< "\n";
if (before.get ("project") != other->get ("project")) ++count;
context.footnote (onProjectChange (before, *other));
++count;
}
} }
} }
} }
} }
context.tdb.commit (); context.tdb2.commit ();
context.tdb.unlock ();
if (context.config.getBoolean ("echo.command")) if (context.config.getBoolean ("echo.command"))
out << format ((count == 1 out << format ((count == 1