| 1894 | } |
| 1895 | |
| 1896 | static bool gf_batch_unique(gf_batch_work_t *work, cbm_git_facts_error_t *error) { |
| 1897 | size_t count = work->request->count, width = work->facts->identity.oid_hex_length; |
| 1898 | for (size_t i = 0; i < count; i++) { |
| 1899 | if (!gf_gate(work->facts, error)) |
| 1900 | return false; |
| 1901 | if (!i || memcmp(work->picks[i - 1].entry->oid, work->picks[i].entry->oid, width) != 0) |
| 1902 | work->unique_count++; |
| 1903 | work->picks[i].object_index = work->unique_count - 1; |
| 1904 | } |
| 1905 | work->objects = gf_batch_array(work->facts, work->unique_count, sizeof(*work->objects), error); |
| 1906 | if (!work->objects) |
| 1907 | return false; |
| 1908 | work->line_length = width + 1; |
| 1909 | if (work->unique_count > SIZE_MAX / work->line_length / 2 || |
| 1910 | work->unique_count * work->line_length * 2 > work->facts->batch_budget->input_limit) |
| 1911 | return gf_limit(work->facts, error, "Git batch cumulative stdin limit exceeded"); |
| 1912 | work->lines = gf_batch_array(work->facts, work->unique_count, work->line_length, error); |
| 1913 | if (!work->lines) |
| 1914 | return false; |
| 1915 | for (size_t i = 0; i < count; i++) { |
| 1916 | if (!gf_gate(work->facts, error)) |
| 1917 | return false; |
| 1918 | size_t object = work->picks[i].object_index; |
| 1919 | if (i && object == work->picks[i - 1].object_index) |
| 1920 | continue; |
| 1921 | const char *oid = work->picks[i].entry->oid; |
| 1922 | if (!gf_batch_canonical_oid(oid, width)) |
| 1923 | return gf_error(error, CBM_GIT_FACTS_COMMAND, "Invalid owned Git batch object ID"); |
| 1924 | work->objects[object] = (gf_batch_object_t){.oid = oid}; |
| 1925 | unsigned char *line = work->lines + object * work->line_length; |
| 1926 | memcpy(line, oid, width); |
| 1927 | line[width] = '\n'; |
| 1928 | } |
| 1929 | return gf_gate(work->facts, error); |
| 1930 | } |
| 1931 | |
| 1932 | static size_t gf_batch_digits(size_t value) { |
| 1933 | size_t digits = 1; |
no test coverage detected