mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-19 00:43:07 +02:00
make TDB2.undo non-public
The stats command calls an API to provide this information in a way that will still be relevant for TaskChampion, while CmdInfo's access to the data remains. The TaskChampion interface for per-task hitsory is still not ready.
This commit is contained in:
parent
2f30bc8cbf
commit
4ebd0ffb39
4 changed files with 33 additions and 25 deletions
|
@ -1266,6 +1266,13 @@ int TDB2::num_local_changes ()
|
|||
return std::count_if(lines.begin(), lines.end(), [](const auto& line){ return line.front() == '{'; });
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int TDB2::num_reverts_possible ()
|
||||
{
|
||||
std::vector <std::string> lines = undo.get_lines ();
|
||||
return std::count(lines.begin(), lines.end(), "---");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
size_t TDB2::data_size ()
|
||||
{
|
||||
|
|
|
@ -136,6 +136,7 @@ public:
|
|||
bool read_only ();
|
||||
|
||||
int num_local_changes ();
|
||||
int num_reverts_possible ();
|
||||
size_t data_size ();
|
||||
|
||||
void clear ();
|
||||
|
@ -154,11 +155,12 @@ private:
|
|||
public:
|
||||
TF2 pending;
|
||||
TF2 completed;
|
||||
TF2 undo;
|
||||
|
||||
protected:
|
||||
friend class CmdSync; // CmdSync accesses the backlog directly
|
||||
TF2 backlog;
|
||||
friend class CmdInfo; // CmdInfo uses undo data to give history
|
||||
TF2 undo;
|
||||
|
||||
private:
|
||||
std::string _location;
|
||||
|
|
|
@ -65,9 +65,8 @@ int CmdStats::execute (std::string& output)
|
|||
// Go get the file sizes.
|
||||
size_t dataSize = Context::getContext ().tdb2.data_size ();
|
||||
|
||||
// Count the undo transactions.
|
||||
std::vector <std::string> undoTxns = Context::getContext ().tdb2.undo.get_lines ();
|
||||
int undoCount = std::count(undoTxns.begin(), undoTxns.end(), "---");
|
||||
// Count the possible reverts.
|
||||
int undoCount = Context::getContext ().tdb2.num_reverts_possible ();
|
||||
|
||||
// Count the backlog transactions.
|
||||
int numLocalChanges = Context::getContext ().tdb2.num_local_changes ();
|
||||
|
|
|
@ -60,40 +60,40 @@ int main (int, char**)
|
|||
// Try reading an empty database.
|
||||
std::vector <Task> pending = context.tdb2.pending.get_tasks ();
|
||||
std::vector <Task> completed = context.tdb2.completed.get_tasks ();
|
||||
std::vector <std::string> undo = context.tdb2.undo.get_lines ();
|
||||
int num_reverts_possible = context.tdb2.num_reverts_possible ();
|
||||
int num_local_changes = context.tdb2.num_local_changes ();
|
||||
|
||||
t.is ((int) pending.size (), 0, "TDB2 Read empty pending");
|
||||
t.is ((int) completed.size (), 0, "TDB2 Read empty completed");
|
||||
t.is ((int) undo.size (), 0, "TDB2 Read empty undo");
|
||||
t.is ((int) num_local_changes, 0, "TDB2 Read empty backlog");
|
||||
t.is ((int) pending.size (), 0, "TDB2 Read empty pending");
|
||||
t.is ((int) completed.size (), 0, "TDB2 Read empty completed");
|
||||
t.is ((int) num_reverts_possible, 0, "TDB2 Read empty undo");
|
||||
t.is ((int) num_local_changes, 0, "TDB2 Read empty backlog");
|
||||
|
||||
// Add a task.
|
||||
Task task (R"([description:"description" name:"value"])");
|
||||
context.tdb2.add (task);
|
||||
|
||||
pending = context.tdb2.pending.get_tasks ();
|
||||
completed = context.tdb2.completed.get_tasks ();
|
||||
undo = context.tdb2.undo.get_lines ();
|
||||
num_local_changes = context.tdb2.num_local_changes ();
|
||||
pending = context.tdb2.pending.get_tasks ();
|
||||
completed = context.tdb2.completed.get_tasks ();
|
||||
num_reverts_possible = context.tdb2.num_reverts_possible ();
|
||||
num_local_changes = context.tdb2.num_local_changes ();
|
||||
|
||||
t.is ((int) pending.size (), 1, "TDB2 after add, 1 pending task");
|
||||
t.is ((int) completed.size (), 0, "TDB2 after add, 0 completed tasks");
|
||||
t.is ((int) undo.size (), 3, "TDB2 after add, 3 undo lines");
|
||||
t.is ((int) num_local_changes, 1, "TDB2 after add, 1 backlog task");
|
||||
t.is ((int) pending.size (), 1, "TDB2 after add, 1 pending task");
|
||||
t.is ((int) completed.size (), 0, "TDB2 after add, 0 completed tasks");
|
||||
t.is ((int) num_reverts_possible, 3, "TDB2 after add, 3 undo lines");
|
||||
t.is ((int) num_local_changes, 1, "TDB2 after add, 1 backlog task");
|
||||
|
||||
task.set ("description", "This is a test");
|
||||
context.tdb2.modify (task);
|
||||
|
||||
pending = context.tdb2.pending.get_tasks ();
|
||||
completed = context.tdb2.completed.get_tasks ();
|
||||
undo = context.tdb2.undo.get_lines ();
|
||||
num_local_changes = context.tdb2.num_local_changes ();
|
||||
pending = context.tdb2.pending.get_tasks ();
|
||||
completed = context.tdb2.completed.get_tasks ();
|
||||
num_reverts_possible = context.tdb2.num_reverts_possible ();
|
||||
num_local_changes = context.tdb2.num_local_changes ();
|
||||
|
||||
t.is ((int) pending.size (), 1, "TDB2 after add, 1 pending task");
|
||||
t.is ((int) completed.size (), 0, "TDB2 after add, 0 completed tasks");
|
||||
t.is ((int) undo.size (), 7, "TDB2 after add, 7 undo lines");
|
||||
t.is ((int) num_local_changes, 2, "TDB2 after add, 2 backlog task");
|
||||
t.is ((int) pending.size (), 1, "TDB2 after add, 1 pending task");
|
||||
t.is ((int) completed.size (), 0, "TDB2 after add, 0 completed tasks");
|
||||
t.is ((int) num_reverts_possible, 7, "TDB2 after add, 7 undo lines");
|
||||
t.is ((int) num_local_changes, 2, "TDB2 after add, 2 backlog task");
|
||||
|
||||
context.tdb2.commit ();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue