- Colorized the merge process.
- Added whitespace to the merge output for alignment and a less cramped
  look.
- De-tabbed.
- Changed "(*foo).method ()" to "foo->method ()" or clarity.
- Removed two tests that relied upon the (removed) "Redo" message.
This commit is contained in:
Paul Beckingham
2010-10-15 00:18:58 -04:00
parent bb6f456e04
commit 783867c512
5 changed files with 71 additions and 27 deletions

View File

@@ -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. a change that is to be reverted.
.RE .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 .TP
.B rule.precedence.color=overdue,tag,project,keyword,active,... .B rule.precedence.color=overdue,tag,project,keyword,active,...
.RS .RS

View File

@@ -136,6 +136,10 @@ std::string Config::defaults =
"color.history.done=color0 on rgb050 # Color of completed tasks in ghistory report\n" "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" "color.history.delete=color0 on rgb550 # Color of deleted tasks in ghistory report\n"
"\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.before=color1 # Color of values before a change\n"
"color.undo.after=color2 # Color of values after a change\n" "color.undo.after=color2 # Color of values after a change\n"
"\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.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" "color.history.delete=black on yellow # Color of deleted tasks in ghistory report\n"
"\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.before=red # Color of values before a change\n"
"color.undo.after=green # Color of values after a change\n" "color.undo.after=green # Color of values after a change\n"
"\n" "\n"

View File

