| 1747 | } gfb_fixture_t; |
| 1748 | |
| 1749 | static bool gfb_open(gfb_fixture_t *f, bool sha256) { |
| 1750 | memset(f, 0, sizeof(*f)); |
| 1751 | cbm_arena_init_lazy(&f->arena, 4096); |
| 1752 | if (!gf_fixture_open(&f->git, sha256)) |
| 1753 | return false; |
| 1754 | bool ok = gf_object(&f->git, "blob", "", 0, f->empty_oid) && |
| 1755 | gf_object(&f->git, "blob", gfb_binary, sizeof(gfb_binary), f->binary_oid) && |
| 1756 | gf_object(&f->git, "blob", gfb_header_body, sizeof(gfb_header_body)-1, f->header_oid); |
| 1757 | for (int j = 0; ok && j < 3; j++) { |
| 1758 | f->large[j] = cbm_arena_alloc(&f->arena, GFB_BODY); |
| 1759 | ok = f->large[j] != NULL; |
| 1760 | for (size_t i = 0; ok && i < GFB_BODY; i++) |
| 1761 | f->large[j][i] = (unsigned char)((i + (size_t)j * 31) % 251); |
| 1762 | if (ok) |
| 1763 | ok = gf_object(&f->git, "blob", f->large[j], GFB_BODY, f->large_oid[j]); |
| 1764 | } |
| 1765 | const char *paths[] = {":colon", "[g]*", "back\\slash", "empty", "header", "large-a", |
| 1766 | "large-b", "large-c", "line\nbreak", "link", "p.txt", "submodule", "tab\tname", gfb_utf}; |
| 1767 | const char *oids[] = {f->binary_oid, f->binary_oid, f->binary_oid, f->empty_oid, |
| 1768 | f->header_oid, f->large_oid[0], f->large_oid[1], f->large_oid[2], f->binary_oid, |
| 1769 | f->git.link, f->git.head_text, f->git.a, f->binary_oid, f->binary_oid}; |
| 1770 | gfi_raw_entry_t rows[GFB_COUNT]; |
| 1771 | for (size_t i = 0; i < GFB_COUNT; i++) { |
| 1772 | uint32_t mode = i == GFB_EXEC ? 0100755 : i == GFB_LINK ? 0120000 : |
| 1773 | i == GFB_SUBMODULE ? 0160000 : 0100644; |
| 1774 | const char *mode_text = i == GFB_EXEC ? "100755" : i == GFB_LINK ? "120000" : |
| 1775 | i == GFB_SUBMODULE ? "160000" : "100644"; |
| 1776 | size_t length = i == GFB_UTF ? sizeof(gfb_utf) : strlen(paths[i]); |
| 1777 | f->expected[i] = (gfi_expected_t){paths[i], length, mode, |
| 1778 | i == GFB_SUBMODULE ? CBM_GIT_TREE_COMMIT : CBM_GIT_TREE_BLOB, oids[i]}; |
| 1779 | rows[i] = (gfi_raw_entry_t){mode_text, paths[i], length, oids[i]}; |
| 1780 | } |
| 1781 | char th[65], tm[65], q[65], h[65], b[65]; |
| 1782 | ok = ok && gfi_raw_tree(&f->git, rows, GFB_COUNT, th); |
| 1783 | rows[GFB_TEXT].oid = f->git.old_text; |
| 1784 | ok = ok && gfi_raw_tree(&f->git, rows, GFB_COUNT, tm) && |
| 1785 | gf_commit(&f->git, tm, f->git.a, NULL, "batch Q", q) && |
| 1786 | gf_commit(&f->git, th, f->git.p, q, "batch H", h) && |
| 1787 | gf_commit(&f->git, tm, q, NULL, "batch B", b) && |
| 1788 | gf_ref(&f->git, "refs/heads/topic", h) && gf_ref(&f->git, "refs/heads/base", b); |
| 1789 | if (ok) { |
| 1790 | memcpy(f->git.q, q, f->git.oid_length+1); |
| 1791 | memcpy(f->git.head, h, f->git.oid_length+1); |
| 1792 | memcpy(f->git.base, b, f->git.oid_length+1); |
| 1793 | } |
| 1794 | return ok; |
| 1795 | } |
| 1796 | |
| 1797 | static int gfb_close(gfb_fixture_t *f) { |
| 1798 | cbm_arena_destroy(&f->arena); |
no test coverage detected