From 29a7837fda1de1c58f027be227abfa68729539ff Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 21 Feb 2016 10:13:21 -0500 Subject: [PATCH] TD-104: Unrecognized taskwarrior file format - Thanks to Jeremy John Reeder, Reg. --- AUTHORS | 1 + ChangeLog | 2 ++ src/Config.cpp | 2 +- src/Task.cpp | 47 +++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/AUTHORS b/AUTHORS index 9180d257f..ac6e20d23 100644 --- a/AUTHORS +++ b/AUTHORS @@ -286,3 +286,4 @@ suggestions: Simon Michael Robin Green pawprint + Reg diff --git a/ChangeLog b/ChangeLog index 1b33d807d..fd7c472e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,7 @@ 2.5.1 () - +- TD-104 Unrecognized taskwarrior file format + (thanks to Jeremy John Reeder, Reg). - TW-38 Dates in the far future give bad estimates in burndown (thanks to Ben Boeckel). - TW-188 short help text diff --git a/src/Config.cpp b/src/Config.cpp index 035059cf0..92e9ff146 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -99,7 +99,7 @@ std::string Config::_defaults = "xterm.title=no # Sets xterm title for some commands\n" "expressions=infix # Prefer infix over postfix expressions\n" "json.array=on # Enclose JSON output in [ ]\n" - "json.depends.array=on # Encode dependencies as a JSON array\n" + "json.depends.array=off # Encode dependencies as a JSON array\n" "abbreviation.minimum=2 # Shortest allowed abbreviation\n" "\n" "# Dates\n" diff --git a/src/Task.cpp b/src/Task.cpp index d260f7214..35191c9b6 100644 --- a/src/Task.cpp +++ b/src/Task.cpp @@ -661,26 +661,42 @@ void Task::parseJSON (const json::object* root_obj) addTag (tag->_data); } } - // This is a temporary measure to allow Mirakel sync, and will be removed - // in a future release. + // This is a temporary measure to accomodate a malformed JSON message from + // Mirakel sync. + // + // 2016-02-21 Mirakel dropped sync support in late 2015. This can be + // removed in a later release. else if (i.first == "tags" && i.second->type() == json::j_string) { json::string* tag = (json::string*)i.second; addTag (tag->_data); } - // Dependencies can be exported as a single comma-separated string, or as - // an array of strings. + // Dependencies can be exported as an array of strings. + // 2016-02-21: This will be the only option in future releases. + // See other 2016-02-21 comments for details. else if (i.first == "depends" && i.second->type() == json::j_array) { - json::array* tags = (json::array*)i.second; - for (auto& t : tags->_data) + json::array* deps = (json::array*)i.second; + for (auto& t : deps->_data) { - json::string* tag = (json::string*)t; - addDependency (tag->_data); + json::string* dep = (json::string*)t; + addDependency (dep->_data); } } + // Dependencies can be exported as a single comma-separated string. + // 2016-02-21: Deprecated - see other 2016-02-21 comments for details. + else if (i.first == "depends" && i.second->type() == json::j_string) + { + json::string* deps = (json::string*)i.second; + std::vector uuids; + split (uuids, deps->_data, ','); + + for (const auto& uuid : uuids) + addDependency (uuid); + } + // Strings are decoded. else if (type == "string") set (i.first, json::decode (unquoteText (i.second->dump ()))); @@ -892,6 +908,21 @@ std::string Task::composeJSON (bool decorate /*= false*/) const // Dependencies are an array by default. else if (i.first == "depends" #ifdef PRODUCT_TASKWARRIOR + // 2016-02-20: Taskwarrior 2.5.0 introduced the 'json.depends.array' setting + // which defaulted to 'on', and emitted this JSON for + // dependencies: + // + // With json.depends.array=on "depends":["",""] + // With json.depends.array=off "depends":"," + // + // Taskwarrior 2.5.1 defaults this to 'off', because Taskserver + // 1.0.0 and 1.1.0 both expect that. Taskserver 1.2.0 will + // accept both forms, but emit the 'off' variant. + // + // When Taskwarrior 2.5.0 is no longer the dominant version, + // and Taskserver 1.2.0 is released, the default for + // 'json.depends.array' can revert to 'on'. + && context.config.getBoolean ("json.depends.array") #endif )