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:
Dustin J. Mitchell
2024-08-10 22:06:00 -04:00
committed by GitHub
parent 0f96fd31bf
commit 4ff63a7960
59 changed files with 1531 additions and 7631 deletions

View File

@@ -31,7 +31,7 @@
#include <JSON.h>
#include <Table.h>
#include <stdio.h>
#include <tc/Task.h>
#include <taskchampion-cpp/lib.h>
#include <time.h>
#include <map>
@@ -66,7 +66,7 @@ class Task {
bool operator!=(const Task&);
Task(const std::string&);
Task(const json::object*);
Task(tc::Task);
Task(rust::Box<tc::TaskData>);
void parse(const std::string&);
std::string composeJSON(bool decorate = false) const;
@@ -88,8 +88,6 @@ class Task {
// Series of helper functions.
static status textToStatus(const std::string&);
static std::string statusToText(status);
static tc::Status status2tc(const Task::status);
static Task::status tc2status(const tc::Status);
void setAsNow(const std::string&);
bool has(const std::string&) const;
@@ -186,7 +184,7 @@ class Task {
int determineVersion(const std::string&);
void parseJSON(const std::string&);
void parseJSON(const json::object*);
void parseTC(const tc::Task&);
void parseTC(rust::Box<tc::TaskData>);
void parseLegacy(const std::string&);
void validate_before(const std::string&, const std::string&);
const std::string encode(const std::string&) const;