Exemple #1
0
static int note_write(git_oid *out,
	git_repository *repo,
	const git_signature *author,
	const git_signature *committer,
	const char *notes_ref,
	const char *note,
	git_tree *commit_tree,
	const char *target,
	git_commit **parents)
{
	int error;
	git_oid oid;
	git_tree *tree = NULL;
	
	// TODO: should we apply filters?
	/* create note object */
	if ((error = git_blob_create_frombuffer(&oid, repo, note, strlen(note))) < 0)
		goto cleanup;

	if ((error = manipulate_note_in_tree_r(
		&tree, repo, commit_tree, &oid, target, 0,
		insert_note_in_tree_eexists_cb, insert_note_in_tree_enotfound_cb)) < 0)
		goto cleanup;

	if (out)
		git_oid_cpy(out, &oid);

	error = git_commit_create(&oid, repo, notes_ref, author, committer,
				  NULL, GIT_NOTES_DEFAULT_MSG_ADD,
				  tree, *parents == NULL ? 0 : 1, (const git_commit **) parents);

cleanup:
	git_tree_free(tree);
	return error;
}
Exemple #2
0
void test_object_blob_filter__initialize(void)
{
	int i;

	g_repo = cl_git_sandbox_init("empty_standard_repo");

	for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) {
		if (g_crlf_raw_len[i] < 0)
			g_crlf_raw_len[i] = strlen(g_crlf_raw[i]);

		cl_git_pass(git_blob_create_frombuffer(
			&g_crlf_oids[i], g_repo, g_crlf_raw[i], (size_t)g_crlf_raw_len[i]));
	}
}
Exemple #3
0
/*
 * Write a membuffer to the git repo, and free it
 */
static int blob_insert(git_repository *repo, struct dir *tree, struct membuffer *b, const char *fmt, ...)
{
	int ret;
	git_oid blob_id;
	struct membuffer name = { 0 };

	ret = git_blob_create_frombuffer(&blob_id, repo, b->buffer, b->len);
	free_buffer(b);
	if (ret)
		return ret;

	VA_BUF(&name, fmt);
	ret = tree_insert(tree->files, mb_cstring(&name), 1, &blob_id, GIT_FILEMODE_BLOB);
	free_buffer(&name);
	return ret;
}
/*
 *  call-seq:
 *    Blob.from_buffer(repository, bytes) -> oid
 *
 *  Write a blob to +repository+ with the contents specified
 *  in +buffer+. In Ruby 1.9.x, the encoding of +buffer+ is
 *  ignored and bytes are copied as-is.
 */
static VALUE rb_git_blob_from_buffer(VALUE self, VALUE rb_repo, VALUE rb_buffer)
{
	int error;
	git_oid oid;
	git_repository *repo;

	Check_Type(rb_buffer, T_STRING);
	rugged_check_repo(rb_repo);

	Data_Get_Struct(rb_repo, git_repository, repo);

	error = git_blob_create_frombuffer(&oid, repo, RSTRING_PTR(rb_buffer), RSTRING_LEN(rb_buffer));
	rugged_exception_check(error);

	return rugged_create_oid(&oid);
}
Exemple #5
0
PyObject *
Repository_create_blob(Repository *self, PyObject *args)
{
    git_oid oid;
    const char *raw;
    Py_ssize_t size;
    int err;

    if (!PyArg_ParseTuple(args, "s#", &raw, &size))
        return NULL;

    err = git_blob_create_frombuffer(&oid, self->repo, (const void*)raw, size);
    if (err < 0)
        return Error_set(err);

    return git_oid_to_python(&oid);
}
Exemple #6
0
/*
 *	call-seq:
 *		Blob.create(repository, bytes) -> oid
 *
 *	Write a blob to +repository+ with the contents specified
 *	in +buffer+. In Ruby 1.9.x, the encoding of +buffer+ is
 *	ignored and bytes are copied as-is.
 */
static VALUE rb_git_blob_create(VALUE self, VALUE rb_repo, VALUE rb_buffer)
{
	int error;
	git_oid oid;
	git_repository *repo;

	Check_Type(rb_buffer, T_STRING);
	if (!rb_obj_is_instance_of(rb_repo, rb_cRuggedRepo))
		rb_raise(rb_eTypeError, "Expecting a Rugged Repository");

	Data_Get_Struct(rb_repo, git_repository, repo);

	error = git_blob_create_frombuffer(&oid, repo, RSTRING_PTR(rb_buffer), RSTRING_LEN(rb_buffer));
	rugged_exception_check(error);

	return rugged_create_oid(&oid);
}
Exemple #7
0
//## @Native void GitBlob.close();
KMETHOD GitBlob_close(CTX ctx, ksfp_t *sfp _RIX)
{
    kGitBlob_free(ctx, sfp[0].p);
    RETURNvoid_();
}

/* Write an in-memory buffer to the ODB as a blob */
//## @Native @Static GitOid GitBlob.createFromBuffer(GitRepository repo, Bytes buffer);
KMETHOD GitBlob_createFromBuffer(CTX ctx, ksfp_t *sfp _RIX)
{
    git_oid *oid = (git_oid *)KNH_MALLOC(ctx, sizeof(git_oid));
    git_repository *repo = RawPtr_to(git_repository *, sfp[1]);
    const void *buffer = (const void *)BA_totext(sfp[2].ba);
    size_t len = BA_size(sfp[2].ba);
    int error = git_blob_create_frombuffer(oid, repo, buffer, len);
    if (error < GIT_SUCCESS) {
        TRACE_ERROR(ctx, "git_blob_create_frombuffer", error);
        KNH_FREE(ctx, oid, sizeof(git_oid));
        RETURN_(KNH_NULL);
    }
    RETURN_(new_ReturnRawPtr(ctx, sfp, oid));
}

/* Read a file from the working folder of a repository and write it to the
 * Object Database as a loose blob */
//## @Native @Static GitOid GitBlob.createFromFile(GitRepository repo, String path);
KMETHOD GitBlob_createFromFile(CTX ctx, ksfp_t *sfp _RIX)
{
    git_oid *oid = (git_oid *)KNH_MALLOC(ctx, sizeof(git_oid));
    git_repository *repo = RawPtr_to(git_repository *, sfp[1]);