smart.h 4.55 KB
Newer Older
1
/*
Edward Thomson committed
2
 * Copyright (C) the libgit2 contributors. All rights reserved.
3 4 5 6
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */
7 8
#ifndef INCLUDE_transports_smart_h__
#define INCLUDE_transports_smart_h__
9 10 11

#include "common.h"

12 13 14 15
#include "git2.h"
#include "vector.h"
#include "netops.h"
#include "buffer.h"
16
#include "push.h"
17
#include "git2/sys/transport.h"
18 19 20 21 22 23 24

#define GIT_SIDE_BAND_DATA     1
#define GIT_SIDE_BAND_PROGRESS 2
#define GIT_SIDE_BAND_ERROR    3

#define GIT_CAP_OFS_DELTA "ofs-delta"
#define GIT_CAP_MULTI_ACK "multi_ack"
25
#define GIT_CAP_MULTI_ACK_DETAILED "multi_ack_detailed"
26 27 28
#define GIT_CAP_SIDE_BAND "side-band"
#define GIT_CAP_SIDE_BAND_64K "side-band-64k"
#define GIT_CAP_INCLUDE_TAG "include-tag"
29 30
#define GIT_CAP_DELETE_REFS "delete-refs"
#define GIT_CAP_REPORT_STATUS "report-status"
31
#define GIT_CAP_THIN_PACK "thin-pack"
32
#define GIT_CAP_SYMREF "symref"
33

34 35
extern bool git_smart__ofs_delta_enabled;

36
typedef enum {
37 38 39 40 41 42 43 44 45 46
	GIT_PKT_CMD,
	GIT_PKT_FLUSH,
	GIT_PKT_REF,
	GIT_PKT_HAVE,
	GIT_PKT_ACK,
	GIT_PKT_NAK,
	GIT_PKT_COMMENT,
	GIT_PKT_ERR,
	GIT_PKT_DATA,
	GIT_PKT_PROGRESS,
47 48 49
	GIT_PKT_OK,
	GIT_PKT_NG,
	GIT_PKT_UNPACK,
50
} git_pkt_type;
51

Etienne Samson committed
52
/* Used for multi_ack and multi_ack_detailed */
53 54 55 56 57 58 59 60 61
enum git_ack_status {
	GIT_ACK_NONE,
	GIT_ACK_CONTINUE,
	GIT_ACK_COMMON,
	GIT_ACK_READY
};

/* This would be a flush pkt */
typedef struct {
62
	git_pkt_type type;
63 64 65
} git_pkt;

struct git_pkt_cmd {
66
	git_pkt_type type;
67 68 69 70 71 72 73
	char *cmd;
	char *path;
	char *host;
};

/* This is a pkt-line with some info in it */
typedef struct {
74
	git_pkt_type type;
75 76 77 78 79 80
	git_remote_head head;
	char *capabilities;
} git_pkt_ref;

/* Useful later */
typedef struct {
81
	git_pkt_type type;
82 83 84 85 86
	git_oid oid;
	enum git_ack_status status;
} git_pkt_ack;

typedef struct {
87
	git_pkt_type type;
88 89 90 91
	char comment[GIT_FLEX_ARRAY];
} git_pkt_comment;

typedef struct {
92
	git_pkt_type type;
93
	size_t len;
94 95 96 97 98 99
	char data[GIT_FLEX_ARRAY];
} git_pkt_data;

typedef git_pkt_data git_pkt_progress;

typedef struct {
100
	git_pkt_type type;
101
	size_t len;
102 103 104
	char error[GIT_FLEX_ARRAY];
} git_pkt_err;

105
typedef struct {
106
	git_pkt_type type;
107 108 109 110
	char *ref;
} git_pkt_ok;

typedef struct {
111
	git_pkt_type type;
112 113 114 115 116
	char *ref;
	char *msg;
} git_pkt_ng;

typedef struct {
117
	git_pkt_type type;
118 119 120
	int unpack_ok;
} git_pkt_unpack;

121 122 123 124
typedef struct transport_smart_caps {
	int common:1,
		ofs_delta:1,
		multi_ack: 1,
125
		multi_ack_detailed: 1,
126 127
		side_band:1,
		side_band_64k:1,
128 129
		include_tag:1,
		delete_refs:1,
130 131
		report_status:1,
		thin_pack:1;
132 133
} transport_smart_caps;

134
typedef int (*packetsize_cb)(size_t received, void *payload);
135 136 137

typedef struct {
	git_transport parent;
138
	git_remote *owner;
139
	char *url;
140
	git_credential_acquire_cb cred_acquire_cb;
141
	void *cred_acquire_payload;
142
	git_proxy_options proxy;
143 144 145 146
	int direction;
	int flags;
	git_transport_message_cb progress_cb;
	git_transport_message_cb error_cb;
147
	git_transport_certificate_check_cb certificate_check_cb;
148
	void *message_cb_payload;
149
	git_strarray custom_headers;
150 151 152 153
	git_smart_subtransport *wrapped;
	git_smart_subtransport_stream *current_stream;
	transport_smart_caps caps;
	git_vector refs;
154
	git_vector heads;
155 156 157 158 159 160 161 162 163 164 165 166 167
	git_vector common;
	git_atomic cancelled;
	packetsize_cb packetsize_cb;
	void *packetsize_payload;
	unsigned rpc : 1,
		have_refs : 1,
		connected : 1;
	gitno_buffer buffer;
	char buffer_data[65536];
} transport_smart;

/* smart_protocol.c */
int git_smart__store_refs(transport_smart *t, int flushes);
168
int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vector *symrefs);
169
int git_smart__push(git_transport *transport, git_push *push, const git_remote_callbacks *cbs);
170 171 172 173 174 175 176 177 178 179

int git_smart__negotiate_fetch(
	git_transport *transport,
	git_repository *repo,
	const git_remote_head * const *refs,
	size_t count);

int git_smart__download_pack(
	git_transport *transport,
	git_repository *repo,
180 181
	git_indexer_progress *stats,
	git_indexer_progress_cb progress_cb,
182 183 184 185
	void *progress_payload);

/* smart.c */
int git_smart__negotiation_step(git_transport *transport, void *data, size_t len);
186
int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream **out);
187

188
int git_smart__update_heads(transport_smart *t, git_vector *symrefs);
189

190
/* smart_pkt.c */
191
int git_pkt_parse_line(git_pkt **head, const char **endptr, const char *line, size_t linelen);
192 193 194 195 196 197
int git_pkt_buffer_flush(git_buf *buf);
int git_pkt_send_flush(GIT_SOCKET s);
int git_pkt_buffer_done(git_buf *buf);
int git_pkt_buffer_wants(const git_remote_head * const *refs, size_t count, transport_smart_caps *caps, git_buf *buf);
int git_pkt_buffer_have(git_oid *oid, git_buf *buf);
void git_pkt_free(git_pkt *pkt);
198 199

#endif