mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-23 05:27:47 +02:00
Dependencies
- Fixed bug in Task::addDependency where a 'dup dep' error string was not properly composed, which cause the error message to be shown as 'k'. - Relocated expression evaluation on modification to only be processed for date attributes. This impacts DOM, but fixes more than it breaks. - Corrected unit test that was expecting an old-style error message. - Added protection against array overrun in next_mod_group. Again.
This commit is contained in:
parent
d1e52c05d6
commit
776bfea402
3 changed files with 21 additions and 18 deletions
|
@ -711,19 +711,20 @@ void Task::addDependency (int id)
|
||||||
if (id == this->id)
|
if (id == this->id)
|
||||||
throw std::string (STRING_TASK_DEPEND_ITSELF);
|
throw std::string (STRING_TASK_DEPEND_ITSELF);
|
||||||
|
|
||||||
// Check for extant dependency.
|
// Check that id is resolvable.
|
||||||
std::string uuid = context.tdb2.pending.uuid (id);
|
std::string uuid = context.tdb2.pending.uuid (id);
|
||||||
if (uuid == "")
|
if (uuid == "")
|
||||||
throw format (STRING_TASK_DEPEND_MISSING, id);
|
throw format (STRING_TASK_DEPEND_MISSING, id);
|
||||||
|
|
||||||
// Store the dependency.
|
// Store the dependency.
|
||||||
std::string depends = get ("depends");
|
std::string depends = get ("depends");
|
||||||
if (depends.length ())
|
if (depends != "")
|
||||||
{
|
{
|
||||||
|
// Check for extant dependency.
|
||||||
if (depends.find (uuid) == std::string::npos)
|
if (depends.find (uuid) == std::string::npos)
|
||||||
set ("depends", depends + "," + uuid);
|
set ("depends", depends + "," + uuid);
|
||||||
else
|
else
|
||||||
throw std::string (STRING_TASK_DEPEND_DUP, this->id, id);
|
throw format (STRING_TASK_DEPEND_DUP, this->id, id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
set ("depends", uuid);
|
set ("depends", uuid);
|
||||||
|
|
|
@ -426,21 +426,13 @@ void Command::modify_task (
|
||||||
A3::extract_attr (arg._raw, name, value);
|
A3::extract_attr (arg._raw, name, value);
|
||||||
if (A3::is_attribute (name, name)) // Canonicalize
|
if (A3::is_attribute (name, name)) // Canonicalize
|
||||||
{
|
{
|
||||||
// std::cout << "# Command::modify_task name='" << name << "' value='" << value << "'\n";
|
//std::cout << "# Command::modify_task name='" << name << "' value='" << value << "'\n";
|
||||||
|
|
||||||
// Get the column info.
|
// Get the column info.
|
||||||
Column* column = context.columns[name];
|
Column* column = context.columns[name];
|
||||||
|
|
||||||
// All values must be eval'd first.
|
|
||||||
A3 value_tokens;
|
|
||||||
value_tokens.capture (value);
|
|
||||||
value_tokens = value_tokens.postfix (value_tokens.tokenize (value_tokens));
|
|
||||||
|
|
||||||
E9 e (value_tokens);
|
if (value == "")
|
||||||
std::string result = e.evalExpression (task);
|
|
||||||
context.debug (std::string ("Eval '") + value + "' --> '" + result + "'");
|
|
||||||
|
|
||||||
if (result == "")
|
|
||||||
{
|
{
|
||||||
task.remove (name);
|
task.remove (name);
|
||||||
}
|
}
|
||||||
|
@ -451,7 +443,7 @@ void Command::modify_task (
|
||||||
{
|
{
|
||||||
// Convert ID to UUID.
|
// Convert ID to UUID.
|
||||||
std::vector <std::string> deps;
|
std::vector <std::string> deps;
|
||||||
split (deps, result, ',');
|
split (deps, value, ',');
|
||||||
|
|
||||||
// Apply or remove dendencies in turn.
|
// Apply or remove dendencies in turn.
|
||||||
std::vector <std::string>::iterator i;
|
std::vector <std::string>::iterator i;
|
||||||
|
@ -468,6 +460,15 @@ void Command::modify_task (
|
||||||
// Dates are special, maybe.
|
// Dates are special, maybe.
|
||||||
else if (column->type () == "date")
|
else if (column->type () == "date")
|
||||||
{
|
{
|
||||||
|
// All values must be eval'd first.
|
||||||
|
A3 value_tokens;
|
||||||
|
value_tokens.capture (value);
|
||||||
|
value_tokens = value_tokens.postfix (value_tokens.tokenize (value_tokens));
|
||||||
|
|
||||||
|
E9 e (value_tokens);
|
||||||
|
std::string result = e.evalExpression (task);
|
||||||
|
context.debug (std::string ("Eval '") + value + "' --> '" + result + "'");
|
||||||
|
|
||||||
// If the date value is less than 5 years, it is a duration, not a
|
// If the date value is less than 5 years, it is a duration, not a
|
||||||
// date, therefore add 'now'.
|
// date, therefore add 'now'.
|
||||||
long l = strtol (result.c_str (), NULL, 10);
|
long l = strtol (result.c_str (), NULL, 10);
|
||||||
|
@ -483,7 +484,7 @@ void Command::modify_task (
|
||||||
|
|
||||||
// By default, just add/remove it.
|
// By default, just add/remove it.
|
||||||
else
|
else
|
||||||
task.set (name, result);
|
task.set (name, value);
|
||||||
|
|
||||||
// Warn about deprecated/obsolete attribute usage.
|
// Warn about deprecated/obsolete attribute usage.
|
||||||
legacyAttributeCheck (name);
|
legacyAttributeCheck (name);
|
||||||
|
@ -572,8 +573,9 @@ bool Command::next_mod_group (const A3& input, Arg& arg, unsigned int& pos)
|
||||||
|
|
||||||
else if (arg._raw == "depends")
|
else if (arg._raw == "depends")
|
||||||
{
|
{
|
||||||
while (input[pos]._category == Arg::cat_op ||
|
while (pos < input.size () &&
|
||||||
input[pos]._type == Arg::type_number)
|
(input[pos]._category == Arg::cat_op ||
|
||||||
|
input[pos]._type == Arg::type_number))
|
||||||
{
|
{
|
||||||
arg._raw += input[pos++]._raw;
|
arg._raw += input[pos++]._raw;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ like ($output, qr/Could not create a dependency on task 99 - not found\./, 'depe
|
||||||
|
|
||||||
# [4]
|
# [4]
|
||||||
$output = qx{../src/task rc:dep.rc 99 modify dep:1};
|
$output = qx{../src/task rc:dep.rc 99 modify dep:1};
|
||||||
like ($output, qr/Task 99 not found\./, 'dependencies - add dependency to nonexistent task');
|
like ($output, qr/No tasks specified\./, 'dependencies - add dependency to nonexistent task');
|
||||||
|
|
||||||
# [5,6] t 1 dep:2; t info 1 => blocked by 2
|
# [5,6] t 1 dep:2; t info 1 => blocked by 2
|
||||||
$output = qx{../src/task rc:dep.rc 1 modify dep:2; ../src/task rc:dep.rc info 1};
|
$output = qx{../src/task rc:dep.rc 1 modify dep:2; ../src/task rc:dep.rc info 1};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue