mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Copyright
- Fixed typo in copyright. - Added 'merge.autopush' as a valid config variable.
This commit is contained in:
parent
2eaba55481
commit
4d46be0767
3 changed files with 87 additions and 79 deletions
|
@ -1,7 +1,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// taskwarrior - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2010, Paul Beckingham, Johannes Schlatow.
|
||||
// Copyright 2010, Johannes Schlatow.
|
||||
// All rights reserved.
|
||||
//
|
||||
// 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)
|
||||
{
|
||||
executable = "";
|
||||
|
||||
|
||||
parseUri(uri);
|
||||
}
|
||||
|
||||
|
@ -58,18 +58,18 @@ Transport::~Transport ()
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Transport::parseUri(std::string uri)
|
||||
{
|
||||
std::string::size_type pos;
|
||||
std::string::size_type pos;
|
||||
std::string uripart;
|
||||
|
||||
|
||||
user = "";
|
||||
port = "";
|
||||
|
||||
|
||||
// skip ^.*://
|
||||
if ((pos = uri.find ("://")) != std::string::npos)
|
||||
{
|
||||
uri = uri.substr (pos+3);
|
||||
}
|
||||
|
||||
|
||||
// get host part
|
||||
if ((pos = uri.find ("/")) != std::string::npos)
|
||||
{
|
||||
|
@ -80,14 +80,14 @@ void Transport::parseUri(std::string uri)
|
|||
{
|
||||
throw std::string ("Could not parse \""+uri+"\"");
|
||||
}
|
||||
|
||||
|
||||
// parse host
|
||||
if ((pos = host.find ("@")) != std::string::npos)
|
||||
{
|
||||
user = host.substr (0, pos);
|
||||
host = host.substr (pos+1);
|
||||
}
|
||||
|
||||
|
||||
if ((pos = host.find (":")) != std::string::npos)
|
||||
{
|
||||
port = host.substr (pos+1);
|
||||
|
@ -101,54 +101,57 @@ Transport* Transport::getTransport(const std::string& uri)
|
|||
if (uri.find("ssh://") == 0) {
|
||||
return new TransportSSH(uri);
|
||||
}
|
||||
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Transport::execute()
|
||||
{
|
||||
if (executable == "")
|
||||
if (executable == "")
|
||||
return -1;
|
||||
|
||||
|
||||
pid_t child_pid = fork();
|
||||
|
||||
|
||||
if (child_pid == 0)
|
||||
{
|
||||
// this is done by the child process
|
||||
// this is done by the child process
|
||||
char shell[] = "sh";
|
||||
char opt[] = "-c";
|
||||
|
||||
|
||||
std::string cmdline = executable;
|
||||
|
||||
|
||||
std::vector <std::string>::iterator it;
|
||||
for (it = arguments.begin(); it != arguments.end(); ++it)
|
||||
{
|
||||
std::string tmp = *it;
|
||||
cmdline += " " + tmp;
|
||||
cmdline += " " + tmp;
|
||||
}
|
||||
|
||||
|
||||
char** argv = new char*[4];
|
||||
argv[0] = shell; // sh
|
||||
argv[1] = opt; // -c
|
||||
argv[2] = (char*)cmdline.c_str(); // e.g. scp undo.data user@host:.task/
|
||||
argv[3] = NULL; // required by execv
|
||||
|
||||
int ret = execvp("sh", argv);
|
||||
int ret = execvp("sh", argv);
|
||||
delete[] argv;
|
||||
|
||||
|
||||
exit(ret);
|
||||
}
|
||||
else
|
||||
{
|
||||
// this is done by the parent process
|
||||
int child_status;
|
||||
|
||||
|
||||
pid_t pid = waitpid(child_pid, &child_status, 0);
|
||||
|
||||
|
||||
if (pid == -1)
|
||||
return -1;
|
||||
else
|
||||
return child_status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
// taskwarrior - a command line task list manager.
|
||||
//
|
||||
// Copyright 2006 - 2010, Paul Beckingham, Johannes Schlatow.
|
||||
// Copyright 2010, Johannes Schlatow.
|
||||
// All rights reserved.
|
||||
//
|
||||
// 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(
|
||||
const std::string& host,
|
||||
const std::string& path,
|
||||
const std::string& host,
|
||||
const std::string& path,
|
||||
const std::string& user,
|
||||
const std::string& port) : Transport (host,path,user,port)
|
||||
{
|
||||
|
@ -49,7 +49,7 @@ void TransportSSH::send(const std::string& source)
|
|||
if (host == "") {
|
||||
throw std::string ("Hostname is empty");
|
||||
}
|
||||
|
||||
|
||||
// Is there more than one file to transfer?
|
||||
// Then path has to end with a '/'
|
||||
if ( (source.find ("*") != std::string::npos)
|
||||
|
@ -57,23 +57,23 @@ void TransportSSH::send(const std::string& source)
|
|||
|| (source.find (" ") != std::string::npos) )
|
||||
{
|
||||
std::string::size_type pos;
|
||||
|
||||
|
||||
pos = path.find_last_of ("/");
|
||||
if (pos != path.length()-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 != "")
|
||||
{
|
||||
arguments.push_back ("-P");
|
||||
arguments.push_back (port);
|
||||
}
|
||||
|
||||
|
||||
arguments.push_back (source);
|
||||
|
||||
|
||||
if (user != "")
|
||||
{
|
||||
arguments.push_back (user + "@" + host + ":" + path);
|
||||
|
@ -82,38 +82,38 @@ void TransportSSH::send(const std::string& source)
|
|||
{
|
||||
arguments.push_back (host + ":" + path);
|
||||
}
|
||||
|
||||
|
||||
if (execute())
|
||||
throw std::string ("Failed to run scp!");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void TransportSSH::recv(std::string target)
|
||||
{
|
||||
{
|
||||
if (host == "") {
|
||||
throw std::string ("Hostname is empty");
|
||||
}
|
||||
|
||||
|
||||
// Is there more than one file to transfer?
|
||||
// Then target has to end with a '/'
|
||||
if ( (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 ("/");
|
||||
if (pos != target.length()-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 != "")
|
||||
{
|
||||
arguments.push_back ("-P");
|
||||
arguments.push_back (port);
|
||||
}
|
||||
|
||||
|
||||
if (user != "")
|
||||
{
|
||||
arguments.push_back (user + "@" + host + ":" + path);
|
||||
|
@ -122,9 +122,11 @@ void TransportSSH::recv(std::string target)
|
|||
{
|
||||
arguments.push_back (host + ":" + path);
|
||||
}
|
||||
|
||||
|
||||
arguments.push_back (target);
|
||||
|
||||
|
||||
if (execute())
|
||||
throw std::string ("Failed to run scp!");
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -598,50 +598,50 @@ void handleMerge (std::string& outs)
|
|||
{
|
||||
std::string file = trim (context.task.get ("description"));
|
||||
std::string tmpfile = "";
|
||||
|
||||
|
||||
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
|
||||
if (file.find ("undo.data") == std::string::npos)
|
||||
{
|
||||
if (file[file.length()-1] != '/')
|
||||
file += "/";
|
||||
|
||||
|
||||
file += "undo.data";
|
||||
}
|
||||
|
||||
|
||||
Transport* transport;
|
||||
if ((transport = Transport::getTransport (file)) != NULL )
|
||||
{
|
||||
tmpfile = location.data + "/undo_remote.data";
|
||||
transport->recv (tmpfile);
|
||||
delete transport;
|
||||
|
||||
|
||||
file = tmpfile;
|
||||
}
|
||||
|
||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||
|
||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||
context.tdb.merge (file);
|
||||
context.tdb.unlock ();
|
||||
|
||||
|
||||
context.hooks.trigger ("post-merge-command");
|
||||
|
||||
if (tmpfile != "")
|
||||
{
|
||||
remove (tmpfile.c_str());
|
||||
|
||||
remove (tmpfile.c_str());
|
||||
|
||||
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?")) )
|
||||
|| (autopush == "yes") )
|
||||
{
|
||||
std::string out;
|
||||
handlePush(out);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
else // TODO : get default source from config file
|
||||
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"))
|
||||
{
|
||||
std::string file = trim (context.task.get ("description"));
|
||||
|
||||
|
||||
if (file.length () > 0)
|
||||
{
|
||||
Directory location (context.config.get ("data.location"));
|
||||
|
||||
Directory location (context.config.get ("data.location"));
|
||||
|
||||
Transport* transport;
|
||||
if ((transport = Transport::getTransport (file)) != NULL )
|
||||
{
|
||||
|
@ -796,23 +796,25 @@ int handleShow (std::string &outs)
|
|||
// search for whole words.
|
||||
std::string recognized =
|
||||
" annotations blanklines bulk calendar.details calendar.details.report "
|
||||
"calendar.holidays calendar.legend color color.active color.due color.due.today "
|
||||
"color.blocked color.overdue color.pri.H color.pri.L color.pri.M color.pri.none "
|
||||
"color.recurring color.tagged color.footnote color.header color.debug "
|
||||
"color.alternate color.calendar.today color.calendar.due color.calendar.due.today "
|
||||
"color.calendar.overdue color.calendar.weekend color.calendar.holiday "
|
||||
"color.calendar.weeknumber color.summary.background color.summary.bar "
|
||||
"color.history.add color.history.done color.history.delete color.undo.before "
|
||||
"color.undo.after confirmation curses data.location dateformat dateformat.holiday "
|
||||
"dateformat.report dateformat.annotation debug default.command "
|
||||
"default.priority default.project defaultwidth due locale displayweeknumber "
|
||||
"export.ical.class echo.command fontunderline locking monthsperline nag next "
|
||||
"journal.time journal.time.start.annotation journal.time.stop.annotation "
|
||||
"project shadow.command shadow.file shadow.notify weekstart editor "
|
||||
"import.synonym.id import.synonym.uuid complete.all.projects 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 "
|
||||
"calendar.holidays calendar.legend color color.active color.due "
|
||||
"color.due.today color.blocked color.overdue color.pri.H color.pri.L "
|
||||
"color.pri.M color.pri.none color.recurring color.tagged color.footnote "
|
||||
"color.header color.debug color.alternate color.calendar.today "
|
||||
"color.calendar.due color.calendar.due.today color.calendar.overdue "
|
||||
"color.calendar.weekend color.calendar.holiday color.calendar.weeknumber "
|
||||
"color.summary.background color.summary.bar color.history.add "
|
||||
"color.history.done color.history.delete color.undo.before "
|
||||
"color.undo.after confirmation curses data.location dateformat "
|
||||
"dateformat.holiday dateformat.report dateformat.annotation debug "
|
||||
"default.command default.priority default.project defaultwidth due "
|
||||
"locale displayweeknumber export.ical.class echo.command fontunderline "
|
||||
"locking monthsperline nag next journal.time "
|
||||
"journal.time.start.annotation journal.time.stop.annotation project "
|
||||
"shadow.command shadow.file shadow.notify weekstart editor "
|
||||
"import.synonym.id import.synonym.uuid complete.all.projects "
|
||||
"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
|
||||
"shell.prompt "
|
||||
#endif
|
||||
|
@ -821,10 +823,11 @@ int handleShow (std::string &outs)
|
|||
"import.synonym.end import.synonym.project import.synonym.priority "
|
||||
"import.synonym.fg import.synonym.bg import.synonym.description "
|
||||
|
||||
"urgency.next.coefficient urgency.blocking.coefficient urgency.blocked.coefficient "
|
||||
"urgency.due.coefficient urgency.priority.coefficient urgency.waiting.coefficient "
|
||||
"urgency.active.coefficient urgency.project.coefficient urgency.tags.coefficient "
|
||||
"urgency.annotations.coefficient ";
|
||||
"urgency.next.coefficient urgency.blocking.coefficient "
|
||||
"urgency.blocked.coefficient urgency.due.coefficient "
|
||||
"urgency.priority.coefficient urgency.waiting.coefficient "
|
||||
"urgency.active.coefficient urgency.project.coefficient "
|
||||
"urgency.tags.coefficient urgency.annotations.coefficient ";
|
||||
|
||||
// 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue