mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Make TDB2.backlog non-public
The stats command gets this information from an API that will also work for TaskChampion. The sync command still accesses the field directly, as the command must be completely rewritten for TaskChampion.
This commit is contained in:
parent
d699ce8cba
commit
c8cfcec48b
6 changed files with 37 additions and 28 deletions
|
@ -90,13 +90,8 @@ bool getDOM (const std::string& name, Variant& value)
|
|||
if (name == "tw.syncneeded")
|
||||
{
|
||||
value = Variant (0);
|
||||
for (const auto& line : Context::getContext ().tdb2.backlog.get_lines ())
|
||||
{
|
||||
if (line[0] == '{')
|
||||
{
|
||||
value = Variant (1);
|
||||
break;
|
||||
}
|
||||
if (Context::getContext ().tdb2.num_local_changes () > 0) {
|
||||
value = Variant (1);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
|
13
src/TDB2.cpp
13
src/TDB2.cpp
|
@ -1259,6 +1259,19 @@ bool TDB2::read_only ()
|
|||
;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int TDB2::num_local_changes ()
|
||||
{
|
||||
std::vector <std::string> lines = backlog.get_lines ();
|
||||
return std::count_if(lines.begin(), lines.end(), [](const auto& line){ return line.front() == '{'; });
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
size_t TDB2::data_size ()
|
||||
{
|
||||
return pending._file.size () + completed._file.size () + undo._file.size () + backlog._file.size ();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void TDB2::clear ()
|
||||
{
|
||||
|
|
|
@ -135,6 +135,9 @@ public:
|
|||
// Read-only mode.
|
||||
bool read_only ();
|
||||
|
||||
int num_local_changes ();
|
||||
size_t data_size ();
|
||||
|
||||
void clear ();
|
||||
void dump ();
|
||||
|
||||
|
@ -152,6 +155,9 @@ public:
|
|||
TF2 pending;
|
||||
TF2 completed;
|
||||
TF2 undo;
|
||||
|
||||
protected:
|
||||
friend class CmdSync; // CmdSync accesses the backlog directly
|
||||
TF2 backlog;
|
||||
|
||||
private:
|
||||
|
|
|
@ -63,18 +63,14 @@ int CmdStats::execute (std::string& output)
|
|||
std::string dateformat = Context::getContext ().config.get ("dateformat");
|
||||
|
||||
// Go get the file sizes.
|
||||
size_t dataSize = Context::getContext ().tdb2.pending._file.size ()
|
||||
+ Context::getContext ().tdb2.completed._file.size ()
|
||||
+ Context::getContext ().tdb2.undo._file.size ()
|
||||
+ Context::getContext ().tdb2.backlog._file.size ();
|
||||
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 backlog transactions.
|
||||
std::vector <std::string> backlogTxns = Context::getContext ().tdb2.backlog.get_lines ();
|
||||
int backlogCount = std::count_if(backlogTxns.begin(), backlogTxns.end(), [](const auto& tx){ return tx.front() == '{'; });
|
||||
int numLocalChanges = Context::getContext ().tdb2.num_local_changes ();
|
||||
|
||||
// Get all the tasks.
|
||||
Filter filter;
|
||||
|
@ -207,7 +203,7 @@ int CmdStats::execute (std::string& output)
|
|||
|
||||
row = view.addRow ();
|
||||
view.set (row, 0, "Sync backlog transactions");
|
||||
view.set (row, 1, backlogCount);
|
||||
view.set (row, 1, numLocalChanges);
|
||||
|
||||
if (totalT)
|
||||
{
|
||||
|
|
|
@ -210,8 +210,7 @@ void feedback_backlog ()
|
|||
if (Context::getContext ().config.get ("taskd.server") != "" &&
|
||||
Context::getContext ().verbose ("sync"))
|
||||
{
|
||||
std::vector <std::string> lines = Context::getContext ().tdb2.backlog.get_lines ();
|
||||
int count = std::count_if(lines.begin(), lines.end(), [](const auto& line){ return line.front() == '{'; });
|
||||
int count = Context::getContext ().tdb2.num_local_changes ();
|
||||
if (count)
|
||||
Context::getContext ().footnote (format (count > 1 ? "There are {1} local changes. Sync required."
|
||||
: "There is {1} local change. Sync required.", count));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue