Task: Improved method signature

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

View file

@ -30,6 +30,9 @@
(thanks to Flavio Poletti). (thanks to Flavio Poletti).
- TW-1857 Change Task::get call to the more efficient Task::has - TW-1857 Change Task::get call to the more efficient Task::has
(thanks to Zachary Manning). (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 - TW-1873 Specify different path to extensions/hooks directory
(thanks to Eli). (thanks to Eli).
- TW-1878 uuids subcommand produces a space-delimited list, not comma-delimited - 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 Task::urgency_inherit () const
{ {
float v = FLT_MIN;
#ifdef PRODUCT_TASKWARRIOR
// Calling dependencyGetBlocked is rather expensive. // Calling dependencyGetBlocked is rather expensive.
// It is called recursively for each dependency in the chain here. // It is called recursively for each dependency in the chain here.
std::vector <Task> blocked; for (auto& task : dependencyGetBlocked (*this))
#ifdef PRODUCT_TASKWARRIOR
dependencyGetBlocked (*this, blocked);
#endif
float v = FLT_MIN;
for (auto& task : blocked)
{ {
// Find highest urgency in all blocked tasks. // Find highest urgency in all blocked tasks.
v = std::max (v, task.urgency ()); v = std::max (v, task.urgency ());
} }
#endif
return v; return v;
} }

View file

@ -170,17 +170,17 @@ private:
const std::string decode (const std::string&) const; const std::string decode (const std::string&) const;
public: public:
float urgency_project () const; float urgency_project () const;
float urgency_active () const; float urgency_active () const;
float urgency_scheduled () const; float urgency_scheduled () const;
float urgency_waiting () const; float urgency_waiting () const;
float urgency_blocked () const; float urgency_blocked () const;
float urgency_inherit () const; float urgency_inherit () const;
float urgency_annotations () const; float urgency_annotations () const;
float urgency_tags () const; float urgency_tags () const;
float urgency_due () const; float urgency_due () const;
float urgency_blocking () const; float urgency_blocking () const;
float urgency_age () const; float urgency_age () const;
}; };
#endif #endif

View file

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

View file

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

View file

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

View file

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

View file

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