@@ -1122,10 +1122,10 @@ void TDB::merge (const std::string& mergeFile)
rit = r.begin (); rit = r.begin ();
lit = l.begin (); lit = l.begin ();
if (rit != r.end()) if (rit != r.end())
rline = *rit; rline = *rit;
if (lit != l.end()) if (lit != l.end())
lline = *lit; lline = *lit;
/////////////////////////////////////// ///////////////////////////////////////
// find the branch-off point: // 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()) // at this point we can assume: (lline==rline) || (lit == l.end())
// thus we search for the first non-equal lines or the EOF // thus we search for the first non-equal lines or the EOF
bool found = false; bool found = false;
@@ -1169,9 +1176,10 @@ void TDB::merge (const std::string& mergeFile)
} }
} }
std::cout << "\n";
/////////////////////////////////////// ///////////////////////////////////////
// branch-off point found: // branch-off point found:
if (found) if (found)
{ {
DEBUG_STR_PART ("Branch-off point found at: "); DEBUG_STR_PART ("Branch-off point found at: ");
@@ -1195,13 +1203,13 @@ void TDB::merge (const std::string& mergeFile)
std::list<Taskmod>::iterator lmod_it; std::list<Taskmod>::iterator lmod_it;
for (lmod_it = lmods.begin (); lmod_it != lmods.end (); 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 " std::cout << "Skipping new local task "
<< (*lmod_it).getUuid() << lmod_it->getUuid()
<< "\n"; << "\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 ()) if (tmod.isNew ())
{ {
std::cout << "Adding new remote task " std::cout << "Adding new remote task "
<< tmod.getUuid() << (useColor ? colorAdded.colorize (tmod.getUuid ()) : tmod.getUuid ())
<< "\n"; << "\n";
uuid_new.insert (tmod.getUuid ()); uuid_new.insert (tmod.getUuid ());
mods.push_back (tmod); mods.push_back (tmod);
rmods.erase (current); rmods.erase (current);
@@ -1292,7 +1301,9 @@ void TDB::merge (const std::string& mergeFile)
// which one is newer? // which one is newer?
if (tmod_r > tmod_l) 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); mods.push_front(tmod_r);
@@ -1305,15 +1316,18 @@ void TDB::merge (const std::string& mergeFile)
} }
else 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 // inserting right mod into history of local database
// so that it can be restored later // so that it can be restored later
// TODO feature: make rejected changes on the remote branch restorable // TODO feature: make rejected changes on the remote branch restorable
// Taskmod reverse_tmod; // Taskmod reverse_tmod;
// //
// tmod_r.setBefore((*lmod_rit).getAfter()); // tmod_r.setBefore(lmod_rit->getAfter());
// tmod_r.setTimestamp((*lmod_rit).getTimestamp()+1); // tmod_r.setTimestamp(lmod_rit->getTimestamp()+1);
// //
// reverse_tmod.setAfter(tmod_r.getBefore()); // reverse_tmod.setAfter(tmod_r.getBefore());
// reverse_tmod.setBefore(tmod_r.getAfter()); // reverse_tmod.setBefore(tmod_r.getAfter());
@@ -1359,9 +1373,9 @@ void TDB::merge (const std::string& mergeFile)
// nothing happend on the local branch either // nothing happend on the local branch either
if (lit == l.end()) if (lit == l.end())
throw std::string ("Database is up to date."); throw std::string ("Database is up to date.");
else else
std::cout << "No changes were made on the remote database.\n"; std::cout << "No changes were made on the remote database.\n";
} }
else // lit == l.end () else // lit == l.end ()
{ {
@@ -1415,7 +1429,9 @@ void TDB::merge (const std::string& mergeFile)
if (it->find (uuid) != std::string::npos) if (it->find (uuid) != std::string::npos)
{ {
// Update the completed record. // Update the completed record.
std::cout << "Modifying " << uuid << "\n"; std::cout << "Modifying "
<< (useColor ? colorChanged.colorize (uuid) : uuid)
<< "\n";
// remove the \n from composeF4() string // remove the \n from composeF4() string
std::string newline = tmod.getAfter ().composeF4 (); std::string newline = tmod.getAfter ().composeF4 ();
@@ -1445,15 +1461,18 @@ void TDB::merge (const std::string& mergeFile)
break; break;
} }
} }
} else { }
else
{
// Find the same uuid in the pending data. // Find the same uuid in the pending data.
for (it = pending.begin (); it != pending.end (); ++it) for (it = pending.begin (); it != pending.end (); ++it)
{ {
if (it->find (uuid) != std::string::npos) if (it->find (uuid) != std::string::npos)
{ {
// Update the pending record. // Update the pending record.
std::cout << "Modifying " << uuid << "\n"; std::cout << "Modifying "
<< (useColor ? colorChanged.colorize (uuid) : uuid)
<< "\n";
// remove the \n from composeF4() string // remove the \n from composeF4() string
// which will replace the current line // which will replace the current line
@@ -1485,10 +1504,11 @@ void TDB::merge (const std::string& mergeFile)
if (!found) if (!found)
{ {
std::cout << "Missing " << uuid << "\n"; std::cout << "Missing "
<< (useColor ? colorRejected.colorize (uuid) : uuid)
<< "\n";
mods.erase (current); mods.erase (current);
} }
} }
else else
{ {
@@ -1509,7 +1529,10 @@ void TDB::merge (const std::string& mergeFile)
if (!found) if (!found)
{ {
std::cout << "Adding " << uuid << "\n"; std::cout << "Adding "
<< (useColor ? colorAdded.colorize (uuid) : uuid)
<< "\n";
// remove the \n from composeF4() string // remove the \n from composeF4() string
std::string newline = tmod.getAfter ().composeF4 (); std::string newline = tmod.getAfter ().composeF4 ();
newline = newline.substr (0, newline.length ()-1); newline = newline.substr (0, newline.length ()-1);
@@ -1517,12 +1540,14 @@ void TDB::merge (const std::string& mergeFile)
} }
else else
{ {
std::cout << "Skipping duplicate " << uuid << "\n"; std::cout << "Skipping duplicate " << uuid << "\n";
mods.erase (current); mods.erase (current);
} }
} }
} }
std::cout << "\n";
// write pending file // write pending file
if (! File::write (pendingFile, pending)) if (! File::write (pendingFile, pending))
throw std::string ("Could not write '") + pendingFile + "'."; throw std::string ("Could not write '") + pendingFile + "'.";

View File

@@ -877,6 +877,7 @@ int handleShow (std::string &outs)
"color.calendar.weekend color.calendar.holiday color.calendar.weeknumber " "color.calendar.weekend color.calendar.holiday color.calendar.weeknumber "
"color.summary.background color.summary.bar color.history.add " "color.summary.background color.summary.bar color.history.add "
"color.history.done color.history.delete color.undo.before " "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 " "color.undo.after confirmation curses data.location dateformat "
"dateformat.holiday dateformat.report dateformat.annotation debug " "dateformat.holiday dateformat.report dateformat.annotation debug "
"default.command default.priority default.project defaultwidth due " "default.command default.priority default.project defaultwidth due "

View File

@@ -28,7 +28,7 @@
use strict; use strict;
use warnings; use warnings;
use Test::More tests => 43; use Test::More tests => 41;
use File::Copy; use File::Copy;
use constant false => 0; 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/}; my $output_l = qx{../task rc:local.rc merge remote/};
#check output #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/Missing/, "local-merge: no missing entry");
unlike ($output_l, qr/Not adding duplicate/, "local-merge: no duplicates"); 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}; my $output_r = qx{../task rc:remote.rc merge local/undo.save};
# check output # 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/Missing/, "remote-merge: no missing entry");
unlike ($output_r, qr/Not adding duplicate/, "remote-merge: no duplicates"); unlike ($output_r, qr/Not adding duplicate/, "remote-merge: no duplicates");