diff --git a/ChangeLog b/ChangeLog index d1913c941..f61db1518 100644 --- a/ChangeLog +++ b/ChangeLog @@ -14,6 +14,8 @@ Features + #1256 Supports default values for UDA fields (thanks to Thomas Sullivan). + Stores un-synched transactions in /backlog.data. + Adds a new 'synchronize' command to sync data with a task server. + + Adds a new 'initialize' synchronize command argument that uploads all pending + tasks for first-time initialization. + Adds a new 'sync' verbosity token, which will remind when a backlog builds up and needs a sync. + Supports IPv4 and IPv6 server addresses. diff --git a/doc/man/task-sync.5.in b/doc/man/task-sync.5.in index fa1cc3e25..479d3870b 100644 --- a/doc/man/task-sync.5.in +++ b/doc/man/task-sync.5.in @@ -340,7 +340,7 @@ need to retype the URI every time. You can also use this configuration scheme to set alias names, e.g. set pull.desktop.uri and run 'task pull desktop'. .RE -Note that, when using SSH/scp, hostnames will be expanded due to the ssh +Note that, when using SSH/scp, hostnames will be expanded due to the ssh configuration file ~/.ssh/config. .SH EXTERNAL DEPENDENCIES diff --git a/src/commands/CmdSync.cpp b/src/commands/CmdSync.cpp index 8d44cf697..8fc191fcc 100644 --- a/src/commands/CmdSync.cpp +++ b/src/commands/CmdSync.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -42,7 +43,7 @@ extern Context context; CmdSync::CmdSync () { _keyword = "synchronize"; - _usage = "task synchronize"; + _usage = "task synchronize [initialize]"; _description = STRING_CMD_SYNC_USAGE; _read_only = false; _displays_id = false; @@ -58,6 +59,22 @@ int CmdSync::execute (std::string& output) std::stringstream out; + // Loog for the 'init' keyword to indicate one-time pending.data upload. + bool first_time_init = false; + std::vector words = context.a3.extract_words (); + std::vector ::iterator word; + for (word = words.begin (); word != words.end (); ++word) + { + if (closeEnough ("initialize", *word, 4)) + { + if (!context.config.getBoolean ("confirmation") || + confirm (STRING_CMD_SYNC_INIT)) + first_time_init = true; + else + throw std::string (STRING_CMD_SYNC_NO_INIT); + } + } + // If no server is set up, quit. std::string connection = context.config.get ("taskd.server"); if (connection == "" || @@ -78,21 +95,30 @@ int CmdSync::execute (std::string& output) if (certificate == "") throw std::string (STRING_CMD_SYNC_BAD_CERT); - // Read backlog.data. + // If this is a first-time initialization, send pending.data, not + // backlog.data. std::string payload = ""; - File backlog (context.config.get ("data.location") + "/backlog.data"); - if (backlog.exists ()) - backlog.read (payload); - - // Count the number of tasks being uploaded. int upload_count = 0; + if (first_time_init) { - std::vector lines; - split (lines, payload, "\n"); + std::vector pending = context.tdb2.pending.get_tasks (); + std::vector ::iterator i; + for (i = pending.begin (); i != pending.end (); ++i) + { + payload += i->composeJSON () + "\n"; + ++upload_count; + } + } + else + { + std::vector lines = context.tdb2.backlog.get_lines (); std::vector ::iterator i; for (i = lines.begin (); i != lines.end (); ++i) if ((*i)[0] == '{') + { + payload += *i + "\n"; ++upload_count; + } } // Send 'sync' + payload. @@ -103,8 +129,6 @@ int CmdSync::execute (std::string& output) request.set ("user", credentials[1]); request.set ("key", credentials[2]); - // TODO Add the other necessary header fields. - request.setPayload (payload); out << format (STRING_CMD_SYNC_PROGRESS, connection) diff --git a/src/en-US.h b/src/en-US.h index cf82bf804..e8fa1643f 100644 --- a/src/en-US.h +++ b/src/en-US.h @@ -418,6 +418,8 @@ #define STRING_CMD_SYNC_FAIL_CONNECT "Sync failed. Could not connect to the Task Server." #define STRING_CMD_SYNC_BAD_SERVER "Sync failed. Malformed configuration setting '{1}'" #define STRING_CMD_SYNC_NO_TLS "Taskwarrior was built without GnuTLS support. Sync is not available." +#define STRING_CMD_SYNC_INIT "Please confirm that you wish to upload all your pending tasks to the Task Server?" +#define STRING_CMD_SYNC_NO_INIT "Taskwarrior will not proceed with first-time sync initialization." #define STRING_CMD_DIAG_USAGE "Platform, build and environment details" #define STRING_CMD_DIAG_PLATFORM "Platform" #define STRING_CMD_DIAG_UNKNOWN "" diff --git a/src/es-ES.h b/src/es-ES.h index fd6da7f30..2dafba366 100644 --- a/src/es-ES.h +++ b/src/es-ES.h @@ -429,7 +429,8 @@ #define STRING_CMD_SYNC_FAIL_CONNECT "Sincronización fallida. No se pudo conectar con el Servidor Task." #define STRING_CMD_SYNC_BAD_SERVER "Sincronización fallida. Ajuste de configuración '{1}' incorrecto" #define STRING_CMD_SYNC_NO_TLS "Taskwarrior was built without GnuTLS support. Sync is not available." - +#define STRING_CMD_SYNC_INIT "Please confirm that you wish to upload all your pending tasks to the Task Server?" +#define STRING_CMD_SYNC_NO_INIT "Taskwarrior will not proceed with first-time sync initialization." #define STRING_CMD_DIAG_USAGE "Detalles de plataforma, construcción y entorno" #define STRING_CMD_DIAG_PLATFORM "Plataforma" #define STRING_CMD_DIAG_UNKNOWN "" diff --git a/src/fr-FR.h b/src/fr-FR.h index 4f2db021e..cd271ca9b 100644 --- a/src/fr-FR.h +++ b/src/fr-FR.h @@ -418,6 +418,8 @@ #define STRING_CMD_SYNC_FAIL_CONNECT "Sync failed. Could not connect to the Task Server." #define STRING_CMD_SYNC_BAD_SERVER "Sync failed. Malformed configuration setting '{1}'" #define STRING_CMD_SYNC_NO_TLS "Taskwarrior was built without GnuTLS support. Sync is not available." +#define STRING_CMD_SYNC_INIT "Please confirm that you wish to upload all your pending tasks to the Task Server?" +#define STRING_CMD_SYNC_NO_INIT "Taskwarrior will not proceed with first-time sync initialization." #define STRING_CMD_DIAG_USAGE "Platform, build and environment details" #define STRING_CMD_DIAG_PLATFORM "Platform" #define STRING_CMD_DIAG_UNKNOWN "" diff --git a/src/it-IT.h b/src/it-IT.h index f65baec66..ec84b001e 100644 --- a/src/it-IT.h +++ b/src/it-IT.h @@ -419,6 +419,8 @@ #define STRING_CMD_SYNC_FAIL_CONNECT "Sincronizzazione fallita. Impossibile connettersi al Task Server." #define STRING_CMD_SYNC_BAD_SERVER "Sincronizzazione fallita. Impostazione di configurazione '{1}' malformata" #define STRING_CMD_SYNC_NO_TLS "Taskwarrior was built without GnuTLS support. Sync is not available." +#define STRING_CMD_SYNC_INIT "Please confirm that you wish to upload all your pending tasks to the Task Server?" +#define STRING_CMD_SYNC_NO_INIT "Taskwarrior will not proceed with first-time sync initialization." #define STRING_CMD_DIAG_USAGE "Dettagli su piattaforma, build e ambiente" #define STRING_CMD_DIAG_PLATFORM "Piattaforma" #define STRING_CMD_DIAG_UNKNOWN ""