mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
CmdImport: Neglect attributes with dynamic default values
If not explicitly stated on import, values with default dynamic values (such as modified, entry or end) can produce a false notion of incoming 'modified' data, where the only difference between the data in the database and data being imported is that the dynamic defaults differ, since they have been generated at different times. Solve the issue by neglecting the attributes with dynamic defaults, if they have been generated.
This commit is contained in:
parent
3765aacc73
commit
6c7aecc2a6
1 changed files with 26 additions and 4 deletions
|
@ -176,17 +176,39 @@ void CmdImport::importSingleTask (json::object* obj)
|
||||||
{
|
{
|
||||||
// Parse the whole thing, validate the data.
|
// Parse the whole thing, validate the data.
|
||||||
Task task (obj);
|
Task task (obj);
|
||||||
|
|
||||||
|
bool hasGeneratedEntry = not task.has ("entry");
|
||||||
|
bool hasExplicitEnd = task.has ("end");
|
||||||
|
|
||||||
task.validate ();
|
task.validate ();
|
||||||
|
|
||||||
|
bool hasGeneratedEnd = not hasExplicitEnd and task.has ("end");
|
||||||
|
|
||||||
// Check whether the imported task is new or a modified existing task.
|
// Check whether the imported task is new or a modified existing task.
|
||||||
Task before;
|
Task before;
|
||||||
if (context.tdb2.get (task.get ("uuid"), before))
|
if (context.tdb2.get (task.get ("uuid"), before))
|
||||||
{
|
{
|
||||||
// "modified:" is automatically set to the current time when a task is
|
// We need to neglect updates from attributes with dynamic defaults
|
||||||
// changed. If the imported task has a modification timestamp we need
|
// unless they have been explicitly specified on import.
|
||||||
// to ignore it in task comparison in order to check for meaningful
|
//
|
||||||
// differences. Setting it to the previous value achieves just that.
|
// There are three attributes with dynamic defaults, besites uuid:
|
||||||
|
// - modified: Ignored in any case.
|
||||||
|
// - entry: Ignored if generated.
|
||||||
|
// - end: Ignored if generated.
|
||||||
|
|
||||||
|
// The 'modified' attribute is ignored in any case, since if it
|
||||||
|
// were the only difference between the tasks, it would have been
|
||||||
|
// neglected anyway, since it is bumped on each modification.
|
||||||
task.set ("modified", before.get ("modified"));
|
task.set ("modified", before.get ("modified"));
|
||||||
|
|
||||||
|
// Other generated values are replaced by values from existing task,
|
||||||
|
// so that they are ignored on comparison.
|
||||||
|
if (hasGeneratedEntry)
|
||||||
|
task.set ("entry", before.get ("entry"));
|
||||||
|
|
||||||
|
if (hasGeneratedEnd)
|
||||||
|
task.set ("end", before.get ("end"));
|
||||||
|
|
||||||
if (before != task)
|
if (before != task)
|
||||||
{
|
{
|
||||||
CmdModify modHelper;
|
CmdModify modHelper;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue