git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
git_object *obj;
- cl_git_pass(git_repository_open(&g_repo, cl_fixture("../..")));
+ /* If we can't open the libgit2 repo or if it isn't a full repo
+ * with proper history, just skip this test */
+ if (git_repository_open(&g_repo, cl_fixture("../..")) < 0)
+ cl_skip();
- /* This test can't work on a shallow clone */
if (git_repository_is_shallow(g_repo))
- return;
+ cl_skip();
+
+ if (git_revparse_single(&obj, g_repo, "359fc2d") < 0)
+ cl_skip();
- cl_git_pass(git_revparse_single(&obj, g_repo, "359fc2d"));
git_oid_cpy(&opts.newest_commit, git_object_id(obj));
git_object_free(obj);
check_blame_hunk_index(g_repo, g_blame, 49, 60, 1, 0, "d12299fe", "src/git.h");
}
+/* This was leading to segfaults on some systems during cache eviction. */
+void test_blame_simple__trivial_libgit2_under_cache_pressure(void)
+{
+ ssize_t old_max_storage = git_cache__max_storage;
+ git_cache__max_storage = 1024 * 1024;
+ test_blame_simple__trivial_libgit2();
+ git_cache__max_storage = old_max_storage;
+}
/*
* $ git blame -n b.txt -L 8
check_blame_hunk_index(g_repo, g_blame, 1, 11, 5, 0, "aa06ecca", "b.txt");
}
+/*
+ * $ git blame -n c.txt
+ * orig line no final line no
+ * commit V author timestamp V
+ * 702c7aa5 1 (Carl Schwan 2020-01-29 01:52:31 +0100 4
+ */
+void test_blame_simple__can_ignore_whitespace_change(void)
+{
+ git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
+
+ cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git")));
+
+ opts.flags |= GIT_BLAME_IGNORE_WHITESPACE;
+ cl_git_pass(git_blame_file(&g_blame, g_repo, "c.txt", &opts));
+ cl_assert_equal_i(1, git_blame_get_hunk_count(g_blame));
+ check_blame_hunk_index(g_repo, g_blame, 0, 1, 4, 0, "702c7aa5", "c.txt");
+}
+
/*
* $ git blame -n b.txt -L ,6
* orig line no final line no
check_blame_hunk_index(g_repo, g_blame, 2, 6, 2, 0, "63d671eb", "b.txt");
}
+void test_blame_simple__can_blame_huge_file(void)
+{
+ git_blame_options opts = GIT_BLAME_OPTIONS_INIT;
+
+ cl_git_pass(git_repository_open(&g_repo, cl_fixture("blametest.git")));
+
+ cl_git_pass(git_blame_file(&g_blame, g_repo, "huge.txt", &opts));
+ cl_assert_equal_i(2, git_blame_get_hunk_count(g_blame));
+ check_blame_hunk_index(g_repo, g_blame, 0, 1, 65536, 0, "4eecfea", "huge.txt");
+ check_blame_hunk_index(g_repo, g_blame, 1, 65537, 1, 0, "6653ff4", "huge.txt");
+}
+
/*
* $ git blame -n branch_file.txt be3563a..HEAD
* orig line no final line no