mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Enhancement - Path integration
- Obsoleted util.cpp spit, slurp calls
This commit is contained in:
parent
a8f03679ed
commit
abffaa184b
8 changed files with 19 additions and 110 deletions
21
src/TDB.cpp
21
src/TDB.cpp
|
@ -36,6 +36,7 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "TDB.h"
|
#include "TDB.h"
|
||||||
#include "Directory.h"
|
#include "Directory.h"
|
||||||
|
#include "File.h"
|
||||||
#include "Table.h"
|
#include "Table.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
#include "Color.h"
|
#include "Color.h"
|
||||||
|
@ -513,7 +514,7 @@ void TDB::undo ()
|
||||||
|
|
||||||
// load undo.data
|
// load undo.data
|
||||||
std::vector <std::string> u;
|
std::vector <std::string> u;
|
||||||
slurp (undoFile, u);
|
File::read (undoFile, u);
|
||||||
|
|
||||||
if (u.size () < 3)
|
if (u.size () < 3)
|
||||||
throw std::string ("There are no recorded transactions to undo.");
|
throw std::string ("There are no recorded transactions to undo.");
|
||||||
|
@ -645,7 +646,7 @@ void TDB::undo ()
|
||||||
|
|
||||||
// load pending.data
|
// load pending.data
|
||||||
std::vector <std::string> p;
|
std::vector <std::string> p;
|
||||||
slurp (pendingFile, p);
|
File::read (pendingFile, p);
|
||||||
|
|
||||||
// is 'current' in pending?
|
// is 'current' in pending?
|
||||||
foreach (task, p)
|
foreach (task, p)
|
||||||
|
@ -667,15 +668,15 @@ void TDB::undo ()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rewrite files.
|
// Rewrite files.
|
||||||
spit (pendingFile, p);
|
File::write (pendingFile, p);
|
||||||
spit (undoFile, u);
|
File::write (undoFile, u);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// load completed.data
|
// load completed.data
|
||||||
std::vector <std::string> c;
|
std::vector <std::string> c;
|
||||||
slurp (completedFile, c);
|
File::read (completedFile, c);
|
||||||
|
|
||||||
// is 'current' in completed?
|
// is 'current' in completed?
|
||||||
foreach (task, c)
|
foreach (task, c)
|
||||||
|
@ -691,17 +692,17 @@ void TDB::undo ()
|
||||||
{
|
{
|
||||||
c.erase (task);
|
c.erase (task);
|
||||||
p.push_back (prior);
|
p.push_back (prior);
|
||||||
spit (completedFile, c);
|
File::write (completedFile, c);
|
||||||
spit (pendingFile, p);
|
File::write (pendingFile, p);
|
||||||
spit (undoFile, u);
|
File::write (undoFile, u);
|
||||||
std::cout << "Modified task reverted." << std::endl;
|
std::cout << "Modified task reverted." << std::endl;
|
||||||
context.debug ("TDB::undo - task belongs in pending.data");
|
context.debug ("TDB::undo - task belongs in pending.data");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*task = prior;
|
*task = prior;
|
||||||
spit (completedFile, c);
|
File::write (completedFile, c);
|
||||||
spit (undoFile, u);
|
File::write (undoFile, u);
|
||||||
std::cout << "Modified task reverted." << std::endl;
|
std::cout << "Modified task reverted." << std::endl;
|
||||||
context.debug ("TDB::undo - task belongs in completed.data");
|
context.debug ("TDB::undo - task belongs in completed.data");
|
||||||
}
|
}
|
||||||
|
|
|
@ -533,7 +533,7 @@ void editFile (Task& task)
|
||||||
|
|
||||||
// Format the contents, T -> text, write to a file.
|
// Format the contents, T -> text, write to a file.
|
||||||
std::string before = formatTask (task);
|
std::string before = formatTask (task);
|
||||||
spit (file.str (), before);
|
File::write (file.str (), before);
|
||||||
|
|
||||||
// Determine correct editor: .taskrc:editor > $VISUAL > $EDITOR > vi
|
// Determine correct editor: .taskrc:editor > $VISUAL > $EDITOR > vi
|
||||||
std::string editor = context.config.get ("editor");
|
std::string editor = context.config.get ("editor");
|
||||||
|
@ -557,7 +557,7 @@ ARE_THESE_REALLY_HARMFUL:
|
||||||
|
|
||||||
// Slurp file.
|
// Slurp file.
|
||||||
std::string after;
|
std::string after;
|
||||||
slurp (file.str (), after, false);
|
File::read (file.str (), after);
|
||||||
|
|
||||||
// Update task based on what can be parsed back out of the file, but only
|
// Update task based on what can be parsed back out of the file, but only
|
||||||
// if changes were made.
|
// if changes were made.
|
||||||
|
@ -584,7 +584,7 @@ ARE_THESE_REALLY_HARMFUL:
|
||||||
|
|
||||||
// Preserve the edits.
|
// Preserve the edits.
|
||||||
before = after;
|
before = after;
|
||||||
spit (file.str (), before);
|
File::write (file.str (), before);
|
||||||
|
|
||||||
if (confirm ("Task couldn't handle your edits. Would you like to try again?"))
|
if (confirm ("Task couldn't handle your edits. Would you like to try again?"))
|
||||||
goto ARE_THESE_REALLY_HARMFUL;
|
goto ARE_THESE_REALLY_HARMFUL;
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include "File.h"
|
||||||
#include "Date.h"
|
#include "Date.h"
|
||||||
#include "text.h"
|
#include "text.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
@ -1155,7 +1156,7 @@ int handleImport (std::string &outs)
|
||||||
{
|
{
|
||||||
// Load the file.
|
// Load the file.
|
||||||
std::vector <std::string> all;
|
std::vector <std::string> all;
|
||||||
slurp (file, all, true);
|
File::read (file, all);
|
||||||
|
|
||||||
std::vector <std::string> lines;
|
std::vector <std::string> lines;
|
||||||
std::vector <std::string>::iterator it;
|
std::vector <std::string>::iterator it;
|
||||||
|
|
|
@ -1728,7 +1728,7 @@ int handleReportStats (std::string &outs)
|
||||||
dataSize += undo.size ();
|
dataSize += undo.size ();
|
||||||
|
|
||||||
std::vector <std::string> undoTxns;
|
std::vector <std::string> undoTxns;
|
||||||
slurp (undo, undoTxns, false);
|
File::read (undo, undoTxns);
|
||||||
int undoCount = 0;
|
int undoCount = 0;
|
||||||
foreach (tx, undoTxns)
|
foreach (tx, undoTxns)
|
||||||
if (tx->substr (0, 3) == "---")
|
if (tx->substr (0, 3) == "---")
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <StringTable.h>
|
#include <StringTable.h>
|
||||||
|
#include <File.h>
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
#include <test.h>
|
#include <test.h>
|
||||||
|
|
||||||
|
@ -39,7 +40,7 @@ int main (int argc, char** argv)
|
||||||
|
|
||||||
// Create a string file.
|
// Create a string file.
|
||||||
std::string file = "./strings.xx-XX";
|
std::string file = "./strings.xx-XX";
|
||||||
spit (file, "# comment\n1 found");
|
File::write (file, "# comment\n1 found");
|
||||||
t.is (access (file.c_str (), F_OK), 0, "strings.xx-XX created.");
|
t.is (access (file.c_str (), F_OK), 0, "strings.xx-XX created.");
|
||||||
|
|
||||||
// Load the string file.
|
// Load the string file.
|
||||||
|
|
|
@ -514,10 +514,6 @@ int main (int argc, char** argv)
|
||||||
|
|
||||||
// TODO const std::string uuid ();
|
// TODO const std::string uuid ();
|
||||||
|
|
||||||
// TODO bool slurp (const std::string&, std::vector <std::string>&, bool trimLines = false);
|
|
||||||
// TODO bool slurp (const std::string&, std::string&, bool trimLines = false);
|
|
||||||
// TODO void spit (const std::string&, const std::string&);
|
|
||||||
|
|
||||||
// std::string taskDiff (const Task&, const Task&);
|
// std::string taskDiff (const Task&, const Task&);
|
||||||
Task left;
|
Task left;
|
||||||
left.set ("zero", "0");
|
left.set ("zero", "0");
|
||||||
|
|
86
src/util.cpp
86
src/util.cpp
|
@ -375,92 +375,6 @@ int flock (int fd, int operation)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool slurp (
|
|
||||||
const std::string& file,
|
|
||||||
std::vector <std::string>& contents,
|
|
||||||
bool trimLines /* = false */)
|
|
||||||
{
|
|
||||||
contents.clear ();
|
|
||||||
|
|
||||||
std::ifstream in (file.c_str ());
|
|
||||||
if (in.good ())
|
|
||||||
{
|
|
||||||
std::string line;
|
|
||||||
while (getline (in, line))
|
|
||||||
{
|
|
||||||
if (trimLines) line = trim (line);
|
|
||||||
contents.push_back (line);
|
|
||||||
}
|
|
||||||
|
|
||||||
in.close ();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
bool slurp (
|
|
||||||
const std::string& file,
|
|
||||||
std::string& contents,
|
|
||||||
bool trimLines /* = false */)
|
|
||||||
{
|
|
||||||
contents = "";
|
|
||||||
|
|
||||||
std::ifstream in (file.c_str ());
|
|
||||||
if (in.good ())
|
|
||||||
{
|
|
||||||
std::string line;
|
|
||||||
while (getline (in, line))
|
|
||||||
{
|
|
||||||
if (trimLines) line = trim (line);
|
|
||||||
contents += line + "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
in.close ();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
void spit (const std::string& file, const std::string& contents)
|
|
||||||
{
|
|
||||||
std::ofstream out (file.c_str ());
|
|
||||||
if (out.good ())
|
|
||||||
{
|
|
||||||
out << contents;
|
|
||||||
out.close ();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
throw std::string ("Could not write file '") + file + "'"; // TODO i18n
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
void spit (
|
|
||||||
const std::string& file,
|
|
||||||
const std::vector <std::string>& lines,
|
|
||||||
bool addNewlines /* = true */)
|
|
||||||
{
|
|
||||||
std::ofstream out (file.c_str ());
|
|
||||||
if (out.good ())
|
|
||||||
{
|
|
||||||
foreach (line, lines)
|
|
||||||
{
|
|
||||||
out << *line;
|
|
||||||
|
|
||||||
if (addNewlines)
|
|
||||||
out << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
out.close ();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
throw std::string ("Could not write file '") + file + "'"; // TODO i18n
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
bool taskDiff (const Task& before, const Task& after)
|
bool taskDiff (const Task& before, const Task& after)
|
||||||
{
|
{
|
||||||
|
|
|
@ -70,10 +70,6 @@ const std::string uuid ();
|
||||||
int flock (int, int);
|
int flock (int, int);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool slurp (const std::string&, std::vector <std::string>&, bool trimLines = false);
|
|
||||||
bool slurp (const std::string&, std::string&, bool trimLines = false);
|
|
||||||
void spit (const std::string&, const std::string&);
|
|
||||||
void spit (const std::string&, const std::vector <std::string>&, bool addNewlines = true);
|
|
||||||
bool taskDiff (const Task&, const Task&);
|
bool taskDiff (const Task&, const Task&);
|
||||||
std::string taskDifferences (const Task&, const Task&);
|
std::string taskDifferences (const Task&, const Task&);
|
||||||
std::string renderAttribute (const std::string&, const std::string&);
|
std::string renderAttribute (const std::string&, const std::string&);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue