transport.hon commit fetch, upload-pack: --deepen=N extends shallow boundary by N commits (cccf74e)
   1#ifndef TRANSPORT_H
   2#define TRANSPORT_H
   3
   4#include "cache.h"
   5#include "run-command.h"
   6#include "remote.h"
   7
   8struct string_list;
   9
  10struct git_transport_options {
  11        unsigned thin : 1;
  12        unsigned keep : 1;
  13        unsigned followtags : 1;
  14        unsigned check_self_contained_and_connected : 1;
  15        unsigned self_contained_and_connected : 1;
  16        unsigned update_shallow : 1;
  17        unsigned deepen_relative : 1;
  18        int depth;
  19        const char *deepen_since;
  20        const struct string_list *deepen_not;
  21        const char *uploadpack;
  22        const char *receivepack;
  23        struct push_cas_option *cas;
  24};
  25
  26struct transport {
  27        struct remote *remote;
  28        const char *url;
  29        void *data;
  30        const struct ref *remote_refs;
  31
  32        /**
  33         * Indicates whether we already called get_refs_list(); set by
  34         * transport.c::transport_get_remote_refs().
  35         */
  36        unsigned got_remote_refs : 1;
  37
  38        /*
  39         * Transports that call take-over destroys the data specific to
  40         * the transport type while doing so, and cannot be reused.
  41         */
  42        unsigned cannot_reuse : 1;
  43
  44        /*
  45         * A hint from caller that it will be performing a clone, not
  46         * normal fetch. IOW the repository is guaranteed empty.
  47         */
  48        unsigned cloning : 1;
  49
  50        /**
  51         * Returns 0 if successful, positive if the option is not
  52         * recognized or is inapplicable, and negative if the option
  53         * is applicable but the value is invalid.
  54         **/
  55        int (*set_option)(struct transport *connection, const char *name,
  56                          const char *value);
  57
  58        /**
  59         * Returns a list of the remote side's refs. In order to allow
  60         * the transport to try to share connections, for_push is a
  61         * hint as to whether the ultimate operation is a push or a fetch.
  62         *
  63         * If the transport is able to determine the remote hash for
  64         * the ref without a huge amount of effort, it should store it
  65         * in the ref's old_sha1 field; otherwise it should be all 0.
  66         **/
  67        struct ref *(*get_refs_list)(struct transport *transport, int for_push);
  68
  69        /**
  70         * Fetch the objects for the given refs. Note that this gets
  71         * an array, and should ignore the list structure.
  72         *
  73         * If the transport did not get hashes for refs in
  74         * get_refs_list(), it should set the old_sha1 fields in the
  75         * provided refs now.
  76         **/
  77        int (*fetch)(struct transport *transport, int refs_nr, struct ref **refs);
  78
  79        /**
  80         * Push the objects and refs. Send the necessary objects, and
  81         * then, for any refs where peer_ref is set and
  82         * peer_ref->new_oid is different from old_oid, tell the
  83         * remote side to update each ref in the list from old_oid to
  84         * peer_ref->new_oid.
  85         *
  86         * Where possible, set the status for each ref appropriately.
  87         *
  88         * The transport must modify new_sha1 in the ref to the new
  89         * value if the remote accepted the change. Note that this
  90         * could be a different value from peer_ref->new_oid if the
  91         * process involved generating new commits.
  92         **/
  93        int (*push_refs)(struct transport *transport, struct ref *refs, int flags);
  94        int (*push)(struct transport *connection, int refspec_nr, const char **refspec, int flags);
  95        int (*connect)(struct transport *connection, const char *name,
  96                       const char *executable, int fd[2]);
  97
  98        /** get_refs_list(), fetch(), and push_refs() can keep
  99         * resources (such as a connection) reserved for further
 100         * use. disconnect() releases these resources.
 101         **/
 102        int (*disconnect)(struct transport *connection);
 103        char *pack_lockfile;
 104        signed verbose : 3;
 105        /**
 106         * Transports should not set this directly, and should use this
 107         * value without having to check isatty(2), -q/--quiet
 108         * (transport->verbose < 0), etc. - checking has already been done
 109         * in transport_set_verbosity().
 110         **/
 111        unsigned progress : 1;
 112        /*
 113         * If transport is at least potentially smart, this points to
 114         * git_transport_options structure to use in case transport
 115         * actually turns out to be smart.
 116         */
 117        struct git_transport_options *smart_options;
 118};
 119
 120#define TRANSPORT_PUSH_ALL 1
 121#define TRANSPORT_PUSH_FORCE 2
 122#define TRANSPORT_PUSH_DRY_RUN 4
 123#define TRANSPORT_PUSH_MIRROR 8
 124#define TRANSPORT_PUSH_PORCELAIN 16
 125#define TRANSPORT_PUSH_SET_UPSTREAM 32
 126#define TRANSPORT_RECURSE_SUBMODULES_CHECK 64
 127#define TRANSPORT_PUSH_PRUNE 128
 128#define TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND 256
 129#define TRANSPORT_PUSH_NO_HOOK 512
 130#define TRANSPORT_PUSH_FOLLOW_TAGS 1024
 131#define TRANSPORT_PUSH_CERT_ALWAYS 2048
 132#define TRANSPORT_PUSH_CERT_IF_ASKED 4096
 133#define TRANSPORT_PUSH_ATOMIC 8192
 134
 135#define TRANSPORT_SUMMARY_WIDTH (2 * DEFAULT_ABBREV + 3)
 136#define TRANSPORT_SUMMARY(x) (int)(TRANSPORT_SUMMARY_WIDTH + strlen(x) - gettext_width(x)), (x)
 137
 138/* Returns a transport suitable for the url */
 139struct transport *transport_get(struct remote *, const char *);
 140
 141/*
 142 * Check whether a transport is allowed by the environment. Type should
 143 * generally be the URL scheme, as described in Documentation/git.txt
 144 */
 145int is_transport_allowed(const char *type);
 146
 147/*
 148 * Check whether a transport is allowed by the environment,
 149 * and die otherwise.
 150 */
 151void transport_check_allowed(const char *type);
 152
 153/*
 154 * Returns true if the user has attempted to turn on protocol
 155 * restrictions at all.
 156 */
 157int transport_restrict_protocols(void);
 158
 159/* Transport options which apply to git:// and scp-style URLs */
 160
 161/* The program to use on the remote side to send a pack */
 162#define TRANS_OPT_UPLOADPACK "uploadpack"
 163
 164/* The program to use on the remote side to receive a pack */
 165#define TRANS_OPT_RECEIVEPACK "receivepack"
 166
 167/* Transfer the data as a thin pack if not null */
 168#define TRANS_OPT_THIN "thin"
 169
 170/* Check the current value of the remote ref */
 171#define TRANS_OPT_CAS "cas"
 172
 173/* Keep the pack that was transferred if not null */
 174#define TRANS_OPT_KEEP "keep"
 175
 176/* Limit the depth of the fetch if not null */
 177#define TRANS_OPT_DEPTH "depth"
 178
 179/* Limit the depth of the fetch based on time if not null */
 180#define TRANS_OPT_DEEPEN_SINCE "deepen-since"
 181
 182/* Limit the depth of the fetch based on revs if not null */
 183#define TRANS_OPT_DEEPEN_NOT "deepen-not"
 184
 185/* Limit the deepen of the fetch if not null */
 186#define TRANS_OPT_DEEPEN_RELATIVE "deepen-relative"
 187
 188/* Aggressively fetch annotated tags if possible */
 189#define TRANS_OPT_FOLLOWTAGS "followtags"
 190
 191/* Accept refs that may update .git/shallow without --depth */
 192#define TRANS_OPT_UPDATE_SHALLOW "updateshallow"
 193
 194/* Send push certificates */
 195#define TRANS_OPT_PUSH_CERT "pushcert"
 196
 197/**
 198 * Returns 0 if the option was used, non-zero otherwise. Prints a
 199 * message to stderr if the option is not used.
 200 **/
 201int transport_set_option(struct transport *transport, const char *name,
 202                         const char *value);
 203void transport_set_verbosity(struct transport *transport, int verbosity,
 204        int force_progress);
 205
 206#define REJECT_NON_FF_HEAD     0x01
 207#define REJECT_NON_FF_OTHER    0x02
 208#define REJECT_ALREADY_EXISTS  0x04
 209#define REJECT_FETCH_FIRST     0x08
 210#define REJECT_NEEDS_FORCE     0x10
 211
 212int transport_push(struct transport *connection,
 213                   int refspec_nr, const char **refspec, int flags,
 214                   unsigned int * reject_reasons);
 215
 216const struct ref *transport_get_remote_refs(struct transport *transport);
 217
 218int transport_fetch_refs(struct transport *transport, struct ref *refs);
 219void transport_unlock_pack(struct transport *transport);
 220int transport_disconnect(struct transport *transport);
 221char *transport_anonymize_url(const char *url);
 222void transport_take_over(struct transport *transport,
 223                         struct child_process *child);
 224
 225int transport_connect(struct transport *transport, const char *name,
 226                      const char *exec, int fd[2]);
 227
 228/* Transport methods defined outside transport.c */
 229int transport_helper_init(struct transport *transport, const char *name);
 230int bidirectional_transfer_loop(int input, int output);
 231
 232/* common methods used by transport.c and builtin/send-pack.c */
 233void transport_verify_remote_names(int nr_heads, const char **heads);
 234
 235void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int verbose);
 236
 237int transport_refs_pushed(struct ref *ref);
 238
 239void transport_print_push_status(const char *dest, struct ref *refs,
 240                  int verbose, int porcelain, unsigned int *reject_reasons);
 241
 242typedef void alternate_ref_fn(const struct ref *, void *);
 243extern void for_each_alternate_ref(alternate_ref_fn, void *);
 244#endif