MCPcopy Create free account
hub / github.com/GothenburgBitFactory/taskwarrior / importSingleTask

Method importSingleTask

src/commands/CmdImport.cpp:174–226  ·  view source on GitHub ↗

///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

172
173////////////////////////////////////////////////////////////////////////////////
174void CmdImport::importSingleTask(json::object* obj) {
175 // Parse the whole thing, validate the data.
176 Task task(obj);
177
178 // An empty task is probably not intentional - at least a UUID should be included.
179 if (task.is_empty()) throw format("Cannot import an empty task.");
180
181 auto hasGeneratedEntry = not task.has("entry");
182 auto hasExplicitEnd = task.has("end");
183
184 task.validate();
185
186 auto hasGeneratedEnd = not hasExplicitEnd and task.has("end");
187
188 // Check whether the imported task is new or a modified existing task.
189 Task before;
190 auto uuid = task.get("uuid");
191 uuid_occurrences[uuid]++;
192 if (Context::getContext().tdb2.get(uuid, before)) {
193 // We need to neglect updates from attributes with dynamic defaults
194 // unless they have been explicitly specified on import.
195 //
196 // There are three attributes with dynamic defaults, besides uuid:
197 // - modified: Ignored in any case.
198 // - entry: Ignored if generated.
199 // - end: Ignored if generated.
200
201 // The 'modified' attribute is ignored in any case, since if it
202 // were the only difference between the tasks, it would have been
203 // neglected anyway, since it is bumped on each modification.
204 task.set("modified", before.get("modified"));
205
206 // Other generated values are replaced by values from existing task,
207 // so that they are ignored on comparison.
208 if (hasGeneratedEntry) task.set("entry", before.get("entry"));
209
210 if (hasGeneratedEnd) task.set("end", before.get("end"));
211
212 if (before != task) {
213 CmdModify modHelper;
214 modHelper.checkConsistency(before, task);
215 modHelper.modifyAndUpdate(before, task);
216 std::cout << " mod ";
217 } else {
218 std::cout << " skip ";
219 }
220 } else {
221 Context::getContext().tdb2.add(task);
222 std::cout << " add ";
223 }
224
225 std::cout << task.get("uuid") << ' ' << task.get("description") << '\n';
226}
227
228////////////////////////////////////////////////////////////////////////////////

Callers

nothing calls this directly

Calls 8

setMethod · 0.80
checkConsistencyMethod · 0.80
modifyAndUpdateMethod · 0.80
is_emptyMethod · 0.45
hasMethod · 0.45
validateMethod · 0.45
getMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected