Exemplo n.º 1
0
ERL_NIF_TERM
geef_index_write_tree(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
	geef_index *index;
	geef_repository *repo;
	ErlNifBinary bin;
	git_oid id;
	int error;

	if (!enif_get_resource(env, argv[0], geef_index_type, (void **) &index))
		return enif_make_badarg(env);

	if (argc == 2) {
		if (!enif_get_resource(env, argv[1], geef_repository_type, (void **) &repo))
			return enif_make_badarg(env);

		error = git_index_write_tree_to(&id, index->index, repo->repo);
	} else {
		error = git_index_write_tree(&id, index->index);
	}

	if (error < 0)
		return geef_error(env);

	if (geef_oid_bin(&bin, &id) < 0)
		return geef_oom(env);

	return enif_make_tuple2(env, atoms.ok, enif_make_binary(env, &bin));
}
Exemplo n.º 2
0
ERL_NIF_TERM
geef_index_get(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
	unsigned int stage;
	ErlNifBinary path;
	geef_index *index;
	const git_index_entry *entry;

	if (!enif_get_resource(env, argv[0], geef_index_type, (void **) &index))
		return enif_make_badarg(env);

	if (!enif_get_uint(env, argv[2], &stage))
		return enif_make_badarg(env);

	if (!enif_inspect_iolist_as_binary(env, argv[1], &path))
		return enif_make_badarg(env);

	if (geef_terminate_binary(&path) < 0) {
		enif_release_binary(&path);
		return geef_oom(env);
	}

	entry = git_index_get_bypath(index->index, (char *) path.data, stage);
	enif_release_binary(&path);
	if (entry == NULL)
		return geef_error(env);

	return entry_to_term(env, entry);
}
Exemplo n.º 3
0
ERL_NIF_TERM
geef_reflog_read(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
	git_reflog *reflog;
	geef_repository *repo;
	ErlNifBinary bin;
	int error;
	size_t count, i;
	ERL_NIF_TERM list;

	if (!enif_get_resource(env, argv[0], geef_repository_type, (void **) &repo))
		return enif_make_badarg(env);

	if (!enif_inspect_iolist_as_binary(env, argv[1], &bin))
		return enif_make_badarg(env);

	if (!geef_terminate_binary(&bin))
		return geef_oom(env);

	if ((error = git_reflog_read(&reflog, repo->repo, (char *)bin.data)) < 0)
		return geef_error(env);

	count = git_reflog_entrycount(reflog);
	list = enif_make_list(env, 0);

	for (i = count; i > 0; i--) {
		ErlNifBinary id_old, id_new, message;
		ERL_NIF_TERM tentry, name, email, time, offset;
		const git_reflog_entry *entry;

		entry = git_reflog_entry_byindex(reflog, i-1);

		if (geef_oid_bin(&id_old, git_reflog_entry_id_old(entry)))
			goto on_oom;

		if (geef_oid_bin(&id_new, git_reflog_entry_id_new(entry)))
			goto on_oom;

		if (geef_signature_to_erl(&name, &email, &time, &offset,
					  env, git_reflog_entry_committer(entry)))
			goto on_oom;

		if (geef_string_to_bin(&message, git_reflog_entry_message(entry)))
			goto on_oom;

		tentry = enif_make_tuple7(env, name, email, time, offset,
					  enif_make_binary(env, &id_old),
					  enif_make_binary(env, &id_new),
					  enif_make_binary(env, &message));
		list = enif_make_list_cell(env, tentry, list);
	}

	git_reflog_free(reflog);
	return enif_make_tuple2(env, atoms.ok, list);

on_oom:
	git_reflog_free(reflog);
	return geef_oom(env);
}
Exemplo n.º 4
0
ERL_NIF_TERM
geef_index_write(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
	geef_index *index;

	if (!enif_get_resource(env, argv[0], geef_index_type, (void **) &index))
		return enif_make_badarg(env);

	if (git_index_write(index->index) < 0)
		return geef_error(env);

	return atoms.ok;
}
Exemplo n.º 5
0
ERL_NIF_TERM
geef_index_read_tree(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
	geef_index *index;
	geef_object *tree;

	if (!enif_get_resource(env, argv[0], geef_index_type, (void **) &index))
		return enif_make_badarg(env);

	if (!enif_get_resource(env, argv[0], geef_object_type, (void **) &tree))
		return enif_make_badarg(env);

	if (git_index_read_tree(index->index, (git_tree *)tree->obj) < 0)
		return geef_error(env);

	return atoms.ok;
}
Exemplo n.º 6
0
ERL_NIF_TERM
geef_index_new(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
	geef_index *index;
	ERL_NIF_TERM term;

	index = enif_alloc_resource(geef_index_type, sizeof(geef_index));
	if (!index)
		return geef_oom(env);

	if (git_index_new(&index->index) < 0)
		return geef_error(env);

	term = enif_make_resource(env, index);
	enif_release_resource(index);

	return enif_make_tuple2(env, atoms.ok, term);
}
Exemplo n.º 7
0
ERL_NIF_TERM
geef_index_nth(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
	size_t nth;
	geef_index *index;
	const git_index_entry *entry;

	if (!enif_get_resource(env, argv[0], geef_index_type, (void **) &index))
		return enif_make_badarg(env);

	if (!enif_get_ulong(env, argv[1], &nth))
		return enif_make_badarg(env);

	entry = git_index_get_byindex(index->index, nth);
	if (entry == NULL)
		return geef_error(env);

	return entry_to_term(env, entry);
}
Exemplo n.º 8
0
ERL_NIF_TERM
geef_commit_tree(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
	geef_object *obj, *tree;
	ERL_NIF_TERM term_obj;

	if (!enif_get_resource(env, argv[0], geef_object_type, (void **) &obj))
		return enif_make_badarg(env);

	tree = enif_alloc_resource(geef_object_type, sizeof(geef_object));

	if (git_commit_tree((git_tree **) &tree->obj, (git_commit *) obj->obj) < 0)
		return geef_error(env);

	term_obj = enif_make_resource(env, obj);
	enif_release_resource(obj);

	return enif_make_tuple3(env, atoms.ok, atoms.tree, term_obj);

}
Exemplo n.º 9
0
ERL_NIF_TERM
geef_revparse_single(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
	ErlNifBinary bin, id;
	geef_repository *repo;
	geef_object *obj;
	ERL_NIF_TERM type, term_obj;

	if (!enif_get_resource(env, argv[0], geef_repository_type, (void **) &repo))
		return enif_make_badarg(env);

	if (!enif_inspect_iolist_as_binary(env, argv[1], &bin))
		return enif_make_badarg(env);

	if (geef_terminate_binary(&bin) < 0)
		return geef_oom(env);

	obj = enif_alloc_resource(geef_object_type, sizeof(geef_object));
	if (!obj)
		return geef_oom(env);

	if (git_revparse_single(&obj->obj, repo->repo, (char *) bin.data) < 0) {
		enif_release_binary(&bin);
		enif_release_resource(obj);
		return geef_error(env);
	}

	type = geef_object_type2atom(git_object_type(obj->obj));

	if (geef_oid_bin(&id, git_object_id(obj->obj)) < 0)
		return geef_oom(env);


	term_obj = enif_make_resource(env, obj);
	enif_release_resource(obj);

	obj->repo = repo;
	enif_keep_resource(repo);

	return enif_make_tuple4(env, atoms.ok, term_obj, type, enif_make_binary(env, &id));
}
Exemplo n.º 10
0
ERL_NIF_TERM
geef_reflog_delete(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
	geef_repository *repo;
	ErlNifBinary bin;
	int error;

	if (!enif_get_resource(env, argv[0], geef_repository_type, (void **) &repo))
		return enif_make_badarg(env);

	if (!enif_inspect_iolist_as_binary(env, argv[1], &bin))
		return enif_make_badarg(env);

	if (!geef_terminate_binary(&bin))
		return geef_oom(env);

	error = git_reflog_delete(repo->repo, (char *) bin.data);

	enif_release_binary(&bin);

	return error ? geef_error(env) : atoms.ok;
}
Exemplo n.º 11
0
ERL_NIF_TERM
geef_index_add(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[])
{
	geef_index *index;
	const ERL_NIF_TERM *eentry;
	int arity;
	unsigned int tmp;
	ErlNifBinary path, id;
	git_index_entry entry;

	if (!enif_get_resource(env, argv[0], geef_index_type, (void **) &index))
		return enif_make_badarg(env);

	if (!enif_get_tuple(env, argv[1], &arity, &eentry))
		return enif_make_badarg(env);

	memset(&entry, 0, sizeof(entry));

	if (enif_compare(eentry[1], atoms.undefined) &&
	    !enif_get_int64(env, eentry[1], &entry.ctime.seconds))
		return enif_make_badarg(env);

	if (enif_compare(eentry[2], atoms.undefined) &&
	    !enif_get_int64(env, eentry[2], &entry.mtime.seconds))
		return enif_make_badarg(env);

	if (enif_compare(eentry[3], atoms.undefined) &&
	    !enif_get_uint(env, eentry[3], &entry.dev))
		return enif_make_badarg(env);

	if (enif_compare(eentry[4], atoms.undefined) &&
	    !enif_get_uint(env, eentry[4], &entry.ino))
		return enif_make_badarg(env);

	if (!enif_get_uint(env, eentry[5], &entry.mode))
		return enif_make_badarg(env);

	if (enif_compare(eentry[6], atoms.undefined) &&
	    !enif_get_uint(env, eentry[6], &entry.uid))
		return enif_make_badarg(env);

	if (enif_compare(eentry[7], atoms.undefined) &&
	    !enif_get_uint(env, eentry[7], &entry.gid))
		return enif_make_badarg(env);

	if (!enif_get_int64(env, eentry[8], &entry.file_size))
		return enif_make_badarg(env);

	/* [9] comes later */

	tmp = 0;
	if (enif_compare(eentry[10], atoms.undefined) &&
	    !enif_get_uint(env, eentry[10], &tmp))
		return enif_make_badarg(env);
	entry.flags = tmp;

	tmp = 0;
	if (enif_compare(eentry[11], atoms.undefined) &&
	    !enif_get_uint(env, eentry[11], &tmp))
		return enif_make_badarg(env);
	entry.flags_extended = tmp;

	if (!enif_inspect_iolist_as_binary(env, eentry[12], &path))
		return enif_make_badarg(env);

	if (!geef_terminate_binary(&path))
		return geef_oom(env);

	entry.path = (char *) path.data;

	if (!enif_inspect_binary(env, eentry[9], &id))
		return enif_make_badarg(env);

	git_oid_fromraw(&entry.id, id.data);

	if (git_index_add(index->index, &entry) < 0)
		return geef_error(env);

	return atoms.ok;
}