| 1 | #ifndef TRANSPORT_H |
| 2 | #define TRANSPORT_H |
| 3 | |
| 4 | #include "run-command.h" |
| 5 | #include "remote.h" |
| 6 | #include "list-objects-filter-options.h" |
| 7 | #include "string-list.h" |
| 8 | #include "connect.h" |
| 9 | |
| 10 | struct fetch_object_info_results; |
| 11 | |
| 12 | struct git_transport_options { |
| 13 | unsigned thin : 1; |
| 14 | unsigned keep : 1; |
| 15 | unsigned followtags : 1; |
| 16 | unsigned check_self_contained_and_connected : 1; |
| 17 | unsigned self_contained_and_connected : 1; |
| 18 | unsigned update_shallow : 1; |
| 19 | unsigned reject_shallow : 1; |
| 20 | unsigned deepen_relative : 1; |
| 21 | unsigned refetch : 1; |
| 22 | |
| 23 | /* see documentation of corresponding flag in fetch-pack.h */ |
| 24 | unsigned from_promisor : 1; |
| 25 | |
| 26 | /* |
| 27 | * If this transport supports connect or stateless-connect, |
| 28 | * the corresponding field in struct fetch_pack_args is copied |
| 29 | * here after fetching. |
| 30 | * |
| 31 | * See the definition of connectivity_checked in struct |
| 32 | * fetch_pack_args for more information. |
| 33 | */ |
| 34 | unsigned connectivity_checked:1; |
| 35 | |
| 36 | int depth; |
| 37 | const char *deepen_since; |
| 38 | const struct string_list *deepen_not; |
| 39 | const char *uploadpack; |
| 40 | const char *receivepack; |
| 41 | struct push_cas_option *cas; |
| 42 | struct list_objects_filter_options filter_options; |
| 43 | |
| 44 | /* |
| 45 | * This is only used during fetch. See the documentation of |
| 46 | * these member names in struct fetch_pack_args. |
| 47 | * |
| 48 | * These fields are only supported by transports that support connect or |
| 49 | * stateless_connect. Set this field directly instead of using |
| 50 | * transport_set_option(). |
| 51 | */ |
| 52 | struct oid_array *negotiation_restrict_tips; |
| 53 | struct oid_array *negotiation_include_tips; |
| 54 | |
| 55 | /* |
| 56 | * If allocated, whenever transport_fetch_refs() is called, add known |
| 57 | * common commits to this oidset instead of fetching any packfiles. |
| 58 | */ |
| 59 | struct oidset *acked_commits; |
| 60 | |
| 61 | struct oid_array *object_info_oids; |
| 62 | struct fetch_object_info_results *object_info_results; |
| 63 | }; |
| 64 | |
| 65 | enum transport_family { |
| 66 | TRANSPORT_FAMILY_ALL = 0, |
| 67 | TRANSPORT_FAMILY_IPV4, |
| 68 | TRANSPORT_FAMILY_IPV6 |
| 69 | }; |
| 70 | |
| 71 | struct bundle_list; |
| 72 | struct transport { |
| 73 | const struct transport_vtable *vtable; |
| 74 | |
| 75 | struct remote *remote; |
| 76 | const char *url; |
| 77 | void *data; |
| 78 | const struct ref *remote_refs; |
| 79 | |
| 80 | /** |
| 81 | * Indicates whether we already called get_refs_list(); set by |
| 82 | * transport.c::transport_get_remote_refs(). |
| 83 | */ |
| 84 | unsigned got_remote_refs : 1; |
| 85 | |
| 86 | /** |
| 87 | * Indicates whether we already called get_bundle_uri_list(); set by |
| 88 | * transport.c::transport_get_remote_bundle_uri(). |
| 89 | */ |
| 90 | unsigned got_remote_bundle_uri : 1; |
| 91 | |
| 92 | /* |
| 93 | * The results of "command=bundle-uri", if both sides support |
| 94 | * the "bundle-uri" capability. |
| 95 | */ |
| 96 | struct bundle_list *bundles; |
| 97 | |
| 98 | /* |
| 99 | * Transports that call take-over destroys the data specific to |
| 100 | * the transport type while doing so, and cannot be reused. |
| 101 | */ |
| 102 | unsigned cannot_reuse : 1; |
| 103 | |
| 104 | /* |
| 105 | * A hint from caller that it will be performing a clone, not |
| 106 | * normal fetch. IOW the repository is guaranteed empty. |
| 107 | */ |
| 108 | unsigned cloning : 1; |
| 109 | |
| 110 | /* |
| 111 | * Indicates that the transport is connected via a half-duplex |
| 112 | * connection and should operate in stateless-rpc mode. |
| 113 | */ |
| 114 | unsigned stateless_rpc : 1; |
| 115 | |
| 116 | /* |
| 117 | * These strings will be passed to the {pre, post}-receive hook, |
| 118 | * on the remote side, if both sides support the push options capability. |
| 119 | */ |
| 120 | const struct string_list *push_options; |
| 121 | |
| 122 | /* |
| 123 | * These strings will be passed to the remote side on each command |
| 124 | * request, if both sides support the server-option capability. |
| 125 | */ |
| 126 | const struct string_list *server_options; |
| 127 | |
| 128 | struct string_list pack_lockfiles; |
| 129 | |
| 130 | signed verbose : 3; |
| 131 | /** |
| 132 | * Transports should not set this directly, and should use this |
| 133 | * value without having to check isatty(2), -q/--quiet |
| 134 | * (transport->verbose < 0), etc. - checking has already been done |
| 135 | * in transport_set_verbosity(). |
| 136 | **/ |
| 137 | unsigned progress : 1; |
| 138 | /* |
| 139 | * If transport is at least potentially smart, this points to |
| 140 | * git_transport_options structure to use in case transport |
| 141 | * actually turns out to be smart. |
| 142 | */ |
| 143 | struct git_transport_options *smart_options; |
| 144 | |
| 145 | enum transport_family family; |
| 146 | |
| 147 | const struct git_hash_algo *hash_algo; |
| 148 | }; |
| 149 | |
| 150 | #define TRANSPORT_PUSH_ALL (1<<0) |
| 151 | #define TRANSPORT_PUSH_FORCE (1<<1) |
| 152 | #define TRANSPORT_PUSH_DRY_RUN (1<<2) |
| 153 | #define TRANSPORT_PUSH_MIRROR (1<<3) |
| 154 | #define TRANSPORT_PUSH_PORCELAIN (1<<4) |
| 155 | #define TRANSPORT_PUSH_SET_UPSTREAM (1<<5) |
| 156 | #define TRANSPORT_RECURSE_SUBMODULES_CHECK (1<<6) |
| 157 | #define TRANSPORT_PUSH_PRUNE (1<<7) |
| 158 | #define TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND (1<<8) |
| 159 | #define TRANSPORT_PUSH_NO_HOOK (1<<9) |
| 160 | #define TRANSPORT_PUSH_FOLLOW_TAGS (1<<10) |
| 161 | #define TRANSPORT_PUSH_CERT_ALWAYS (1<<11) |
| 162 | #define TRANSPORT_PUSH_CERT_IF_ASKED (1<<12) |
| 163 | #define TRANSPORT_PUSH_ATOMIC (1<<13) |
| 164 | #define TRANSPORT_PUSH_OPTIONS (1<<14) |
| 165 | #define TRANSPORT_RECURSE_SUBMODULES_ONLY (1<<15) |
| 166 | #define TRANSPORT_PUSH_FORCE_IF_INCLUDES (1<<16) |
| 167 | #define TRANSPORT_PUSH_AUTO_UPSTREAM (1<<17) |
| 168 | |
| 169 | int transport_summary_width(const struct ref *refs); |
| 170 | |
| 171 | /* Returns a transport suitable for the url */ |
| 172 | struct transport *transport_get(struct remote *, const char *); |
| 173 | |
| 174 | /* |
| 175 | * Check whether a transport is allowed by the environment. |
| 176 | * |
| 177 | * Type should generally be the URL scheme, as described in |
| 178 | * Documentation/git.adoc |
| 179 | * |
| 180 | * from_user specifies if the transport was given by the user. If unknown pass |
| 181 | * a -1 to read from the environment to determine if the transport was given by |
| 182 | * the user. |
| 183 | * |
| 184 | */ |
| 185 | int is_transport_allowed(const char *type, int from_user); |
| 186 | |
| 187 | /* |
| 188 | * Check whether a transport is allowed by the environment, |
| 189 | * and die otherwise. |
| 190 | */ |
| 191 | void transport_check_allowed(const char *type); |
| 192 | |
| 193 | /* Transport options which apply to git:// and scp-style URLs */ |
| 194 | |
| 195 | /* The program to use on the remote side to send a pack */ |
| 196 | #define TRANS_OPT_UPLOADPACK "uploadpack" |
| 197 | |
| 198 | /* The program to use on the remote side to receive a pack */ |
| 199 | #define TRANS_OPT_RECEIVEPACK "receivepack" |
| 200 | |
| 201 | /* Transfer the data as a thin pack if not null */ |
| 202 | #define TRANS_OPT_THIN "thin" |
| 203 | |
| 204 | /* Check the current value of the remote ref */ |
| 205 | #define TRANS_OPT_CAS "cas" |
| 206 | |
| 207 | /* Keep the pack that was transferred if not null */ |
| 208 | #define TRANS_OPT_KEEP "keep" |
| 209 | |
| 210 | /* Limit the depth of the fetch if not null */ |
| 211 | #define TRANS_OPT_DEPTH "depth" |
| 212 | |
| 213 | /* Limit the depth of the fetch based on time if not null */ |
| 214 | #define TRANS_OPT_DEEPEN_SINCE "deepen-since" |
| 215 | |
| 216 | /* Limit the depth of the fetch based on revs if not null */ |
| 217 | #define TRANS_OPT_DEEPEN_NOT "deepen-not" |
| 218 | |
| 219 | /* Limit the deepen of the fetch if not null */ |
| 220 | #define TRANS_OPT_DEEPEN_RELATIVE "deepen-relative" |
| 221 | |
| 222 | /* Aggressively fetch annotated tags if possible */ |
| 223 | #define TRANS_OPT_FOLLOWTAGS "followtags" |
| 224 | |
| 225 | /* Reject shallow repo transport */ |
| 226 | #define TRANS_OPT_REJECT_SHALLOW "rejectshallow" |
| 227 | |
| 228 | /* Accept refs that may update .git/shallow without --depth */ |
| 229 | #define TRANS_OPT_UPDATE_SHALLOW "updateshallow" |
| 230 | |
| 231 | /* Send push certificates */ |
| 232 | #define TRANS_OPT_PUSH_CERT "pushcert" |
| 233 | |
| 234 | /* Indicate that these objects are being fetched by a promisor */ |
| 235 | #define TRANS_OPT_FROM_PROMISOR "from-promisor" |
| 236 | |
| 237 | /* Filter objects for partial clone and fetch */ |
| 238 | #define TRANS_OPT_LIST_OBJECTS_FILTER "filter" |
| 239 | |
| 240 | /* Refetch all objects without negotiating */ |
| 241 | #define TRANS_OPT_REFETCH "refetch" |
| 242 | |
| 243 | /* Request atomic (all-or-nothing) updates when pushing */ |
| 244 | #define TRANS_OPT_ATOMIC "atomic" |
| 245 | |
| 246 | /* Require remote changes to be integrated locally. */ |
| 247 | #define TRANS_OPT_FORCE_IF_INCLUDES "force-if-includes" |
| 248 | |
| 249 | /** |
| 250 | * Returns 0 if the option was used, non-zero otherwise. Prints a |
| 251 | * message to stderr if the option is not used. |
| 252 | **/ |
| 253 | int transport_set_option(struct transport *transport, const char *name, |
| 254 | const char *value); |
| 255 | void transport_set_verbosity(struct transport *transport, int verbosity, |
| 256 | int force_progress); |
| 257 | |
| 258 | #define REJECT_NON_FF_HEAD 0x01 |
| 259 | #define REJECT_NON_FF_OTHER 0x02 |
| 260 | #define REJECT_ALREADY_EXISTS 0x04 |
| 261 | #define REJECT_FETCH_FIRST 0x08 |
| 262 | #define REJECT_NEEDS_FORCE 0x10 |
| 263 | #define REJECT_REF_NEEDS_UPDATE 0x20 |
| 264 | |
| 265 | int transport_push(struct repository *repo, |
| 266 | struct transport *connection, |
| 267 | struct refspec *rs, int flags, |
| 268 | unsigned int * reject_reasons); |
| 269 | |
| 270 | struct transport_ls_refs_options { |
| 271 | /* |
| 272 | * Optionally, a list of ref prefixes can be provided which can be sent |
| 273 | * to the server (when communicating using protocol v2) to enable it to |
| 274 | * limit the ref advertisement. Since ref filtering is done on the |
| 275 | * server's end (and only when using protocol v2), |
| 276 | * transport_get_remote_refs() could return refs which don't match the |
| 277 | * provided ref_prefixes. |
| 278 | */ |
| 279 | struct strvec ref_prefixes; |
| 280 | |
| 281 | /* |
| 282 | * If unborn_head_target is not NULL, and the remote reports HEAD as |
| 283 | * pointing to an unborn branch, transport_get_remote_refs() stores the |
| 284 | * unborn branch in unborn_head_target. |
| 285 | */ |
| 286 | const char *unborn_head_target; |
| 287 | }; |
| 288 | #define TRANSPORT_LS_REFS_OPTIONS_INIT { \ |
| 289 | .ref_prefixes = STRVEC_INIT, \ |
| 290 | } |
| 291 | |
| 292 | /** |
| 293 | * Release the "struct transport_ls_refs_options". |
| 294 | */ |
| 295 | void transport_ls_refs_options_release(struct transport_ls_refs_options *opts); |
| 296 | |
| 297 | /* |
| 298 | * Retrieve refs from a remote. |
| 299 | */ |
| 300 | const struct ref *transport_get_remote_refs(struct transport *transport, |
| 301 | struct transport_ls_refs_options *transport_options); |
| 302 | |
| 303 | /** |
| 304 | * Retrieve bundle URI(s) from a remote. Populates "struct |
| 305 | * transport"'s "bundle_uri" and "got_remote_bundle_uri". |
| 306 | */ |
| 307 | int transport_get_remote_bundle_uri(struct transport *transport); |
| 308 | |
| 309 | /* |
| 310 | * Fetch the hash algorithm used by a remote. |
| 311 | * |
| 312 | * This can only be called after fetching the remote refs. |
| 313 | */ |
| 314 | const struct git_hash_algo *transport_get_hash_algo(struct transport *transport); |
| 315 | int transport_fetch_refs(struct transport *transport, struct ref *refs); |
| 316 | |
| 317 | /* |
| 318 | * Fetch the object info from remote |
| 319 | */ |
| 320 | int transport_fetch_object_info(struct transport *transport); |
| 321 | |
| 322 | /* |
| 323 | * If this flag is set, unlocking will avoid to call non-async-signal-safe |
| 324 | * functions. This will necessarily leave behind some data structures which |
| 325 | * cannot be cleaned up. |
| 326 | */ |
| 327 | #define TRANSPORT_UNLOCK_PACK_IN_SIGNAL_HANDLER (1 << 0) |
| 328 | |
| 329 | /* |
| 330 | * Unlock all packfiles locked by the transport. |
| 331 | */ |
| 332 | void transport_unlock_pack(struct transport *transport, unsigned int flags); |
| 333 | |
| 334 | int transport_disconnect(struct transport *transport); |
| 335 | char *transport_anonymize_url(const char *url); |
| 336 | void transport_take_over(struct transport *transport, |
| 337 | struct child_process *child); |
| 338 | |
| 339 | int transport_connect(struct transport *transport, |
| 340 | enum git_connect_service service, |
| 341 | const char *exec, int fd[2]); |
| 342 | |
| 343 | /* Transport methods defined outside transport.c */ |
| 344 | int transport_helper_init(struct transport *transport, const char *name); |
| 345 | int bidirectional_transfer_loop(int input, int output); |
| 346 | |
| 347 | /* common methods used by transport.c and builtin/send-pack.c */ |
| 348 | void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int verbose); |
| 349 | |
| 350 | int transport_refs_pushed(struct ref *ref); |
| 351 | |
| 352 | void transport_print_push_status(const char *dest, struct ref *refs, |
| 353 | int verbose, int porcelain, unsigned int *reject_reasons); |
| 354 | |
| 355 | /* common method used by transport-helper.c and send-pack.c */ |
| 356 | void reject_atomic_push(struct ref *refs, int mirror_mode); |
| 357 | |
| 358 | /* common method to parse push-option or server-option from config */ |
| 359 | int parse_transport_option(const char *var, const char *value, |
| 360 | struct string_list *transport_options); |
| 361 | |
| 362 | #endif |