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

Method add

src/TDB2.cpp:57–93  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////////// Add the new task to the replica.

Source from the content-addressed store, hash-verified

55////////////////////////////////////////////////////////////////////////////////
56// Add the new task to the replica.
57void TDB2::add(Task& task) {
58 // Ensure the task is consistent, and provide defaults if necessary.
59 // bool argument to validate() is "applyDefault", to apply default values for
60 // properties not otherwise given.
61 task.validate(true);
62
63 rust::Vec<tc::Operation> ops;
64 maybe_add_undo_point(ops);
65
66 auto uuid = task.get("uuid");
67 changes[uuid] = task;
68 tc::Uuid tcuuid = tc::uuid_from_string(uuid);
69
70 // run hooks for this new task
71 Context::getContext().hooks.onAdd(task);
72
73 auto taskdata = tc::create_task(tcuuid, ops);
74
75 // add the task attributes
76 for (auto& attr : task.all()) {
77 // TaskChampion does not store uuid or id in the task data
78 if (attr == "uuid" || attr == "id") {
79 continue;
80 }
81
82 taskdata->update(attr, task.get(attr), ops);
83 }
84 replica()->commit_operations(std::move(ops));
85
86 invalidate_cached_info();
87
88 // get the ID that was assigned to this task
89 auto id = working_set()->by_uuid(tcuuid);
90 if (id > 0) {
91 task.id = id;
92 }
93}
94
95////////////////////////////////////////////////////////////////////////////////
96// Modify the task in storage to match the given task.

Callers

nothing calls this directly

Calls 10

uuid_from_stringFunction · 0.85
create_taskFunction · 0.85
working_setFunction · 0.85
onAddMethod · 0.80
updateMethod · 0.80
commit_operationsMethod · 0.80
by_uuidMethod · 0.80
validateMethod · 0.45
getMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected