mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Enhancement - undo
- Now creates/opens/closes undo.data file. - All new tasks are logged in undo.data file.
This commit is contained in:
parent
58d7de8478
commit
c29682b91f
4 changed files with 41 additions and 6 deletions
|
@ -32,6 +32,7 @@ Location::Location ()
|
||||||
: path ("")
|
: path ("")
|
||||||
, pending (NULL)
|
, pending (NULL)
|
||||||
, completed (NULL)
|
, completed (NULL)
|
||||||
|
, undo (NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +48,7 @@ Location::Location (const Location& other)
|
||||||
path = other.path;
|
path = other.path;
|
||||||
pending = other.pending;
|
pending = other.pending;
|
||||||
completed = other.completed;
|
completed = other.completed;
|
||||||
|
undo = other.undo;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -57,6 +59,7 @@ Location& Location::operator= (const Location& other)
|
||||||
path = other.path;
|
path = other.path;
|
||||||
pending = other.pending;
|
pending = other.pending;
|
||||||
completed = other.completed;
|
completed = other.completed;
|
||||||
|
undo = other.undo;
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
|
|
|
@ -43,6 +43,7 @@ public:
|
||||||
std::string path;
|
std::string path;
|
||||||
FILE* pending;
|
FILE* pending;
|
||||||
FILE* completed;
|
FILE* completed;
|
||||||
|
FILE* undo;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
42
src/TDB.cpp
42
src/TDB.cpp
|
@ -124,6 +124,7 @@ void TDB::lock (bool lockFile /* = true */)
|
||||||
{
|
{
|
||||||
location->pending = openAndLock (location->path + "/pending.data");
|
location->pending = openAndLock (location->path + "/pending.data");
|
||||||
location->completed = openAndLock (location->path + "/completed.data");
|
location->completed = openAndLock (location->path + "/completed.data");
|
||||||
|
location->undo = openAndLock (location->path + "/undo.data");
|
||||||
}
|
}
|
||||||
|
|
||||||
mAllOpenAndLocked = true;
|
mAllOpenAndLocked = true;
|
||||||
|
@ -147,6 +148,10 @@ void TDB::unlock ()
|
||||||
fflush (location->completed);
|
fflush (location->completed);
|
||||||
fclose (location->completed);
|
fclose (location->completed);
|
||||||
location->completed = NULL;
|
location->completed = NULL;
|
||||||
|
|
||||||
|
fflush (location->undo);
|
||||||
|
fclose (location->undo);
|
||||||
|
location->completed = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mAllOpenAndLocked = false;
|
mAllOpenAndLocked = false;
|
||||||
|
@ -275,9 +280,6 @@ int TDB::loadCompleted (std::vector <Task>& tasks, Filter& filter)
|
||||||
char line[T_LINE_MAX];
|
char line[T_LINE_MAX];
|
||||||
foreach (location, mLocations)
|
foreach (location, mLocations)
|
||||||
{
|
{
|
||||||
// TODO If the filter contains Status:x where x is not deleted or
|
|
||||||
// completed, then this can be skipped.
|
|
||||||
|
|
||||||
line_number = 1;
|
line_number = 1;
|
||||||
file = location->path + "/completed.data";
|
file = location->path + "/completed.data";
|
||||||
|
|
||||||
|
@ -315,7 +317,6 @@ int TDB::loadCompleted (std::vector <Task>& tasks, Filter& filter)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// TODO Write to transaction log.
|
|
||||||
// Note: mLocations[0] is where all tasks are written.
|
// Note: mLocations[0] is where all tasks are written.
|
||||||
void TDB::add (const Task& task)
|
void TDB::add (const Task& task)
|
||||||
{
|
{
|
||||||
|
@ -324,14 +325,12 @@ void TDB::add (const Task& task)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// TODO Write to transaction log.
|
|
||||||
void TDB::update (const Task& task)
|
void TDB::update (const Task& task)
|
||||||
{
|
{
|
||||||
mModified.push_back (task);
|
mModified.push_back (task);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// TODO Writes all, including comments
|
|
||||||
// Interestingly, only the pending file gets written to. The completed file is
|
// Interestingly, only the pending file gets written to. The completed file is
|
||||||
// only modified by TDB::gc.
|
// only modified by TDB::gc.
|
||||||
int TDB::commit ()
|
int TDB::commit ()
|
||||||
|
@ -351,6 +350,10 @@ int TDB::commit ()
|
||||||
fputs (task->composeF4 ().c_str (), mLocations[0].pending);
|
fputs (task->composeF4 ().c_str (), mLocations[0].pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fseek (mLocations[0].undo, 0, SEEK_END);
|
||||||
|
foreach (task, mNew)
|
||||||
|
writeUndo (*task, mLocations[0].undo);
|
||||||
|
|
||||||
mNew.clear ();
|
mNew.clear ();
|
||||||
return quantity;
|
return quantity;
|
||||||
}
|
}
|
||||||
|
@ -377,6 +380,13 @@ int TDB::commit ()
|
||||||
foreach (task, mPending)
|
foreach (task, mPending)
|
||||||
fputs (task->composeF4 ().c_str (), mLocations[0].pending);
|
fputs (task->composeF4 ().c_str (), mLocations[0].pending);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
// Update the undo log.
|
||||||
|
fseek (mLocations[0].undo, 0, SEEK_END);
|
||||||
|
foreach (task, mPending)
|
||||||
|
writeUndo (*task, mLocations[0].undo);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
return quantity;
|
return quantity;
|
||||||
|
@ -498,3 +508,23 @@ FILE* TDB::openAndLock (const std::string& file)
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void TDB::writeUndo (const Task& after, FILE* file)
|
||||||
|
{
|
||||||
|
Timer t ("TDB::writeUndo");
|
||||||
|
|
||||||
|
// TODO Locate "before" task (match on uuid).
|
||||||
|
|
||||||
|
fprintf (file,
|
||||||
|
"time %u\nnew %s\n---\n",
|
||||||
|
(unsigned int) time (NULL),
|
||||||
|
after.composeF4 ().c_str ());
|
||||||
|
/*
|
||||||
|
fprintf (file,
|
||||||
|
"time %u\nold %s\nnew %s\n---\n",
|
||||||
|
(unsigned int) time (NULL),
|
||||||
|
before.composeF4 ().c_str (),
|
||||||
|
after.composeF4 ().c_str ());
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -64,6 +64,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FILE* openAndLock (const std::string&);
|
FILE* openAndLock (const std::string&);
|
||||||
|
void writeUndo (const Task&, FILE*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector <Location> mLocations;
|
std::vector <Location> mLocations;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue