<commit_before>using GLib;
using Wiz;

public class SyncSource : Object {
	public Wiz.Store store { private get; construct; }

	uint size;
	Wiz.BreadthFirstIterator iter;

	public SyncSource(Wiz.Store store) {
		this.store = store;
	}

	public List<string> tell_me_about(List<string> objects) {
		/*
		 * tell_me_about
		 * @objects: A list of object ids that we want to pull
		 *
		 * Returns: A list of objects that arent on the source
		 *
		 * When pulling from a sync source, a client uses this method
		 * to set which objects to bfs over.
		 *
		 * FIXME: This is a bit FAIL because we can only pull objects
		 * we know about...
		 */
		this.size = 0;
		this.iter = new Wiz.BreadthFirstIterator();
		var retval = new List<string>();
		foreach (var o in objects) {
			if (this.store.has_bit(o)) {
				var bit = this.store.open_bit(o);
				foreach (var t in bit.tips) {
					this.iter.add_version(t);
					this.size++;
				}
			} else {
				retval.append(o);
			}
		}
		return retval;
	}

	public List<string> tell_me_about_that_cheeseburger(List<string> versions) {
		/*
		 * tell_me_about_that_cheeseburger
		 * @versions: A list of versions to kick out of the iterator
		 * 
		 * Returns: A list of versions found by the breadth first search
		 */
		foreach (var v in versions) {
			var wz = this.store.open_version("rarar", v);
			this.iter.kick_out(wz);
		}

		var retval = new List<string>();
		var found = this.iter.get(this.size);
		foreach (var f in found) {
			retval.append(f.version_uuid);
		}
		this.size *= 2;
		return retval;
	}
}

public class SyncClient : Object {
	Wiz.BreadthFirstIterator iter;
	public Wiz.Store store { private get; construct; }

	public SyncClient(Wiz.Store store) {
		this.store = store;
	}

	construct {
		this.iter = new Wiz.BreadthFirstIterator();
	}

	public void pull(SyncSource server, Wiz.Bit bit) {
		var object_uuids = new List<string>();
		object_uuids.append(bit.uuid);

		/* Tell the server what objects we are interested in pulling */
		server.tell_me_about(object_uuids);

		var burgers = server.tell_me_about_that_cheeseburger(new List<string>());
		var sounds_yummy = new List<string>();
		while (burgers.length() > 0) {
			var do_not_want = new List<string>();
			foreach (var additive in burgers) {
				if (this.store.has_version(additive))
					do_not_want.append(additive);
				else
					sounds_yummy.append(additive);
			}

			burgers = server.tell_me_about_that_cheeseburger(do_not_want);
		}

		/*
		do {
			sounds_yummy.pop();
		} while (sounds_yummy.length() > 0);
		*/
	}
}

void test_simple_1()
{
	var a = new Wiz.Store("some_uuid", "data/sync_simple_1_a");

	var z = a.create_bit();

	assert( z.tips.length() == 0 );

	var a1 = z.create_next_version_from_string("1");
	var a2 = z.create_next_version_from_string("2", a1);
	var a3 = z.create_next_version_from_string("3", a2);
	var a4 = z.create_next_version_from_string("4", a3);
	var a5 = z.create_next_version_from_string("5", a4);

	assert( z.tips.length() == 1 );

	var a6 = z.create_next_version_from_string("6", a2);
	var a7 = z.create_next_version_from_string("7", a6);
	var a8 = z.create_next_version_from_string("8", a7);
	var a9 = z.create_next_version_from_string("9", a8);

	assert( z.tips.length() == 2 );

	var b = new Wiz.Store("some_uuid", "data/sync_simple_1_b");

	var sa = new SyncSource(a);<commit_msg>For each commit we are missing, ask for the commit and blob data. Long term, the server will prepare us a pack. But we need a pack first :P<commit_after>using GLib;
using Wiz;

public class SyncSource : Object {
	public Wiz.Store store { private get; construct; }

	uint size;
	Wiz.BreadthFirstIterator iter;

	public SyncSource(Wiz.Store store) {
		this.store = store;
	}

	public List<string> tell_me_about(List<string> objects) {
		/*
		 * tell_me_about
		 * @objects: A list of object ids that we want to pull
		 *
		 * Returns: A list of objects that arent on the source
		 *
		 * When pulling from a sync source, a client uses this method
		 * to set which objects to bfs over.
		 *
		 * FIXME: This is a bit FAIL because we can only pull objects
		 * we know about...
		 */
		this.size = 0;
		this.iter = new Wiz.BreadthFirstIterator();
		var retval = new List<string>();
		foreach (var o in objects) {
			if (this.store.has_bit(o)) {
				var bit = this.store.open_bit(o);
				foreach (var t in bit.tips) {
					this.iter.add_version(t);
					this.size++;
				}
			} else {
				retval.append(o);
			}
		}
		return retval;
	}

	public List<string> tell_me_about_that_cheeseburger(List<string> versions) {
		/*
		 * tell_me_about_that_cheeseburger
		 * @versions: A list of versions to kick out of the iterator
		 * 
		 * Returns: A list of versions found by the breadth first search
		 */
		foreach (var v in versions) {
			var wz = this.store.open_version("rarar", v);
			this.iter.kick_out(wz);
		}

		var retval = new List<string>();
		var found = this.iter.get(this.size);
		foreach (var f in found) {
			retval.append(f.version_uuid);
		}
		this.size *= 2;
		return retval;
	}

	public string ill_have_no_cheese_on_my_burger(string version_uuid) {
		debug("om nom nom on the redveg burger");
		return "crap we have no api to get this";
	}

	public string nom_nom(string version_uuid) {
		var v = this.store.open_version("nomnom", version_uuid);
		return v.read_as_string();
	}
}

public class SyncClient : Object {
	Wiz.BreadthFirstIterator iter;
	public Wiz.Store store { private get; construct; }

	public SyncClient(Wiz.Store store) {
		this.store = store;
	}

	construct {
		this.iter = new Wiz.BreadthFirstIterator();
	}

	public void pull(SyncSource server, Wiz.Bit bit) {
		var object_uuids = new List<string>();
		object_uuids.append(bit.uuid);

		/* Tell the server what objects we are interested in pulling */
		server.tell_me_about(object_uuids);

		var burgers = server.tell_me_about_that_cheeseburger(new List<string>());
		var sounds_yummy = new Queue<string>();
		while (burgers.length() > 0) {
			var do_not_want = new List<string>();
			foreach (var additive in burgers) {
				if (this.store.has_version(additive))
					do_not_want.append(additive);
				else
					sounds_yummy.push_tail(additive);
			}

			burgers = server.tell_me_about_that_cheeseburger(do_not_want);
		}

		/* Get redveg burgers from server, oldest first */
		do {
			var uuid = sounds_yummy.pop_tail();
			var blob = server.ill_have_no_cheese_on_my_burger(uuid);
			var commit = server.nom_nom(uuid);

			debug(blob);
		} while (sounds_yummy.get_length() > 0);
	}
}

void test_simple_1()
{
	var a = new Wiz.Store("some_uuid", "data/sync_simple_1_a");

	var z = a.create_bit();

	assert( z.tips.length() == 0 );

	var a1 = z.create_next_version_from_string("1");
	var a2 = z.create_next_version_from_string("2", a1);
	var a3 = z.create_next_version_from_string("3", a2);
	var a4 = z.create_next_version_from_string("4", a3);
	var a5 = z.create_next_version_from_string("5", a4);

	assert( z.tips.length() == 1 );

	var a6 = z.create_next_version_from_string("6", a2);
	var a7 = z.create_next_version_from_string("7", a6);
	var a8 = z.create_next_version_from_string("8", a7);
	var a9 = z.create_next_version_from_string("9", a8);

	assert( z.tips.length() == 2 );

	var b = new Wiz.Store("some_uuid", "data/sync_simple_1_b");

	var sa = new SyncSource(a);
{'fraction_non_alphanumeric': 0.12318443409153193, 'fraction_numerical': 0.009865716634694436, 'mean_word_length': 3.6788461538461537, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1836224', 'n_tokens_mistral': 2947, 'n_tokens_neox': 2620, 'n_words': 681}