Fossil SCM

fossil-scm / www / sync.wiki
Source Blame History 1120 lines
169a10d… drh 1 <title>The Fossil Sync Protocol</title>
169a10d… drh 2
1fd407f… wyoung 3 This document describes the wire protocol used to synchronize
1fd407f… wyoung 4 content between two Fossil repositories.
adc0b3b… drh 5
adc0b3b… drh 6 <h2>1.0 Overview</h2>
adc0b3b… drh 7
1fd407f… wyoung 8 The global state of a fossil repository consists of an unordered
e57613d… drh 9 [./fileformat.wiki|collection of artifacts]. Each artifact is
e57613d… drh 10 identified by a cryptographic
796db89… drh 11 hash of its content, expressed as a lower-case hexadecimal string.
3dcf69a… drh 12 Synchronization is the process of sharing artifacts between
2b3569d… drh 13 repositories so that all repositories have copies of all artifacts. Because
adc0b3b… drh 14 artifacts are unordered, the order in which artifacts are received
2b3569d… drh 15 is unimportant. It is assumed that the hash names
796db89… drh 16 of artifacts are unique - that every artifact has a different hash.
fcfaae3… jan.nijtmans 17 To a first approximation, synchronization proceeds by sharing lists
3cb8290… drh 18 of hashes for available artifacts, then sharing the content of artifacts
b098c93… jan.nijtmans 19 whose names are missing from one side or the other of the connection.
796db89… drh 20 In practice, a repository might contain millions of artifacts. The list of
796db89… drh 21 hash names for this many artifacts can be large. So optimizations are
796db89… drh 22 employed that usually reduce the number of hashes that need to be
e57613d… drh 23 shared to a few dozen.
796db89… drh 24
1fd407f… wyoung 25 Each repository also has local state. The local state determines
efb759a… drh 26 the web-page formatting preferences, authorized users, ticket formats,
efb759a… drh 27 and similar information that varies from one repository to another.
2b3569d… drh 28 The local state is not usually transferred during a sync. Except,
c64f28d… drh 29 some local state is transferred during a [/help/clone|clone]
39d6fc7… drh 30 in order to initialize the local state of the new repository. Also,
39d6fc7… drh 31 an administrator can sync local state using
c64f28d… drh 32 the [/help/configuration|config push] and
c64f28d… drh 33 [/help/configuration|config pull]
39d6fc7… drh 34 commands.
39d6fc7… drh 35
93cee1f… wyoung 36 <h3 id="crdt">1.1 Conflict-Free Replicated Datatypes</h3>
93cee1f… wyoung 37
1fd407f… wyoung 38 The "bag of artifacts" data model used by Fossil is apparently an
d1ac2f9… stephan 39 implementation of a particular
d1ac2f9… stephan 40 [https://en.wikipedia.org/wiki/Conflict-free_replicated_data_type|Conflict-Free
d1ac2f9… stephan 41 Replicated Datatype (CRDT)] called a "G-Set" or "Grow-only Set". The
d1ac2f9… stephan 42 academic literature on CRDTs only began to appear in about 2011, and
d1ac2f9… stephan 43 Fossil predates that research by at least 4 years. But it is nice to
d1ac2f9… stephan 44 know that theorists have now proven that the underlying data model of
d1ac2f9… stephan 45 Fossil can provide strongly-consistent replicas using only
d1ac2f9… stephan 46 peer-to-peer communication and without any kind of central
1fd407f… wyoung 47 authority.
d1ac2f9… stephan 48
1fd407f… wyoung 49 If you are already familiar with CRDTs and were wondering if Fossil
1fd407f… wyoung 50 used them, the answer is "yes". We just don't call them by that name.
d1ac2f9… stephan 51
d1ac2f9… stephan 52
5ca63ac… wyoung 53 <h2 id="transport">2.0 Transport</h2>
d1ac2f9… stephan 54
1fd407f… wyoung 55 All communication between client and server is via HTTP requests.
f94f7e5… drh 56 The server is listening for incoming HTTP requests. The client
f94f7e5… drh 57 issues one or more HTTP requests and receives replies for each
1fd407f… wyoung 58 request.
3dcf69a… drh 59
1fd407f… wyoung 60 The server might be running as an independent server
c64f28d… drh 61 using the [/help/server|"fossil server" command], or it
e57613d… drh 62 might be launched from inetd or xinetd using the
c64f28d… drh 63 [/help/http|"fossil http" command]. Or the server might
e57613d… drh 64 be [./server/any/cgi.md|launched from CGI] or from
e57613d… drh 65 [./server/any/scgi.md|SCGI].
f146e21… drh 66 (See "[./server/|How To Configure A Fossil Server]" for details.)
3dcf69a… drh 67 The specifics of how the server listens
3dcf69a… drh 68 for incoming HTTP requests is immaterial to this protocol.
f47b705… jan.nijtmans 69 The important point is that the server is listening for requests and
1fd407f… wyoung 70 the client is the issuer of the requests.
3dcf69a… drh 71
c64f28d… drh 72 A single [/help/push|push],
c64f28d… drh 73 [/help/pull|pull], or [/help?cmd=sync|sync]
e57613d… drh 74 might involve multiple HTTP requests.
f94f7e5… drh 75 The client maintains state between all requests. But on the server
f94f7e5… drh 76 side, each request is independent. The server does not preserve
1fd407f… wyoung 77 any information about the client from one request to the next.
2b3569d… drh 78
1fd407f… wyoung 79 Note: Throughout this article, we use the terms "server" and "client"
2b3569d… drh 80 to represent the listener and initiator of the interaction, respectively.
2b3569d… drh 81 Nothing in this protocol requires that the server actually be a back-room
2b3569d… drh 82 processor housed in a datacenter, nor does the client need to be a desktop
2b3569d… drh 83 or handheld device. For the purposes of this article "client" simply means
2b3569d… drh 84 the repository that initiates the conversation and "server" is the repository
1fd407f… wyoung 85 that responds. Nothing more.
1fd407f… wyoung 86
5ca63ac… wyoung 87 <h4 id="https">2.0.1 HTTPS Transport</h4>
e57613d… drh 88
e57613d… drh 89 HTTPS differs from HTTP only in that the HTTPS protocol is
e57613d… drh 90 encrypted as it travels over the wire. The underlying protocol
e57613d… drh 91 is the same. This document describes only the underlying, unencrypted
e57613d… drh 92 messages that go client to server and back to client.
e57613d… drh 93 Whether or not those messages are encrypted does not come into play
e57613d… drh 94 in this document.
e57613d… drh 95
e57613d… drh 96 Fossil includes built-in
e57613d… drh 97 [./ssl-server.md|support for HTTPS encryption] in both client and server.
e57613d… drh 98
5ca63ac… wyoung 99 <h4 id="ssh">2.0.2 SSH Transport</h4>
e57613d… drh 100
a975ccb… wyoung 101 When doing a sync using an "<code>ssh:…</code>" URL, the same HTTP transport protocol
505d9d4… drh 102 is used. Fossil simply uses [https://en.wikipedia.org/wiki/Secure_Shell|ssh]
505d9d4… drh 103 to start an instance of the [/help?cmd=test-http|fossil test-http] command
505d9d4… drh 104 running on the remote machine. It then sends HTTP requests and gets back HTTP
505d9d4… drh 105 replies over the SSH connection, rather than sending and receiving over an
505d9d4… drh 106 internet socket. To see the specific "ssh" command that the Fossil client
505d9d4… drh 107 runs in order to set up a connection, add either of the the "--httptrace" or
505d9d4… drh 108 "--sshtrace" options to the "fossil sync" command line.
a975ccb… wyoung 109
a975ccb… wyoung 110 This method is dependent on the remote <var>PATH</var> set by the SSH
a975ccb… wyoung 111 daemon, which may not be the same as your interactive shell's
a975ccb… wyoung 112 <var>PATH</var> on that same server. It is common to find
a975ccb… wyoung 113 <var>$HOME/bin</var> in the latter but not the former, for instance,
a975ccb… wyoung 114 leading to failures to sync over <code>ssh:…</code> URLs when you
a975ccb… wyoung 115 install the <code>fossil</code> binary in a nonstandard location, as
a975ccb… wyoung 116 with
a975ccb… wyoung 117
a975ccb… wyoung 118 <verbatim>./configure --prefix=$HOME && make install</verbatim>
a975ccb… wyoung 119
a975ccb… wyoung 120 The simpler of the two solutions to this problem is to install Fossil
a975ccb… wyoung 121 where sshd expects to find it, but when that isn't an option, you can
a975ccb… wyoung 122 instead give a URL like this:
a975ccb… wyoung 123
69959fa… wyoung 124 <verbatim>fossil clone ssh://myserver.example.com/path/to/repo.fossil?fossil=/home/me/bin/fossil</verbatim>
a975ccb… wyoung 125
a975ccb… wyoung 126 That gives the local Fossil instance the absolute path to the binary on
a975ccb… wyoung 127 the remote machine for use when calling that Fossil instance through the
a975ccb… wyoung 128 SSH tunnel.
5ca63ac… wyoung 129
5ca63ac… wyoung 130 <h4 id="file">2.0.3 FILE Transport</h4>
1fd407f… wyoung 131
1fd407f… wyoung 132 When doing a sync using a "file:..." URL, the same HTTP protocol is
505d9d4… drh 133 still used. But instead of sending each HTTP request over a socket or
505d9d4… drh 134 via SSH, the HTTP request is written into a temporary file. The client
505d9d4… drh 135 then invokes the [/help?cmd=http|fossil http] command in a subprocess
505d9d4… drh 136 to process the request and and generate a reply. The client then reads
505d9d4… drh 137 the HTTP reply out of a temporary file on disk, and deletes the two
505d9d4… drh 138 temporary files. To see the specific "fossil http" command that is run
505d9d4… drh 139 in order to implement the "file:" transport, add the "--httptrace"
505d9d4… drh 140 option to the "fossil sync" command.
505d9d4… drh 141
5ca63ac… wyoung 142 <h3 id="srv-id">2.1 Server Identification</h3>
505d9d4… drh 143
1fd407f… wyoung 144 The server is identified by a URL argument that accompanies the
f94f7e5… drh 145 push, pull, or sync command on the client. (As a convenience to
f94f7e5… drh 146 users, the URL can be omitted on the client command and the same URL
f94f7e5… drh 147 from the most recent push, pull, or sync will be reused. This saves
f94f7e5… drh 148 typing in the common case where the client does multiple syncs to
1fd407f… wyoung 149 the same server.)
f94f7e5… drh 150
1fd407f… wyoung 151 The client modifies the URL by appending the method name "<b>/xfer</b>"
f94f7e5… drh 152 to the end. For example, if the URL specified on the client command
1fd407f… wyoung 153 line is
1fd407f… wyoung 154
ca5ecf2… stephan 155 <pre>https://fossil-scm.org/home</pre>
1fd407f… wyoung 156
1fd407f… wyoung 157 Then the URL that is really used to do the synchronization will
1fd407f… wyoung 158 be:
1fd407f… wyoung 159
ca5ecf2… stephan 160 <pre>https://fossil-scm.org/home/xfer</pre>
1fd407f… wyoung 161
5ca63ac… wyoung 162 <h3 id="req-format">2.2 HTTP Request Format</h3>
1fd407f… wyoung 163
1fd407f… wyoung 164 The client always sends a POST request to the server. The
1fd407f… wyoung 165 general format of the POST request is as follows:
1fd407f… wyoung 166
8a1ba49… wyoung 167 <pre>
ca5ecf2… stephan 168 POST /home/xfer HTTP/1.0
f94f7e5… drh 169 Host: fossil-scm.hwaci.com:80
f94f7e5… drh 170 Content-Type: application/x-fossil
f94f7e5… drh 171 Content-Length: 4216
8a1ba49… wyoung 172 </pre>
f94f7e5… drh 173
8a1ba49… wyoung 174 <i><pre>content...</pre></i>
f94f7e5… drh 175
1fd407f… wyoung 176 In the example above, the pathname given after the POST keyword
f94f7e5… drh 177 on the first line is a copy of the URL pathname. The Host: parameter
f94f7e5… drh 178 is also taken from the URL. The content type is always either
f94f7e5… drh 179 "application/x-fossil" or "application/x-fossil-debug". The "x-fossil"
f94f7e5… drh 180 content type is the default. The only difference is that "x-fossil"
f94f7e5… drh 181 content is compressed using zlib whereas "x-fossil-debug" is sent
1fd407f… wyoung 182 uncompressed.
f94f7e5… drh 183
1fd407f… wyoung 184 A typical reply from the server might look something like this:
f94f7e5… drh 185
8a1ba49… wyoung 186 <pre>
f94f7e5… drh 187 HTTP/1.0 200 OK
f94f7e5… drh 188 Date: Mon, 10 Sep 2007 12:21:01 GMT
f94f7e5… drh 189 Connection: close
f94f7e5… drh 190 Cache-control: private
f94f7e5… drh 191 Content-Type: application/x-fossil; charset=US-ASCII
f94f7e5… drh 192 Content-Length: 265
8a1ba49… wyoung 193 </pre>
1fd407f… wyoung 194
8a1ba49… wyoung 195 <i><pre>content...</pre></i>
1fd407f… wyoung 196
1fd407f… wyoung 197 The content type of the reply is always the same as the content type
1fd407f… wyoung 198 of the request.
1fd407f… wyoung 199
5ca63ac… wyoung 200 <h2 id="content">3.0 Fossil Synchronization Content</h2>
1fd407f… wyoung 201
1fd407f… wyoung 202 A synchronization request between a client and server consists of
f94f7e5… drh 203 one or more HTTP requests as described in the previous section. This
1fd407f… wyoung 204 section details the "x-fossil" content type.
a9819ba… andybradford 205
5ca63ac… wyoung 206 <h3 id="lines">3.1 Line-oriented Format</h3>
a9819ba… andybradford 207
1fd407f… wyoung 208 The x-fossil content type consists of zero or more "cards". Cards
a9819ba… andybradford 209 are separated by the newline character ("\n"). Leading and trailing
1fd407f… wyoung 210 whitespace on a card is ignored. Blank cards are ignored.
a9819ba… andybradford 211
1fd407f… wyoung 212 Each card is divided into zero or more space separated tokens.
f94f7e5… drh 213 The first token on each card is the operator. Subsequent tokens
f94f7e5… drh 214 are arguments. The set of operators understood by servers is slightly
f94f7e5… drh 215 different from the operators understood by clients, though the two
1fd407f… wyoung 216 are very similar.
1fd407f… wyoung 217
5ca63ac… wyoung 218 <h3 id="login">3.2 Login Cards</h3>
1fd407f… wyoung 219
1fd407f… wyoung 220 Every message from client to server begins with one or more login
1fd407f… wyoung 221 cards. Each login card has the following format:
1fd407f… wyoung 222
8a1ba49… wyoung 223 <pre><b>login</b> <i>userid nonce signature</i></pre>
8a1ba49… wyoung 224
1862890… stephan 225 The userid is the name of the user that is requesting service from the
1862890… stephan 226 server, encoded in "fossilized" form (exactly as described for <a
1862890… stephan 227 href="#error">the error card</a>). The nonce is the SHA1 hash of the
1862890… stephan 228 remainder of the message - all text that follows the newline character
1862890… stephan 229 that terminates the login card. The signature is the SHA1 hash of the
1862890… stephan 230 concatenation of the nonce and the users password.
1862890… stephan 231
1862890… stephan 232 When receving a login card, the server looks up the user and verifies
1862890… stephan 233 that the nonce matches the SHA1 hash of the remainder of the message.
1862890… stephan 234 It then checks the signature hash to make sure the signature matches.
1862890… stephan 235 If everything checks out, then the client is granted all privileges of
1862890… stephan 236 the specified user.
1862890… stephan 237
1862890… stephan 238 Only one login card is permitted. A second login card will trigger
1862890… stephan 239 a sync error. (Prior to 2025-07-21, the protocol permitted multiple
1862890… stephan 240 logins, treating the login as the union of all privileges from all
1862890… stephan 241 login cards. That capability was never used and has been removed.)
1862890… stephan 242
1862890… stephan 243 As of version 2.27, Fossil supports transfering of the login card
1862890… stephan 244 externally to the request payload via a Cookie HTTP header:
1862890… stephan 245
1862890… stephan 246 <verbatim>
afd15bb… stephan 247 Cookie: x-f-l-c=...
1862890… stephan 248 </verbatim>
1862890… stephan 249
afd15bb… stephan 250 Where "..." is the URL-encoded login cookie. <code>x-f-l-c</code> is
afd15bb… stephan 251 short for X-Fossil-Login-Cookie.
1862890… stephan 252
5ca63ac… wyoung 253
5ca63ac… wyoung 254 <h3 id="file">3.3 File Cards</h3>
1fd407f… wyoung 255
1fd407f… wyoung 256 Artifacts are transferred using either "file" cards, or "cfile"
27d743e… drh 257 or "uvfile" cards.
27d743e… drh 258 The name "file" card comes from the fact that most artifacts correspond to
27d743e… drh 259 files that are under version control.
27d743e… drh 260 The "cfile" name is an abbreviation for "compressed file".
27d743e… drh 261 The "uvfile" name is an abbreviation for "unversioned file".
27d743e… drh 262
5ca63ac… wyoung 263 <h4 id="ordinary-fc">3.3.1 Ordinary File Cards</h4>
27d743e… drh 264
1fd407f… wyoung 265 For sync protocols, artifacts are transferred using "file"
d16018c… drh 266 cards. File cards come in two different formats depending
2219110… stephan 267 on whether the artifact is sent directly or as a
6fd7e00… wyoung 268 [./delta_format.wiki|delta] from some
1fd407f… wyoung 269 other artifact.
d16018c… drh 270
8a1ba49… wyoung 271 <pre>
8a1ba49… wyoung 272 <b>file</b> <i>artifact-id size</i> <b>\n</b> <i>content</i>
e8c4f69… drh 273 <b>file</b> <i>artifact-id delta-artifact-id size</i> <b>\n</b> <i>content</i>
8a1ba49… wyoung 274 </pre>
e8c4f69… drh 275
1fd407f… wyoung 276 File cards are followed by in-line "payload" data.
df1205b… drh 277 The content of the artifact
df1205b… drh 278 or the artifact delta is the first <i>size</i> bytes of the
f94f7e5… drh 279 x-fossil content that immediately follow the newline that
df1205b… drh 280 terminates the file card.
f94f7e5… drh 281
1fd407f… wyoung 282
1fd407f… wyoung 283 The first argument of a file card is the ID of the artifact that
e8c4f69… drh 284 is being transferred. The artifact ID is the lower-case hexadecimal
796db89… drh 285 representation of the name hash for the artifact.
f94f7e5… drh 286 The last argument of the file card is the number of bytes of
f94f7e5… drh 287 payload that immediately follow the file card. If the file
f94f7e5… drh 288 card has only two arguments, that means the payload is the
e8c4f69… drh 289 complete content of the artifact. If the file card has three
2219110… stephan 290 arguments, then the payload is a
6fd7e00… wyoung 291 [./delta_format.wiki|delta] and the second argument is
1fd407f… wyoung 292 the ID of another artifact that is the source of the delta.
f94f7e5… drh 293
1fd407f… wyoung 294 File cards are sent in both directions: client to server and
f94f7e5… drh 295 server to client. A delta might be sent before the source of
f94f7e5… drh 296 the delta, so both client and server should remember deltas
1fd407f… wyoung 297 and be able to apply them when their source arrives.
f94f7e5… drh 298
5ca63ac… wyoung 299 <h4 id="compressed-fc">3.3.2 Compressed File Cards</h4>
f94f7e5… drh 300
1fd407f… wyoung 301 A client that sends a clone protocol version "3" or greater will
d16018c… drh 302 receive artifacts as "cfile" cards while cloning. This card was
2219110… stephan 303 introduced to improve the speed of the transfer of content by sending
2219110… stephan 304 the compressed artifact directly from the server database to the
2219110… stephan 305 client. In this case, the containing response body is <em>not</em>
2219110… stephan 306 compressed separately because the vast majority of the response is
2219110… stephan 307 already compressed in cfile cards. In practice, version "3" is
2219110… stephan 308 significantly faster than version "2".
d16018c… drh 309
1fd407f… wyoung 310 Compressed File cards are similar to File cards, sharing the same
d16018c… drh 311 in-line "payload" data characteristics and also the same treatment of
85f957c… drh 312 direct content or delta content. Cfile cards come in two different formats
d16018c… drh 313 depending on whether the artifact is sent directly or as a delta from
1fd407f… wyoung 314 some other artifact.
1fd407f… wyoung 315
8a1ba49… wyoung 316 <pre>
8a1ba49… wyoung 317 <b>cfile</b> <i>artifact-id usize csize</i> <b>\n</b> <i>content</i>
8a1ba49… wyoung 318 <b>cfile</b> <i>artifact-id delta-artifact-id usize csize</i> <b>\n</b> <i>content</i>
8a1ba49… wyoung 319 </pre>
1fd407f… wyoung 320
1fd407f… wyoung 321 The first argument of the cfile card is the ID of the artifact that
d16018c… drh 322 is being transferred. The artifact ID is the lower-case hexadecimal
796db89… drh 323 representation of the name hash for the artifact. The second argument of
d16018c… drh 324 the cfile card is the original size in bytes of the artifact. The last
d16018c… drh 325 argument of the cfile card is the number of compressed bytes of payload
d16018c… drh 326 that immediately follow the cfile card. If the cfile card has only
d16018c… drh 327 three arguments, that means the payload is the complete content of the
d16018c… drh 328 artifact. If the cfile card has four arguments, then the payload is a
d16018c… drh 329 delta and the second argument is the ID of another artifact that is the
d16018c… drh 330 source of the delta and the third argument is the original size of the
1fd407f… wyoung 331 delta artifact.
1fd407f… wyoung 332
1fd407f… wyoung 333 Unlike file cards, cfile cards are only sent in one direction during a
1fd407f… wyoung 334 clone from server to client for clone protocol version "3" or greater.
1fd407f… wyoung 335
5ca63ac… wyoung 336 <h4 id="private">3.3.3 Private artifacts</h4>
1fd407f… wyoung 337
1fd407f… wyoung 338 "Private" content consist of artifacts that are not normally synced.
3dcf69a… drh 339 However, private content will be synced when the
3dcf69a… drh 340 the [/help?cmd=sync|fossil sync] command includes the "--private" option.
1fd407f… wyoung 341
1fd407f… wyoung 342 Private content is marked by a "private" card:
1fd407f… wyoung 343
8a1ba49… wyoung 344 <pre><b>private</b></pre>
1fd407f… wyoung 345
1fd407f… wyoung 346 The private card has no arguments and must directly precede a
1fd407f… wyoung 347 file card that contains the private content.
1fd407f… wyoung 348
5ca63ac… wyoung 349 <h4 id="uv-fc">3.3.4 Unversioned File Cards</h4>
1fd407f… wyoung 350
1fd407f… wyoung 351 Unversioned content is sent in both directions (client to server and
27d743e… drh 352 server to client) using "uvfile" cards in the following format:
27d743e… drh 353
8a1ba49… wyoung 354 <pre><b>uvfile</b> <i>name mtime hash size flags</i> <b>\n</b> <i>content</i></pre>
27d743e… drh 355
1fd407f… wyoung 356 The <i>name</i> field is the name of the unversioned file. The
27d743e… drh 357 <i>mtime</i> is the last modification time of the file in seconds
796db89… drh 358 since 1970. The <i>hash</i> field is the hash of the content
27d743e… drh 359 for the unversioned file, or "<b>-</b>" for deleted content.
27d743e… drh 360 The <i>size</i> field is the (uncompressed) size of the content
27d743e… drh 361 in bytes. The <i>flags</i> field is an integer which is interpreted
27d743e… drh 362 as an array of bits. The 0x0004 bit of <i>flags</i> indicates that
27d743e… drh 363 the <i>content</i> is to be omitted. The content might be omitted if
85f957c… drh 364 it is too large to transmit, or if the sender merely wants to update the
27d743e… drh 365 modification time of the file without changing the files content.
27d743e… drh 366 The <i>content</i> is the (uncompressed) content of the file.
27d743e… drh 367
1fd407f… wyoung 368 The receiver should only accept the uvfile card if the hash and
27d743e… drh 369 size match the content and if the mtime is newer than any existing
27d743e… drh 370 instance of the same file held by the receiver. The sender will not
27d743e… drh 371 normally transmit a uvfile card unless all these constraints are true,
27d743e… drh 372 but the receiver should double-check.
27d743e… drh 373
e57613d… drh 374 A server will only accept uvfile cards if the login user has
27d743e… drh 375 the "y" write-unversioned permission.
27d743e… drh 376
1fd407f… wyoung 377 Servers send uvfile cards in response to uvgimme cards received from
27d743e… drh 378 the client. Clients send uvfile cards when they determine that the server
27d743e… drh 379 needs the content based on uvigot cards previously received from the server.
27d743e… drh 380
5ca63ac… wyoung 381 <h3 id="push" name="pull">3.4 Push and Pull Cards</h3>
27d743e… drh 382
1fd407f… wyoung 383 Among the first cards in a client-to-server message are
a9819ba… andybradford 384 the push and pull cards. The push card tells the server that
a9819ba… andybradford 385 the client is pushing content. The pull card tells the server
f94f7e5… drh 386 that the client wants to pull content. In the event of a sync,
1fd407f… wyoung 387 both cards are sent. The format is as follows:
f94f7e5… drh 388
8a1ba49… wyoung 389 <pre>
8a1ba49… wyoung 390 <b>push</b> <i>servercode projectcode</i>
f94f7e5… drh 391 <b>pull</b> <i>servercode projectcode</i>
8a1ba49… wyoung 392 </pre>
f94f7e5… drh 393
1fd407f… wyoung 394 The <i>servercode</i> argument is the repository ID for the
e315ec8… andybradford 395 client. The <i>projectcode</i> is the identifier
f94f7e5… drh 396 of the software project that the client repository contains.
f94f7e5… drh 397 The projectcode for the client and server must match in order
1fd407f… wyoung 398 for the transaction to proceed.
f94f7e5… drh 399
1fd407f… wyoung 400 The server will also send a push card back to the client
f94f7e5… drh 401 during a clone. This is how the client determines what project
1fd407f… wyoung 402 code to put in the new repository it is constructing.
f94f7e5… drh 403
1fd407f… wyoung 404 The <i>servercode</i> argument is currently unused.
f94f7e5… drh 405
5ca63ac… wyoung 406 <h3 id="clones">3.5 Clone Cards</h3>
3dcf69a… drh 407
1fd407f… wyoung 408 A clone card works like a pull card in that it is sent from
f94f7e5… drh 409 client to server in order to tell the server that the client
aa2fdc2… drh 410 wants to pull content. The clone card comes in two formats. Older
aa2fdc2… drh 411 clients use the no-argument format and newer clients use the
1fd407f… wyoung 412 two-argument format.
f94f7e5… drh 413
8a1ba49… wyoung 414 <pre>
8a1ba49… wyoung 415 <b>clone</b>
aa2fdc2… drh 416 <b>clone</b> <i>protocol-version sequence-number</i>
8a1ba49… wyoung 417 </pre>
f94f7e5… drh 418
d16018c… drh 419 <h4>3.5.1 Protocol 3</h4>
aa2fdc2… drh 420
1fd407f… wyoung 421 The latest clients send a two-argument clone message with a
d16018c… drh 422 protocol version of "3". (Future versions of Fossil might use larger
d16018c… drh 423 protocol version numbers.) Version "3" of the protocol enhanced version
d16018c… drh 424 "2" by introducing the "cfile" card which is intended to speed up clone
d16018c… drh 425 operations. Instead of sending "file" cards, the server will send "cfile"
1fd407f… wyoung 426 cards
d16018c… drh 427
d16018c… drh 428 <h4>3.5.2 Protocol 2</h4>
d16018c… drh 429
1fd407f… wyoung 430 The sequence-number sent is the number
aa2fdc2… drh 431 of artifacts received so far. For the first clone message, the
bbc4b70… stephan 432 sequence number is 1. The server will respond by sending file
aa2fdc2… drh 433 cards for some number of artifacts up to the maximum message size.
aa2fdc2… drh 434
1fd407f… wyoung 435 The server will also send a single "clone_seqno" card to the client
aa2fdc2… drh 436 so that the client can know where the server left off.
aa2fdc2… drh 437
8a1ba49… wyoung 438 <pre>
aa2fdc2… drh 439 <b>clone_seqno</b> <i>sequence-number</i>
8a1ba49… wyoung 440 </pre>
aa2fdc2… drh 441
1fd407f… wyoung 442 The clone message in subsequent HTTP requests for the same clone
aa2fdc2… drh 443 operation will use the sequence-number from the
1fd407f… wyoung 444 clone_seqno of the previous reply.
aa2fdc2… drh 445
1fd407f… wyoung 446 In response to an initial clone message, the server also sends the client
f94f7e5… drh 447 a push message so that the client can discover the projectcode for
1fd407f… wyoung 448 this project.
f94f7e5… drh 449
d16018c… drh 450 <h4>3.5.3 Legacy Protocol</h4>
f94f7e5… drh 451
1fd407f… wyoung 452 Older clients send a clone card with no argument. The server responds
aa2fdc2… drh 453 to a blank clone card by sending an "igot" card for every artifact in the
aa2fdc2… drh 454 repository. The client will then issue "gimme" cards to pull down all the
aa2fdc2… drh 455 content it needs.
aa2fdc2… drh 456
1fd407f… wyoung 457 The legacy protocol works well for smaller repositories (50MB with 50,000
8cf380a… aku 458 artifacts) but is too slow and unwieldy for larger repositories.
aa2fdc2… drh 459 The version 2 protocol is an effort to improve performance. Further
aa2fdc2… drh 460 performance improvements with higher-numbered clone protocols are
aa2fdc2… drh 461 possible in future versions of Fossil.
aa2fdc2… drh 462
5ca63ac… wyoung 463 <h3 id="igot">3.6 Igot Cards</h3>
aa2fdc2… drh 464
1fd407f… wyoung 465 An igot card can be sent from either client to server or from
f94f7e5… drh 466 server to client in order to indicate that the sender holds a copy
1fd407f… wyoung 467 of a particular artifact. The format is:
f94f7e5… drh 468
8a1ba49… wyoung 469 <pre>
3dcf69a… drh 470 <b>igot</b> <i>artifact-id</i> ?<i>flag</i>?
8a1ba49… wyoung 471 </pre>
f94f7e5… drh 472
1fd407f… wyoung 473 The first argument of the igot card is the ID of the artifact that
f94f7e5… drh 474 the sender possesses.
f94f7e5… drh 475 The receiver of an igot card will typically check to see if
e8c4f69… drh 476 it also holds the same artifact and if not it will request the artifact
1fd407f… wyoung 477 using a gimme card in either the reply or in the next message.
f94f7e5… drh 478
1fd407f… wyoung 479 If the second argument exists and is "1", then the artifact
3dcf69a… drh 480 identified by the first argument is private on the sender and should
3dcf69a… drh 481 be ignored unless a "--private" [/help?cmd=sync|sync] is occurring.
f94f7e5… drh 482
1fd407f… wyoung 483 The name "igot" comes from the English slang expression "I got" meaning
1f7b409… drh 484 "I have".
1f7b409… drh 485
27d743e… drh 486 <h4>3.6.1 Unversioned Igot Cards</h4>
27d743e… drh 487
1fd407f… wyoung 488 Zero or more "uvigot" cards are sent from server to client when
27d743e… drh 489 synchronizing unversioned content. The format of a uvigot card is
27d743e… drh 490 as follows:
27d743e… drh 491
8a1ba49… wyoung 492 <pre>
27d743e… drh 493 <b>uvigot</b> <i>name mtime hash size</i>
8a1ba49… wyoung 494 </pre>
27d743e… drh 495
1fd407f… wyoung 496 The <i>name</i> argument is the name of an unversioned file.
27d743e… drh 497 The <i>mtime</i> is the last modification time of the unversioned file
f47b705… jan.nijtmans 498 in seconds since 1970.
b098c93… jan.nijtmans 499 The <i>hash</i> is the SHA1 or SHA3-256 hash of the unversioned file
796db89… drh 500 content, or "<b>-</b>" if the file has been deleted.
27d743e… drh 501 The <i>size</i> is the uncompressed size of the file in bytes.
27d743e… drh 502
1fd407f… wyoung 503 When the server sees a "pragma uv-hash" card for which the hash
27d743e… drh 504 does not match, it sends uvigot cards for every unversioned file that it
27d743e… drh 505 holds. The client will use this information to figure out which
27d743e… drh 506 unversioned files need to be synchronized.
27d743e… drh 507 The server might also send a uvigot card when it receives a uvgimme card
27d743e… drh 508 but its reply message size is already oversized and hence unable to hold
27d743e… drh 509 the usual uvfile reply.
27d743e… drh 510
1fd407f… wyoung 511 When a client receives a "uvigot" card, it checks to see if the
79c2cb0… wyoung 512 file needs to be transferred from client to server or from server to client.
27d743e… drh 513 If a client-to-server transmission is needed, the client schedules that
27d743e… drh 514 transfer to occur on a subsequent HTTP request. If a server-to-client
27d743e… drh 515 transfer is needed, then the client sends a "uvgimme" card back to the
27d743e… drh 516 server to request the file content.
27d743e… drh 517
5ca63ac… wyoung 518 <h3 id="gimme">3.7 Gimme Cards</h3>
27d743e… drh 519
1fd407f… wyoung 520 A gimme card is sent from either client to server or from server
f94f7e5… drh 521 to client. The gimme card asks the receiver to send a particular
1fd407f… wyoung 522 artifact back to the sender. The format of a gimme card is this:
f94f7e5… drh 523
8a1ba49… wyoung 524 <pre>
e8c4f69… drh 525 <b>gimme</b> <i>artifact-id</i>
8a1ba49… wyoung 526 </pre>
f94f7e5… drh 527
1fd407f… wyoung 528 The argument to the gimme card is the ID of the artifact that
f94f7e5… drh 529 the sender wants. The receiver will typically respond to a
f94f7e5… drh 530 gimme card by sending a file card in its reply or in the next
1fd407f… wyoung 531 message.
1f7b409… drh 532
1fd407f… wyoung 533 The "gimme" name means "give me". The imperative "give me" is
1f7b409… drh 534 pronounced as if it were a single word "gimme" in some dialects of
1f7b409… drh 535 English (including the dialect spoken by the original author of Fossil).
f94f7e5… drh 536
27d743e… drh 537 <h4>3.7.1 Unversioned Gimme Cards</h4>
27d743e… drh 538
af1456b… drh 539 When synchronizing unversioned content, the client may send "uvgimme"
27d743e… drh 540 cards to the server. A uvgimme card requests that the server send
27d743e… drh 541 unversioned content to the client. The format of a uvgimme card is
27d743e… drh 542 as follows:
27d743e… drh 543
8a1ba49… wyoung 544 <pre>
27d743e… drh 545 <b>uvgimme</b> <i>name</i>
8a1ba49… wyoung 546 </pre>
27d743e… drh 547
1fd407f… wyoung 548 The <i>name</i> is the name of the unversioned file found on the
27d743e… drh 549 server that the client would like to have. When a server sees a
27d743e… drh 550 uvgimme card, it normally responses with a uvfile card, though it might
d3dabbb… drh 551 also send another uvigot card if the HTTP reply is already oversized.
27d743e… drh 552
5ca63ac… wyoung 553 <h3 id="cookie">3.8 Cookie Cards</h3>
27d743e… drh 554
1fd407f… wyoung 555 A cookie card can be used by a server to record a small amount
f94f7e5… drh 556 of state information on a client. The server sends a cookie to the
f94f7e5… drh 557 client. The client sends the same cookie back to the server on
f94f7e5… drh 558 its next request. The cookie card has a single argument which
1fd407f… wyoung 559 is its payload.
f94f7e5… drh 560
8a1ba49… wyoung 561 <pre>
f94f7e5… drh 562 <b>cookie</b> <i>payload</i>
8a1ba49… wyoung 563 </pre>
f94f7e5… drh 564
1fd407f… wyoung 565 The client is not required to return the cookie to the server on
f94f7e5… drh 566 its next request. Or the client might send a cookie from a different
f94f7e5… drh 567 server on the next request. So the server must not depend on the
f94f7e5… drh 568 cookie and the server must structure the cookie payload in such
f94f7e5… drh 569 a way that it can tell if the cookie it sees is its own cookie or
f94f7e5… drh 570 a cookie from another server. (Typically the server will embed
1fd407f… wyoung 571 its servercode as part of the cookie.)
aa2fdc2… drh 572
5ca63ac… wyoung 573 <h3 id="reqconfig">3.9 Request-Configuration Cards</h3>
aa2fdc2… drh 574
1fd407f… wyoung 575 A request-configuration or "reqconfig" card is sent from client to
aa2fdc2… drh 576 server in order to request that the server send back "configuration"
aa2fdc2… drh 577 data. "Configuration" data is information about users or website
aa2fdc2… drh 578 appearance or other administrative details which are not part of the
aa2fdc2… drh 579 persistent and versioned state of the project. For example, the "name"
aa2fdc2… drh 580 of the project, the default Cascading Style Sheet (CSS) for the web-interface,
aa2fdc2… drh 581 and the project logo displayed on the web-interface are all configuration
aa2fdc2… drh 582 data elements.
aa2fdc2… drh 583
1fd407f… wyoung 584 The reqconfig card is normally sent in response to the
aa2fdc2… drh 585 "fossil configuration pull" command. The format is as follows:
aa2fdc2… drh 586
8a1ba49… wyoung 587 <pre>
aa2fdc2… drh 588 <b>reqconfig</b> <i>configuration-name</i>
8a1ba49… wyoung 589 </pre>
aa2fdc2… drh 590
af1456b… drh 591 As of 2024-10-22, the configuration-name must be one of the
aa2fdc2… drh 592 following values:
aa2fdc2… drh 593
fcfaae3… jan.nijtmans 594 <table border=0 align="center">
aa2fdc2… drh 595 <tr><td valign="top">
aa2fdc2… drh 596 <ul>
aa2fdc2… drh 597 <li> css
aa2fdc2… drh 598 <li> header
af1456b… drh 599 <li> mainmenu
aa2fdc2… drh 600 <li> footer
55cd615… drh 601 <li> details
af1456b… drh 602 <li> js
af1456b… drh 603 <li> default-skin
aa2fdc2… drh 604 <li> logo-mimetype
aa2fdc2… drh 605 <li> logo-image
5098f74… jan.nijtmans 606 <li> background-mimetype
5098f74… jan.nijtmans 607 <li> background-image
af1456b… drh 608 <li> icon-mimetype
af1456b… drh 609 <li> icon-image
aa2fdc2… drh 610 <li> timeline-block-markup
af1456b… drh 611 <li> timeline-date-format
af1456b… drh 612 <li> timeline-default-style
af1456b… drh 613 <ul></td><td valign="top"><ul>
af1456b… drh 614 <li> timeline-dwelltime
af1456b… drh 615 <li> timeline-closetime
af1456b… drh 616 <li> timeline-hard-newlines
aa2fdc2… drh 617 <li> timeline-max-comment
dce0566… jan.nijtmans 618 <li> timeline-plaintext
af1456b… drh 619 <li> timeline-truncate-at-blank
af1456b… drh 620 <li> timeline-tslink-info
af1456b… drh 621 <li> timeline-utc
5098f74… jan.nijtmans 622 <li> adunit
5098f74… jan.nijtmans 623 <li> adunit-omit-if-admin
5098f74… jan.nijtmans 624 <li> adunit-omit-if-user
af1456b… drh 625 <li> default-csp
af1456b… drh 626 <li> sitemap-extra
af1456b… drh 627 <li> safe-html
55cd615… drh 628 <li> th1-hooks
af1456b… drh 629 <li> th1-uri-regexp
5098f74… jan.nijtmans 630 <li> project-name
af1456b… drh 631 <ul></td><td valign="top"><ul>
5098f74… jan.nijtmans 632 <li> short-project-name
5098f74… jan.nijtmans 633 <li> project-description
5098f74… jan.nijtmans 634 <li> index-page
5098f74… jan.nijtmans 635 <li> manifest
5098f74… jan.nijtmans 636 <li> binary-glob
5098f74… jan.nijtmans 637 <li> clean-glob
5098f74… jan.nijtmans 638 <li> ignore-glob
5098f74… jan.nijtmans 639 <li> keep-glob
87320cf… andygoth 640 <li> crlf-glob
5098f74… jan.nijtmans 641 <li> crnl-glob
5098f74… jan.nijtmans 642 <li> encoding-glob
5098f74… jan.nijtmans 643 <li> empty-dirs
8a1ba49… wyoung 644 <li> <s title="removed 2020-08, version 2.12.1">allow-symlinks</s>
1f79752… jan.nijtmans 645 <li> dotfiles
55cd615… drh 646 <li> parent-project-code
af1456b… drh 647 <li> parent-project-name
af1456b… drh 648 <ul></td><td valign="top"><ul>
55cd615… drh 649 <li> hash-policy
af1456b… drh 650 <li> comment-format
af1456b… drh 651 <li> mimetypes
af1456b… drh 652 <li> forbid-delta-manifests
55cd615… drh 653 <li> mv-rm-files
aa2fdc2… drh 654 <li> ticket-table
aa2fdc2… drh 655 <li> ticket-common
dce0566… jan.nijtmans 656 <li> ticket-change
aa2fdc2… drh 657 <li> ticket-newpage
aa2fdc2… drh 658 <li> ticket-viewpage
aa2fdc2… drh 659 <li> ticket-editpage
aa2fdc2… drh 660 <li> ticket-reportlist
aa2fdc2… drh 661 <li> ticket-report-template
aa2fdc2… drh 662 <li> ticket-key-template
aa2fdc2… drh 663 <li> ticket-title-expr
aa2fdc2… drh 664 <li> ticket-closed-expr
af1456b… drh 665 <ul></td><td valign="top"><ul>
af1456b… drh 666 <li> user-color-map
55cd615… drh 667 <li> xfer-common-script
55cd615… drh 668 <li> xfer-push-script
55cd615… drh 669 <li> xfer-commit-script
55cd615… drh 670 <li> xfer-ticket-script
aa2fdc2… drh 671 <li> @reportfmt
aa2fdc2… drh 672 <li> @user
aa2fdc2… drh 673 <li> @concealed
aa2fdc2… drh 674 <li> @shun
af1456b… drh 675 <li> @alias
af1456b… drh 676 <li> @subscriber
af1456b… drh 677 <li> @interwiki
aa2fdc2… drh 678 </ul></td></tr>
fcfaae3… jan.nijtmans 679 </table>
aa2fdc2… drh 680
1fd407f… wyoung 681 New configuration-names are likely to be added in future releases of
aa2fdc2… drh 682 Fossil. If the server receives a configuration-name that it does not
aa2fdc2… drh 683 understand, the entire reqconfig card is silently ignored. The reqconfig
aa2fdc2… drh 684 card might also be ignored if the user lacks sufficient privilege to
aa2fdc2… drh 685 access the requested information.
aa2fdc2… drh 686
1fd407f… wyoung 687 The configuration-names that begin with an alphabetic character refer
aa2fdc2… drh 688 to values in the "config" table of the server database. For example,
aa2fdc2… drh 689 the "logo-image" configuration item refers to the project logo image
aa2fdc2… drh 690 that is configured on the Admin page of the [./webui.wiki | web-interface].
aa2fdc2… drh 691 The value of the configuration item is returned to the client using a
aa2fdc2… drh 692 "config" card.
aa2fdc2… drh 693
1fd407f… wyoung 694 If the configuration-name begins with "@", that refers to a class of
aa2fdc2… drh 695 values instead of a single value. The content of these configuration items
fcfaae3… jan.nijtmans 696 is returned in a "config" card that contains pure SQL text that is
8cf380a… aku 697 intended to be evaluated by the client.
8cf380a… aku 698
1fd407f… wyoung 699 The @user and @concealed configuration items contain sensitive information
8cf380a… aku 700 and are ignored for clients without sufficient privilege.
8cf380a… aku 701
5ca63ac… wyoung 702 <h3 id="config">3.10 Configuration Cards</h3>
8cf380a… aku 703
1fd407f… wyoung 704 A "config" card is used to send configuration information from client
aa2fdc2… drh 705 to server (in response to a "fossil configuration push" command) or
aa2fdc2… drh 706 from server to client (in response to a "fossil configuration pull" or
aa2fdc2… drh 707 "fossil clone" command). The format is as follows:
aa2fdc2… drh 708
8a1ba49… wyoung 709 <pre>
aa2fdc2… drh 710 <b>config</b> <i>configuration-name size</i> <b>\n</b> <i>content</i>
8a1ba49… wyoung 711 </pre>
aa2fdc2… drh 712
1fd407f… wyoung 713 The server will only accept a config card if the user has
aa2fdc2… drh 714 "Admin" privilege. A client will only accept a config card if
8cf380a… aku 715 it had sent a corresponding reqconfig card in its request.
aa2fdc2… drh 716
1fd407f… wyoung 717 The content of the configuration item is used to overwrite the
aa2fdc2… drh 718 corresponding configuration data in the receiver.
aa2fdc2… drh 719
5ca63ac… wyoung 720 <h3 id="pragma">3.11 Pragma Cards</h3>
3dcf69a… drh 721
1fd407f… wyoung 722 The client may try to influence the behavior of the server by
3dcf69a… drh 723 issuing a pragma card:
3dcf69a… drh 724
8a1ba49… wyoung 725 <pre>
3dcf69a… drh 726 <b>pragma</i> <i>name value...</i>
8a1ba49… wyoung 727 </pre>
3dcf69a… drh 728
1fd407f… wyoung 729 The "pragma" card has at least one argument which is the pragma name.
3dcf69a… drh 730 The pragma name defines what the pragma does.
3dcf69a… drh 731 A pragma might have zero or more "value" arguments
3dcf69a… drh 732 depending on the pragma name.
3dcf69a… drh 733
1fd407f… wyoung 734 New pragma names may be added to the protocol from time to time
3dcf69a… drh 735 in order to enhance the capabilities of Fossil.
3dcf69a… drh 736 Unknown pragmas are silently ignored, for backwards compatibility.
3dcf69a… drh 737
1fd407f… wyoung 738 The following are the known pragma names as of 2019-06-30:
3dcf69a… drh 739
3dcf69a… drh 740 <ol>
1fd407f… wyoung 741 <li><b>send-private</b> The send-private pragma instructs the server to send all of its
3dcf69a… drh 742 private artifacts to the client. The server will only obey this
3dcf69a… drh 743 request if the user has the "x" or "Private" privilege.
3dcf69a… drh 744
1fd407f… wyoung 745 <li><b>send-catalog</b> The send-catalog pragma instructs the server to transmit igot
3dcf69a… drh 746 cards for every known artifact. This can help the client and server
3dcf69a… drh 747 to get back in synchronization after a prior protocol error. The
3dcf69a… drh 748 "--verily" option to the [/help?cmd=sync|fossil sync] command causes
1fd407f… wyoung 749 the send-catalog pragma to be transmitted.
27d743e… drh 750
1fd407f… wyoung 751 <li><b>uv-hash</b> <i>HASH</i> The uv-hash pragma is sent from client to server to provoke a
27d743e… drh 752 synchronization of unversioned content. The <i>HASH</i> is a SHA1
27d743e… drh 753 hash of the names, modification times, and individual hashes of all
27d743e… drh 754 unversioned files on the client. If the unversioned content hash
27d743e… drh 755 from the client does not match the unversioned content hash on the
27d743e… drh 756 server, then the server will reply with either a "pragma uv-push-ok"
27d743e… drh 757 or "pragma uv-pull-only" card followed by one "uvigot" card for
27d743e… drh 758 each unversioned file currently held on the server. The collection
27d743e… drh 759 of "uvigot" cards sent in response to a "uv-hash" pragma is called
27d743e… drh 760 the "unversioned catalog". The client will used the unversioned
27d743e… drh 761 catalog to figure out which files (if any) need to be synchronized
27d743e… drh 762 between client and server and send appropriate "uvfile" or "uvgimme"
1fd407f… wyoung 763 cards on the next HTTP request.
27d743e… drh 764
1fd407f… wyoung 765 If a client sends a uv-hash pragma and does not receive back
27d743e… drh 766 either a uv-pull-only or uv-push-ok pragma, that means that the
27d743e… drh 767 content on the server exactly matches the content on the client and
27d743e… drh 768 no further synchronization is required.
27d743e… drh 769
1fd407f… wyoung 770 <li><b>uv-pull-only</b></i> A server sends the uv-pull-only pragma to the client in response
79c2cb0… wyoung 771 to a uv-hash pragma with a mismatched content hash argument. This
79c2cb0… wyoung 772 pragma indicates that there are differences in unversioned content
79c2cb0… wyoung 773 between the client and server but that content can only be transferred
79c2cb0… wyoung 774 from server to client. The server is unwilling to accept content from
79c2cb0… wyoung 775 the client because the client login lacks the "write-unversioned"
1fd407f… wyoung 776 permission.
79c2cb0… wyoung 777
1fd407f… wyoung 778 <li><b>uv-push-ok</b></i> A server sends the uv-push-ok pragma to the client in response
79c2cb0… wyoung 779 to a uv-hash pragma with a mismatched content hash argument. This
79c2cb0… wyoung 780 pragma indicates that there are differences in unversioned content
3f736de… wyoung 781 between the client and server and that content can be transferred
79c2cb0… wyoung 782 in either direction. The server is willing to accept content from
79c2cb0… wyoung 783 the client because the client login has the "write-unversioned"
1fd407f… wyoung 784 permission.
79c2cb0… wyoung 785
1fd407f… wyoung 786 <li><b>ci-lock</b> <i>CHECKIN-HASH CLIENT-ID</i> A client sends the "ci-lock" pragma to the server to indicate
2d7a8a8… drh 787 that it is about to add a new check-in as a child of the
2d7a8a8… drh 788 CHECKIN-HASH check-in and on the same branch as CHECKIN-HASH.
2d7a8a8… drh 789 If some other client has already indicated that it was also
2d7a8a8… drh 790 trying to commit against CHECKIN-HASH, that indicates that a
2d7a8a8… drh 791 fork is about to occur, and the server will reply with
2d7a8a8… drh 792 a "ci-lock-fail" pragma (see below). Check-in locks
2d7a8a8… drh 793 automatically expire when the check-in actually occurs, or
62572ab… stephan 794 after a timeout (currently one minute but subject to change).
2d7a8a8… drh 795
1fd407f… wyoung 796 <li><b>ci-lock-fail</b> <i>LOGIN MTIME</i> When a server receives two or more "ci-lock" pragma messages
2d7a8a8… drh 797 for the same check-in but from different clients, the second a
2d7a8a8… drh 798 subsequent ci-lock will provoke a ci-lock-fail pragma in the
2d7a8a8… drh 799 reply to let the client know that it if continues with the
2d7a8a8… drh 800 check-in it will likely generate a fork. The LOGIN and MTIME
2d7a8a8… drh 801 arguments are intended to provide information to the client to
2d7a8a8… drh 802 help it generate a more useful error message.
1eefb8d… drh 803
1fd407f… wyoung 804 <li><b>ci-unlock</b> <i>CLIENT-ID</i> A client sends the "ci-unlock" pragma to the server after
1eefb8d… drh 805 a successful commit. This instructs the server to release
1eefb8d… drh 806 any lock on any check-in previously held by that client.
1eefb8d… drh 807 The ci-unlock pragma helps to avoid false-positive lock warnings
1eefb8d… drh 808 that might arise if a check-in is aborted and then restarted
1eefb8d… drh 809 on a branch.
5f87217… drh 810
5f87217… drh 811 <li><b>req-clusters</b> A client sends the "req-clusters" pragma
5f87217… drh 812 to the server to ask the server to reply with "igot" cards for
5f87217… drh 813 every [./fileformat.wiki#cluster|cluster artifact] that it holds. The
5f87217… drh 814 client typically does this when it thinks that it might be attempting
5f87217… drh 815 to pull a long chain of cluster artifacts. Sending the artifacts
5f87217… drh 816 all at once can dramatically reduce the number of round trip
5f87217… drh 817 messages needed to complete the synchronization.
3dcf69a… drh 818 </ol>
3dcf69a… drh 819
5ca63ac… wyoung 820 <h3 id="comment">3.12 Comment Cards</h3>
1fd407f… wyoung 821
1fd407f… wyoung 822 Any card that begins with "#" (ASCII 0x23) is a comment card and
1fd407f… wyoung 823 is silently ignored.
1fd407f… wyoung 824
5ca63ac… wyoung 825 <h3 id="error">3.13 Message and Error Cards</h3>
1fd407f… wyoung 826
1fd407f… wyoung 827 If the server discovers anything wrong with a request, it generates
f94f7e5… drh 828 an error card in its reply. When the client sees the error card,
f94f7e5… drh 829 it displays an error message to the user and aborts the sync
1fd407f… wyoung 830 operation. An error card looks like this:
f94f7e5… drh 831
8a1ba49… wyoung 832 <pre>
f94f7e5… drh 833 <b>error</b> <i>error-message</i>
8a1ba49… wyoung 834 </pre>
f94f7e5… drh 835
1fd407f… wyoung 836 The error message is English text that is encoded in order to
f94f7e5… drh 837 be a single token.
f94f7e5… drh 838 A space (ASCII 0x20) is represented as "\s" (ASCII 0x5C, 0x73). A
fcfaae3… jan.nijtmans 839 newline (ASCII 0x0a) is "\n" (ASCII 0x6C, x6E). A backslash
f94f7e5… drh 840 (ASCII 0x5C) is represented as two backslashes "\\". Apart from
f94f7e5… drh 841 space and newline, no other whitespace characters nor any
f94f7e5… drh 842 unprintable characters are allowed in
1fd407f… wyoung 843 the error message.
55cd615… drh 844
1fd407f… wyoung 845 The server can also send a message card that also prints a
55cd615… drh 846 message on the client console, but which is not an error:
55cd615… drh 847
8a1ba49… wyoung 848 <pre>
55cd615… drh 849 <b>message</b> <i>message-text</i>
8a1ba49… wyoung 850 </pre>
1fd407f… wyoung 851
1fd407f… wyoung 852 The message-text uses the same format as an error message.
1fd407f… wyoung 853
5ca63ac… wyoung 854 <h3 id="unknown">3.14 Unknown Cards</h3>
1fd407f… wyoung 855
1fd407f… wyoung 856 If either the client or the server sees a card that is not
1fd407f… wyoung 857 described above, then it generates an error and aborts.
1fd407f… wyoung 858
5ca63ac… wyoung 859 <h2 id="phantoms" name="clusters">4.0 Phantoms And Clusters</h2>
1fd407f… wyoung 860
1fd407f… wyoung 861 When a repository knows that an artifact exists and knows the ID of
e8c4f69… drh 862 that artifact, but it does not know the artifact content, then it stores that
e8c4f69… drh 863 artifact as a "phantom". A repository will typically create a phantom when
f1b148d… andybradford 864 it receives an igot card for an artifact that it does not hold or when it
f94f7e5… drh 865 receives a file card that references a delta source that it does not
f94f7e5… drh 866 hold. When a server is generating its reply or when a client is
f94f7e5… drh 867 generating a new request, it will usually send gimme cards for every
1fd407f… wyoung 868 phantom that it holds.
f94f7e5… drh 869
1fd407f… wyoung 870 A cluster is a special artifact that tells of the existence of other
e8c4f69… drh 871 artifacts. Any artifact in the repository that follows the syntactic rules
1fd407f… wyoung 872 of a cluster is considered a cluster.
f94f7e5… drh 873
1fd407f… wyoung 874 A cluster is line oriented. Each line of a cluster
f94f7e5… drh 875 is a card. The cards are separated by the newline ("\n") character.
f94f7e5… drh 876 Each card consists of a single character card type, a space, and a
f94f7e5… drh 877 single argument. No extra whitespace and no trailing or leading
f94f7e5… drh 878 whitespace is allowed. All cards in the cluster must occur in
1fd407f… wyoung 879 strict lexicographical order.
f94f7e5… drh 880
1fd407f… wyoung 881 A cluster consists of one or more "M" cards followed by a single
f1b148d… andybradford 882 "Z" card. Each M card holds an argument which is an artifact ID for an
e8c4f69… drh 883 artifact in the repository. The Z card has a single argument which is the
f94f7e5… drh 884 lower-case hexadecimal representation of the MD5 checksum of all
f94f7e5… drh 885 preceding M cards up to and included the newline character that
1fd407f… wyoung 886 occurred just before the Z that starts the Z card.
f94f7e5… drh 887
1fd407f… wyoung 888 Any artifact that does not match the specifications of a cluster
f94f7e5… drh 889 exactly is not a cluster. There must be no extra whitespace in
e8c4f69… drh 890 the artifact. There must be one or more M cards. There must be a
f94f7e5… drh 891 single Z card with a correct MD5 checksum. And all cards must
1fd407f… wyoung 892 be in strict lexicographical order.
f94f7e5… drh 893
5ca63ac… wyoung 894 <h3 id="unclustered">4.1 The Unclustered Table</h3>
f94f7e5… drh 895
1fd407f… wyoung 896 Every repository maintains a table named "<b>unclustered</b>"
e8c4f69… drh 897 which records the identity of every artifact and phantom it holds that is not
f94f7e5… drh 898 mentioned in a cluster. The entries in the unclustered table can
e8c4f69… drh 899 be thought of as leaves on a tree of artifacts. Some of the unclustered
e8c4f69… drh 900 artifacts will be other clusters. Those clusters may contain other clusters,
f94f7e5… drh 901 which might contain still more clusters, and so forth. Beginning
e8c4f69… drh 902 with the artifacts in the unclustered table, one can follow the chain
1fd407f… wyoung 903 of clusters to find every artifact in the repository.
1fd407f… wyoung 904
5ca63ac… wyoung 905 <h2 id="strategies">5.0 Synchronization Strategies</h2>
1fd407f… wyoung 906
5ca63ac… wyoung 907 <h3 id="pull-strategy">5.1 Pull</h3>
1fd407f… wyoung 908
1fd407f… wyoung 909 A typical pull operation proceeds as shown below. Details
af1456b… drh 910 of the actual implementation may vary slightly but the gist of
1fd407f… wyoung 911 a pull is captured in the following steps:
f94f7e5… drh 912
f94f7e5… drh 913 <ol>
f94f7e5… drh 914 <li>The client sends login and pull cards.
f94f7e5… drh 915 <li>The client sends a cookie card if it has previously received a cookie.
f94f7e5… drh 916 <li>The client sends gimme cards for every phantom that it holds.
f94f7e5… drh 917 <hr>
f94f7e5… drh 918 <li>The server checks the login password and rejects the session if
f94f7e5… drh 919 the user does not have permission to pull.
4b565c4… drh 920 <li>If the number of entries in the unclustered table on the server is
e8c4f69… drh 921 greater than 100, then the server constructs a new cluster artifact to
f94f7e5… drh 922 cover all those unclustered entries.
f94f7e5… drh 923 <li>The server sends file cards for every gimme card it received
f94f7e5… drh 924 from the client.
4b565c4… drh 925 <li>The server sends igot cards for every artifact in its unclustered
f94f7e5… drh 926 table that is not a phantom.
f94f7e5… drh 927 <hr>
f94f7e5… drh 928 <li>The client adds the content of file cards to its repository.
4b565c4… drh 929 <li>The client creates a phantom for every igot card in the server reply
e8c4f69… drh 930 that mentions an artifact that the client does not possess.
f94f7e5… drh 931 <li>The client creates a phantom for the delta source of file cards when
e8c4f69… drh 932 the delta source is an artifact that the client does not possess.
f94f7e5… drh 933 </ol>
f94f7e5… drh 934
1fd407f… wyoung 935 These ten steps represent a single HTTP round-trip request.
f94f7e5… drh 936 The first three steps are the processing that occurs on the client
f94f7e5… drh 937 to generate the request. The middle four steps are processing
f94f7e5… drh 938 that occurs on the server to interpret the request and generate a
f94f7e5… drh 939 reply. And the last three steps are the processing that the
1fd407f… wyoung 940 client does to interpret the reply.
f94f7e5… drh 941
1fd407f… wyoung 942 During a pull, the client will keep sending HTTP requests
1fd407f… wyoung 943 until it holds all artifacts that exist on the server.
f94f7e5… drh 944
1fd407f… wyoung 945 Note that the server tries
f94f7e5… drh 946 to limit the size of its reply message to something reasonable
f94f7e5… drh 947 (usually about 1MB) so that it might stop sending file cards as
1fd407f… wyoung 948 described in step (6) if the reply becomes too large.
f94f7e5… drh 949
1fd407f… wyoung 950 Step (5) is the only way in which new clusters can be created.
f94f7e5… drh 951 By only creating clusters on the server, we hope to minimize the
f94f7e5… drh 952 amount of overlap between clusters in the common configuration where
f94f7e5… drh 953 there is a single server and many clients. The same synchronization
f94f7e5… drh 954 protocol will continue to work even if there are multiple servers
f94f7e5… drh 955 or if servers and clients sometimes change roles. The only negative
f94f7e5… drh 956 effects of these unusual arrangements is that more than the minimum
1fd407f… wyoung 957 number of clusters might be generated.
f94f7e5… drh 958
5ca63ac… wyoung 959 <h3 id="push-stragegy">5.2 Push</h3>
f94f7e5… drh 960
1fd407f… wyoung 961 A typical push operation proceeds roughly as shown below. As
1fd407f… wyoung 962 with a pull, the actual implementation may vary slightly.
f94f7e5… drh 963
f94f7e5… drh 964 <ol>
f94f7e5… drh 965 <li>The client sends login and push cards.
e8c4f69… drh 966 <li>The client sends file cards for any artifacts that it holds that have
e8c4f69… drh 967 never before been pushed - artifacts that come from local check-ins.
f94f7e5… drh 968 <li>If this is the second or later cycle in a push, then the
f94f7e5… drh 969 client sends file cards for any gimme cards that the server sent
f94f7e5… drh 970 in the previous cycle.
e8c4f69… drh 971 <li>The client sends igot cards for every artifact in its unclustered table
f94f7e5… drh 972 that is not a phantom.
f94f7e5… drh 973 <hr>
f94f7e5… drh 974 <li>The server checks the login and push cards and issues an error if
f94f7e5… drh 975 anything is amiss.
e8c4f69… drh 976 <li>The server accepts file cards from the client and adds those artifacts
f94f7e5… drh 977 to its repository.
e8c4f69… drh 978 <li>The server creates phantoms for igot cards that mention artifacts it
e8c4f69… drh 979 does not possess or for file cards that mention delta source artifacts that
f94f7e5… drh 980 it does not possess.
f94f7e5… drh 981 <li>The server issues gimme cards for all phantoms.
f94f7e5… drh 982 <hr>
f94f7e5… drh 983 <li>The client remembers the gimme cards from the server so that it
f94f7e5… drh 984 can generate file cards in reply on the next cycle.
f94f7e5… drh 985 </ol>
f94f7e5… drh 986
1fd407f… wyoung 987 As with a pull, the steps of a push operation repeat until the
e8c4f69… drh 988 server knows all artifacts that exist on the client. Also, as with
f94f7e5… drh 989 pull, the client attempts to keep the size of the request from
f94f7e5… drh 990 growing too large by suppressing file cards once the
1fd407f… wyoung 991 size of the request reaches 1MB.
f94f7e5… drh 992
5ca63ac… wyoung 993 <h3 id="sync-strategy">5.3 Sync</h3>
f94f7e5… drh 994
1fd407f… wyoung 995 A sync is just a pull and a push that happen at the same time.
f94f7e5… drh 996 The first three steps of a pull are combined with the first five steps
f94f7e5… drh 997 of a push. Steps (4) through (7) of a pull are combined with steps
f94f7e5… drh 998 (5) through (8) of a push. And steps (8) through (10) of a pull
1fd407f… wyoung 999 are combined with step (9) of a push.
27d743e… drh 1000
5ca63ac… wyoung 1001 <h3 id="uv-strategy">5.4 Unversioned File Sync</h3>
27d743e… drh 1002
1fd407f… wyoung 1003 "Unversioned files" are files held in the repository
27d743e… drh 1004 where only the most recent version of the file is kept rather than
27d743e… drh 1005 the entire change history. Unversioned files are intended to be
27d743e… drh 1006 used to store ephemeral content, such as compiled binaries of the
27d743e… drh 1007 most recent release.
27d743e… drh 1008
1fd407f… wyoung 1009 Unversioned files are identified by name and timestamp (mtime).
27d743e… drh 1010 Only the most recent version of each file (the version with
27d743e… drh 1011 the largest mtime value) is retained.
27d743e… drh 1012
1fd407f… wyoung 1013 Unversioned files are synchronized using the
27d743e… drh 1014 [/help?cmd=unversioned|fossil unversioned sync] command.
27d743e… drh 1015
1fd407f… wyoung 1016 A schematic of an unversioned file synchronization is as follows:
27d743e… drh 1017
27d743e… drh 1018 <ol>
27d743e… drh 1019 <li>The client sends a "pragma uv-hash" card to the server. The argument
27d743e… drh 1020 to the uv-hash pragma is a hash of all filesnames, mtimes, and
27d743e… drh 1021 content hashes for the unversioned files held by the client.
27d743e… drh 1022 <hr>
d3dabbb… drh 1023 <li>If the unversioned content hash from the client matches the unversioned
27d743e… drh 1024 content hash on the server, then nothing needs to be done and the
27d743e… drh 1025 server no-ops. But if the hashes are different, then the server
27d743e… drh 1026 replies with either a uv-pull-only or a uv-push-ok pragma followed by
27d743e… drh 1027 uvigot cards for all unversioned files held on the server.
27d743e… drh 1028 <hr>
27d743e… drh 1029 <li>The client examines the uvigot cards received from the server and
27d743e… drh 1030 determines which unversioned files need to be exchanged in order
27d743e… drh 1031 to bring the client and server into synchronization. The client
27d743e… drh 1032 then sends appropriate "uvgimme" or "uvfile" cards back to the
27d743e… drh 1033 server.
27d743e… drh 1034 <hr>
27d743e… drh 1035 <li>The server updates its unversioned file store with received "uvfile"
27d743e… drh 1036 cards and answers "uvgimme" cards with "uvfile" cards in its reply.
27d743e… drh 1037 </ol>
27d743e… drh 1038
1fd407f… wyoung 1039 The last two steps might be repeated multiple
27d743e… drh 1040 times if there is more unversioned content to be transferred than will
27d743e… drh 1041 fit comfortably in a single HTTP request.
f94f7e5… drh 1042
5ca63ac… wyoung 1043 <h2 id="summary">6.0 Summary</h2>
f94f7e5… drh 1044
1fd407f… wyoung 1045 Here are the key points of the synchronization protocol:
f94f7e5… drh 1046
f94f7e5… drh 1047 <ol>
f94f7e5… drh 1048 <li>The client sends one or more PUSH HTTP requests to the server.
f94f7e5… drh 1049 The request and reply content type is "application/x-fossil".
f94f7e5… drh 1050 <li>HTTP request content is compressed using zlib.
f94f7e5… drh 1051 <li>The content of request and reply consists of cards with one
fcfaae3… jan.nijtmans 1052 card per line.
f94f7e5… drh 1053 <li>Card formats are:
f94f7e5… drh 1054 <ul>
f94f7e5… drh 1055 <li> <b>login</b> <i>userid nonce signature</i>
f94f7e5… drh 1056 <li> <b>push</b> <i>servercode projectcode</i>
f94f7e5… drh 1057 <li> <b>pull</b> <i>servercode projectcode</i>
f94f7e5… drh 1058 <li> <b>clone</b>
15b0110… stephan 1059 <li> <b>clone</b> <i>protocol-version sequence-number</i>
e8c4f69… drh 1060 <li> <b>file</b> <i>artifact-id size</i> <b>\n</b> <i>content</i>
e8c4f69… drh 1061 <li> <b>file</b> <i>artifact-id delta-artifact-id size</i> <b>\n</b> <i>content</i>
3dcf69a… drh 1062 <li> <b>cfile</b> <i>artifact-id size</i> <b>\n</b> <i>content</i>
3dcf69a… drh 1063 <li> <b>cfile</b> <i>artifact-id delta-artifact-id size</i> <b>\n</b> <i>content</i>
27d743e… drh 1064 <li> <b>uvfile</b> <i>name mtime hash size flags</i> <b>\n</b> <i>content</i>
3dcf69a… drh 1065 <li> <b>private</b>
3dcf69a… drh 1066 <li> <b>igot</b> <i>artifact-id</i> ?<i>flag</i>?
27d743e… drh 1067 <li> <b>uvigot</b> <i>name mtime hash size</i>
e8c4f69… drh 1068 <li> <b>gimme</b> <i>artifact-id</i>
27d743e… drh 1069 <li> <b>uvgimme</b> <i>name</i>
f94f7e5… drh 1070 <li> <b>cookie</b> <i>cookie-text</i>
efb759a… drh 1071 <li> <b>reqconfig</b> <i>parameter-name</i>
efb759a… drh 1072 <li> <b>config</b> <i>parameter-name size</i> <b>\n</b> <i>content</i>
3dcf69a… drh 1073 <li> <b>pragma</b> <i>name</i> <i>value...</i>
f94f7e5… drh 1074 <li> <b>error</b> <i>error-message</i>
55cd615… drh 1075 <li> <b>message</b> <i>text-messate</i>
3dcf69a… drh 1076 <li> <b>#</b> <i>arbitrary-text...</i>
f94f7e5… drh 1077 </ul>
e8c4f69… drh 1078 <li>Phantoms are artifacts that a repository knows exist but does not possess.
e8c4f69… drh 1079 <li>Clusters are artifacts that contain IDs of other artifacts.
f94f7e5… drh 1080 <li>Clusters are created automatically on the server during a pull.
e8c4f69… drh 1081 <li>Repositories keep track of all artifacts that are not named in any
e8c4f69… drh 1082 cluster and send igot messages for those artifacts.
f94f7e5… drh 1083 <li>Repositories keep track of all the phantoms they hold and send
e8c4f69… drh 1084 gimme messages for those artifacts.
e8c4f69… drh 1085 </ol>
505d9d4… drh 1086
5ca63ac… wyoung 1087 <h2 id="troubleshooting">7.0 Troubleshooting And Debugging Hints</h2>
505d9d4… drh 1088
505d9d4… drh 1089 If you run the [/help?cmd=sync|fossil sync] command
505d9d4… drh 1090 (or [/help?cmd=pull|pull] or [/help?cmd=push|push] or
505d9d4… drh 1091 [/help?cmd=clone|clone]) with the --httptrace option, Fossil
505d9d4… drh 1092 will keep a copy of each HTTP request and reply in files
505d9d4… drh 1093 named:
505d9d4… drh 1094 <ul>
505d9d4… drh 1095 <li> <tt>http-request-</tt><i>N</i><tt>.txt</tt>
505d9d4… drh 1096 <li> <tt>http-reply-</tt><i>N</i><tt>.txt</tt>
505d9d4… drh 1097 </ul>
505d9d4… drh 1098
1fd407f… wyoung 1099 In the above, <i>N</i> is an integer that increments with each
505d9d4… drh 1100 round-trip. If you are having trouble on the server side,
505d9d4… drh 1101 you can run the "[/help?cmd=test-http|fossil test-http]" command in a
505d9d4… drh 1102 debugger using one the "http-request-N.txt" files as input and
505d9d4… drh 1103 single step through the processing performed by the server.
505d9d4… drh 1104
1fd407f… wyoung 1105 The "--transport-command CMD" option on [/help?cmd=sync|fossil sync]
505d9d4… drh 1106 (and similar) causes the external program "CMD" to be used to move
505d9d4… drh 1107 the sync message to the server and retrieve the sync reply. The
505d9d4… drh 1108 CMD is given three arguments:
505d9d4… drh 1109 <ol>
505d9d4… drh 1110 <li> The URL of the server
505d9d4… drh 1111 <li> The name of a temporary file that contains the output-bound sync
505d9d4… drh 1112 protocol text, with the HTTP headers
505d9d4… drh 1113 <li> The name of a temporary file into which the CMD should write the
505d9d4… drh 1114 reply sync protocol text, again without any HTTP headers
505d9d4… drh 1115 </ol>
505d9d4… drh 1116
1fd407f… wyoung 1117 In a complex debugging situation, you can run the command
505d9d4… drh 1118 "fossil sync --transport-command ./debugging_script" where
505d9d4… drh 1119 "debugging_script" is some script of your own that invokes
af1456b… drh 1120 the anomalous behavior you are trying to debug.

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button