From b041e54be6ae919d589bd57c91fe6dfa3eea92f3 Mon Sep 17 00:00:00 2001 From: Johannes Schlatow Date: Wed, 6 Oct 2010 12:57:14 +0200 Subject: [PATCH] Merge command - improved merge.autopush=ask - fixed newline issues - fixed: entries for new tasks got lost in undo.data --- src/TDB.cpp | 14 ++++++++++---- src/command.cpp | 43 +++++++++++++++++++++++++++---------------- src/tests/merge.t | 2 ++ 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/TDB.cpp b/src/TDB.cpp index 5c6a3cdb9..2f523b2ec 100644 --- a/src/TDB.cpp +++ b/src/TDB.cpp @@ -1141,7 +1141,7 @@ void TDB::merge (const std::string& mergeFile) lline = *lit; // push the line to the new undo.data - undo.push_back (lline); + undo.push_back (lline + "\n"); // found first matching lines? if (lline.compare (rline) == 0) @@ -1389,7 +1389,8 @@ void TDB::merge (const std::string& mergeFile) // iterate over taskmod list std::list::iterator it; - for (it = mods.begin (); it != mods.end (); ) { + for (it = mods.begin (); it != mods.end (); ) + { std::list::iterator current = it++; Taskmod tmod = *current; @@ -1507,11 +1508,16 @@ void TDB::merge (const std::string& mergeFile) if (!found) { std::cout << "Adding " << uuid << "\n"; - pending.push_back (tmod.getAfter ().composeF4 ()); + // remove the \n from composeF4() string + std::string newline = tmod.getAfter ().composeF4 (); + newline = newline.substr (0, newline.length ()-1); + pending.push_back (newline); } else + { std::cout << "Not adding duplicate " << uuid << "\n"; mods.erase (current); + } } } @@ -1535,7 +1541,7 @@ void TDB::merge (const std::string& mergeFile) } // write undo file - if (! File::write (undoFile, undo, true)) + if (! File::write (undoFile, undo, false)) throw std::string ("Could not write '") + undoFile + "'."; } else // nothing to be done diff --git a/src/command.cpp b/src/command.cpp index bf0247fee..390fe3978 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -583,17 +583,27 @@ void handleMerge (std::string& outs) if (context.hooks.trigger ("pre-merge-command")) { std::string file = trim (context.task.get ("description")); + std::string pushfile = ""; std::string tmpfile = ""; + + std::string sAutopush = context.config.get ("merge.autopush"); + bool bAutopush = context.config.getBoolean("merge.autopush"); if (file.length () == 0) { // get default target from config file = context.config.get ("merge.default.uri"); + + if (sAutopush == "ask") + pushfile = context.config.get ("push.default.uri"); } else { // replace argument with uri from config std::string tmp = context.config.get ("merge." + file + ".uri"); + + if (sAutopush == "ask") + pushfile = context.config.get ("push." + file + ".uri"); if (tmp != "") file = tmp; @@ -631,20 +641,17 @@ void handleMerge (std::string& outs) if (tmpfile != "") { remove (tmpfile.c_str()); - - std::string autopush = context.config.get ("merge.autopush"); - - // TODO Task accepts many different values for "yes". Try Config::getBoolean. - if ( ((autopush == "ask") && (confirm ("Do you want to push the changes to the database you merged from?")) ) - || (autopush == "yes") ) - { - std::string out; - handlePush(out); - } + } + + if ( ((sAutopush == "ask") && (confirm ("Do you want to push the changes to \'" + pushfile + "\'?")) ) + || (bAutopush) ) + { + std::string out; + handlePush(out); } - + } - else // TODO : get default source from config file + else throw std::string ("You must specify a file to merge."); } } @@ -663,7 +670,7 @@ void handlePush (std::string& outs) } else { - // replace argument with uri from config + // try to replace argument with uri from config std::string tmp = context.config.get ("push." + file + ".uri"); if (tmp != "") @@ -682,12 +689,16 @@ void handlePush (std::string& outs) } else { - throw std::string ("Push failed"); + // TODO copy files + //std::ifstream ifile (location.data + "/undo.data", std::ios_base::binary); + //std::ofstream ofile (location.data + "/undo.data", std::ios_base::binary); + + throw std::string ("Push to local targets is not (yet) supported."); } context.hooks.trigger ("post-push-command"); } - else // TODO : get default target from config file + else throw std::string ("You must specify a target."); } } @@ -739,7 +750,7 @@ void handlePull (std::string& outs) context.hooks.trigger ("post-pull-command"); } - else // TODO : get default target from config file + else throw std::string ("You must specify a target."); } } diff --git a/src/tests/merge.t b/src/tests/merge.t index de7de36d9..3150c69fe 100755 --- a/src/tests/merge.t +++ b/src/tests/merge.t @@ -136,7 +136,9 @@ sleep(1); qx{../task rc:remote.rc 4 +gym}; # right_newer # merge remote into local +copy("local/undo.data", "local/undo.save") or fail("copy local/undo.data to local/undo.save"); my $output_l = qx{../task rc:local.rc merge remote/undo.data}; +rename("local/undo.save", "local/undo.data") or fail("rename local/undo.save in local/undo.data"); #check output like ($output_l, qr/Running redo/, "local-merge finished");