mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Filters
- Implemented Command::filter_shortcut to detect when a filter begins with "status:pending" and skip the loading/parsing of completed.data. - Removed obsolete att.t.cpp tests. - Removed diagnostics from TDB2::TDB2 that were causing a segfault. I suppose there is no std::cout available during global ctors?
This commit is contained in:
parent
424dc50a36
commit
3a5370ddf1
5 changed files with 44 additions and 10 deletions
|
@ -266,9 +266,6 @@ int Context::dispatch (std::string &out)
|
||||||
return c->execute (out);
|
return c->execute (out);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Need to invoke 'information' when a sequence/filter is present, but
|
|
||||||
// no command is specified.
|
|
||||||
|
|
||||||
return commands["help"]->execute (out);
|
return commands["help"]->execute (out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
src/TDB2.cpp
10
src/TDB2.cpp
|
@ -316,7 +316,6 @@ TDB2::TDB2 ()
|
||||||
: _location ("")
|
: _location ("")
|
||||||
, _id (1)
|
, _id (1)
|
||||||
{
|
{
|
||||||
std::cout << "# TDB2::TDB2\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -324,7 +323,6 @@ TDB2::TDB2 ()
|
||||||
// already called, if data is to be preserved.
|
// already called, if data is to be preserved.
|
||||||
TDB2::~TDB2 ()
|
TDB2::~TDB2 ()
|
||||||
{
|
{
|
||||||
std::cout << "# TDB2::~TDB2\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -387,6 +385,10 @@ void TDB2::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 TDB2::gc ()
|
int TDB2::gc ()
|
||||||
{
|
{
|
||||||
std::cout << "# TDB2::gc\n";
|
std::cout << "# TDB2::gc\n";
|
||||||
|
@ -407,6 +409,10 @@ int TDB2::gc ()
|
||||||
completed.remove
|
completed.remove
|
||||||
pending.add
|
pending.add
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// TODO Remove dangling dependencies
|
||||||
|
// TODO Wake up expired waiting tasks
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -297,7 +297,6 @@ void Command::filter (std::vector <Task>& output)
|
||||||
if (f.size ())
|
if (f.size ())
|
||||||
{
|
{
|
||||||
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
|
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
|
||||||
const std::vector <Task>& completed = context.tdb2.completed.get_tasks (); // TODO Optional
|
|
||||||
|
|
||||||
Expression e (f);
|
Expression e (f);
|
||||||
|
|
||||||
|
@ -307,9 +306,15 @@ void Command::filter (std::vector <Task>& output)
|
||||||
if (e.eval (*task))
|
if (e.eval (*task))
|
||||||
output.push_back (*task);
|
output.push_back (*task);
|
||||||
|
|
||||||
for (task = completed.begin (); task != completed.end (); ++task)
|
if (! filter_shortcut (f))
|
||||||
if (e.eval (*task))
|
{
|
||||||
output.push_back (*task);
|
const std::vector <Task>& completed = context.tdb2.completed.get_tasks (); // TODO Optional
|
||||||
|
for (task = completed.begin (); task != completed.end (); ++task)
|
||||||
|
if (e.eval (*task))
|
||||||
|
output.push_back (*task);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
context.debug ("Command::filter skipping completed.data");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -325,6 +330,31 @@ void Command::filter (std::vector <Task>& output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// If the filter contains the restriction "status:pending", as the first filter
|
||||||
|
// term, then completed.data does not need to be loaded.
|
||||||
|
bool Command::filter_shortcut (const Arguments& filter)
|
||||||
|
{
|
||||||
|
/**/
|
||||||
|
if (filter.size () >= 3)
|
||||||
|
{
|
||||||
|
std::cout << "# filter[0] " << filter[0]._first << "\n"
|
||||||
|
<< "# filter[1] " << filter[1]._first << "\n"
|
||||||
|
<< "# filter[2] " << filter[2]._first << "\n";
|
||||||
|
}
|
||||||
|
/**/
|
||||||
|
|
||||||
|
// Postfix: <status> <"pending"> <=>
|
||||||
|
// 0 1 2
|
||||||
|
if (filter.size () >= 3 &&
|
||||||
|
filter[0]._first == "status" &&
|
||||||
|
filter[1]._first.find ("pending") != std::string::npos &&
|
||||||
|
filter[2]._first == "=")
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Apply the modifications in arguments to the task.
|
// Apply the modifications in arguments to the task.
|
||||||
void Command::modify_task_description_replace (Task& task, Arguments& arguments)
|
void Command::modify_task_description_replace (Task& task, Arguments& arguments)
|
||||||
|
|
|
@ -55,6 +55,7 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void filter (std::vector <Task>&, std::vector <Task>&);
|
void filter (std::vector <Task>&, std::vector <Task>&);
|
||||||
void filter (std::vector <Task>&);
|
void filter (std::vector <Task>&);
|
||||||
|
bool filter_shortcut (const Arguments&);
|
||||||
|
|
||||||
void modify_task_description_replace (Task&, Arguments&);
|
void modify_task_description_replace (Task&, Arguments&);
|
||||||
void modify_task_description_prepend (Task&, Arguments&);
|
void modify_task_description_prepend (Task&, Arguments&);
|
||||||
|
|
|
@ -34,7 +34,7 @@ Context context;
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
int main (int argc, char** argv)
|
int main (int argc, char** argv)
|
||||||
{
|
{
|
||||||
UnitTest t (121);
|
UnitTest t (118);
|
||||||
|
|
||||||
Att a;
|
Att a;
|
||||||
t.notok (a.valid ("name"), "Att::valid name -> fail");
|
t.notok (a.valid ("name"), "Att::valid name -> fail");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue