]> git.proxmox.com Git - libgit2.git/blob - src/transports/smart.h
New upstream version 1.4.3+dfsg.1
[libgit2.git] / src / transports / smart.h
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
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 */
7 #ifndef INCLUDE_transports_smart_h__
8 #define INCLUDE_transports_smart_h__
9
10 #include "common.h"
11
12 #include "git2.h"
13 #include "vector.h"
14 #include "netops.h"
15 #include "push.h"
16 #include "str.h"
17 #include "git2/sys/transport.h"
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"
25 #define GIT_CAP_MULTI_ACK_DETAILED "multi_ack_detailed"
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"
29 #define GIT_CAP_DELETE_REFS "delete-refs"
30 #define GIT_CAP_REPORT_STATUS "report-status"
31 #define GIT_CAP_THIN_PACK "thin-pack"
32 #define GIT_CAP_SYMREF "symref"
33 #define GIT_CAP_WANT_TIP_SHA1 "allow-tip-sha1-in-want"
34 #define GIT_CAP_WANT_REACHABLE_SHA1 "allow-reachable-sha1-in-want"
35
36 extern bool git_smart__ofs_delta_enabled;
37
38 typedef enum {
39 GIT_PKT_CMD,
40 GIT_PKT_FLUSH,
41 GIT_PKT_REF,
42 GIT_PKT_HAVE,
43 GIT_PKT_ACK,
44 GIT_PKT_NAK,
45 GIT_PKT_COMMENT,
46 GIT_PKT_ERR,
47 GIT_PKT_DATA,
48 GIT_PKT_PROGRESS,
49 GIT_PKT_OK,
50 GIT_PKT_NG,
51 GIT_PKT_UNPACK
52 } git_pkt_type;
53
54 /* Used for multi_ack and multi_ack_detailed */
55 enum 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 */
63 typedef struct {
64 git_pkt_type type;
65 } git_pkt;
66
67 struct git_pkt_cmd {
68 git_pkt_type type;
69 char *cmd;
70 char *path;
71 char *host;
72 };
73
74 /* This is a pkt-line with some info in it */
75 typedef struct {
76 git_pkt_type type;
77 git_remote_head head;
78 char *capabilities;
79 } git_pkt_ref;
80
81 /* Useful later */
82 typedef struct {
83 git_pkt_type type;
84 git_oid oid;
85 enum git_ack_status status;
86 } git_pkt_ack;
87
88 typedef struct {
89 git_pkt_type type;
90 char comment[GIT_FLEX_ARRAY];
91 } git_pkt_comment;
92
93 typedef struct {
94 git_pkt_type type;
95 size_t len;
96 char data[GIT_FLEX_ARRAY];
97 } git_pkt_data;
98
99 typedef git_pkt_data git_pkt_progress;
100
101 typedef struct {
102 git_pkt_type type;
103 size_t len;
104 char error[GIT_FLEX_ARRAY];
105 } git_pkt_err;
106
107 typedef struct {
108 git_pkt_type type;
109 char *ref;
110 } git_pkt_ok;
111
112 typedef struct {
113 git_pkt_type type;
114 char *ref;
115 char *msg;
116 } git_pkt_ng;
117
118 typedef struct {
119 git_pkt_type type;
120 int unpack_ok;
121 } git_pkt_unpack;
122
123 typedef struct transport_smart_caps {
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;
136 } transport_smart_caps;
137
138 typedef int (*packetsize_cb)(size_t received, void *payload);
139
140 typedef struct {
141 git_transport parent;
142 git_remote *owner;
143 char *url;
144 git_remote_connect_options connect_opts;
145 int direction;
146 git_smart_subtransport *wrapped;
147 git_smart_subtransport_stream *current_stream;
148 transport_smart_caps caps;
149 git_vector refs;
150 git_vector heads;
151 git_vector common;
152 git_atomic32 cancelled;
153 packetsize_cb packetsize_cb;
154 void *packetsize_payload;
155 unsigned rpc : 1,
156 have_refs : 1,
157 connected : 1;
158 gitno_buffer buffer;
159 char buffer_data[65536];
160 } transport_smart;
161
162 /* smart_protocol.c */
163 int git_smart__store_refs(transport_smart *t, int flushes);
164 int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps, git_vector *symrefs);
165 int git_smart__push(git_transport *transport, git_push *push);
166
167 int git_smart__negotiate_fetch(
168 git_transport *transport,
169 git_repository *repo,
170 const git_remote_head * const *refs,
171 size_t count);
172
173 int git_smart__download_pack(
174 git_transport *transport,
175 git_repository *repo,
176 git_indexer_progress *stats);
177
178 /* smart.c */
179 int git_smart__negotiation_step(git_transport *transport, void *data, size_t len);
180 int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream **out);
181
182 int git_smart__update_heads(transport_smart *t, git_vector *symrefs);
183
184 /* smart_pkt.c */
185 int git_pkt_parse_line(git_pkt **head, const char **endptr, const char *line, size_t linelen);
186 int git_pkt_buffer_flush(git_str *buf);
187 int git_pkt_send_flush(GIT_SOCKET s);
188 int git_pkt_buffer_done(git_str *buf);
189 int git_pkt_buffer_wants(const git_remote_head * const *refs, size_t count, transport_smart_caps *caps, git_str *buf);
190 int git_pkt_buffer_have(git_oid *oid, git_str *buf);
191 void git_pkt_free(git_pkt *pkt);
192
193 #endif