Bug - DOM lookup for 'id' was not supported
- Removed DOM caching, which appears to be a problem. - Added 'id' and 'uuid' to DOM::get, which were missing, and therefore caused all filters with sequences to fail. - Modified CmdInfo to load all tasks, until TDB2 is here.
This commit is contained in:
106
src/DOM.cpp
106
src/DOM.cpp
@@ -27,6 +27,7 @@
|
|||||||
|
|
||||||
#define L10N // Localization complete.
|
#define L10N // Localization complete.
|
||||||
|
|
||||||
|
//#include <iostream> // TODO Remove
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <Context.h>
|
#include <Context.h>
|
||||||
#include <Nibbler.h>
|
#include <Nibbler.h>
|
||||||
@@ -72,25 +73,24 @@ DOM::~DOM ()
|
|||||||
const std::string DOM::get (const std::string& name)
|
const std::string DOM::get (const std::string& name)
|
||||||
{
|
{
|
||||||
// Cache test.
|
// Cache test.
|
||||||
|
/*
|
||||||
std::map <std::string, std::string>::iterator hit = _cache.find (name);
|
std::map <std::string, std::string>::iterator hit = _cache.find (name);
|
||||||
if (hit != _cache.end ())
|
if (hit != _cache.end ())
|
||||||
return hit->second;
|
return hit->second;
|
||||||
|
*/
|
||||||
|
|
||||||
int len = name.length ();
|
int len = name.length ();
|
||||||
Nibbler n (name);
|
Nibbler n (name);
|
||||||
|
|
||||||
// Primitives
|
// Primitives
|
||||||
if (is_primitive (name))
|
if (is_primitive (name))
|
||||||
{
|
return /*_cache[name] =*/ name;
|
||||||
_cache[name] = name;
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
// rc. --> context.config
|
// rc. --> context.config
|
||||||
else if (len > 3 &&
|
else if (len > 3 &&
|
||||||
name.substr (0, 3) == "rc.")
|
name.substr (0, 3) == "rc.")
|
||||||
{
|
{
|
||||||
return _cache[name] = context.config.get (name.substr (3));
|
return /*_cache[name] =*/ context.config.get (name.substr (3));
|
||||||
}
|
}
|
||||||
|
|
||||||
// context.*
|
// context.*
|
||||||
@@ -98,25 +98,25 @@ const std::string DOM::get (const std::string& name)
|
|||||||
name.substr (0, 8) == "context.")
|
name.substr (0, 8) == "context.")
|
||||||
{
|
{
|
||||||
if (name == "context.program")
|
if (name == "context.program")
|
||||||
return _cache[name] = context.args[0].first;
|
return /*_cache[name] =*/ context.args[0].first;
|
||||||
|
|
||||||
else if (name == "context.args")
|
else if (name == "context.args")
|
||||||
{
|
{
|
||||||
std::string combined;
|
std::string combined;
|
||||||
join (combined, " ", context.args.list ());
|
join (combined, " ", context.args.list ());
|
||||||
return _cache[name] = combined;
|
return /*_cache[name] =*/ combined;
|
||||||
}
|
}
|
||||||
else if (name == "context.width")
|
else if (name == "context.width")
|
||||||
{
|
{
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << context.terminal_width;
|
s << context.terminal_width;
|
||||||
return _cache[name] = s.str ();
|
return /*_cache[name] =*/ s.str ();
|
||||||
}
|
}
|
||||||
else if (name == "context.height")
|
else if (name == "context.height")
|
||||||
{
|
{
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
s << context.terminal_height;
|
s << context.terminal_height;
|
||||||
return _cache[name] = s.str ();
|
return /*_cache[name] =*/ s.str ();
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
@@ -132,39 +132,39 @@ const std::string DOM::get (const std::string& name)
|
|||||||
{
|
{
|
||||||
// Taskwarrior version number.
|
// Taskwarrior version number.
|
||||||
if (name == "system.version")
|
if (name == "system.version")
|
||||||
return _cache[name] = VERSION;
|
return /*_cache[name] =*/ VERSION;
|
||||||
|
|
||||||
#ifdef HAVE_LIBLUA
|
#ifdef HAVE_LIBLUA
|
||||||
// Lua version number.
|
// Lua version number.
|
||||||
else if (name == "system.lua.version")
|
else if (name == "system.lua.version")
|
||||||
return _cache[name] = LUA_RELEASE;
|
return /*_cache[name] =*/ LUA_RELEASE;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// OS type.
|
// OS type.
|
||||||
else if (name == "system.os")
|
else if (name == "system.os")
|
||||||
#if defined (DARWIN)
|
#if defined (DARWIN)
|
||||||
return _cache[name] = "Darwin";
|
return /*_cache[name] =*/ "Darwin";
|
||||||
#elif defined (SOLARIS)
|
#elif defined (SOLARIS)
|
||||||
return _cache[name] = "Solaris";
|
return /*_cache[name] =*/ "Solaris";
|
||||||
#elif defined (CYGWIN)
|
#elif defined (CYGWIN)
|
||||||
return _cache[name] = "Cygwin";
|
return /*_cache[name] =*/ "Cygwin";
|
||||||
#elif defined (OPENBSD)
|
#elif defined (OPENBSD)
|
||||||
return _cache[name] = "OpenBSD";
|
return /*_cache[name] =*/ "OpenBSD";
|
||||||
#elif defined (HAIKU)
|
#elif defined (HAIKU)
|
||||||
return _cache[name] = "Haiku";
|
return /*_cache[name] =*/ "Haiku";
|
||||||
#elif defined (FREEBSD)
|
#elif defined (FREEBSD)
|
||||||
return _cache[name] = "FreeBSD";
|
return /*_cache[name] =*/ "FreeBSD";
|
||||||
#elif defined (LINUX)
|
#elif defined (LINUX)
|
||||||
return _cache[name] = "Linux";
|
return /*_cache[name] =*/ "Linux";
|
||||||
#else
|
#else
|
||||||
return _cache[name] = STRING_DOM_UNKNOWN
|
return /*_cache[name] =*/ STRING_DOM_UNKNOWN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
else
|
else
|
||||||
throw format (STRING_DOM_UNREC, name);
|
throw format (STRING_DOM_UNREC, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
return _cache[name] = name;
|
return /*_cache[name] =*/ name;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -206,9 +206,11 @@ const std::string DOM::get (const std::string& name)
|
|||||||
const std::string DOM::get (const std::string& name, Task& task)
|
const std::string DOM::get (const std::string& name, Task& task)
|
||||||
{
|
{
|
||||||
// Cache test.
|
// Cache test.
|
||||||
|
/*
|
||||||
std::map <std::string, std::string>::iterator hit = _cache.find (name);
|
std::map <std::string, std::string>::iterator hit = _cache.find (name);
|
||||||
if (hit != _cache.end ())
|
if (hit != _cache.end ())
|
||||||
return hit->second;
|
return hit->second;
|
||||||
|
*/
|
||||||
|
|
||||||
Nibbler n (name);
|
Nibbler n (name);
|
||||||
int id;
|
int id;
|
||||||
@@ -216,7 +218,7 @@ const std::string DOM::get (const std::string& name, Task& task)
|
|||||||
|
|
||||||
// Primitives
|
// Primitives
|
||||||
if (is_primitive (name))
|
if (is_primitive (name))
|
||||||
return _cache[name] = name;
|
return /*_cache[name] =*/ name;
|
||||||
|
|
||||||
// <id>.<name>
|
// <id>.<name>
|
||||||
else if (n.getInt (id))
|
else if (n.getInt (id))
|
||||||
@@ -224,25 +226,14 @@ const std::string DOM::get (const std::string& name, Task& task)
|
|||||||
if (n.skip ('.'))
|
if (n.skip ('.'))
|
||||||
{
|
{
|
||||||
// TODO Obtain task 'id' from TDB2.
|
// TODO Obtain task 'id' from TDB2.
|
||||||
|
// std::cout << "# DOM::get " << name << "\n";
|
||||||
|
|
||||||
std::string attr;
|
std::string attr;
|
||||||
n.getUntilEOS (attr);
|
n.getUntilEOS (attr);
|
||||||
|
|
||||||
if (attr == "description") return task.get ("description");
|
if (attr == "id") return format (task.id);
|
||||||
else if (attr == "status") return task.get ("status");
|
else if (attr == "urgency") return format (task.urgency (), 4, 3);
|
||||||
else if (attr == "project") return task.get ("project");
|
else return task.get (attr);
|
||||||
else if (attr == "priority") return task.get ("priority");
|
|
||||||
else if (attr == "parent") return task.get ("parent");
|
|
||||||
else if (attr == "tags") return task.get ("tags");
|
|
||||||
else if (attr == "urgency") return format (task.urgency (), 4, 3);
|
|
||||||
else if (attr == "recur") return task.get ("recur");
|
|
||||||
else if (attr == "depends") return task.get ("depends");
|
|
||||||
else if (attr == "entry") return task.get ("entry");
|
|
||||||
else if (attr == "start") return task.get ("start");
|
|
||||||
else if (attr == "end") return task.get ("end");
|
|
||||||
else if (attr == "due") return task.get ("due");
|
|
||||||
else if (attr == "until") return task.get ("until");
|
|
||||||
else if (attr == "wait") return task.get ("wait");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,46 +243,26 @@ const std::string DOM::get (const std::string& name, Task& task)
|
|||||||
if (n.skip ('.'))
|
if (n.skip ('.'))
|
||||||
{
|
{
|
||||||
// TODO Obtain task 'uuid' from TDB2.
|
// TODO Obtain task 'uuid' from TDB2.
|
||||||
|
// std::cout << "# DOM::get name\n";
|
||||||
|
|
||||||
std::string attr;
|
std::string attr;
|
||||||
n.getUntilEOS (attr);
|
n.getUntilEOS (attr);
|
||||||
|
|
||||||
if (attr == "description") return task.get ("description");
|
if (attr == "id") return format (task.id);
|
||||||
else if (attr == "status") return task.get ("status");
|
else if (attr == "urgency") return format (task.urgency (), 4, 3);
|
||||||
else if (attr == "project") return task.get ("project");
|
else return task.get (attr);
|
||||||
else if (attr == "priority") return task.get ("priority");
|
|
||||||
else if (attr == "parent") return task.get ("parent");
|
|
||||||
else if (attr == "tags") return task.get ("tags");
|
|
||||||
else if (attr == "urgency") return format (task.urgency (), 4, 3);
|
|
||||||
else if (attr == "recur") return task.get ("recur");
|
|
||||||
else if (attr == "depends") return task.get ("depends");
|
|
||||||
else if (attr == "entry") return task.get ("entry");
|
|
||||||
else if (attr == "start") return task.get ("start");
|
|
||||||
else if (attr == "end") return task.get ("end");
|
|
||||||
else if (attr == "due") return task.get ("due");
|
|
||||||
else if (attr == "until") return task.get ("until");
|
|
||||||
else if (attr == "wait") return task.get ("wait");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// [<task>.] <name>
|
// [<task>.] <name>
|
||||||
if (name == "description") return task.get ("description");
|
// std::cout << "# DOM::get " << name << "\n";
|
||||||
else if (name == "status") return task.get ("status");
|
|
||||||
else if (name == "project") return task.get ("project");
|
if (name == "id") return format (task.id);
|
||||||
else if (name == "priority") return task.get ("priority");
|
else if (name == "urgency") return format (task.urgency (), 4, 3);
|
||||||
else if (name == "parent") return task.get ("parent");
|
else return task.get (name);
|
||||||
else if (name == "tags") return task.get ("tags");
|
|
||||||
else if (name == "urgency") return format (task.urgency (), 4, 3);
|
|
||||||
else if (name == "recur") return task.get ("recur");
|
|
||||||
else if (name == "depends") return task.get ("depends");
|
|
||||||
else if (name == "entry") return task.get ("entry");
|
|
||||||
else if (name == "start") return task.get ("start");
|
|
||||||
else if (name == "end") return task.get ("end");
|
|
||||||
else if (name == "due") return task.get ("due");
|
|
||||||
else if (name == "until") return task.get ("until");
|
|
||||||
else if (name == "wait") return task.get ("wait");
|
|
||||||
|
|
||||||
// Delegate to the context-free version of DOM::get.
|
// Delegate to the context-free version of DOM::get.
|
||||||
|
// std::cout << "# DOM::get delegate...\n";
|
||||||
return this->get (name);
|
return this->get (name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -304,8 +275,7 @@ void DOM::set (const std::string& name, const std::string& value)
|
|||||||
if (len > 3 &&
|
if (len > 3 &&
|
||||||
name.substr (0, 3) == "rc.")
|
name.substr (0, 3) == "rc.")
|
||||||
{
|
{
|
||||||
_cache[name] = value;
|
context.config.set (name.substr (3), /*_cache[name] =*/ value);
|
||||||
context.config.set (name.substr (3), value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unrecognized --> error.
|
// Unrecognized --> error.
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ bool Expression::eval (Task& task)
|
|||||||
right._raw_type = value_stack.back ()._raw_type;
|
right._raw_type = value_stack.back ()._raw_type;
|
||||||
}
|
}
|
||||||
value_stack.pop_back ();
|
value_stack.pop_back ();
|
||||||
|
// std::cout << "# right raw=" << right._raw << " type=" << right._type << " value=" << right._string << "\n";
|
||||||
|
|
||||||
// lvalue (dom).
|
// lvalue (dom).
|
||||||
Variant left (value_stack.back ());
|
Variant left (value_stack.back ());
|
||||||
@@ -138,6 +139,7 @@ bool Expression::eval (Task& task)
|
|||||||
left._raw_type = value_stack.back ()._raw_type;
|
left._raw_type = value_stack.back ()._raw_type;
|
||||||
}
|
}
|
||||||
value_stack.pop_back ();
|
value_stack.pop_back ();
|
||||||
|
// std::cout << "# left raw=" << left._raw << " type=" << left._type << " value=" << left._string << "\n";
|
||||||
|
|
||||||
// Now the binary operators.
|
// Now the binary operators.
|
||||||
if (arg->first == "and")
|
if (arg->first == "and")
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ int CmdInfo::execute (std::string& output)
|
|||||||
std::vector <Task> tasks;
|
std::vector <Task> tasks;
|
||||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||||
handleRecurrence ();
|
handleRecurrence ();
|
||||||
context.tdb.loadPending (tasks);
|
context.tdb.load (tasks);
|
||||||
context.tdb.commit ();
|
context.tdb.commit ();
|
||||||
context.tdb.unlock ();
|
context.tdb.unlock ();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user