Use Taskchampion to store Taskwarrior data

This replaces the TF2 task files with a TaskChampion replica.
This commit is contained in:
Dustin J. Mitchell 2022-12-15 02:52:47 +00:00 committed by Dustin J. Mitchell
parent 4b814bc602
commit 5bb9857984
24 changed files with 537 additions and 1362 deletions

View file

@ -35,71 +35,8 @@
#include <stdio.h>
#include <FS.h>
#include <Task.h>
// TF2 Class represents a single file in the task database.
class TF2
{
public:
TF2 ();
~TF2 ();
void target (const std::string&);
const std::vector <Task>& get_tasks ();
const std::vector <std::string>& get_lines ();
bool get (int, Task&);
bool get (const std::string&, Task&);
bool has (const std::string&);
void add_task (Task&);
bool modify_task (const Task&);
bool purge_task (const Task&);
void add_line (const std::string&);
void clear_tasks ();
void clear_lines ();
void commit ();
Task load_task (const std::string&);
void load_gc (Task&);
void load_tasks (bool from_gc = false);
void load_lines ();
// ID <--> UUID mapping.
std::string uuid (int);
int id (const std::string&);
void has_ids ();
void auto_dep_scan ();
void clear ();
const std::string dump ();
void dependency_scan ();
bool _read_only;
bool _dirty;
bool _loaded_tasks;
bool _loaded_lines;
bool _has_ids;
bool _auto_dep_scan;
std::vector <Task> _tasks;
// _tasks_map was introduced mainly for speeding up "task import".
// Iterating over all _tasks for each imported task is slow, making use of
// appropriate data structures is fast.
std::unordered_map <std::string, Task> _tasks_map;
std::vector <Task> _added_tasks;
std::vector <Task> _modified_tasks;
std::unordered_set <std::string> _purged_tasks;
std::vector <std::string> _lines;
std::vector <std::string> _added_lines;
File _file;
private:
std::unordered_map <int, std::string> _I2U; // ID -> UUID map
std::unordered_map <std::string, int> _U2I; // UUID -> ID map
};
#include <tc/WorkingSet.h>
#include <tc/Replica.h>
// TDB2 Class represents all the files in the task database.
class TDB2
@ -109,14 +46,13 @@ public:
TDB2 ();
void set_location (const std::string&);
void open_replica (const std::string&, bool create_if_missing);
void add (Task&, bool add_to_backlog = true);
void modify (Task&, bool add_to_backlog = true);
void commit ();
void get_changes (std::vector <Task>&);
void revert ();
void gc ();
int next_id ();
int latest_id ();
// Generalized task accessors.
@ -139,28 +75,11 @@ public:
void dump ();
private:
void gather_changes ();
void update (Task&, const bool, const bool addition = false);
bool verifyUniqueUUID (const std::string&);
tc::Replica replica;
std::optional<tc::WorkingSet> _working_set;
const tc::WorkingSet &working_set ();
void show_diff (const std::string&, const std::string&, const std::string&);
void revert_undo (std::vector <std::string>&, std::string&, std::string&, std::string&, std::string&);
void revert_pending (std::vector <std::string>&, const std::string&, const std::string&);
void revert_completed (std::vector <std::string>&, std::vector <std::string>&, const std::string&, const std::string&);
void revert_backlog (std::vector <std::string>&, const std::string&, const std::string&, const std::string&);
protected:
friend class TF2; // TF2 reaches into TDB2 internals for gc
TF2 pending;
TF2 completed;
friend class CmdSync; // CmdSync accesses the backlog directly
TF2 backlog;
TF2 undo;
private:
std::string _location;
int _id;
std::vector <Task> _changes;
};
#endif