ColDepends: Allow specifying short(er) UUIDs

This commit is contained in:
Tomas Babej 2021-12-03 03:57:37 -05:00
parent 01add8a34a
commit 3a00956144
3 changed files with 30 additions and 3 deletions

View file

@ -43,6 +43,7 @@
#include <shared.h> #include <shared.h>
#include <format.h> #include <format.h>
#include <main.h> #include <main.h>
#include <regex>
#ifdef HAVE_COMMIT #ifdef HAVE_COMMIT
#include <commit.h> #include <commit.h>
@ -667,9 +668,13 @@ int Context::initialize (int argc, const char** argv)
rc = 4; rc = 4;
} }
catch (const std::regex_error& e)
{
std::cout << "regex_error caught: " << e.what() << '\n';
}
catch (...) catch (...)
{ {
error ("Unknown error. Please report."); error ("knknown error. Please report.");
rc = 3; rc = 3;
} }

View file

@ -34,6 +34,7 @@
#include <main.h> #include <main.h>
#include <util.h> #include <util.h>
#include <stdlib.h> #include <stdlib.h>
#include <regex>
#define STRING_COLUMN_LABEL_DEP "Depends" #define STRING_COLUMN_LABEL_DEP "Depends"
@ -164,10 +165,25 @@ void ColumnDepends::modify (Task& task, const std::string& value)
{ {
auto hyphen = dep.find ('-'); auto hyphen = dep.find ('-');
long lower, upper; // For ID ranges long lower, upper; // For ID ranges
std::regex valid_uuid ("[a-f0-9]{8}([a-f0-9-]{4,28})?"); // TODO: Make more precise
// UUID // UUID
if (dep.length () == 36) if (dep.length () >= 8 && std::regex_match (dep, valid_uuid))
task.addDependency (dep); {
// 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 // ID range
else if (dep.find ('-') != std::string::npos && else if (dep.find ('-') != std::string::npos &&
extractLongInteger (dep.substr (0, hyphen), lower) && extractLongInteger (dep.substr (0, hyphen), lower) &&

View file

@ -29,6 +29,7 @@
#include <new> #include <new>
#include <cstring> #include <cstring>
#include <Context.h> #include <Context.h>
#include <regex>
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int main (int argc, const char** argv) int main (int argc, const char** argv)
@ -64,6 +65,11 @@ int main (int argc, const char** argv)
status = -3; status = -3;
} }
catch (const std::regex_error& e)
{
std::cout << "regex_error caught: " << e.what() << '\n';
}
catch (...) catch (...)
{ {
std::cerr << "Unknown error. Please report.\n"; std::cerr << "Unknown error. Please report.\n";