]> git.proxmox.com Git - libgit2.git/blame - src/transports/smart.h
New upstream version 1.4.3+dfsg.1
[libgit2.git] / src / transports / smart.h
CommitLineData
41fb1ca0 1/*
359fc2d2 2 * Copyright (C) the libgit2 contributors. All rights reserved.
41fb1ca0
PK
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
eae0bfdc
PP
7#ifndef INCLUDE_transports_smart_h__
8#define INCLUDE_transports_smart_h__
9
10#include "common.h"
11
41fb1ca0
PK
12#include "git2.h"
13#include "vector.h"
14#include "netops.h"
613d5eb9 15#include "push.h"
e579e0f7 16#include "str.h"
c180c065 17#include "git2/sys/transport.h"
41fb1ca0
PK
18
19#define GIT_SIDE_BAND_DATA 1
20#define GIT_SIDE_BAND_PROGRESS 2
21#define GIT_SIDE_BAND_ERROR 3
22
23#define GIT_CAP_OFS_DELTA "ofs-delta"
24#define GIT_CAP_MULTI_ACK "multi_ack"
2f8c481c 25#define GIT_CAP_MULTI_ACK_DETAILED "multi_ack_detailed"
41fb1ca0
PK
26#define GIT_CAP_SIDE_BAND "side-band"
27#define GIT_CAP_SIDE_BAND_64K "side-band-64k"
28#define GIT_CAP_INCLUDE_TAG "include-tag"
613d5eb9
PK
29#define GIT_CAP_DELETE_REFS "delete-refs"
30#define GIT_CAP_REPORT_STATUS "report-status"
b4342b11 31#define GIT_CAP_THIN_PACK "thin-pack"
8156835d 32#define GIT_CAP_SYMREF "symref"
e579e0f7
MB
33#define GIT_CAP_WANT_TIP_SHA1 "allow-tip-sha1-in-want"
34#define GIT_CAP_WANT_REACHABLE_SHA1 "allow-reachable-sha1-in-want"
41fb1ca0 35
61acc9fa
GS
36extern bool git_smart__ofs_delta_enabled;
37
6c7cee42 38typedef enum {
41fb1ca0
PK
39 GIT_PKT_CMD,
40 GIT_PKT_FLUSH,
41 GIT_PKT_REF,
42 GIT_PKT_HAVE,
43 GIT_PKT_ACK,
44 GIT_PKT_NAK,
41fb1ca0
PK
45 GIT_PKT_COMMENT,
46 GIT_PKT_ERR,
47 GIT_PKT_DATA,
48 GIT_PKT_PROGRESS,
613d5eb9
PK
49 GIT_PKT_OK,
50 GIT_PKT_NG,
e579e0f7 51 GIT_PKT_UNPACK
6c7cee42 52} git_pkt_type;
41fb1ca0 53
ac3d33df 54/* Used for multi_ack and multi_ack_detailed */
41fb1ca0
PK
55enum git_ack_status {
56 GIT_ACK_NONE,
57 GIT_ACK_CONTINUE,
58 GIT_ACK_COMMON,
59 GIT_ACK_READY
60};
61
62/* This would be a flush pkt */
63typedef struct {
6c7cee42 64 git_pkt_type type;
41fb1ca0
PK
65} git_pkt;
66
67struct git_pkt_cmd {
6c7cee42 68 git_pkt_type type;
41fb1ca0
PK
69 char *cmd;
70 char *path;
71 char *host;
72};
73
74/* This is a pkt-line with some info in it */
75typedef struct {
6c7cee42 76 git_pkt_type type;
41fb1ca0
PK
77 git_remote_head head;
78 char *capabilities;
79} git_pkt_ref;
80
81/* Useful later */
82typedef struct {
6c7cee42 83 git_pkt_type type;
41fb1ca0
PK
84 git_oid oid;
85 enum git_ack_status status;
86} git_pkt_ack;
87
88typedef struct {
6c7cee42 89 git_pkt_type type;
41fb1ca0
PK
90 char comment[GIT_FLEX_ARRAY];
91} git_pkt_comment;
92
93typedef struct {
6c7cee42
RD
94 git_pkt_type type;
95 size_t len;
41fb1ca0
PK
96 char data[GIT_FLEX_ARRAY];
97} git_pkt_data;
98
99typedef git_pkt_data git_pkt_progress;
100
101typedef struct {
6c7cee42
RD
102 git_pkt_type type;
103 size_t len;
41fb1ca0
PK
104 char error[GIT_FLEX_ARRAY];
105} git_pkt_err;
106
613d5eb9 107typedef struct {
6c7cee42 108 git_pkt_type type;
613d5eb9
PK
109 char *ref;
110} git_pkt_ok;
111
112typedef struct {
6c7cee42 113 git_pkt_type type;
613d5eb9
PK
114 char *ref;
115 char *msg;
116} git_pkt_ng;
117
118typedef struct {
6c7cee42 119 git_pkt_type type;
613d5eb9
PK
120 int unpack_ok;
121} git_pkt_unpack;
122
41fb1ca0 123typedef struct transport_smart_caps {
e579e0f7
MB
124 unsigned int common:1,
125 ofs_delta:1,
126 multi_ack:1,
127 multi_ack_detailed:1,
128 side_band:1,
129 side_band_64k:1,
130 include_tag:1,
131 delete_refs:1,
132 report_status:1,
133 thin_pack:1,
134 want_tip_sha1:1,
135 want_reachable_sha1:1;
41fb1ca0
PK
136} transport_smart_caps;
137
5b188225 138typedef int (*packetsize_cb)(size_t received, void *payload);
41fb1ca0
PK
139
140typedef struct {
141 git_transport parent;
613d5eb9 142 git_remote *owner;
41fb1ca0 143 char *url;
e579e0f7 144 git_remote_connect_options connect_opts;
41fb1ca0 145 int direction;
41fb1ca0
PK
146 git_smart_subtransport *wrapped;
147 git_smart_subtransport_stream *current_stream;
148 transport_smart_caps caps;
149 git_vector refs;
359dce72 150 git_vector heads;
41fb1ca0 151 git_vector common;
c25aa7cd 152 git_atomic32 cancelled;
41fb1ca0
PK
153 packetsize_cb packetsize_cb;
154 void *packetsize_payload;
155 unsigned rpc : 1,
e579e0f7
MB
156 have_refs : 1,
157 connected : 1;
41fb1ca0
PK
158 gitno_buffer buffer;
159 char buffer_data[65536];
160} transport_smart;
161
162/* smart_protocol.c */
163int git_smart__store_refs(transport_smart *t, int flushes);
8156835d 164int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vector *symrefs);
e579e0f7 165int git_smart__push(git_transport *transport, git_push *push);
41fb1ca0
PK
166
167int git_smart__negotiate_fetch(
168 git_transport *transport,
169 git_repository *repo,
170 const git_remote_head * const *refs,
171 size_t count);
172
173int git_smart__download_pack(
174 git_transport *transport,
175 git_repository *repo,
e579e0f7 176 git_indexer_progress *stats);
41fb1ca0
PK
177
178/* smart.c */
179int git_smart__negotiation_step(git_transport *transport, void *data, size_t len);
613d5eb9 180int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream **out);
41fb1ca0 181
8156835d 182int git_smart__update_heads(transport_smart *t, git_vector *symrefs);
a6192d7c 183
41fb1ca0 184/* smart_pkt.c */
6c7cee42 185int git_pkt_parse_line(git_pkt **head, const char **endptr, const char *line, size_t linelen);
e579e0f7 186int git_pkt_buffer_flush(git_str *buf);
41fb1ca0 187int git_pkt_send_flush(GIT_SOCKET s);
e579e0f7
MB
188int git_pkt_buffer_done(git_str *buf);
189int git_pkt_buffer_wants(const git_remote_head * const *refs, size_t count, transport_smart_caps *caps, git_str *buf);
190int git_pkt_buffer_have(git_oid *oid, git_str *buf);
41fb1ca0 191void git_pkt_free(git_pkt *pkt);
eae0bfdc
PP
192
193#endif