mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
TDB2
- Now updates the task ID of any new task, therefore avoiding off-by-one errors that occur when code calls TDB2::next_id.
This commit is contained in:
parent
45e6512c02
commit
6faf6bb678
4 changed files with 11 additions and 14 deletions
19
src/TDB2.cpp
19
src/TDB2.cpp
|
@ -135,26 +135,23 @@ bool TF2::get (const std::string& uuid, Task& task)
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void TF2::add_task (const Task& task)
|
||||
void TF2::add_task (Task& task)
|
||||
{
|
||||
Task hookTask (task);
|
||||
context.hooks.onAdd (hookTask);
|
||||
context.hooks.onAdd (task);
|
||||
_tasks.push_back (task); // For subsequent queries
|
||||
_added_tasks.push_back (task); // For commit/synch
|
||||
|
||||
_tasks.push_back (hookTask); // For subsequent queries
|
||||
_added_tasks.push_back (hookTask); // For commit/synch
|
||||
|
||||
int id = task.id;
|
||||
Task::status status = task.getStatus ();
|
||||
if (id == 0 &&
|
||||
if (task.id == 0 &&
|
||||
(status == Task::pending ||
|
||||
status == Task::recurring ||
|
||||
status == Task::waiting))
|
||||
{
|
||||
id = context.tdb2.next_id ();
|
||||
task.id = context.tdb2.next_id ();
|
||||
}
|
||||
|
||||
_I2U[id] = task.get ("uuid");
|
||||
_U2I[task.get ("uuid")] = id;
|
||||
_I2U[task.id] = task.get ("uuid");
|
||||
_U2I[task.get ("uuid")] = task.id;
|
||||
|
||||
_dirty = true;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,7 @@ public:
|
|||
bool get (int, Task&);
|
||||
bool get (const std::string&, Task&);
|
||||
|
||||
void add_task (const Task&);
|
||||
void add_task (Task&);
|
||||
bool modify_task (const Task&);
|
||||
void add_line (const std::string&);
|
||||
void clear_tasks ();
|
||||
|
|
|
@ -55,7 +55,7 @@ int CmdAdd::execute (std::string& output)
|
|||
context.tdb2.add (task);
|
||||
|
||||
if (context.verbose ("new-id"))
|
||||
output += format (STRING_CMD_ADD_FEEDBACK, context.tdb2.next_id ()) + "\n";
|
||||
output += format (STRING_CMD_ADD_FEEDBACK, task.id) + "\n";
|
||||
else if (context.verbose ("new-uuid"))
|
||||
output += format (STRING_CMD_ADD_FEEDBACK, task.get ("uuid")) + "\n";
|
||||
|
||||
|
|
|
@ -110,7 +110,7 @@ int CmdDuplicate::execute (std::string& output)
|
|||
feedback_affected (STRING_CMD_DUPLICATE_TASK, *task);
|
||||
|
||||
if (context.verbose ("new-id"))
|
||||
std::cout << format (STRING_CMD_ADD_FEEDBACK, context.tdb2.next_id ()) + "\n";
|
||||
std::cout << format (STRING_CMD_ADD_FEEDBACK, dup.id) + "\n";
|
||||
else if (context.verbose ("new-uuid"))
|
||||
std::cout << format (STRING_CMD_ADD_FEEDBACK, dup.get ("uuid")) + "\n";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue