smart.h 4.36 KB
Newer Older
1
/*
Edward Thomson committed
2
 * Copyright (C) the libgit2 contributors. All rights reserved.
3 4 5 6 7 8 9 10
 *
 * This file is part of libgit2, distributed under the GNU GPL v2 with
 * a Linking Exception. For full terms see the included COPYING file.
 */
#include "git2.h"
#include "vector.h"
#include "netops.h"
#include "buffer.h"
11
#include "push.h"
12
#include "git2/sys/transport.h"
13 14 15 16 17 18 19

#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"
20
#define GIT_CAP_MULTI_ACK_DETAILED "multi_ack_detailed"
21 22 23
#define GIT_CAP_SIDE_BAND "side-band"
#define GIT_CAP_SIDE_BAND_64K "side-band-64k"
#define GIT_CAP_INCLUDE_TAG "include-tag"
24 25
#define GIT_CAP_DELETE_REFS "delete-refs"
#define GIT_CAP_REPORT_STATUS "report-status"
26
#define GIT_CAP_THIN_PACK "thin-pack"
27
#define GIT_CAP_SYMREF "symref"
28 29 30 31 32 33 34 35 36 37 38 39 40

enum git_pkt_type {
	GIT_PKT_CMD,
	GIT_PKT_FLUSH,
	GIT_PKT_REF,
	GIT_PKT_HAVE,
	GIT_PKT_ACK,
	GIT_PKT_NAK,
	GIT_PKT_PACK,
	GIT_PKT_COMMENT,
	GIT_PKT_ERR,
	GIT_PKT_DATA,
	GIT_PKT_PROGRESS,
41 42 43
	GIT_PKT_OK,
	GIT_PKT_NG,
	GIT_PKT_UNPACK,
44 45
};

46
/* Used for multi_ack and mutli_ack_detailed */
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
enum git_ack_status {
	GIT_ACK_NONE,
	GIT_ACK_CONTINUE,
	GIT_ACK_COMMON,
	GIT_ACK_READY
};

/* This would be a flush pkt */
typedef struct {
	enum git_pkt_type type;
} git_pkt;

struct git_pkt_cmd {
	enum git_pkt_type type;
	char *cmd;
	char *path;
	char *host;
};

/* This is a pkt-line with some info in it */
typedef struct {
	enum git_pkt_type type;
	git_remote_head head;
	char *capabilities;
} git_pkt_ref;

/* Useful later */
typedef struct {
	enum git_pkt_type type;
	git_oid oid;
	enum git_ack_status status;
} git_pkt_ack;

typedef struct {
	enum git_pkt_type type;
	char comment[GIT_FLEX_ARRAY];
} git_pkt_comment;

typedef struct {
	enum git_pkt_type type;
	int len;
	char data[GIT_FLEX_ARRAY];
} git_pkt_data;

typedef git_pkt_data git_pkt_progress;

typedef struct {
	enum git_pkt_type type;
95
	int len;
96 97 98
	char error[GIT_FLEX_ARRAY];
} git_pkt_err;

99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
typedef struct {
	enum git_pkt_type type;
	char *ref;
} git_pkt_ok;

typedef struct {
	enum git_pkt_type type;
	char *ref;
	char *msg;
} git_pkt_ng;

typedef struct {
	enum git_pkt_type type;
	int unpack_ok;
} git_pkt_unpack;

115 116 117 118
typedef struct transport_smart_caps {
	int common:1,
		ofs_delta:1,
		multi_ack: 1,
119
		multi_ack_detailed: 1,
120 121
		side_band:1,
		side_band_64k:1,
122 123
		include_tag:1,
		delete_refs:1,
124 125
		report_status:1,
		thin_pack:1;
126 127
} transport_smart_caps;

128
typedef int (*packetsize_cb)(size_t received, void *payload);
129 130 131

typedef struct {
	git_transport parent;
132
	git_remote *owner;
133
	char *url;
134
	git_cred_acquire_cb cred_acquire_cb;
135
	void *cred_acquire_payload;
136 137 138 139
	int direction;
	int flags;
	git_transport_message_cb progress_cb;
	git_transport_message_cb error_cb;
140
	git_transport_certificate_check_cb certificate_check_cb;
141 142 143 144 145
	void *message_cb_payload;
	git_smart_subtransport *wrapped;
	git_smart_subtransport_stream *current_stream;
	transport_smart_caps caps;
	git_vector refs;
146
	git_vector heads;
147 148 149 150 151 152 153 154 155 156 157 158 159
	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);
160
int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vector *symrefs);
161
int git_smart__push(git_transport *transport, git_push *push);
162 163 164 165 166 167 168 169 170 171 172

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,
	git_transfer_progress *stats,
173
	git_transfer_progress_cb progress_cb,
174 175 176 177
	void *progress_payload);

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

180
int git_smart__update_heads(transport_smart *t, git_vector *symrefs);
181

182 183 184 185 186 187 188 189
/* smart_pkt.c */
int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t len);
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);