|
Packit Service |
20376f |
#include "blame_helpers.h"
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
void hunk_message(size_t idx, const git_blame_hunk *hunk, const char *fmt, ...)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
va_list arglist;
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
printf("Hunk %"PRIuZ" (line %"PRIuZ" +%"PRIuZ"): ", idx,
|
|
Packit Service |
20376f |
hunk->final_start_line_number, hunk->lines_in_hunk-1);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
va_start(arglist, fmt);
|
|
Packit Service |
20376f |
vprintf(fmt, arglist);
|
|
Packit Service |
20376f |
va_end(arglist);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
printf("\n");
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
void check_blame_hunk_index(git_repository *repo, git_blame *blame, int idx,
|
|
Packit Service |
20376f |
size_t start_line, size_t len, char boundary, const char *commit_id, const char *orig_path)
|
|
Packit Service |
20376f |
{
|
|
Packit Service |
20376f |
char expected[GIT_OID_HEXSZ+1] = {0}, actual[GIT_OID_HEXSZ+1] = {0};
|
|
Packit Service |
20376f |
const git_blame_hunk *hunk = git_blame_get_hunk_byindex(blame, idx);
|
|
Packit Service |
20376f |
cl_assert(hunk);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
if (!strncmp(commit_id, "0000", 4)) {
|
|
Packit Service |
20376f |
strcpy(expected, "0000000000000000000000000000000000000000");
|
|
Packit Service |
20376f |
} else {
|
|
Packit Service |
20376f |
git_object *obj;
|
|
Packit Service |
20376f |
cl_git_pass(git_revparse_single(&obj, repo, commit_id));
|
|
Packit Service |
20376f |
git_oid_fmt(expected, git_object_id(obj));
|
|
Packit Service |
20376f |
git_object_free(obj);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
if (hunk->final_start_line_number != start_line) {
|
|
Packit Service |
20376f |
hunk_message(idx, hunk, "mismatched start line number: expected %d, got %d",
|
|
Packit Service |
20376f |
start_line, hunk->final_start_line_number);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
cl_assert_equal_i(hunk->final_start_line_number, start_line);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
if (hunk->lines_in_hunk != len) {
|
|
Packit Service |
20376f |
hunk_message(idx, hunk, "mismatched line count: expected %d, got %d",
|
|
Packit Service |
20376f |
len, hunk->lines_in_hunk);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
cl_assert_equal_i(hunk->lines_in_hunk, len);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
git_oid_fmt(actual, &hunk->final_commit_id);
|
|
Packit Service |
20376f |
if (strcmp(expected, actual)) {
|
|
Packit Service |
20376f |
hunk_message(idx, hunk, "has mismatched original id (got %s, expected %s)\n",
|
|
Packit Service |
20376f |
actual, expected);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
cl_assert_equal_s(actual, expected);
|
|
Packit Service |
20376f |
cl_assert_equal_oid(&hunk->final_commit_id, &hunk->orig_commit_id);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
if (strcmp(hunk->orig_path, orig_path)) {
|
|
Packit Service |
20376f |
hunk_message(idx, hunk, "has mismatched original path (got '%s', expected '%s')\n",
|
|
Packit Service |
20376f |
hunk->orig_path, orig_path);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
cl_assert_equal_s(hunk->orig_path, orig_path);
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
if (hunk->boundary != boundary) {
|
|
Packit Service |
20376f |
hunk_message(idx, hunk, "doesn't match boundary flag (got %d, expected %d)\n",
|
|
Packit Service |
20376f |
hunk->boundary, boundary);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
cl_assert_equal_i(boundary, hunk->boundary);
|
|
Packit Service |
20376f |
}
|
|
Packit Service |
20376f |
|
|
Packit Service |
20376f |
|