Copyright

- Fixed typo in copyright.
- Added 'merge.autopush' as a valid config variable.
This commit is contained in:
Paul Beckingham
2010-09-01 22:26:09 -04:00
parent 2eaba55481
commit 4d46be0767
3 changed files with 87 additions and 79 deletions

View File

@@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager. // taskwarrior - a command line task list manager.
// //
// Copyright 2006 - 2010, Paul Beckingham, Johannes Schlatow. // Copyright 2010, Johannes Schlatow.
// All rights reserved. // All rights reserved.
// //
// This program is free software; you can redistribute it and/or modify it under // This program is free software; you can redistribute it and/or modify it under
@@ -46,7 +46,7 @@ Transport::Transport (const std::string& host, const std::string& path, const st
Transport::Transport (const std::string& uri) Transport::Transport (const std::string& uri)
{ {
executable = ""; executable = "";
parseUri(uri); parseUri(uri);
} }
@@ -58,18 +58,18 @@ Transport::~Transport ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void Transport::parseUri(std::string uri) void Transport::parseUri(std::string uri)
{ {
std::string::size_type pos; std::string::size_type pos;
std::string uripart; std::string uripart;
user = ""; user = "";
port = ""; port = "";
// skip ^.*:// // skip ^.*://
if ((pos = uri.find ("://")) != std::string::npos) if ((pos = uri.find ("://")) != std::string::npos)
{ {
uri = uri.substr (pos+3); uri = uri.substr (pos+3);
} }
// get host part // get host part
if ((pos = uri.find ("/")) != std::string::npos) if ((pos = uri.find ("/")) != std::string::npos)
{ {
@@ -80,14 +80,14 @@ void Transport::parseUri(std::string uri)
{ {
throw std::string ("Could not parse \""+uri+"\""); throw std::string ("Could not parse \""+uri+"\"");
} }
// parse host // parse host
if ((pos = host.find ("@")) != std::string::npos) if ((pos = host.find ("@")) != std::string::npos)
{ {
user = host.substr (0, pos); user = host.substr (0, pos);
host = host.substr (pos+1); host = host.substr (pos+1);
} }
if ((pos = host.find (":")) != std::string::npos) if ((pos = host.find (":")) != std::string::npos)
{ {
port = host.substr (pos+1); port = host.substr (pos+1);
@@ -101,54 +101,57 @@ Transport* Transport::getTransport(const std::string& uri)
if (uri.find("ssh://") == 0) { if (uri.find("ssh://") == 0) {
return new TransportSSH(uri); return new TransportSSH(uri);
} }
return NULL; return NULL;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int Transport::execute() int Transport::execute()
{ {
if (executable == "") if (executable == "")
return -1; return -1;
pid_t child_pid = fork(); pid_t child_pid = fork();
if (child_pid == 0) if (child_pid == 0)
{ {
// this is done by the child process // this is done by the child process
char shell[] = "sh"; char shell[] = "sh";
char opt[] = "-c"; char opt[] = "-c";
std::string cmdline = executable; std::string cmdline = executable;
std::vector <std::string>::iterator it; std::vector <std::string>::iterator it;
for (it = arguments.begin(); it != arguments.end(); ++it) for (it = arguments.begin(); it != arguments.end(); ++it)
{ {
std::string tmp = *it; std::string tmp = *it;
cmdline += " " + tmp; cmdline += " " + tmp;
} }
char** argv = new char*[4]; char** argv = new char*[4];
argv[0] = shell; // sh argv[0] = shell; // sh
argv[1] = opt; // -c argv[1] = opt; // -c
argv[2] = (char*)cmdline.c_str(); // e.g. scp undo.data user@host:.task/ argv[2] = (char*)cmdline.c_str(); // e.g. scp undo.data user@host:.task/
argv[3] = NULL; // required by execv argv[3] = NULL; // required by execv
int ret = execvp("sh", argv); int ret = execvp("sh", argv);
delete[] argv; delete[] argv;
exit(ret); exit(ret);
} }
else else
{ {
// this is done by the parent process // this is done by the parent process
int child_status; int child_status;
pid_t pid = waitpid(child_pid, &child_status, 0); pid_t pid = waitpid(child_pid, &child_status, 0);
if (pid == -1) if (pid == -1)
return -1; return -1;
else else
return child_status; return child_status;
} }
} }
////////////////////////////////////////////////////////////////////////////////

View File

@@ -1,7 +1,7 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager. // taskwarrior - a command line task list manager.
// //
// Copyright 2006 - 2010, Paul Beckingham, Johannes Schlatow. // Copyright 2010, Johannes Schlatow.
// All rights reserved. // All rights reserved.
// //
// This program is free software; you can redistribute it and/or modify it under // This program is free software; you can redistribute it and/or modify it under
@@ -35,8 +35,8 @@ TransportSSH::TransportSSH(const std::string& uri) : Transport(uri)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
TransportSSH::TransportSSH( TransportSSH::TransportSSH(
const std::string& host, const std::string& host,
const std::string& path, const std::string& path,
const std::string& user, const std::string& user,
const std::string& port) : Transport (host,path,user,port) const std::string& port) : Transport (host,path,user,port)
{ {
@@ -49,7 +49,7 @@ void TransportSSH::send(const std::string& source)
if (host == "") { if (host == "") {
throw std::string ("Hostname is empty"); throw std::string ("Hostname is empty");
} }
// Is there more than one file to transfer? // Is there more than one file to transfer?
// Then path has to end with a '/' // Then path has to end with a '/'
if ( (source.find ("*") != std::string::npos) if ( (source.find ("*") != std::string::npos)
@@ -57,23 +57,23 @@ void TransportSSH::send(const std::string& source)
|| (source.find (" ") != std::string::npos) ) || (source.find (" ") != std::string::npos) )
{ {
std::string::size_type pos; std::string::size_type pos;
pos = path.find_last_of ("/"); pos = path.find_last_of ("/");
if (pos != path.length()-1) if (pos != path.length()-1)
{ {
path = path.substr (0, pos+1); path = path.substr (0, pos+1);
} }
} }
// cmd line is: scp [-p port] [user@]host:path // cmd line is: scp [-p port] [user@]host:path
if (port != "") if (port != "")
{ {
arguments.push_back ("-P"); arguments.push_back ("-P");
arguments.push_back (port); arguments.push_back (port);
} }
arguments.push_back (source); arguments.push_back (source);
if (user != "") if (user != "")
{ {
arguments.push_back (user + "@" + host + ":" + path); arguments.push_back (user + "@" + host + ":" + path);
@@ -82,38 +82,38 @@ void TransportSSH::send(const std::string& source)
{ {
arguments.push_back (host + ":" + path); arguments.push_back (host + ":" + path);
} }
if (execute()) if (execute())
throw std::string ("Failed to run scp!"); throw std::string ("Failed to run scp!");
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
void TransportSSH::recv(std::string target) void TransportSSH::recv(std::string target)
{ {
if (host == "") { if (host == "") {
throw std::string ("Hostname is empty"); throw std::string ("Hostname is empty");
} }
// Is there more than one file to transfer? // Is there more than one file to transfer?
// Then target has to end with a '/' // Then target has to end with a '/'
if ( (path.find ("*") != std::string::npos) if ( (path.find ("*") != std::string::npos)
|| (path.find ("?") != std::string::npos) ) || (path.find ("?") != std::string::npos) )
{ {
std::string::size_type pos; std::string::size_type pos;
pos = target.find_last_of ("/"); pos = target.find_last_of ("/");
if (pos != target.length()-1) if (pos != target.length()-1)
{ {
target = target.substr( 0, pos+1); target = target.substr( 0, pos+1);
} }
} }
// cmd line is: scp [-p port] [user@]host:path // cmd line is: scp [-p port] [user@]host:path
if (port != "") if (port != "")
{ {
arguments.push_back ("-P"); arguments.push_back ("-P");
arguments.push_back (port); arguments.push_back (port);
} }
if (user != "") if (user != "")
{ {
arguments.push_back (user + "@" + host + ":" + path); arguments.push_back (user + "@" + host + ":" + path);
@@ -122,9 +122,11 @@ void TransportSSH::recv(std::string target)
{ {
arguments.push_back (host + ":" + path); arguments.push_back (host + ":" + path);
} }
arguments.push_back (target); arguments.push_back (target);
if (execute()) if (execute())
throw std::string ("Failed to run scp!"); throw std::string ("Failed to run scp!");
} }
////////////////////////////////////////////////////////////////////////////////

View File

@@ -598,50 +598,50 @@ void handleMerge (std::string& outs)
{ {
std::string file = trim (context.task.get ("description")); std::string file = trim (context.task.get ("description"));
std::string tmpfile = ""; std::string tmpfile = "";
if (file.length () > 0) if (file.length () > 0)
{ {
Directory location (context.config.get ("data.location")); Directory location (context.config.get ("data.location"));
// add undo.data to path if necessary // add undo.data to path if necessary
if (file.find ("undo.data") == std::string::npos) if (file.find ("undo.data") == std::string::npos)
{ {
if (file[file.length()-1] != '/') if (file[file.length()-1] != '/')
file += "/"; file += "/";
file += "undo.data"; file += "undo.data";
} }
Transport* transport; Transport* transport;
if ((transport = Transport::getTransport (file)) != NULL ) if ((transport = Transport::getTransport (file)) != NULL )
{ {
tmpfile = location.data + "/undo_remote.data"; tmpfile = location.data + "/undo_remote.data";
transport->recv (tmpfile); transport->recv (tmpfile);
delete transport; delete transport;
file = tmpfile; file = tmpfile;
} }
context.tdb.lock (context.config.getBoolean ("locking")); context.tdb.lock (context.config.getBoolean ("locking"));
context.tdb.merge (file); context.tdb.merge (file);
context.tdb.unlock (); context.tdb.unlock ();
context.hooks.trigger ("post-merge-command"); context.hooks.trigger ("post-merge-command");
if (tmpfile != "") if (tmpfile != "")
{ {
remove (tmpfile.c_str()); remove (tmpfile.c_str());
std::string autopush = context.config.get ("merge.autopush"); std::string autopush = context.config.get ("merge.autopush");
if ( ((autopush == "ask") && (confirm ("Do you want to push the changes to the database you merged from?")) ) if ( ((autopush == "ask") && (confirm ("Do you want to push the changes to the database you merged from?")) )
|| (autopush == "yes") ) || (autopush == "yes") )
{ {
std::string out; std::string out;
handlePush(out); handlePush(out);
} }
} }
} }
else // TODO : get default source from config file else // TODO : get default source from config file
throw std::string ("You must specify a file to merge."); throw std::string ("You must specify a file to merge.");
@@ -654,11 +654,11 @@ void handlePush (std::string& outs)
if (context.hooks.trigger ("pre-push-command")) if (context.hooks.trigger ("pre-push-command"))
{ {
std::string file = trim (context.task.get ("description")); std::string file = trim (context.task.get ("description"));
if (file.length () > 0) if (file.length () > 0)
{ {
Directory location (context.config.get ("data.location")); Directory location (context.config.get ("data.location"));
Transport* transport; Transport* transport;
if ((transport = Transport::getTransport (file)) != NULL ) if ((transport = Transport::getTransport (file)) != NULL )
{ {
@@ -796,23 +796,25 @@ int handleShow (std::string &outs)
// search for whole words. // search for whole words.
std::string recognized = std::string recognized =
" annotations blanklines bulk calendar.details calendar.details.report " " annotations blanklines bulk calendar.details calendar.details.report "
"calendar.holidays calendar.legend color color.active color.due color.due.today " "calendar.holidays calendar.legend color color.active color.due "
"color.blocked color.overdue color.pri.H color.pri.L color.pri.M color.pri.none " "color.due.today color.blocked color.overdue color.pri.H color.pri.L "
"color.recurring color.tagged color.footnote color.header color.debug " "color.pri.M color.pri.none color.recurring color.tagged color.footnote "
"color.alternate color.calendar.today color.calendar.due color.calendar.due.today " "color.header color.debug color.alternate color.calendar.today "
"color.calendar.overdue color.calendar.weekend color.calendar.holiday " "color.calendar.due color.calendar.due.today color.calendar.overdue "
"color.calendar.weeknumber color.summary.background color.summary.bar " "color.calendar.weekend color.calendar.holiday color.calendar.weeknumber "
"color.history.add color.history.done color.history.delete color.undo.before " "color.summary.background color.summary.bar color.history.add "
"color.undo.after confirmation curses data.location dateformat dateformat.holiday " "color.history.done color.history.delete color.undo.before "
"dateformat.report dateformat.annotation debug default.command " "color.undo.after confirmation curses data.location dateformat "
"default.priority default.project defaultwidth due locale displayweeknumber " "dateformat.holiday dateformat.report dateformat.annotation debug "
"export.ical.class echo.command fontunderline locking monthsperline nag next " "default.command default.priority default.project defaultwidth due "
"journal.time journal.time.start.annotation journal.time.stop.annotation " "locale displayweeknumber export.ical.class echo.command fontunderline "
"project shadow.command shadow.file shadow.notify weekstart editor " "locking monthsperline nag next journal.time "
"import.synonym.id import.synonym.uuid complete.all.projects complete.all.tags " "journal.time.start.annotation journal.time.stop.annotation project "
"search.case.sensitive hooks active.indicator tag.indicator recurrence.indicator " "shadow.command shadow.file shadow.notify weekstart editor "
"recurrence.limit list.all.projects list.all.tags undo.style verbose " "import.synonym.id import.synonym.uuid complete.all.projects "
"rule.precedence.color " "complete.all.tags search.case.sensitive hooks active.indicator "
"tag.indicator recurrence.indicator recurrence.limit list.all.projects "
"list.all.tags undo.style verbose rule.precedence.color merge.autopush "
#ifdef FEATURE_SHELL #ifdef FEATURE_SHELL
"shell.prompt " "shell.prompt "
#endif #endif
@@ -821,10 +823,11 @@ int handleShow (std::string &outs)
"import.synonym.end import.synonym.project import.synonym.priority " "import.synonym.end import.synonym.project import.synonym.priority "
"import.synonym.fg import.synonym.bg import.synonym.description " "import.synonym.fg import.synonym.bg import.synonym.description "
"urgency.next.coefficient urgency.blocking.coefficient urgency.blocked.coefficient " "urgency.next.coefficient urgency.blocking.coefficient "
"urgency.due.coefficient urgency.priority.coefficient urgency.waiting.coefficient " "urgency.blocked.coefficient urgency.due.coefficient "
"urgency.active.coefficient urgency.project.coefficient urgency.tags.coefficient " "urgency.priority.coefficient urgency.waiting.coefficient "
"urgency.annotations.coefficient "; "urgency.active.coefficient urgency.project.coefficient "
"urgency.tags.coefficient urgency.annotations.coefficient ";
// This configuration variable is supported, but not documented. It exists // This configuration variable is supported, but not documented. It exists
// so that unit tests can force color to be on even when the output from task // so that unit tests can force color to be on even when the output from task