Method: Rugged::Repository#write

Defined in:
ext/rugged/rugged_repo.c

#write(buffer, type) ⇒ Object

Write the data contained in the buffer string as a raw object of the given type into the repository’s object database.

type can be either :tag, :commit, :tree or :blob.

Returns the newly created object’s oid.

[View source]

1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
# File 'ext/rugged/rugged_repo.c', line 1388

static VALUE rb_git_repo_write(VALUE self, VALUE rb_buffer, VALUE rub_type)
{
	git_repository *repo;
	git_odb_stream *stream;

	git_odb *odb;
	git_oid oid;
	int error;

	git_otype type;

	Data_Get_Struct(self, git_repository, repo);
	Check_Type(rb_buffer, T_STRING);

	error = git_repository_odb(&odb, repo);
	rugged_exception_check(error);

	type = rugged_otype_get(rub_type);

	error = git_odb_open_wstream(&stream, odb, RSTRING_LEN(rb_buffer), type);
	git_odb_free(odb);
	rugged_exception_check(error);

	error = git_odb_stream_write(stream, RSTRING_PTR(rb_buffer), RSTRING_LEN(rb_buffer));
	if (!error)
		error = git_odb_stream_finalize_write(&oid, stream);

	git_odb_stream_free(stream);
	rugged_exception_check(error);

	return rugged_create_oid(&oid);
}