예제 #1
0
파일: blame.c 프로젝트: carlosmn/pygit2
PyObject*
wrap_blame_hunk(const git_blame_hunk *hunk, Blame *blame)
{
    BlameHunk *py_hunk = NULL;

    if (!hunk)
        Py_RETURN_NONE;

    py_hunk = PyObject_New(BlameHunk, &BlameHunkType);
    if (py_hunk != NULL) {
        py_hunk->lines_in_hunk = hunk->lines_in_hunk;
        py_hunk->final_commit_id = git_oid_allocfmt(&hunk->final_commit_id);
        py_hunk->final_start_line_number = hunk->final_start_line_number;
        py_hunk->final_signature = hunk->final_signature != NULL ?
                                   git_signature_dup(hunk->final_signature) : NULL;
        py_hunk->orig_commit_id = git_oid_allocfmt(&hunk->orig_commit_id);
        py_hunk->orig_path = hunk->orig_path != NULL ?
                             strdup(hunk->orig_path) : NULL;
        py_hunk->orig_start_line_number = hunk->orig_start_line_number;
        py_hunk->orig_signature = hunk->orig_signature != NULL ?
                                  git_signature_dup(hunk->orig_signature) : NULL;
        py_hunk->boundary = hunk->boundary;
    }

    return (PyObject*) py_hunk;
}
예제 #2
0
void verify_remote_refs(const git_remote_head *actual_refs[], size_t actual_refs_len, const expected_ref expected_refs[], size_t expected_refs_len)
{
	size_t i, j = 0;
	git_buf msg = GIT_BUF_INIT;
	const git_remote_head *actual;
	char *oid_str;
	bool master_present = false;

	/* We don't care whether "master" is present on the other end or not */
	for (i = 0; i < actual_refs_len; i++) {
		actual = actual_refs[i];
		if (!strcmp(actual->name, "refs/heads/master")) {
			master_present = true;
			break;
		}
	}

	if (expected_refs_len + (master_present ? 1 : 0) != actual_refs_len)
		goto failed;

	for (i = 0; i < actual_refs_len; i++) {
		actual = actual_refs[i];
		if (master_present && !strcmp(actual->name, "refs/heads/master"))
			continue;

		if (strcmp(expected_refs[j].name, actual->name) ||
			git_oid_cmp(expected_refs[j].oid, &actual->oid))
			goto failed;

		j++;
	}

	return;

failed:
	git_buf_puts(&msg, "Expected and actual refs differ:\nEXPECTED:\n");

	for(i = 0; i < expected_refs_len; i++) {
		cl_assert(oid_str = git_oid_allocfmt(expected_refs[i].oid));
		cl_git_pass(git_buf_printf(&msg, "%s = %s\n", expected_refs[i].name, oid_str));
		git__free(oid_str);
	}

	git_buf_puts(&msg, "\nACTUAL:\n");
	for (i = 0; i < actual_refs_len; i++) {
		actual = actual_refs[i];
		if (master_present && !strcmp(actual->name, "refs/heads/master"))
			continue;

		cl_assert(oid_str = git_oid_allocfmt(&actual->oid));
		cl_git_pass(git_buf_printf(&msg, "%s = %s\n", actual->name, oid_str));
		git__free(oid_str);
	}

	cl_fail(git_buf_cstr(&msg));

	git_buf_free(&msg);
}
예제 #3
0
int git_note_create(
	git_oid *out,
	git_repository *repo,
	const git_signature *author,
	const git_signature *committer,
	const char *notes_ref,
	const git_oid *oid,
	const char *note)
{
	int error;
	char *target = NULL;
	git_commit *commit = NULL;
	git_tree *tree = NULL;

	target = git_oid_allocfmt(oid);
	GITERR_CHECK_ALLOC(target);

	error = retrieve_note_tree_and_commit(&tree, &commit, repo, &notes_ref);

	if (error < 0 && error != GIT_ENOTFOUND)
		goto cleanup;

	error = note_write(out, repo, author, committer, notes_ref,
			note, tree, target, &commit);

cleanup:
	git__free(target);
	git_commit_free(commit);
	git_tree_free(tree);
	return error;
}
예제 #4
0
void merge__dump_reuc(git_index *index)
{
	size_t i;
	const git_index_reuc_entry *reuc;

	printf ("\nREUC:\n");
	for (i = 0; i < git_index_reuc_entrycount(index); i++) {
		reuc = git_index_reuc_get_byindex(index, i);

		printf("%s ", reuc->path);
		printf("%o ", reuc->mode[0]);
		printf("%s\n", git_oid_allocfmt(&reuc->oid[0]));
		printf("          %o ", reuc->mode[1]);
		printf("          %s\n", git_oid_allocfmt(&reuc->oid[1]));
		printf("          %o ", reuc->mode[2]);
		printf("          %s ", git_oid_allocfmt(&reuc->oid[2]));
		printf("\n");
	}
	printf("\n");
}
예제 #5
0
파일: stash.c 프로젝트: aep/libgit2
static int append_abbreviated_oid(git_buf *out, const git_oid *b_commit)
{
	char *formatted_oid;

	formatted_oid = git_oid_allocfmt(b_commit);
	GITERR_CHECK_ALLOC(formatted_oid);

	git_buf_put(out, formatted_oid, 7);
	git__free(formatted_oid);

	return git_buf_oom(out) ? -1 : 0;
}
예제 #6
0
PyObject* RefLogIter_iternext(RefLogIter *self)
{
    const git_reflog_entry *entry;
    RefLogEntry *py_entry;

    if (self->i < self->size) {
        entry = git_reflog_entry_byindex(self->reflog, self->i);
        py_entry = PyObject_New(RefLogEntry, &RefLogEntryType);

        py_entry->oid_old = git_oid_allocfmt(git_reflog_entry_id_old(entry));
        py_entry->oid_new = git_oid_allocfmt(git_reflog_entry_id_new(entry));
        py_entry->message = strdup(git_reflog_entry_message(entry));
        py_entry->signature = git_signature_dup(
            git_reflog_entry_committer(entry));

        ++(self->i);

        return (PyObject*) py_entry;
    }

    PyErr_SetNone(PyExc_StopIteration);
    return NULL;
}
예제 #7
0
파일: save.c 프로젝트: ralpheav/PM_GIT
void test_stash_save__stashing_updates_the_reflog(void)
{
	char *sha;

	assert_object_oid("refs/stash@{0}", NULL, GIT_OBJ_COMMIT);

	cl_git_pass(git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT));

	sha = git_oid_allocfmt(&stash_tip_oid);

	assert_object_oid("refs/stash@{0}", sha, GIT_OBJ_COMMIT);
	assert_object_oid("refs/stash@{1}", NULL, GIT_OBJ_COMMIT);

	git__free(sha);
}
예제 #8
0
void merge__dump_index_entries(git_vector *index_entries)
{
	size_t i;
	const git_index_entry *index_entry;

	printf ("\nINDEX [%d]:\n", (int)index_entries->length);
	for (i = 0; i < index_entries->length; i++) {
		index_entry = index_entries->contents[i];

		printf("%o ", index_entry->mode);
		printf("%s ", git_oid_allocfmt(&index_entry->oid));
		printf("%d ", git_index_entry_stage(index_entry));
		printf("%s ", index_entry->path);
		printf("\n");
	}
	printf("\n");
}
예제 #9
0
파일: notes.c 프로젝트: 0CV0/libgit2
int git_note_read(git_note **out, git_repository *repo,
		  const char *notes_ref, const git_oid *oid)
{
	int error;
	char *target = NULL;
	git_tree *tree = NULL;
	git_commit *commit = NULL;

	target = git_oid_allocfmt(oid);
	GITERR_CHECK_ALLOC(target);

	if (!(error = retrieve_note_tree_and_commit(
			&tree, &commit, repo, &notes_ref)))
		error = note_lookup(out, repo, tree, target);

	git__free(target);
	git_tree_free(tree);
	git_commit_free(commit);
	return error;
}
예제 #10
0
파일: note.c 프로젝트: Rekii008/pygit2
PyObject*
wrap_note(Repository* repo, git_oid* annotated_id, const char* ref)
{
    Note* py_note = NULL;
    int err = GIT_ERROR;

    py_note = PyObject_New(Note, &NoteType);
    if (py_note == NULL) {
        PyErr_NoMemory();
        return NULL;
    }

    err = git_note_read(&py_note->note, repo->repo, ref, annotated_id);
    if (err < 0)
        return Error_set(err);

    py_note->repo = repo;
    Py_INCREF(repo);
    py_note->annotated_id = git_oid_allocfmt(annotated_id);

    return (PyObject*) py_note;
}
예제 #11
0
파일: notes.c 프로젝트: 0CV0/libgit2
int git_note_remove(git_repository *repo, const char *notes_ref,
		const git_signature *author, const git_signature *committer,
		const git_oid *oid)
{
	int error;
	char *target = NULL;
	git_commit *commit = NULL;
	git_tree *tree = NULL;

	target = git_oid_allocfmt(oid);
	GITERR_CHECK_ALLOC(target);

	if (!(error = retrieve_note_tree_and_commit(
			&tree, &commit, repo, &notes_ref)))
		error = note_remove(
			repo, author, committer, notes_ref, tree, target, &commit);

	git__free(target);
	git_commit_free(commit);
	git_tree_free(tree);
	return error;
}
예제 #12
0
파일: diff.c 프로젝트: goibibo/pygit2
PyObject *
wrap_patch(git_patch *patch)
{
    Patch *py_patch;

    if (!patch)
        Py_RETURN_NONE;

    py_patch = PyObject_New(Patch, &PatchType);
    if (py_patch) {
        size_t i, j, hunk_amounts, lines_in_hunk, additions, deletions;
        const git_diff_delta *delta;
        const git_diff_hunk *hunk;
        const git_diff_line *line;
        int err;

        delta = git_patch_get_delta(patch);

        py_patch->old_file_path = delta->old_file.path;
        py_patch->new_file_path = delta->new_file.path;
        py_patch->status = git_diff_status_char(delta->status);
        py_patch->similarity = delta->similarity;
        py_patch->flags = delta->flags;
        py_patch->old_id = git_oid_allocfmt(&delta->old_file.id);
        py_patch->new_id = git_oid_allocfmt(&delta->new_file.id);

        git_patch_line_stats(NULL, &additions, &deletions, patch);
        py_patch->additions = additions;
        py_patch->deletions = deletions;

        hunk_amounts = git_patch_num_hunks(patch);
        py_patch->hunks = PyList_New(hunk_amounts);
        for (i = 0; i < hunk_amounts; ++i) {
            Hunk *py_hunk = NULL;

            err = git_patch_get_hunk(&hunk, &lines_in_hunk, patch, i);
            if (err < 0)
                return Error_set(err);

            py_hunk = PyObject_New(Hunk, &HunkType);
            if (py_hunk != NULL) {
                py_hunk->old_start = hunk->old_start;
                py_hunk->old_lines = hunk->old_lines;
                py_hunk->new_start = hunk->new_start;
                py_hunk->new_lines = hunk->new_lines;

                py_hunk->lines = PyList_New(lines_in_hunk);
                for (j = 0; j < lines_in_hunk; ++j) {
                    PyObject *py_line_origin = NULL, *py_line = NULL;

                    err = git_patch_get_line_in_hunk(&line, patch, i, j);
                    if (err < 0)
                        return Error_set(err);

                    py_line_origin = to_unicode_n(&line->origin, 1,
                        NULL, NULL);
                    py_line = to_unicode_n(line->content, line->content_len,
                        NULL, NULL);
                    PyList_SetItem(py_hunk->lines, j,
                        Py_BuildValue("OO", py_line_origin, py_line));

                    Py_DECREF(py_line_origin);
                    Py_DECREF(py_line);
                }

                PyList_SetItem((PyObject*) py_patch->hunks, i,
                    (PyObject*) py_hunk);
            }
        }
    }
    git_patch_free(patch);

    return (PyObject*) py_patch;
}
예제 #13
0
파일: diff.c 프로젝트: heynemann/pygit2
PyObject*
diff_get_patch_byindex(git_diff_list* list, size_t idx)
{
    const git_diff_delta* delta;
    const git_diff_range* range;
    git_diff_patch* patch = NULL;
    size_t i, j, hunk_amounts, lines_in_hunk, line_len, header_len;
    const char* line, *header;
    int err;
    Hunk *py_hunk = NULL;
    Patch *py_patch = NULL;

    err = git_diff_get_patch(&patch, &delta, list, idx);
    if (err < 0)
        return Error_set(err);

    py_patch = PyObject_New(Patch, &PatchType);
    if (py_patch != NULL) {
        py_patch->old_file_path = delta->old_file.path;
        py_patch->new_file_path = delta->new_file.path;
        py_patch->status = git_diff_status_char(delta->status);
        py_patch->similarity = delta->similarity;
        py_patch->old_oid = git_oid_allocfmt(&delta->old_file.oid);
        py_patch->new_oid = git_oid_allocfmt(&delta->new_file.oid);


        hunk_amounts = git_diff_patch_num_hunks(patch);
        py_patch->hunks = PyList_New(hunk_amounts);
        for (i=0; i < hunk_amounts; ++i) {
            err = git_diff_patch_get_hunk(&range, &header, &header_len,
                      &lines_in_hunk, patch, i);

            if (err < 0)
                goto cleanup;

            py_hunk = PyObject_New(Hunk, &HunkType);
            if (py_hunk != NULL) {
                py_hunk->old_start = range->old_start;
                py_hunk->old_lines = range->old_lines;
                py_hunk->new_start = range->new_start;
                py_hunk->new_lines = range->new_lines;

                py_hunk->lines = PyList_New(lines_in_hunk + 1);
                PyList_SetItem(py_hunk->lines, 0,
                    to_unicode_n(header, header_len, NULL, NULL));
                for (j=1; j < lines_in_hunk + 1; ++j) {
                    err = git_diff_patch_get_line_in_hunk(&py_hunk->origin,
                              &line, &line_len, NULL, NULL, patch, i, j - 1);

                    if (err < 0)
                      goto cleanup;

                    PyList_SetItem(py_hunk->lines, j,
                        to_unicode_n(line, line_len, NULL, NULL));
                }

                PyList_SetItem((PyObject*) py_patch->hunks, i,
                    (PyObject*) py_hunk);
            }
        }
    }

cleanup:
    git_diff_patch_free(patch);

    return (err < 0) ? Error_set(err) : (PyObject*) py_patch;
}
예제 #14
0
/* fields */
//## @Native String GitOid.getId();
KMETHOD GitOid_getId(CTX ctx, ksfp_t *sfp _RIX)
{
    const git_oid *oid = RawPtr_to(const git_oid *, sfp[0]);
    char out[GIT_OID_HEXSZ + 2] = {0};
    char *str = git_oid_to_string(out, GIT_OID_HEXSZ + 1, oid);
    RETURN_(new_String(ctx, str));
}

/* Format a git_oid into a newly allocated c-string. */
//## @Native String GitOid.allocfmt();
KMETHOD GitOid_allocfmt(CTX ctx, ksfp_t *sfp _RIX)
{
    const git_oid *oid = RawPtr_to(const git_oid *, sfp[0]);
    char *s = git_oid_allocfmt(oid);
    kString *str = new_String(ctx, s);
    free(s);
    RETURN_(str);
}

/* Copy an oid from one structure to another. */
//## @Native GitOid GitOid.cpy();
KMETHOD GitOid_cpy(CTX ctx, ksfp_t *sfp _RIX)
{
    git_oid *out = (git_oid *)KNH_MALLOC(ctx, sizeof(git_oid));
    const git_oid *src = RawPtr_to(const git_oid *, sfp[0]);
    git_oid_cpy(out, src);
    RETURN_(new_ReturnRawPtr(ctx, sfp, out));
}