Пример #1
0
void test_blame_getters__byindex(void)
{
	const git_blame_hunk *h = git_blame_get_hunk_byindex(g_blame, 2);
	cl_assert(h);
	cl_assert_equal_s(h->orig_path, "c");

	h = git_blame_get_hunk_byindex(g_blame, 95);
	cl_assert_equal_p(h, NULL);
}
Пример #2
0
PyObject *
Blame_getitem(Blame *self, PyObject *value)
{
    size_t i;
    const git_blame_hunk *hunk;

    if (PyLong_Check(value) < 0) {
        PyErr_SetObject(PyExc_IndexError, value);
        return NULL;
    }

    i = PyLong_AsUnsignedLong(value);
    if (PyErr_Occurred()) {
        PyErr_SetObject(PyExc_IndexError, value);
        return NULL;
    }

    hunk = git_blame_get_hunk_byindex(self->blame, i);
    if (!hunk) {
        PyErr_SetObject(PyExc_IndexError, value);
        return NULL;
    }

    return wrap_blame_hunk(hunk, self);
}
Пример #3
0
PyObject *
BlameIter_iternext(BlameIter *self)
{
    if (self->i < self->n)
        return wrap_blame_hunk(git_blame_get_hunk_byindex(
                                   self->blame->blame, self->i++), self->blame);

    PyErr_SetNone(PyExc_StopIteration);
    return NULL;
}
Пример #4
0
void check_blame_hunk_index(git_repository *repo, git_blame *blame, int idx,
		int start_line, int len, char boundary, const char *commit_id, const char *orig_path)
{
	char expected[GIT_OID_HEXSZ+1] = {0}, actual[GIT_OID_HEXSZ+1] = {0};
	const git_blame_hunk *hunk = git_blame_get_hunk_byindex(blame, idx);
	cl_assert(hunk);

	if (!strncmp(commit_id, "0000", 4)) {
		strcpy(expected, "0000000000000000000000000000000000000000");
	} else {
		git_object *obj;
		cl_git_pass(git_revparse_single(&obj, repo, commit_id));
		git_oid_fmt(expected, git_object_id(obj));
		git_object_free(obj);
	}

	if (hunk->final_start_line_number != start_line) {
		hunk_message(idx, hunk, "mismatched start line number: expected %d, got %d",
				start_line, hunk->final_start_line_number);
	}
	cl_assert_equal_i(hunk->final_start_line_number, start_line);

	if (hunk->lines_in_hunk != len) {
		hunk_message(idx, hunk, "mismatched line count: expected %d, got %d",
				len, hunk->lines_in_hunk);
	}
	cl_assert_equal_i(hunk->lines_in_hunk, len);

	git_oid_fmt(actual, &hunk->final_commit_id);
	if (strcmp(expected, actual)) {
		hunk_message(idx, hunk, "has mismatched original id (got %s, expected %s)\n",
				actual, expected);
	}
	cl_assert_equal_s(actual, expected);
	cl_assert_equal_oid(&hunk->final_commit_id, &hunk->orig_commit_id);


	if (strcmp(hunk->orig_path, orig_path)) {
		hunk_message(idx, hunk, "has mismatched original path (got '%s', expected '%s')\n",
				hunk->orig_path, orig_path);
	}
	cl_assert_equal_s(hunk->orig_path, orig_path);

	if (hunk->boundary != boundary) {
		hunk_message(idx, hunk, "doesn't match boundary flag (got %d, expected %d)\n",
				hunk->boundary, boundary);
	}
	cl_assert_equal_i(boundary, hunk->boundary);
}
Пример #5
0
emacs_value egit_blame_get_hunk_byindex(emacs_env *env, emacs_value _blame, emacs_value _index)
{
    EGIT_ASSERT_BLAME(_blame);
    EM_ASSERT_INTEGER(_index);

    git_blame *blame = EGIT_EXTRACT(_blame);
    uint32_t index = (uint32_t) env->extract_integer(env, _index);

    const git_blame_hunk *hunk = git_blame_get_hunk_byindex(blame, index);
    if (!hunk) {
        em_signal_args_out_of_range(env, index);
        return em_nil;
    }

    return egit_wrap(env, EGIT_BLAME_HUNK, hunk, EM_EXTRACT_USER_PTR(_blame));
}