Jonathan Tan | e967ca3 | 2017-12-14 13:44:45 -0800 | [diff] [blame] | 1 | #ifndef TRANSPORT_INTERNAL_H |
| 2 | #define TRANSPORT_INTERNAL_H |
| 3 | |
| 4 | struct ref; |
| 5 | struct transport; |
Jeff King | 873cd28 | 2020-07-28 16:23:25 -0400 | [diff] [blame] | 6 | struct strvec; |
Jonathan Tan | 3983540 | 2021-02-05 12:48:48 -0800 | [diff] [blame] | 7 | struct transport_ls_refs_options; |
Jonathan Tan | e967ca3 | 2017-12-14 13:44:45 -0800 | [diff] [blame] | 8 | |
| 9 | struct transport_vtable { |
| 10 | /** |
| 11 | * Returns 0 if successful, positive if the option is not |
| 12 | * recognized or is inapplicable, and negative if the option |
| 13 | * is applicable but the value is invalid. |
| 14 | **/ |
| 15 | int (*set_option)(struct transport *connection, const char *name, |
| 16 | const char *value); |
| 17 | /** |
| 18 | * Returns a list of the remote side's refs. In order to allow |
| 19 | * the transport to try to share connections, for_push is a |
| 20 | * hint as to whether the ultimate operation is a push or a fetch. |
| 21 | * |
| 22 | * If the transport is able to determine the remote hash for |
| 23 | * the ref without a huge amount of effort, it should store it |
| 24 | * in the ref's old_sha1 field; otherwise it should be all 0. |
| 25 | **/ |
Brandon Williams | 834cf34 | 2018-03-15 10:31:22 -0700 | [diff] [blame] | 26 | struct ref *(*get_refs_list)(struct transport *transport, int for_push, |
Jonathan Tan | 3983540 | 2021-02-05 12:48:48 -0800 | [diff] [blame] | 27 | struct transport_ls_refs_options *transport_options); |
Jonathan Tan | e967ca3 | 2017-12-14 13:44:45 -0800 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Fetch the objects for the given refs. Note that this gets |
| 31 | * an array, and should ignore the list structure. |
| 32 | * |
| 33 | * If the transport did not get hashes for refs in |
| 34 | * get_refs_list(), it should set the old_sha1 fields in the |
| 35 | * provided refs now. |
| 36 | **/ |
Ævar Arnfjörð Bjarmason | 9b1cdd3 | 2021-08-05 03:25:35 +0200 | [diff] [blame] | 37 | int (*fetch_refs)(struct transport *transport, int refs_nr, struct ref **refs); |
Jonathan Tan | e967ca3 | 2017-12-14 13:44:45 -0800 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * Push the objects and refs. Send the necessary objects, and |
| 41 | * then, for any refs where peer_ref is set and |
| 42 | * peer_ref->new_oid is different from old_oid, tell the |
| 43 | * remote side to update each ref in the list from old_oid to |
| 44 | * peer_ref->new_oid. |
| 45 | * |
| 46 | * Where possible, set the status for each ref appropriately. |
| 47 | * |
| 48 | * The transport must modify new_sha1 in the ref to the new |
| 49 | * value if the remote accepted the change. Note that this |
| 50 | * could be a different value from peer_ref->new_oid if the |
| 51 | * process involved generating new commits. |
| 52 | **/ |
| 53 | int (*push_refs)(struct transport *transport, struct ref *refs, int flags); |
| 54 | int (*connect)(struct transport *connection, const char *name, |
| 55 | const char *executable, int fd[2]); |
| 56 | |
| 57 | /** get_refs_list(), fetch(), and push_refs() can keep |
| 58 | * resources (such as a connection) reserved for further |
| 59 | * use. disconnect() releases these resources. |
| 60 | **/ |
| 61 | int (*disconnect)(struct transport *connection); |
| 62 | }; |
| 63 | |
| 64 | #endif |