- More work on the output text from merge.  Improved, but not yet finished.
This commit is contained in:
Paul Beckingham 2010-10-17 01:12:00 -04:00
parent d177acfcbd
commit 837b89dd2d
3 changed files with 42 additions and 31 deletions

View file

@ -1198,7 +1198,7 @@ void TDB::merge (const std::string& mergeFile)
// helper lists // helper lists
std::set<std::string> uuid_new, uuid_left; std::set<std::string> uuid_new, uuid_left;
// 1. read tasmods out of the remaining lines // 1. read taskmods out of the remaining lines
readTaskmods (l, lit, lmods); readTaskmods (l, lit, lmods);
readTaskmods (r, rit, rmods); readTaskmods (r, rit, rmods);
@ -1213,9 +1213,11 @@ void TDB::merge (const std::string& mergeFile)
{ {
if (lmod_it->isNew ()) if (lmod_it->isNew ())
{ {
std::cout << "Skipping new local task " /*
<< lmod_it->getUuid() std::cout << "New local task "
<< (useColor ? colorAdded.colorize (lmod_it->getUuid ()) : lmod_it->getUuid ())
<< "\n"; << "\n";
*/
uuid_left.insert (lmod_it->getUuid ()); uuid_left.insert (lmod_it->getUuid ());
} }
@ -1237,9 +1239,11 @@ void TDB::merge (const std::string& mergeFile)
// new uuid? // new uuid?
if (tmod.isNew ()) if (tmod.isNew ())
{ {
/*
std::cout << "Adding new remote task " std::cout << "Adding new remote task "
<< (useColor ? colorAdded.colorize (tmod.getUuid ()) : 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);
@ -1270,8 +1274,8 @@ void TDB::merge (const std::string& mergeFile)
DEBUG_STR (" left uuid: " + uuid); DEBUG_STR (" left uuid: " + uuid);
// skip if uuid had already been merged // skip if uuid had already been merged
if (uuid_left.find (uuid) == uuid_left.end ()) { if (uuid_left.find (uuid) == uuid_left.end ())
{
bool rwin = false; bool rwin = false;
bool lwin = false; bool lwin = false;
for (rmod_rit = rmods.rbegin (); rmod_rit != rmods.rend (); rmod_rit++) for (rmod_rit = rmods.rbegin (); rmod_rit != rmods.rend (); rmod_rit++)
@ -1309,7 +1313,7 @@ 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 " std::cout << "Found remote change to "
<< (useColor ? colorChanged.colorize (uuid) : uuid) << (useColor ? colorChanged.colorize (uuid) : uuid)
<< "\n"; << "\n";
@ -1324,7 +1328,7 @@ void TDB::merge (const std::string& mergeFile)
} }
else else
{ {
std::cout << "Rejecting remote changes for uuid " std::cout << "Retaining local changes to "
<< (useColor ? colorRejected.colorize (uuid) : uuid) << (useColor ? colorRejected.colorize (uuid) : uuid)
<< "\n"; << "\n";
@ -1372,7 +1376,6 @@ void TDB::merge (const std::string& mergeFile)
DEBUG_STR ("sorting taskmod list"); DEBUG_STR ("sorting taskmod list");
mods.sort (); mods.sort ();
} }
else if (rit == r.end ()) else if (rit == r.end ())
{ {
@ -1380,21 +1383,27 @@ void TDB::merge (const std::string& mergeFile)
// local branch is up-to-date // local branch is up-to-date
// nothing happend on the local branch either // nothing happend on the local branch either
if (lit == l.end()) /*
throw std::string ("Database is up to date."); if (lit != l.end ())
else std::cout << "No remote changes detected.\n";
std::cout << "No changes were made on the remote database.\n"; */
} }
else // lit == l.end () else // lit == l.end ()
{ {
// nothing happend on the local branch // nothing happend on the local branch
std::cout << "No changes were made on the local database. Adding remote changes...\n"; /*
std::cout << "No local changes detected.\n";
*/
// add remaining lines (remote branch) to the list of modifications // add remaining lines (remote branch) to the list of modifications
/*
std::cout << "Remote changes detected.\n";
*/
readTaskmods (r, rit, mods); readTaskmods (r, rit, mods);
} }
/////////////////////////////////////// ///////////////////////////////////////
// Now apply the changes.
// redo command: // redo command:
if (!mods.empty ()) if (!mods.empty ())
@ -1429,17 +1438,19 @@ void TDB::merge (const std::string& mergeFile)
bool found = false; bool found = false;
if ( (statusBefore == Task::completed) if ( (statusBefore == Task::completed)
|| (statusBefore == Task::deleted) ) { || (statusBefore == Task::deleted) )
{
// Find the same uuid in completed data // Find the same uuid in completed data
for (it = completed.begin (); it != completed.end (); ++it) for (it = completed.begin (); it != completed.end (); ++it)
{ {
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 " std::cout << "Modifying "
<< (useColor ? colorChanged.colorize (uuid) : uuid) << (useColor ? colorChanged.colorize (uuid) : uuid)
<< "\n"; << "\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 ();
@ -1478,7 +1489,7 @@ void TDB::merge (const std::string& mergeFile)
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 " std::cout << "Found remote change to "
<< (useColor ? colorChanged.colorize (uuid) : uuid) << (useColor ? colorChanged.colorize (uuid) : uuid)
<< "\n"; << "\n";
@ -1537,7 +1548,7 @@ void TDB::merge (const std::string& mergeFile)
if (!found) if (!found)
{ {
std::cout << "Adding " std::cout << "Merging new remote task "
<< (useColor ? colorAdded.colorize (uuid) : uuid) << (useColor ? colorAdded.colorize (uuid) : uuid)
<< "\n"; << "\n";
@ -1548,14 +1559,11 @@ void TDB::merge (const std::string& mergeFile)
} }
else else
{ {
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 + "'.";
@ -1571,9 +1579,7 @@ void TDB::merge (const std::string& mergeFile)
// generate undo.data format // generate undo.data format
for (it = mods.begin (); it != mods.end (); it++) for (it = mods.begin (); it != mods.end (); it++)
{
undo.push_back(it->toString ()); undo.push_back(it->toString ());
}
// write undo file // write undo file
if (! File::write (undoFile, undo, false)) if (! File::write (undoFile, undo, false))

View file

@ -606,7 +606,7 @@ void handleMerge (std::string& outs)
Directory location (context.config.get ("data.location")); Directory location (context.config.get ("data.location"));
// be sure that uri points to a file // be sure that uri points to a file
uri.append("undo.data"); uri.append ("undo.data");
Transport* transport; Transport* transport;
if ((transport = Transport::getTransport (uri)) != NULL ) if ((transport = Transport::getTransport (uri)) != NULL )
@ -624,12 +624,14 @@ void handleMerge (std::string& outs)
context.tdb.merge (file); context.tdb.merge (file);
context.tdb.unlock (); context.tdb.unlock ();
std::cout << "Merge complete.\n";
context.hooks.trigger ("post-merge-command"); context.hooks.trigger ("post-merge-command");
if (tmpfile != "") if (tmpfile != "")
remove (tmpfile.c_str()); remove (tmpfile.c_str ());
if ( ((sAutopush == "ask") && (confirm ("Would you like to push the changes to \'" + pushfile + "\'?")) ) if ( ((sAutopush == "ask") && (confirm ("Would you like to push the merged changes to \'" + pushfile + "\'?")) )
|| (bAutopush) ) || (bAutopush) )
{ {
std::string out; std::string out;
@ -677,18 +679,20 @@ void handlePush (std::string& outs)
throw std::string ("The uri '") + uri.path + "' is not a local directory."; throw std::string ("The uri '") + uri.path + "' is not a local directory.";
std::ifstream ifile1 ((location.data + "/undo.data").c_str(), std::ios_base::binary); std::ifstream ifile1 ((location.data + "/undo.data").c_str(), std::ios_base::binary);
std::ofstream ofile1 ((uri.path + "undo.data").c_str(), std::ios_base::binary); std::ofstream ofile1 ((uri.path + "/undo.data").c_str(), std::ios_base::binary);
ofile1 << ifile1.rdbuf(); ofile1 << ifile1.rdbuf();
std::ifstream ifile2 ((location.data + "/pending.data").c_str(), std::ios_base::binary); std::ifstream ifile2 ((location.data + "/pending.data").c_str(), std::ios_base::binary);
std::ofstream ofile2 ((uri.path + "pending.data").c_str(), std::ios_base::binary); std::ofstream ofile2 ((uri.path + "/pending.data").c_str(), std::ios_base::binary);
ofile2 << ifile2.rdbuf(); ofile2 << ifile2.rdbuf();
std::ifstream ifile3 ((location.data + "/completed.data").c_str(), std::ios_base::binary); std::ifstream ifile3 ((location.data + "/completed.data").c_str(), std::ios_base::binary);
std::ofstream ofile3 ((uri.path + "completed.data").c_str(), std::ios_base::binary); std::ofstream ofile3 ((uri.path + "/completed.data").c_str(), std::ios_base::binary);
ofile3 << ifile3.rdbuf(); ofile3 << ifile3.rdbuf();
} }
std::cout << "Local tasks transferred to " << uri.data << "\n";
context.hooks.trigger ("post-push-command"); context.hooks.trigger ("post-push-command");
} }
else else
@ -740,7 +744,7 @@ void handlePull (std::string& outs)
if (path1.exists() && path2.exists() && path3.exists()) if (path1.exists() && path2.exists() && path3.exists())
{ {
// if (confirm ("xxxxxxxxxxxxx")) // if (confirm ("xxxxxxxxxxxxx"))
// { // {
std::ofstream ofile1 ((location.data + "/undo.data").c_str(), std::ios_base::binary); std::ofstream ofile1 ((location.data + "/undo.data").c_str(), std::ios_base::binary);
std::ifstream ifile1 (path1.data.c_str() , std::ios_base::binary); std::ifstream ifile1 (path1.data.c_str() , std::ios_base::binary);
@ -761,6 +765,8 @@ void handlePull (std::string& outs)
} }
} }
std::cout << "Tasks transferred from " << uri.data << "\n";
context.hooks.trigger ("post-pull-command"); context.hooks.trigger ("post-pull-command");
} }
else else

View file

@ -28,7 +28,7 @@
use strict; use strict;
use warnings; use warnings;
use Test::More tests => 16; use Test::More tests => 15;
# Create the rc file. # Create the rc file.
if (open my $fh, '>', 'dup.rc') if (open my $fh, '>', 'dup.rc')
@ -58,7 +58,6 @@ like ($output, qr/Tags\s+tag/, 'duplicate added tag');
# Test the output of the duplicate command - returning id of duplicated task # Test the output of the duplicate command - returning id of duplicated task
$output = qx{../task rc:dup.rc duplicate 1}; $output = qx{../task rc:dup.rc duplicate 1};
like ($output, qr/Duplicated\s+1\s+'foo'/, 'duplicate output task id and description'); like ($output, qr/Duplicated\s+1\s+'foo'/, 'duplicate output task id and description');
like ($output, qr/Duplicated\s+1\s+task/, 'duplicate output number of tasks duplicated');
like ($output, qr/Created\s+task\s+4/, 'duplicate output of new task id'); like ($output, qr/Created\s+task\s+4/, 'duplicate output of new task id');
# Cleanup. # Cleanup.