From 3a009561448924a321f1abba8dc40d18afc96930 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Fri, 3 Dec 2021 03:57:37 -0500 Subject: [PATCH] ColDepends: Allow specifying short(er) UUIDs --- src/Context.cpp | 7 ++++++- src/columns/ColDepends.cpp | 20 ++++++++++++++++++-- src/main.cpp | 6 ++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/src/Context.cpp b/src/Context.cpp index ea1055ecc..a1edaa1b4 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -43,6 +43,7 @@ #include #include #include +#include #ifdef HAVE_COMMIT #include @@ -667,9 +668,13 @@ int Context::initialize (int argc, const char** argv) rc = 4; } + catch (const std::regex_error& e) + { + std::cout << "regex_error caught: " << e.what() << '\n'; + } catch (...) { - error ("Unknown error. Please report."); + error ("knknown error. Please report."); rc = 3; } diff --git a/src/columns/ColDepends.cpp b/src/columns/ColDepends.cpp index 551af3ec5..9c2847322 100644 --- a/src/columns/ColDepends.cpp +++ b/src/columns/ColDepends.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #define STRING_COLUMN_LABEL_DEP "Depends" @@ -164,10 +165,25 @@ void ColumnDepends::modify (Task& task, const std::string& value) { auto hyphen = dep.find ('-'); long lower, upper; // For ID ranges + std::regex valid_uuid ("[a-f0-9]{8}([a-f0-9-]{4,28})?"); // TODO: Make more precise // UUID - if (dep.length () == 36) - task.addDependency (dep); + if (dep.length () >= 8 && std::regex_match (dep, valid_uuid)) + { + // Full UUID, can be added directly + if (dep.length () == 36) + task.addDependency (dep); + + // Short UUID, need to look up full form + else + { + Task loaded_task; + if (Context::getContext ().tdb2.get (dep, loaded_task)) + task.addDependency (loaded_task.get ("uuid")); + else + throw format ("Dependency could not be set - task with UUID '{1}' does not exist.", dep); + } + } // ID range else if (dep.find ('-') != std::string::npos && extractLongInteger (dep.substr (0, hyphen), lower) && diff --git a/src/main.cpp b/src/main.cpp index 0fa007588..07ac2fd22 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,6 +29,7 @@ #include #include #include +#include //////////////////////////////////////////////////////////////////////////////// int main (int argc, const char** argv) @@ -64,6 +65,11 @@ int main (int argc, const char** argv) status = -3; } + catch (const std::regex_error& e) + { + std::cout << "regex_error caught: " << e.what() << '\n'; + } + catch (...) { std::cerr << "Unknown error. Please report.\n";