mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
TDB2 Conversion
- Migrated several commands over to use TDB2. Have to start somewhere.
This commit is contained in:
parent
e573801517
commit
1dc2257156
8 changed files with 49 additions and 49 deletions
31
src/TDB2.cpp
31
src/TDB2.cpp
|
@ -25,7 +25,7 @@
|
||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
//#include <iostream> // TODO Remove.
|
#include <iostream> // TODO Remove.
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <Color.h>
|
#include <Color.h>
|
||||||
#include <text.h>
|
#include <text.h>
|
||||||
|
@ -98,6 +98,13 @@ void TF2::add_task (const Task& task)
|
||||||
|
|
||||||
_tasks.push_back (task); // For subsequent queries
|
_tasks.push_back (task); // For subsequent queries
|
||||||
_added_tasks.push_back (task); // For commit/synch
|
_added_tasks.push_back (task); // For commit/synch
|
||||||
|
|
||||||
|
/*
|
||||||
|
int id = next_id ();
|
||||||
|
_I2U[id] = task.get ("uuid");
|
||||||
|
_U2I[task.get ("uuid")] = id;
|
||||||
|
*/
|
||||||
|
|
||||||
_dirty = true;
|
_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -237,6 +244,25 @@ void TF2::commit ()
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void TF2::commitUndo ()
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
for each _added_task
|
||||||
|
fprintf (file,
|
||||||
|
"time %u\nnew %s---\n",
|
||||||
|
(unsigned int) time (NULL),
|
||||||
|
after.composeF4 ().c_str ());
|
||||||
|
|
||||||
|
for each _modified_task
|
||||||
|
fprintf (file,
|
||||||
|
"time %u\nold %snew %s---\n",
|
||||||
|
(unsigned int) time (NULL),
|
||||||
|
before.composeF4 ().c_str (),
|
||||||
|
after.composeF4 ().c_str ());
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void TF2::load_tasks ()
|
void TF2::load_tasks ()
|
||||||
{
|
{
|
||||||
|
@ -451,6 +477,7 @@ void TDB2::add (const Task& task)
|
||||||
else
|
else
|
||||||
pending.add_task (task);
|
pending.add_task (task);
|
||||||
|
|
||||||
|
undo.add_task (task);
|
||||||
backlog.add_task (task);
|
backlog.add_task (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,7 +504,7 @@ void TDB2::commit ()
|
||||||
|
|
||||||
pending.commit ();
|
pending.commit ();
|
||||||
completed.commit ();
|
completed.commit ();
|
||||||
undo.commit ();
|
undo.commitUndo ();
|
||||||
backlog.commit ();
|
backlog.commit ();
|
||||||
synch_key.commit ();
|
synch_key.commit ();
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,7 @@ public:
|
||||||
void add_line (const std::string&);
|
void add_line (const std::string&);
|
||||||
void clear_lines ();
|
void clear_lines ();
|
||||||
void commit ();
|
void commit ();
|
||||||
|
void commitUndo ();
|
||||||
|
|
||||||
void load_tasks ();
|
void load_tasks ();
|
||||||
void load_lines ();
|
void load_lines ();
|
||||||
|
|
|
@ -48,17 +48,9 @@ CmdCount::CmdCount ()
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int CmdCount::execute (std::string& output)
|
int CmdCount::execute (std::string& output)
|
||||||
{
|
{
|
||||||
// Get all the tasks.
|
|
||||||
std::vector <Task> tasks;
|
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
|
||||||
handleRecurrence ();
|
|
||||||
context.tdb.load (tasks);
|
|
||||||
context.tdb.commit ();
|
|
||||||
context.tdb.unlock ();
|
|
||||||
|
|
||||||
// Apply filter.
|
// Apply filter.
|
||||||
std::vector <Task> filtered;
|
std::vector <Task> filtered;
|
||||||
filter (tasks, filtered);
|
filter (filtered);
|
||||||
|
|
||||||
// Find number of matching tasks. Skip recurring parent tasks.
|
// Find number of matching tasks. Skip recurring parent tasks.
|
||||||
int count = 0;
|
int count = 0;
|
||||||
|
|
|
@ -93,7 +93,6 @@ int CmdCustom::execute (std::string& output)
|
||||||
|
|
||||||
// Load the data.
|
// Load the data.
|
||||||
handleRecurrence ();
|
handleRecurrence ();
|
||||||
context.tdb2.commit ();
|
|
||||||
std::vector <Task> filtered;
|
std::vector <Task> filtered;
|
||||||
filter (filtered);
|
filter (filtered);
|
||||||
|
|
||||||
|
@ -177,6 +176,8 @@ int CmdCustom::execute (std::string& output)
|
||||||
rc = 1;
|
rc = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.tdb2.commit ();
|
||||||
|
|
||||||
output = out.str ();
|
output = out.str ();
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,17 +50,11 @@ CmdIDs::CmdIDs ()
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int CmdIDs::execute (std::string& output)
|
int CmdIDs::execute (std::string& output)
|
||||||
{
|
{
|
||||||
// Scan the pending tasks, applying any filter.
|
|
||||||
std::vector <Task> tasks;
|
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
|
||||||
handleRecurrence ();
|
|
||||||
context.tdb.load (tasks);
|
|
||||||
context.tdb.commit ();
|
|
||||||
context.tdb.unlock ();
|
|
||||||
|
|
||||||
// Apply filter.
|
// Apply filter.
|
||||||
|
handleRecurrence ();
|
||||||
std::vector <Task> filtered;
|
std::vector <Task> filtered;
|
||||||
filter (tasks, filtered);
|
filter (filtered);
|
||||||
|
context.tdb.commit ();
|
||||||
|
|
||||||
// Find number of matching tasks.
|
// Find number of matching tasks.
|
||||||
std::vector <int> ids;
|
std::vector <int> ids;
|
||||||
|
@ -87,15 +81,11 @@ CmdCompletionIds::CmdCompletionIds ()
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int CmdCompletionIds::execute (std::string& output)
|
int CmdCompletionIds::execute (std::string& output)
|
||||||
{
|
{
|
||||||
std::vector <Task> tasks;
|
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
|
||||||
context.tdb.loadPending (tasks);
|
|
||||||
context.tdb.commit ();
|
|
||||||
context.tdb.unlock ();
|
|
||||||
|
|
||||||
// Apply filter.
|
// Apply filter.
|
||||||
|
handleRecurrence ();
|
||||||
std::vector <Task> filtered;
|
std::vector <Task> filtered;
|
||||||
filter (tasks, filtered);
|
filter (filtered);
|
||||||
|
context.tdb.commit ();
|
||||||
|
|
||||||
std::vector <int> ids;
|
std::vector <int> ids;
|
||||||
std::vector <Task>::iterator task;
|
std::vector <Task>::iterator task;
|
||||||
|
@ -128,15 +118,11 @@ CmdZshCompletionIds::CmdZshCompletionIds ()
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int CmdZshCompletionIds::execute (std::string& output)
|
int CmdZshCompletionIds::execute (std::string& output)
|
||||||
{
|
{
|
||||||
std::vector <Task> tasks;
|
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
|
||||||
context.tdb.loadPending (tasks);
|
|
||||||
context.tdb.commit ();
|
|
||||||
context.tdb.unlock ();
|
|
||||||
|
|
||||||
// Apply filter.
|
// Apply filter.
|
||||||
|
handleRecurrence ();
|
||||||
std::vector <Task> filtered;
|
std::vector <Task> filtered;
|
||||||
filter (tasks, filtered);
|
filter (filtered);
|
||||||
|
context.tdb.commit ();
|
||||||
|
|
||||||
std::stringstream out;
|
std::stringstream out;
|
||||||
std::vector <Task>::iterator task;
|
std::vector <Task>::iterator task;
|
||||||
|
|
|
@ -81,16 +81,9 @@ int CmdStatistics::execute (std::string& output)
|
||||||
++undoCount;
|
++undoCount;
|
||||||
|
|
||||||
// Get all the tasks.
|
// Get all the tasks.
|
||||||
std::vector <Task> tasks;
|
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
|
||||||
handleRecurrence ();
|
|
||||||
context.tdb.load (tasks);
|
|
||||||
context.tdb.commit ();
|
|
||||||
context.tdb.unlock ();
|
|
||||||
|
|
||||||
// Apply filter.
|
|
||||||
std::vector <Task> filtered;
|
std::vector <Task> filtered;
|
||||||
filter (tasks, filtered);
|
filter (context.tdb2.pending.get_tasks (), filtered);
|
||||||
|
filter (context.tdb2.completed.get_tasks (), filtered);
|
||||||
|
|
||||||
Date now;
|
Date now;
|
||||||
time_t earliest = time (NULL);
|
time_t earliest = time (NULL);
|
||||||
|
|
|
@ -267,7 +267,7 @@ bool Command::displays_id () const
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Filter a specific list of tasks.
|
// Filter a specific list of tasks.
|
||||||
void Command::filter (std::vector <Task>& input, std::vector <Task>& output)
|
void Command::filter (const std::vector <Task>& input, std::vector <Task>& output)
|
||||||
{
|
{
|
||||||
context.timer_filter.start ();
|
context.timer_filter.start ();
|
||||||
|
|
||||||
|
@ -278,7 +278,7 @@ void Command::filter (std::vector <Task>& input, std::vector <Task>& output)
|
||||||
{
|
{
|
||||||
E9 e (filt);
|
E9 e (filt);
|
||||||
|
|
||||||
std::vector <Task>::iterator task;
|
std::vector <Task>::const_iterator task;
|
||||||
for (task = input.begin (); task != input.end (); ++task)
|
for (task = input.begin (); task != input.end (); ++task)
|
||||||
if (e.evalFilter (*task))
|
if (e.evalFilter (*task))
|
||||||
output.push_back (*task);
|
output.push_back (*task);
|
||||||
|
|
|
@ -53,7 +53,7 @@ public:
|
||||||
virtual int execute (std::string&) = 0;
|
virtual int execute (std::string&) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void filter (std::vector <Task>&, std::vector <Task>&);
|
void filter (const std::vector <Task>&, std::vector <Task>&);
|
||||||
void filter (std::vector <Task>&);
|
void filter (std::vector <Task>&);
|
||||||
bool filter_shortcut (const A3&);
|
bool filter_shortcut (const A3&);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue