/////////////////////////////////////////////////////////////////////////// Determine whether a dependency chain is being broken, assuming that 'task' is either completed or deleted. blocked task blocking action ------- ---- -------- ----------------------------- [1] 2 Chain broken Nag message generated Repair offered: 1 dep:-2 [1] 2 Chain broken 3 Nag message generated R
| 111 | // 4 dep:3,5 |
| 112 | // |
| 113 | void dependencyChainOnComplete(Task& task) { |
| 114 | auto blocking = task.getDependencyTasks(); |
| 115 | |
| 116 | // If the task is anything but the tail end of a dependency chain. |
| 117 | if (blocking.size()) { |
| 118 | auto blocked = task.getBlockedTasks(); |
| 119 | |
| 120 | // Nag about broken chain. |
| 121 | if (Context::getContext().config.getBoolean("dependency.reminder")) { |
| 122 | std::cout << format(STRING_DEPEND_BLOCKED, task.identifier()) << '\n'; |
| 123 | |
| 124 | for (const auto& b : blocking) |
| 125 | std::cout << " " << b.id << ' ' << b.get("description") << '\n'; |
| 126 | } |
| 127 | |
| 128 | // If there are both blocking and blocked tasks, the chain is broken. |
| 129 | if (blocked.size()) { |
| 130 | if (Context::getContext().config.getBoolean("dependency.reminder")) { |
| 131 | std::cout << "and is blocking:\n"; |
| 132 | |
| 133 | for (const auto& b : blocked) |
| 134 | std::cout << " " << b.id << ' ' << b.get("description") << '\n'; |
| 135 | } |
| 136 | |
| 137 | if (!Context::getContext().config.getBoolean("dependency.confirmation") || |
| 138 | confirm("Would you like the dependency chain fixed?")) { |
| 139 | // Repair the chain - everything in blocked should now depend on |
| 140 | // everything in blocking, instead of task.id. |
| 141 | for (auto& left : blocked) { |
| 142 | left.removeDependency(task.id); |
| 143 | |
| 144 | for (const auto& right : blocking) left.addDependency(right.id); |
| 145 | } |
| 146 | |
| 147 | // Now update TDB2, now that the updates have all occurred. |
| 148 | for (auto& left : blocked) Context::getContext().tdb2.modify(left); |
| 149 | |
| 150 | for (auto& right : blocking) Context::getContext().tdb2.modify(right); |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | //////////////////////////////////////////////////////////////////////////////// |
| 157 | void dependencyChainOnStart(Task& task) { |
no test coverage detected