Ramsay Jones | 0009d35 | 2018-10-17 23:13:26 +0100 | [diff] [blame] | 1 | #ifndef FETCH_NEGOTIATOR_H |
| 2 | #define FETCH_NEGOTIATOR_H |
Jonathan Tan | ec06283 | 2018-06-14 15:54:28 -0700 | [diff] [blame] | 3 | |
| 4 | struct commit; |
Derrick Stolee | aaf633c | 2019-08-13 11:37:48 -0700 | [diff] [blame] | 5 | struct repository; |
Jonathan Tan | ec06283 | 2018-06-14 15:54:28 -0700 | [diff] [blame] | 6 | |
| 7 | /* |
| 8 | * An object that supplies the information needed to negotiate the contents of |
| 9 | * the to-be-sent packfile during a fetch. |
| 10 | * |
| 11 | * To set up the negotiator, call fetch_negotiator_init(), then known_common() |
| 12 | * (0 or more times), then add_tip() (0 or more times). |
| 13 | * |
| 14 | * Then, when "have" lines are required, call next(). Call ack() to report what |
| 15 | * the server tells us. |
| 16 | * |
| 17 | * Once negotiation is done, call release(). The negotiator then cannot be used |
| 18 | * (unless reinitialized with fetch_negotiator_init()). |
| 19 | */ |
| 20 | struct fetch_negotiator { |
| 21 | /* |
| 22 | * Before negotiation starts, indicate that the server is known to have |
| 23 | * this commit. |
| 24 | */ |
| 25 | void (*known_common)(struct fetch_negotiator *, struct commit *); |
| 26 | |
| 27 | /* |
| 28 | * Once this function is invoked, known_common() cannot be invoked any |
| 29 | * more. |
| 30 | * |
| 31 | * Indicate that this commit and all its ancestors are to be checked |
| 32 | * for commonality with the server. |
| 33 | */ |
| 34 | void (*add_tip)(struct fetch_negotiator *, struct commit *); |
| 35 | |
| 36 | /* |
| 37 | * Once this function is invoked, known_common() and add_tip() cannot |
| 38 | * be invoked any more. |
| 39 | * |
| 40 | * Return the next commit that the client should send as a "have" line. |
| 41 | */ |
| 42 | const struct object_id *(*next)(struct fetch_negotiator *); |
| 43 | |
| 44 | /* |
| 45 | * Inform the negotiator that the server has the given commit. This |
| 46 | * method must only be called on commits returned by next(). |
| 47 | */ |
| 48 | int (*ack)(struct fetch_negotiator *, struct commit *); |
| 49 | |
| 50 | void (*release)(struct fetch_negotiator *); |
| 51 | |
| 52 | /* internal use */ |
| 53 | void *data; |
| 54 | }; |
| 55 | |
Robert Coup | 1836836 | 2022-03-28 14:02:05 +0000 | [diff] [blame] | 56 | /* |
| 57 | * Initialize a negotiator based on the repository settings. |
| 58 | */ |
Derrick Stolee | aaf633c | 2019-08-13 11:37:48 -0700 | [diff] [blame] | 59 | void fetch_negotiator_init(struct repository *r, |
| 60 | struct fetch_negotiator *negotiator); |
Jonathan Tan | ec06283 | 2018-06-14 15:54:28 -0700 | [diff] [blame] | 61 | |
Robert Coup | 1836836 | 2022-03-28 14:02:05 +0000 | [diff] [blame] | 62 | /* |
| 63 | * Initialize a noop negotiator. |
| 64 | */ |
| 65 | void fetch_negotiator_init_noop(struct fetch_negotiator *negotiator); |
| 66 | |
Jonathan Tan | ec06283 | 2018-06-14 15:54:28 -0700 | [diff] [blame] | 67 | #endif |