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CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\n";

	cl_git_pass(git_blame_buffer(&g_bufferblame, g_fileblame, buffer, strlen(buffer)));
	cl_assert_equal_i(5, git_blame_get_hunk_count(g_bufferblame));
	check_blame_hunk_index(g_repo, g_bufferblame, 2, 6, 1, 0, "000000", "b.txt");

	hunk = git_blame_get_hunk_byline(g_bufferblame, 16);
	cl_assert(hunk);
	cl_assert_equal_s("Ben Straub", hunk->final_signature->name);
}
Exemple #2
0
void test_blame_buffer__add_lines_at_end(void)
{
	const char *buffer = "\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE\n\
\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\n\
\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC\n\
\n\
abc\n\
def\n";
	cl_git_pass(git_blame_buffer(&g_bufferblame, g_fileblame, buffer, strlen(buffer)));

	cl_assert_equal_i(5, git_blame_get_hunk_count(g_bufferblame));
	check_blame_hunk_index(g_repo, g_bufferblame, 0,  1, 4, 0, "da237394", "b.txt");
	check_blame_hunk_index(g_repo, g_bufferblame, 1,  5, 1, 1, "b99f7ac0", "b.txt");
	check_blame_hunk_index(g_repo, g_bufferblame, 2,  6, 5, 0, "63d671eb", "b.txt");
	check_blame_hunk_index(g_repo, g_bufferblame, 3, 11, 5, 0, "aa06ecca", "b.txt");
	check_blame_hunk_index(g_repo, g_bufferblame, 4, 16, 2, 0, "00000000", "b.txt");
}
Exemple #3
0
emacs_value egit_blame_get_hunk_count(emacs_env *env, emacs_value _blame)
{
    EGIT_ASSERT_BLAME(_blame);
    git_blame *blame = EGIT_EXTRACT(_blame);

    uint32_t count = git_blame_get_hunk_count(blame);
    return EM_INTEGER(count);
}
Exemple #4
0
/*
 * $ git blame -s branch_file.txt
 *    orig line no                        final line no
 * commit   V  author       timestamp                 V
 * c47800c7 1 (Scott Chacon 2010-05-25 11:58:14 -0700 1
 * a65fedf3 2 (Scott Chacon 2011-08-09 19:33:46 -0700 2
 */
void test_blame_simple__trivial_testrepo(void)
{
	cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo/.gitted")));
	cl_git_pass(git_blame_file(&g_blame, g_repo, "branch_file.txt", NULL));

	cl_assert_equal_i(2, git_blame_get_hunk_count(g_blame));
	check_blame_hunk_index(g_repo, g_blame, 0, 1, 1, 0, "c47800c7", "branch_file.txt");
	check_blame_hunk_index(g_repo, g_blame, 1, 2, 1, 0, "a65fedf3", "branch_file.txt");
}
Exemple #5
0
/*
 * $ git blame -n b.txt
 *    orig line no                          final line no
 * commit    V  author     timestamp                  V
 * da237394  1 (Ben Straub 2013-02-12 15:11:30 -0800  1
 * da237394  2 (Ben Straub 2013-02-12 15:11:30 -0800  2
 * da237394  3 (Ben Straub 2013-02-12 15:11:30 -0800  3
 * da237394  4 (Ben Straub 2013-02-12 15:11:30 -0800  4
 * ^b99f7ac  1 (Ben Straub 2013-02-12 15:10:12 -0800  5
 * 63d671eb  6 (Ben Straub 2013-02-12 15:13:04 -0800  6
 * 63d671eb  7 (Ben Straub 2013-02-12 15:13:04 -0800  7
 * 63d671eb  8 (Ben Straub 2013-02-12 15:13:04 -0800  8
 * 63d671eb  9 (Ben Straub 2013-02-12 15:13:04 -0800  9
 * 63d671eb 10 (Ben Straub 2013-02-12 15:13:04 -0800 10
 * aa06ecca  6 (Ben Straub 2013-02-12 15:14:46 -0800 11
 * aa06ecca  7 (Ben Straub 2013-02-12 15:14:46 -0800 12
 * aa06ecca  8 (Ben Straub 2013-02-12 15:14:46 -0800 13
 * aa06ecca  9 (Ben Straub 2013-02-12 15:14:46 -0800 14
 * aa06ecca 10 (Ben Straub 2013-02-12 15:14:46 -0800 15
 */
void test_blame_simple__trivial_blamerepo(void)
{
	cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git")));
	cl_git_pass(git_blame_file(&g_blame, g_repo, "b.txt", NULL));

	cl_assert_equal_i(4, git_blame_get_hunk_count(g_blame));
	check_blame_hunk_index(g_repo, g_blame, 0,  1, 4, 0, "da237394", "b.txt");
	check_blame_hunk_index(g_repo, g_blame, 1,  5, 1, 1, "b99f7ac0", "b.txt");
	check_blame_hunk_index(g_repo, g_blame, 2,  6, 5, 0, "63d671eb", "b.txt");
	check_blame_hunk_index(g_repo, g_blame, 3, 11, 5, 0, "aa06ecca", "b.txt");
}
Exemple #6
0
/*
 * $ git blame -n b.txt -L 8
 *    orig line no                          final line no
 * commit    V  author     timestamp                  V
 * 63d671eb  8 (Ben Straub 2013-02-12 15:13:04 -0800  8
 * 63d671eb  9 (Ben Straub 2013-02-12 15:13:04 -0800  9
 * 63d671eb 10 (Ben Straub 2013-02-12 15:13:04 -0800 10
 * aa06ecca  6 (Ben Straub 2013-02-12 15:14:46 -0800 11
 * aa06ecca  7 (Ben Straub 2013-02-12 15:14:46 -0800 12
 * aa06ecca  8 (Ben Straub 2013-02-12 15:14:46 -0800 13
 * aa06ecca  9 (Ben Straub 2013-02-12 15:14:46 -0800 14
 * aa06ecca 10 (Ben Straub 2013-02-12 15:14:46 -0800 15
 */
void test_blame_simple__can_restrict_lines_min(void)
{
	git_blame_options opts = GIT_BLAME_OPTIONS_INIT;

	cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git")));

	opts.min_line = 8;
	cl_git_pass(git_blame_file(&g_blame, g_repo, "b.txt", &opts));
	cl_assert_equal_i(2, git_blame_get_hunk_count(g_blame));
	check_blame_hunk_index(g_repo, g_blame, 0,  8, 3, 0, "63d671eb", "b.txt");
	check_blame_hunk_index(g_repo, g_blame, 1, 11, 5, 0, "aa06ecca", "b.txt");
}
Exemple #7
0
/*
 * $ git blame -n b.txt -L ,6
 *    orig line no                          final line no
 * commit    V  author     timestamp                  V
 * da237394  1 (Ben Straub 2013-02-12 15:11:30 -0800  1
 * da237394  2 (Ben Straub 2013-02-12 15:11:30 -0800  2
 * da237394  3 (Ben Straub 2013-02-12 15:11:30 -0800  3
 * da237394  4 (Ben Straub 2013-02-12 15:11:30 -0800  4
 * ^b99f7ac  1 (Ben Straub 2013-02-12 15:10:12 -0800  5
 * 63d671eb  6 (Ben Straub 2013-02-12 15:13:04 -0800  6
 */
void test_blame_simple__can_restrict_lines_max(void)
{
	git_blame_options opts = GIT_BLAME_OPTIONS_INIT;

	cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git")));

	opts.max_line = 6;
	cl_git_pass(git_blame_file(&g_blame, g_repo, "b.txt", &opts));
	cl_assert_equal_i(3, git_blame_get_hunk_count(g_blame));
	check_blame_hunk_index(g_repo, g_blame, 0,  1, 4, 0, "da237394", "b.txt");
	check_blame_hunk_index(g_repo, g_blame, 1,  5, 1, 1, "b99f7ac0", "b.txt");
	check_blame_hunk_index(g_repo, g_blame, 2,  6, 1, 0, "63d671eb", "b.txt");
}
Exemple #8
0
void test_blame_simple__can_restrict_to_first_parent_commits(void)
{
	git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
	opts.flags |= GIT_BLAME_FIRST_PARENT;

	cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git")));

	cl_git_pass(git_blame_file(&g_blame, g_repo, "b.txt", &opts));
	cl_assert_equal_i(4, git_blame_get_hunk_count(g_blame));
	check_blame_hunk_index(g_repo, g_blame, 0,  1, 4, 0, "da237394", "b.txt");
	check_blame_hunk_index(g_repo, g_blame, 1,  5, 1, 1, "b99f7ac0", "b.txt");
	check_blame_hunk_index(g_repo, g_blame, 2,  6, 5, 0, "63d671eb", "b.txt");
	check_blame_hunk_index(g_repo, g_blame, 3, 11, 5, 0, "bc7c5ac2", "b.txt");
}
Exemple #9
0
PyObject *
Blame_iter(Blame *self)
{
    BlameIter *iter;

    iter = PyObject_New(BlameIter, &BlameIterType);
    if (iter != NULL) {
        Py_INCREF(self);
        iter->blame = self;
        iter->i = 0;
        iter->n = git_blame_get_hunk_count(self->blame);
    }
    return (PyObject*)iter;
}
Exemple #10
0
/*
 * $ git blame -n branch_file.txt be3563a..HEAD
 *    orig line no                          final line no
 * commit   V  author       timestamp                 V
 * ^be3563a 1 (Scott Chacon 2010-05-25 11:58:27 -0700 1) hi
 * a65fedf3 2 (Scott Chacon 2011-08-09 19:33:46 -0700 2) bye!
 */
void test_blame_simple__can_restrict_to_newish_commits(void)
{
	git_blame_options opts = GIT_BLAME_OPTIONS_INIT;

	cl_git_pass(git_repository_open(&g_repo, cl_fixture("testrepo.git")));

	{
		git_object *obj;
		cl_git_pass(git_revparse_single(&obj, g_repo, "be3563a"));
		git_oid_cpy(&opts.oldest_commit, git_object_id(obj));
		git_object_free(obj);
	}

	cl_git_pass(git_blame_file(&g_blame, g_repo, "branch_file.txt", &opts));

	cl_assert_equal_i(2, git_blame_get_hunk_count(g_blame));
	check_blame_hunk_index(g_repo, g_blame, 0,  1, 1, 1, "be3563a", "branch_file.txt");
	check_blame_hunk_index(g_repo, g_blame, 1,  2, 1, 0, "a65fedf", "branch_file.txt");
}
Exemple #11
0
Py_ssize_t
Blame_len(Blame *self)
{
    assert(self->blame);
    return (Py_ssize_t)git_blame_get_hunk_count(self->blame);
}