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 ("")
|
||||
, pending (NULL)
|
||||
, completed (NULL)
|
||||
, undo (NULL)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -47,6 +48,7 @@ Location::Location (const Location& other)
|
|||
path = other.path;
|
||||
pending = other.pending;
|
||||
completed = other.completed;
|
||||
undo = other.undo;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -57,6 +59,7 @@ Location& Location::operator= (const Location& other)
|
|||
path = other.path;
|
||||
pending = other.pending;
|
||||
completed = other.completed;
|
||||
undo = other.undo;
|
||||
}
|
||||
|
||||
return *this;
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
std::string path;
|
||||
FILE* pending;
|
||||
FILE* completed;
|
||||
FILE* undo;
|
||||
};
|
||||
|
||||
#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->completed = openAndLock (location->path + "/completed.data");
|
||||
location->undo = openAndLock (location->path + "/undo.data");
|
||||
}
|
||||
|
||||
mAllOpenAndLocked = true;
|
||||
|
@ -147,6 +148,10 @@ void TDB::unlock ()
|
|||
fflush (location->completed);
|
||||
fclose (location->completed);
|
||||
location->completed = NULL;
|
||||
|
||||
fflush (location->undo);
|
||||
fclose (location->undo);
|
||||
location->completed = NULL;
|
||||
}
|
||||
|
||||
mAllOpenAndLocked = false;
|
||||
|
@ -275,9 +280,6 @@ int TDB::loadCompleted (std::vector <Task>& tasks, Filter& filter)
|
|||
char line[T_LINE_MAX];
|
||||
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;
|
||||
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.
|
||||
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)
|
||||
{
|
||||
mModified.push_back (task);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// TODO Writes all, including comments
|
||||
// Interestingly, only the pending file gets written to. The completed file is
|
||||
// only modified by TDB::gc.
|
||||
int TDB::commit ()
|
||||
|
@ -351,6 +350,10 @@ int TDB::commit ()
|
|||
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 ();
|
||||
return quantity;
|
||||
}
|
||||
|
@ -377,6 +380,13 @@ int TDB::commit ()
|
|||
foreach (task, mPending)
|
||||
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;
|
||||
|
@ -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:
|
||||
FILE* openAndLock (const std::string&);
|
||||
void writeUndo (const Task&, FILE*);
|
||||
|
||||
private:
|
||||
std::vector <Location> mLocations;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue