Context: Now obeys command DNA

- Applying a context filter is now performed only when a command requests it.
This commit is contained in:
Paul Beckingham
2015-08-02 10:08:04 -04:00
parent 8d5a60a2a2
commit 758df84539
6 changed files with 14 additions and 11 deletions

View File

@@ -601,13 +601,16 @@ void CLI2::addContextFilter ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Parse the command line, identifiying filter components, expanding syntactic // Parse the command line, identifiying filter components, expanding syntactic
// sugar as necessary. // sugar as necessary.
void CLI2::prepareFilter (bool applyContext) void CLI2::prepareFilter ()
{ {
// Clear and re-populate. // Clear and re-populate.
_id_ranges.clear (); _id_ranges.clear ();
_uuid_list.clear (); _uuid_list.clear ();
if (applyContext) // Context is only applied for commands that request it.
std::string command = getCommand ();
Command* cmd = context.commands[command];
if (cmd && cmd->uses_context ())
addContextFilter (); addContextFilter ();
// Classify FILTER and MODIFICATION args, based on CMD and READCMD/WRITECMD. // Classify FILTER and MODIFICATION args, based on CMD and READCMD/WRITECMD.

View File

@@ -77,7 +77,7 @@ public:
void analyze (); void analyze ();
void addFilter (const std::string& arg); void addFilter (const std::string& arg);
void addContextFilter (); void addContextFilter ();
void prepareFilter (bool applyContext = true); void prepareFilter ();
const std::vector <std::string> getWords (bool filtered = true); const std::vector <std::string> getWords (bool filtered = true);
bool canonicalize (std::string&, const std::string&, const std::string&) const; bool canonicalize (std::string&, const std::string&, const std::string&) const;
std::string getBinary () const; std::string getBinary () const;

View File

@@ -69,12 +69,12 @@ Filter::~Filter ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Take an input set of tasks and filter into a subset. // Take an input set of tasks and filter into a subset.
void Filter::subset (const std::vector <Task>& input, std::vector <Task>& output, bool applyContext /* = true */) void Filter::subset (const std::vector <Task>& input, std::vector <Task>& output)
{ {
context.timer_filter.start (); context.timer_filter.start ();
_startCount = (int) input.size (); _startCount = (int) input.size ();
context.cli2.prepareFilter (applyContext); context.cli2.prepareFilter ();
std::vector <std::pair <std::string, Lexer::Type>> precompiled; std::vector <std::pair <std::string, Lexer::Type>> precompiled;
for (auto& a : context.cli2._args) for (auto& a : context.cli2._args)
@@ -115,11 +115,11 @@ void Filter::subset (const std::vector <Task>& input, std::vector <Task>& output
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Take the set of all tasks and filter into a subset. // Take the set of all tasks and filter into a subset.
void Filter::subset (std::vector <Task>& output, bool applyContext /* = true */) void Filter::subset (std::vector <Task>& output)
{ {
context.timer_filter.start (); context.timer_filter.start ();
context.cli2.prepareFilter (applyContext); context.cli2.prepareFilter ();
std::vector <std::pair <std::string, Lexer::Type>> precompiled; std::vector <std::pair <std::string, Lexer::Type>> precompiled;
for (auto& a : context.cli2._args) for (auto& a : context.cli2._args)

View File

@@ -40,8 +40,8 @@ public:
Filter (); Filter ();
~Filter (); ~Filter ();
void subset (const std::vector <Task>&, std::vector <Task>&, bool applyContext = true); void subset (const std::vector <Task>&, std::vector <Task>&);
void subset (std::vector <Task>&, bool applyContext = true); void subset (std::vector <Task>&);
bool hasFilter (); bool hasFilter ();
bool hasModifications (); bool hasModifications ();
bool pendingOnly (); bool pendingOnly ();

View File

@@ -296,7 +296,7 @@ void TF2::load_tasks ()
{ {
Task::status status = task.getStatus (); Task::status status = task.getStatus ();
// Completed / deleted tasks in pending.data get an ID if GC is off. // Completed / deleted tasks in pending.data get an ID if GC is off.
if (!context.run_gc || if (! context.run_gc ||
(status != Task::completed && status != Task::deleted)) (status != Task::completed && status != Task::deleted))
task.id = context.tdb2.next_id (); task.id = context.tdb2.next_id ();
} }

View File

@@ -60,7 +60,7 @@ int CmdExport::execute (std::string& output)
// Apply filter. // Apply filter.
Filter filter; Filter filter;
std::vector <Task> filtered; std::vector <Task> filtered;
filter.subset (filtered, false); filter.subset (filtered);
if (filter.hasModifications ()) if (filter.hasModifications ())
throw std::string (STRING_ERROR_NO_MODS); throw std::string (STRING_ERROR_NO_MODS);