| 1 | #ifndef DIFF_PROVIDER_INTERNAL_H |
| 2 | #define DIFF_PROVIDER_INTERNAL_H |
| 3 | |
| 4 | #include "diff-provider.h" |
| 5 | |
| 6 | /* |
| 7 | * The implementor-facing half of the hunk provider interface: the |
| 8 | * provider chain a repository owns, and the rules a provider applies |
| 9 | * to its own answer before any consumer sees it. Provider |
| 10 | * implementations include this header; consumers of the interface |
| 11 | * use only diff-provider.h. |
| 12 | */ |
| 13 | |
| 14 | /* |
| 15 | * A provider's verdict on one request. Only the chain walk |
| 16 | * (diff-provider.c) sees these; it maps the dispositions of a whole |
| 17 | * walk onto the public outcome set. |
| 18 | */ |
| 19 | enum diff_provider_disposition { |
| 20 | /* |
| 21 | * The provider failed to produce the answer it owns. Only |
| 22 | * the computing provider returns this: its compute leg is |
| 23 | * the one part of a consultation that can fail, and the walk |
| 24 | * ends with the public error outcome. |
| 25 | */ |
| 26 | DIFF_PROVIDER_DISP_ERROR = -1, |
| 27 | |
| 28 | /* |
| 29 | * Answered: every hunk of the pair has been emitted through |
| 30 | * the consumer's callback. |
| 31 | */ |
| 32 | DIFF_PROVIDER_DISP_ANSWERED = 0, |
| 33 | |
| 34 | /* Not this provider's request: the walk consults the next one. */ |
| 35 | DIFF_PROVIDER_DISP_PASS, |
| 36 | |
| 37 | /* |
| 38 | * The pair must not be answered from identity nor recorded: |
| 39 | * the request is shaped by parameters the provider's |
| 40 | * recording key cannot express, so a recorded answer would |
| 41 | * not match this request, and this request's result must not |
| 42 | * be recorded under that key. The walk goes on, but consults |
| 43 | * only the computing provider, and its fall-through outcome |
| 44 | * tells the consumer not to record. |
| 45 | */ |
| 46 | DIFF_PROVIDER_DISP_STOP_NO_RECORD, |
| 47 | }; |
| 48 | |
| 49 | /* |
| 50 | * One provider in a repository's chain (repository.h). The chain is |
| 51 | * assembled in diff-provider.c with a fixed composition; whether a |
| 52 | * provider applies to a request is decided by nobody but the |
| 53 | * provider, whose consult gates itself and passes. Chain position |
| 54 | * carries the authority resolution: an earlier provider's answer or |
| 55 | * refusal outranks every provider after it. |
| 56 | */ |
| 57 | struct diff_provider { |
| 58 | /* |
| 59 | * Consult this provider for one request. fill is NULL on a |
| 60 | * consult-only walk; only the computing provider reads it, |
| 61 | * and it must pass when fill is NULL. |
| 62 | */ |
| 63 | enum diff_provider_disposition |
| 64 | (*consult)(struct diff_provider *provider, |
| 65 | const struct diff_provider_request *req, |
| 66 | diff_provider_fill_fn fill, void *fill_data, |
| 67 | xdl_emit_hunk_consume_func_t hunk_cb, |
| 68 | void *cb_data); |
| 69 | |
| 70 | /* |
| 71 | * Tear down the provider's state, or NULL when it owns none. |
| 72 | * Runs when the owning repository is cleared; the chain frees |
| 73 | * the provider itself afterwards. |
| 74 | */ |
| 75 | void (*release)(struct diff_provider *provider); |
| 76 | |
| 77 | void *state; |
| 78 | |
| 79 | /* |
| 80 | * Set on the provider that loads content and computes rather |
| 81 | * than answering from the request's identity. It alone is |
| 82 | * still consulted after a stop-no-record: an identity answer |
| 83 | * may no longer be served, but the computation must still |
| 84 | * run. |
| 85 | */ |
| 86 | unsigned computes:1; |
| 87 | |
| 88 | struct diff_provider *next; |
| 89 | }; |
| 90 | |
| 91 | /* |
| 92 | * The providers Git ships, besides the builtin computation that |
| 93 | * diff-provider.c holds itself. Each call returns a fresh provider |
| 94 | * for one repository's chain. |
| 95 | */ |
| 96 | struct diff_provider *diff_process_provider_new(void); |
| 97 | struct diff_provider *diff_hunks_store_provider_new(void); |
| 98 | |
| 99 | /* |
| 100 | * Incremental well-formedness check for a provider-supplied hunk |
| 101 | * sequence, shared by every provider. Each coordinate, and each |
| 102 | * hunk's end (its start plus count), must fit int32 (a consumer may |
| 103 | * truncate to int, and a provider may serialize as such); hunks must |
| 104 | * be in order and must not overlap; and the unchanged run between |
| 105 | * hunks must be the same length on both sides, or a consumer that |
| 106 | * walks the two files in lockstep desynchronizes. Every rule |
| 107 | * constrains differences between coordinates, so the check applies |
| 108 | * to 0-based and 1-based sequences alike. |
| 109 | * |
| 110 | * Feed the hunks in order to a zero-initialized struct; the first |
| 111 | * nonzero return names the violated rule, and the whole sequence must |
| 112 | * then be discarded unemitted. |
| 113 | */ |
| 114 | struct diff_provider_hunks_check { |
| 115 | int64_t prev_old_end, prev_new_end; |
| 116 | }; |
| 117 | |
| 118 | enum diff_provider_hunks_error { |
| 119 | DIFF_PROVIDER_HUNKS_OK = 0, |
| 120 | DIFF_PROVIDER_HUNKS_RANGE, /* negative or beyond int32 */ |
| 121 | DIFF_PROVIDER_HUNKS_OVERLAP, /* out of order or overlapping */ |
| 122 | DIFF_PROVIDER_HUNKS_MISALIGNED, /* unchanged runs differ in length */ |
| 123 | }; |
| 124 | |
| 125 | enum diff_provider_hunks_error |
| 126 | diff_provider_check_hunk(struct diff_provider_hunks_check *c, |
| 127 | long old_start, long old_count, |
| 128 | long new_start, long new_count); |
| 129 | |
| 130 | #endif /* DIFF_PROVIDER_INTERNAL_H */ |