void AutoMergeConfiguration::configureMerger(ThreeWayMerge& merger)
{
	auto metaMergeStrategy = new MetaMergeStrategy(merger);
	allocatedStrategies.push_back(metaMergeStrategy);
	merger.addConflictStrategy(metaMergeStrategy);

	auto autoMergeStrategy = new AutoMergeStrategy();
	allocatedStrategies.push_back(autoMergeStrategy);
	merger.addConflictStrategy(autoMergeStrategy);
}
void OverwriteMergeConfiguration::configureMerger (ThreeWayMerge & merger)
{
	auto metaMergeStrategy = new MetaMergeStrategy (merger);
	allocatedStrategies.push_back (metaMergeStrategy);
	merger.addConflictStrategy (metaMergeStrategy);

	auto oneSideStrategy = new OneSideStrategy (winningSide);
	allocatedStrategies.push_back (oneSideStrategy);
	merger.addConflictStrategy (oneSideStrategy);
}
void ImportMergeConfiguration::configureMerger (ThreeWayMerge & merger)
{
	auto metaMergeStrategy = new MetaMergeStrategy (merger);
	allocatedStrategies.push_back (metaMergeStrategy);
	merger.addConflictStrategy (metaMergeStrategy);

	auto newKeyStrategy = new NewKeyStrategy ();
	allocatedStrategies.push_back (newKeyStrategy);
	merger.addConflictStrategy (newKeyStrategy);

	auto oneSideValueStrategy = new OneSideValueStrategy (THEIRS);
	allocatedStrategies.push_back (oneSideValueStrategy);
	merger.addConflictStrategy (oneSideValueStrategy);
}
void OneSideMergeConfiguration::configureMerger(ThreeWayMerge& merger)
{
	AutoMergeConfiguration::configureMerger(merger);
	OneSideStrategy *oneSideStrategy = new OneSideStrategy(winningSide);
	allocatedStrategies.push_back(oneSideStrategy);
	merger.addConflictStrategy(oneSideStrategy);
}
Beispiel #5
0
void TreeViewModel::importConfiguration(const QString& name, const QString& format, QString& file, const QVariantList &mergeStrategies)
{
	Key		root(name.toStdString(), KEY_END);
	KeySet	originalKeys = collectCurrentKeySet();
	KeySet	base = originalKeys.cut(root);
	printWarnings (cerr, root);

	KeySet importedKeys;

	string formatString = format.toStdString();
	string fileString = file.remove("file://").toStdString();

	Modules modules;
	PluginPtr plugin = modules.load(formatString);

	Key errorKey (root);
	errorKey.setString (fileString);

	plugin->get(importedKeys, errorKey);

	stringstream ws;
	stringstream es;
	QString warnings;
	QString errors;

	printWarnings(ws, errorKey);
	warnings = QString::fromStdString(ws.str());
	printError(es, errorKey);
	errors  = QString::fromStdString(es.str());

	if(!errors.isEmpty())
	{
		emit showMessage(tr("Error"), tr("Failed to import configuration from %1 to %2.").arg(file, QString::fromStdString(root.getName())), errors);
		return;
	}

	ThreeWayMerge merger;

	foreach(QVariant s, mergeStrategies)
	{
		MergeConflictStrategy* strategy = getMergeStrategy(s.toString());

		if(strategy)
			merger.addConflictStrategy(strategy);
	}
TEST_F(MetaMergeStrategyTest, MergesMetaWithInnerStrategy)
{
	base.lookup ("user/parentb/config/key1").setMeta ("testmeta", "valueb");
	ours.lookup ("user/parento/config/key1").setMeta ("testmeta", "valueo");
	theirs.lookup ("user/parentt/config/key1").setMeta ("testmeta", "valuet");
	Key conflictKey = mk1;
	result.addConflict (conflictKey, CONFLICT_META, CONFLICT_META);
	conflictKey = result.getConflictSet ().at (0);

	ThreeWayMerge merger;
	MergeConflictStrategy *strategy = new OneSideStrategy (OURS);
	merger.addConflictStrategy (strategy);
	MetaMergeStrategy metaStrategy (merger);
	metaStrategy.resolveConflict (task, conflictKey, result);
	delete (strategy);

	EXPECT_FALSE(result.hasConflicts()) << "Invalid conflict detected";
	KeySet merged = result.getMergedKeys ();
	cout << merged << endl;
	EXPECT_EQ(4, merged.size ());

	EXPECT_EQ("valueo", merged.lookup (mk1).getMeta<string> ("testmeta"));
}