Task: Improved method signature

This commit is contained in:
Paul Beckingham 2016-12-31 16:33:39 -05:00
parent 245ed39b78
commit b0a4a409a6
8 changed files with 40 additions and 48 deletions

View file

@ -30,6 +30,9 @@
(thanks to Flavio Poletti).
- TW-1857 Change Task::get call to the more efficient Task::has
(thanks to Zachary Manning).
- TW1858 Change signature for dependencyGetBlocked
- TW-1859 Change signature of Task::getTags
- TW-1860 Change signature of Task::getAnnotations
- TW-1873 Specify different path to extensions/hooks directory
(thanks to Eli).
- TW-1878 uuids subcommand produces a space-delimited list, not comma-delimited

View file

@ -1865,19 +1865,16 @@ float Task::urgency ()
////////////////////////////////////////////////////////////////////////////////
float Task::urgency_inherit () const
{
float v = FLT_MIN;
#ifdef PRODUCT_TASKWARRIOR
// Calling dependencyGetBlocked is rather expensive.
// It is called recursively for each dependency in the chain here.
std::vector <Task> blocked;
#ifdef PRODUCT_TASKWARRIOR
dependencyGetBlocked (*this, blocked);
#endif
float v = FLT_MIN;
for (auto& task : blocked)
for (auto& task : dependencyGetBlocked (*this))
{
// Find highest urgency in all blocked tasks.
v = std::max (v, task.urgency ());
}
#endif
return v;
}

View file

@ -78,17 +78,14 @@ void ColumnDepends::measure (Task& task, unsigned int& minimum, unsigned int& ma
else if (_style == "count")
{
std::vector <Task> blocking;
dependencyGetBlocking (task, blocking);
minimum = maximum = 2 + format ((int) blocking.size ()).length ();
minimum = maximum = 2 + format ((int) dependencyGetBlocking (task).size ()).length ();
}
else if (_style == "default" ||
_style == "list")
{
minimum = maximum = 0;
std::vector <Task> blocking;
dependencyGetBlocking (task, blocking);
auto blocking = dependencyGetBlocking (task);
std::vector <int> blocking_ids;
for (auto& i : blocking)
@ -126,17 +123,13 @@ void ColumnDepends::render (
else if (_style == "count")
{
std::vector <Task> blocking;
dependencyGetBlocking (task, blocking);
renderStringRight (lines, width, color, '[' + format (static_cast <int>(blocking.size ())) + ']');
renderStringRight (lines, width, color, '[' + format (static_cast <int>(dependencyGetBlocking (task).size ())) + ']');
}
else if (_style == "default" ||
_style == "list")
{
std::vector <Task> blocking;
dependencyGetBlocking (task, blocking);
auto blocking = dependencyGetBlocking (task);
std::vector <int> blocking_ids;
for (const auto& t : blocking)

View file

@ -160,8 +160,7 @@ int CmdInfo::execute (std::string& output)
// dependencies: blocked
{
std::vector <Task> blocked;
dependencyGetBlocking (task, blocked);
auto blocked = dependencyGetBlocking (task);
if (blocked.size ())
{
std::stringstream message;
@ -176,8 +175,7 @@ int CmdInfo::execute (std::string& output)
// dependencies: blocking
{
std::vector <Task> blocking;
dependencyGetBlocked (task, blocking);
auto blocking = dependencyGetBlocked (task);
if (blocking.size ())
{
std::stringstream message;

View file

@ -38,29 +38,35 @@
extern Context context;
////////////////////////////////////////////////////////////////////////////////
void dependencyGetBlocked (const Task& task, std::vector <Task>& blocked)
std::vector <Task> dependencyGetBlocked (const Task& task)
{
std::string uuid = task.get ("uuid");
auto all = context.tdb2.pending.get_tasks ();
for (auto& it : all)
std::vector <Task> blocked;
for (auto& it : context.tdb2.pending.get_tasks ())
if (it.getStatus () != Task::completed &&
it.getStatus () != Task::deleted &&
it.has ("depends") &&
it.get ("depends").find (uuid) != std::string::npos)
blocked.push_back (it);
return blocked;
}
////////////////////////////////////////////////////////////////////////////////
void dependencyGetBlocking (const Task& task, std::vector <Task>& blocking)
std::vector <Task> dependencyGetBlocking (const Task& task)
{
std::string depends = task.get ("depends");
std::vector <Task> blocking;
if (depends != "")
for (auto& it : context.tdb2.pending.get_tasks ())
if (it.getStatus () != Task::completed &&
it.getStatus () != Task::deleted &&
depends.find (it.get ("uuid")) != std::string::npos)
blocking.push_back (it);
return blocking;
}
////////////////////////////////////////////////////////////////////////////////
@ -145,14 +151,12 @@ bool dependencyIsCircular (const Task& task)
//
void dependencyChainOnComplete (Task& task)
{
std::vector <Task> blocking;
dependencyGetBlocking (task, blocking);
auto blocking = dependencyGetBlocking (task);
// If the task is anything but the tail end of a dependency chain.
if (blocking.size ())
{
std::vector <Task> blocked;
dependencyGetBlocked (task, blocked);
auto blocked = dependencyGetBlocked (task);
// Nag about broken chain.
if (context.config.getBoolean ("dependency.reminder"))
@ -205,8 +209,7 @@ void dependencyChainOnStart (Task& task)
{
if (context.config.getBoolean ("dependency.reminder"))
{
std::vector <Task> blocking;
dependencyGetBlocking (task, blocking);
auto blocking = dependencyGetBlocking (task);
// If the task is anything but the tail end of a dependency chain, nag about
// broken chain.

View file

@ -381,14 +381,12 @@ void feedback_unblocked (const Task& task)
if (context.verbose ("affected"))
{
// Get a list of tasks that depended on this task.
std::vector <Task> blocked;
dependencyGetBlocked (task, blocked);
auto blocked = dependencyGetBlocked (task);
// Scan all the tasks that were blocked by this task
for (auto& i : blocked)
{
std::vector <Task> blocking;
dependencyGetBlocking (i, blocking);
auto blocking = dependencyGetBlocking (i);
if (blocking.size () == 0)
{
if (i.id)

View file

@ -52,8 +52,8 @@ std::string colorizeError (const std::string&);
std::string colorizeDebug (const std::string&);
// dependency.cpp
void dependencyGetBlocked (const Task&, std::vector <Task>&);
void dependencyGetBlocking (const Task&, std::vector <Task>&);
std::vector <Task> dependencyGetBlocked (const Task&);
std::vector <Task> dependencyGetBlocking (const Task&);
bool dependencyIsCircular (const Task&);
void dependencyChainOnComplete (Task&);
void dependencyChainOnStart (Task&);