diff --git a/doc/man/taskrc.5 b/doc/man/taskrc.5 index d79546f0e..1afc284e1 100644 --- a/doc/man/taskrc.5 +++ b/doc/man/taskrc.5 @@ -711,6 +711,18 @@ Colors used by the undo command, to indicate the values both before and after a change that is to be reverted. .RE +.TP +.B color.sync.added=green +.RE +.br +.B color.sync.changed=yellow +.RE +.br +.B color.sync.rejected=red +.RS +Colors the output of the merge command. +.RE + .TP .B rule.precedence.color=overdue,tag,project,keyword,active,... .RS diff --git a/src/Config.cpp b/src/Config.cpp index c018ca417..f8b8a29ae 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -136,6 +136,10 @@ std::string Config::defaults = "color.history.done=color0 on rgb050 # Color of completed tasks in ghistory report\n" "color.history.delete=color0 on rgb550 # Color of deleted tasks in ghistory report\n" "\n" + "color.sync.added=rgb005 # Color of added tasks in sync output\n" + "color.sync.changed=rgb550 # Color of changed tasks in sync output\n" + "color.sync.rejected=rgb500 # Color of rejected tasks in sync output\n" + "\n" "color.undo.before=color1 # Color of values before a change\n" "color.undo.after=color2 # Color of values after a change\n" "\n" @@ -177,6 +181,10 @@ std::string Config::defaults = "color.history.done=black on green # Color of completed tasks in ghistory report\n" "color.history.delete=black on yellow # Color of deleted tasks in ghistory report\n" "\n" + "color.sync.added=green # Color of added tasks in sync output\n" + "color.sync.changed=yellow # Color of changed tasks in sync output\n" + "color.sync.rejected=red # Color of rejected tasks in sync output\n" + "\n" "color.undo.before=red # Color of values before a change\n" "color.undo.after=green # Color of values after a change\n" "\n" diff --git a/src/TDB.cpp b/src/TDB.cpp index 15339e6c6..600189e18 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -1122,10 +1122,10 @@ void TDB::merge (const std::string& mergeFile) rit = r.begin (); lit = l.begin (); - if (rit != r.end()) - rline = *rit; - if (lit != l.end()) - lline = *lit; + if (rit != r.end()) + rline = *rit; + if (lit != l.end()) + lline = *lit; /////////////////////////////////////// // find the branch-off point: @@ -1148,6 +1148,13 @@ void TDB::merge (const std::string& mergeFile) } } + // Add some color. + bool useColor = (context.config.getBoolean ("color") || context.config.getBoolean ("_forcecolor")) + ? true : false; + Color colorAdded (context.config.get ("color.sync.added")); + Color colorChanged (context.config.get ("color.sync.changed")); + Color colorRejected (context.config.get ("color.sync.rejected")); + // at this point we can assume: (lline==rline) || (lit == l.end()) // thus we search for the first non-equal lines or the EOF bool found = false; @@ -1169,9 +1176,10 @@ void TDB::merge (const std::string& mergeFile) } } + std::cout << "\n"; + /////////////////////////////////////// // branch-off point found: - if (found) { DEBUG_STR_PART ("Branch-off point found at: "); @@ -1195,13 +1203,13 @@ void TDB::merge (const std::string& mergeFile) std::list::iterator lmod_it; for (lmod_it = lmods.begin (); lmod_it != lmods.end (); lmod_it++) { - if ( (*lmod_it).isNew ()) + if (lmod_it->isNew ()) { std::cout << "Skipping new local task " - << (*lmod_it).getUuid() + << lmod_it->getUuid() << "\n"; - uuid_left.insert ( (*lmod_it).getUuid ()); + uuid_left.insert (lmod_it->getUuid ()); } } @@ -1222,8 +1230,9 @@ void TDB::merge (const std::string& mergeFile) if (tmod.isNew ()) { std::cout << "Adding new remote task " - << tmod.getUuid() + << (useColor ? colorAdded.colorize (tmod.getUuid ()) : tmod.getUuid ()) << "\n"; + uuid_new.insert (tmod.getUuid ()); mods.push_back (tmod); rmods.erase (current); @@ -1292,7 +1301,9 @@ void TDB::merge (const std::string& mergeFile) // which one is newer? if (tmod_r > tmod_l) { - std::cout << "Applying remote changes for uuid " << uuid << "\n"; + std::cout << "Applying remote changes for uuid " + << (useColor ? colorChanged.colorize (uuid) : uuid) + << "\n"; mods.push_front(tmod_r); @@ -1305,15 +1316,18 @@ void TDB::merge (const std::string& mergeFile) } else { - std::cout << "Rejecting remote changes for uuid " << uuid << "\n"; + std::cout << "Rejecting remote changes for uuid " + << (useColor ? colorRejected.colorize (uuid) : uuid) + << "\n"; + // inserting right mod into history of local database // so that it can be restored later // TODO feature: make rejected changes on the remote branch restorable // Taskmod reverse_tmod; // -// tmod_r.setBefore((*lmod_rit).getAfter()); -// tmod_r.setTimestamp((*lmod_rit).getTimestamp()+1); +// tmod_r.setBefore(lmod_rit->getAfter()); +// tmod_r.setTimestamp(lmod_rit->getTimestamp()+1); // // reverse_tmod.setAfter(tmod_r.getBefore()); // reverse_tmod.setBefore(tmod_r.getAfter()); @@ -1359,9 +1373,9 @@ void TDB::merge (const std::string& mergeFile) // nothing happend on the local branch either if (lit == l.end()) - throw std::string ("Database is up to date."); - else - std::cout << "No changes were made on the remote database.\n"; + throw std::string ("Database is up to date."); + else + std::cout << "No changes were made on the remote database.\n"; } else // lit == l.end () { @@ -1415,7 +1429,9 @@ void TDB::merge (const std::string& mergeFile) if (it->find (uuid) != std::string::npos) { // Update the completed record. - std::cout << "Modifying " << uuid << "\n"; + std::cout << "Modifying " + << (useColor ? colorChanged.colorize (uuid) : uuid) + << "\n"; // remove the \n from composeF4() string std::string newline = tmod.getAfter ().composeF4 (); @@ -1445,15 +1461,18 @@ void TDB::merge (const std::string& mergeFile) break; } } - } else { - + } + else + { // Find the same uuid in the pending data. for (it = pending.begin (); it != pending.end (); ++it) { if (it->find (uuid) != std::string::npos) { // Update the pending record. - std::cout << "Modifying " << uuid << "\n"; + std::cout << "Modifying " + << (useColor ? colorChanged.colorize (uuid) : uuid) + << "\n"; // remove the \n from composeF4() string // which will replace the current line @@ -1485,10 +1504,11 @@ void TDB::merge (const std::string& mergeFile) if (!found) { - std::cout << "Missing " << uuid << "\n"; + std::cout << "Missing " + << (useColor ? colorRejected.colorize (uuid) : uuid) + << "\n"; mods.erase (current); } - } else { @@ -1509,7 +1529,10 @@ void TDB::merge (const std::string& mergeFile) if (!found) { - std::cout << "Adding " << uuid << "\n"; + std::cout << "Adding " + << (useColor ? colorAdded.colorize (uuid) : uuid) + << "\n"; + // remove the \n from composeF4() string std::string newline = tmod.getAfter ().composeF4 (); newline = newline.substr (0, newline.length ()-1); @@ -1517,12 +1540,14 @@ void TDB::merge (const std::string& mergeFile) } else { - std::cout << "Skipping duplicate " << uuid << "\n"; + std::cout << "Skipping duplicate " << uuid << "\n"; mods.erase (current); } } } + std::cout << "\n"; + // write pending file if (! File::write (pendingFile, pending)) throw std::string ("Could not write '") + pendingFile + "'."; diff --git a/src/command.cpp b/src/command.cpp index 48ce4262c..07a3c5db2 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -877,6 +877,7 @@ int handleShow (std::string &outs) "color.calendar.weekend color.calendar.holiday color.calendar.weeknumber " "color.summary.background color.summary.bar color.history.add " "color.history.done color.history.delete color.undo.before " + "color.sync.added color.sync.changed color.sync.rejected " "color.undo.after confirmation curses data.location dateformat " "dateformat.holiday dateformat.report dateformat.annotation debug " "default.command default.priority default.project defaultwidth due " diff --git a/src/tests/merge.t b/src/tests/merge.t index ea0dad0a3..471d4d5c7 100755 --- a/src/tests/merge.t +++ b/src/tests/merge.t @@ -28,7 +28,7 @@ use strict; use warnings; -use Test::More tests => 43; +use Test::More tests => 41; use File::Copy; use constant false => 0; @@ -140,7 +140,6 @@ copy("local/undo.data", "local/undo.save") or fail("copy local/undo.data to loca my $output_l = qx{../task rc:local.rc merge remote/}; #check output -like ($output_l, qr/Running redo/, "local-merge finished"); unlike ($output_l, qr/Missing/, "local-merge: no missing entry"); unlike ($output_l, qr/Not adding duplicate/, "local-merge: no duplicates"); @@ -148,7 +147,6 @@ unlike ($output_l, qr/Not adding duplicate/, "local-merge: no duplicates"); my $output_r = qx{../task rc:remote.rc merge local/undo.save}; # check output -like ($output_r, qr/Running redo/, "remote-merge finished"); unlike ($output_r, qr/Missing/, "remote-merge: no missing entry"); unlike ($output_r, qr/Not adding duplicate/, "remote-merge: no duplicates");