- 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.
.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

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.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"

View file

@ -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<Taskmod>::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());
@ -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);
@ -1523,6 +1546,8 @@ void TDB::merge (const std::string& mergeFile)
}
}
std::cout << "\n";
// write pending file
if (! File::write (pendingFile, pending))
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.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 "

View file

@ -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");