Use TaskChampion 0.7.0, now via cxx instead of hand-rolled FFI (#3588)
TC 0.7.0 introduces a new `TaskData` type that maps to Taskwarrior's `Task` type more cleanly. It also introduces the idea of gathering lists of operations and "committing" them to a replica. A consequence of this change is that TaskChampion no longer automatically maintains dependency information, so Taskwarrior must do so, with its `TDB2::dependency_sync` method. This method does a very similar thing to what TaskChampion had been doing, so this is a shift of responsibility but not a major performance difference. Cxx is .. not great. It is missing a lot of useful things that make a general-purpose bridge impractical: - no support for trait objects - no support for `Option<T>` (https://github.com/dtolnay/cxx/issues/87) - no support for `Vec<Box<..>>` As a result, some creativity is required in writing the bridge, for example returning a `Vec<OptionTaskData>` from `all_task_data` to allow individual `TaskData` values to be "taken" from the vector. That said, Cxx is the current state-of-the-art, and does a good job of ensuring memory safety, at the cost of some slightly awkward APIs. Subsequent work can remove the "TDB2" layer and allow commands and other parts of Taskwarrior to interface directly with the `Replica`.
This commit is contained in:
committed by
GitHub
parent
0f96fd31bf
commit
4ff63a7960
28
src/TDB2.h
28
src/TDB2.h
@@ -30,25 +30,21 @@
|
||||
#include <FS.h>
|
||||
#include <Task.h>
|
||||
#include <stdio.h>
|
||||
#include <tc/Replica.h>
|
||||
#include <tc/WorkingSet.h>
|
||||
#include <taskchampion-cpp/lib.h>
|
||||
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
namespace tc {
|
||||
class Server;
|
||||
}
|
||||
|
||||
// TDB2 Class represents all the files in the task database.
|
||||
class TDB2 {
|
||||
public:
|
||||
static bool debug_mode;
|
||||
|
||||
TDB2();
|
||||
TDB2() = default;
|
||||
|
||||
void open_replica(const std::string &, bool create_if_missing);
|
||||
void add(Task &);
|
||||
@@ -79,18 +75,24 @@ class TDB2 {
|
||||
|
||||
void dump();
|
||||
|
||||
void sync(tc::Server server, bool avoid_snapshots);
|
||||
bool confirm_revert(struct tc::ffi::TCReplicaOpList);
|
||||
bool confirm_revert(rust::Vec<tc::Operation> &);
|
||||
|
||||
rust::Box<tc::Replica> &replica();
|
||||
|
||||
private:
|
||||
tc::Replica replica;
|
||||
std::optional<tc::WorkingSet> _working_set;
|
||||
std::optional<rust::Box<tc::Replica>> _replica;
|
||||
|
||||
// Cached information from the replica
|
||||
std::optional<rust::Box<tc::WorkingSet>> _working_set;
|
||||
std::optional<std::vector<Task>> _pending_tasks;
|
||||
std::optional<std::vector<Task>> _completed_tasks;
|
||||
void invalidate_cached_info();
|
||||
|
||||
// UUID -> Task containing all tasks modified in this invocation.
|
||||
std::map<std::string, Task> changes;
|
||||
|
||||
const tc::WorkingSet &working_set();
|
||||
static std::string option_string(std::string input);
|
||||
const rust::Box<tc::WorkingSet> &working_set();
|
||||
void maybe_add_undo_point(rust::Vec<tc::Operation> &);
|
||||
static void show_diff(const std::string &, const std::string &, const std::string &);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user