rugged 0.17.0.b7 → 0.18.0.b1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.md +88 -32
- data/ext/rugged/extconf.rb +4 -2
- data/ext/rugged/rugged.c +72 -10
- data/ext/rugged/rugged.h +14 -10
- data/ext/rugged/rugged_blob.c +8 -10
- data/ext/rugged/rugged_branch.c +11 -14
- data/ext/rugged/rugged_commit.c +31 -24
- data/ext/rugged/rugged_config.c +2 -2
- data/ext/rugged/rugged_index.c +133 -198
- data/ext/rugged/rugged_note.c +372 -0
- data/ext/rugged/rugged_object.c +50 -22
- data/ext/rugged/rugged_reference.c +122 -130
- data/ext/rugged/rugged_remote.c +72 -29
- data/ext/rugged/rugged_repo.c +402 -20
- data/ext/rugged/rugged_revwalk.c +7 -3
- data/ext/rugged/rugged_settings.c +110 -0
- data/ext/rugged/rugged_signature.c +23 -7
- data/ext/rugged/rugged_tag.c +32 -16
- data/ext/rugged/rugged_tree.c +44 -15
- data/lib/rugged.rb +1 -0
- data/lib/rugged/index.rb +8 -0
- data/lib/rugged/remote.rb +13 -0
- data/lib/rugged/repository.rb +3 -3
- data/lib/rugged/version.rb +1 -1
- data/test/blob_test.rb +13 -15
- data/test/branch_test.rb +32 -67
- data/test/commit_test.rb +50 -12
- data/test/config_test.rb +12 -11
- data/test/coverage/HEAD.json +1 -1
- data/test/coverage/cover.rb +40 -21
- data/test/errors_test.rb +34 -0
- data/test/fixtures/alternate/objects/14/6ae76773c91e3b1d00cf7a338ec55ae58297e2 +0 -0
- data/test/fixtures/alternate/objects/14/9c32d47e99d0a3572ff1e70a2e0051bbf347a9 +0 -0
- data/test/fixtures/alternate/objects/14/fb3108588f9421bf764041e5e3ac305eb6277f +0 -0
- data/test/fixtures/testrepo.git/logs/refs/notes/commits +1 -0
- data/test/fixtures/testrepo.git/objects/44/1034f860c1d5d90e4188d11ae0d325176869a8 +1 -0
- data/test/fixtures/testrepo.git/objects/60/d415052a33de2150bf68757f6461df4f563ae4 +0 -0
- data/test/fixtures/testrepo.git/objects/68/8a8f4ef7496901d15322972f96e212a9e466cc +1 -0
- data/test/fixtures/testrepo.git/objects/94/eca2de348d5f672faf56b0decafa5937e3235e +0 -0
- data/test/fixtures/testrepo.git/objects/9b/7384fe1676186192842f5d3e129457b62db9e3 +0 -0
- data/test/fixtures/testrepo.git/objects/b7/4713326bc972cc15751ed504dca6f6f3b91f7a +3 -0
- data/test/fixtures/testrepo.git/refs/notes/commits +1 -0
- data/test/index_test.rb +65 -69
- data/test/lib_test.rb +76 -11
- data/test/note_test.rb +158 -0
- data/test/object_test.rb +8 -11
- data/test/reference_test.rb +77 -85
- data/test/remote_test.rb +86 -8
- data/test/repo_pack_test.rb +9 -7
- data/test/repo_reset_test.rb +80 -0
- data/test/repo_test.rb +176 -53
- data/test/tag_test.rb +44 -7
- data/test/test_helper.rb +63 -35
- data/test/tree_test.rb +34 -13
- data/test/walker_test.rb +14 -14
- data/vendor/libgit2/Makefile.embed +1 -1
- data/vendor/libgit2/deps/http-parser/http_parser.c +974 -578
- data/vendor/libgit2/deps/http-parser/http_parser.h +106 -70
- data/vendor/libgit2/deps/regex/regcomp.c +7 -6
- data/vendor/libgit2/deps/regex/regex_internal.c +1 -1
- data/vendor/libgit2/deps/regex/regex_internal.h +12 -3
- data/vendor/libgit2/deps/regex/regexec.c +5 -5
- data/vendor/libgit2/include/git2.h +5 -1
- data/vendor/libgit2/include/git2/attr.h +4 -2
- data/vendor/libgit2/include/git2/blob.h +39 -12
- data/vendor/libgit2/include/git2/branch.h +123 -35
- data/vendor/libgit2/include/git2/checkout.h +206 -48
- data/vendor/libgit2/include/git2/clone.h +72 -27
- data/vendor/libgit2/include/git2/commit.h +20 -17
- data/vendor/libgit2/include/git2/common.h +67 -1
- data/vendor/libgit2/include/git2/config.h +81 -60
- data/vendor/libgit2/include/git2/cred_helpers.h +53 -0
- data/vendor/libgit2/include/git2/diff.h +459 -150
- data/vendor/libgit2/include/git2/errors.h +9 -1
- data/vendor/libgit2/include/git2/graph.h +41 -0
- data/vendor/libgit2/include/git2/ignore.h +7 -6
- data/vendor/libgit2/include/git2/index.h +323 -97
- data/vendor/libgit2/include/git2/indexer.h +27 -59
- data/vendor/libgit2/include/git2/inttypes.h +4 -0
- data/vendor/libgit2/include/git2/merge.h +13 -3
- data/vendor/libgit2/include/git2/message.h +14 -8
- data/vendor/libgit2/include/git2/net.h +9 -7
- data/vendor/libgit2/include/git2/notes.h +88 -29
- data/vendor/libgit2/include/git2/object.h +16 -6
- data/vendor/libgit2/include/git2/odb.h +80 -17
- data/vendor/libgit2/include/git2/odb_backend.h +47 -11
- data/vendor/libgit2/include/git2/oid.h +26 -17
- data/vendor/libgit2/include/git2/pack.h +62 -8
- data/vendor/libgit2/include/git2/push.h +131 -0
- data/vendor/libgit2/include/git2/refdb.h +103 -0
- data/vendor/libgit2/include/git2/refdb_backend.h +109 -0
- data/vendor/libgit2/include/git2/reflog.h +30 -21
- data/vendor/libgit2/include/git2/refs.h +215 -193
- data/vendor/libgit2/include/git2/refspec.h +22 -2
- data/vendor/libgit2/include/git2/remote.h +158 -37
- data/vendor/libgit2/include/git2/repository.h +150 -31
- data/vendor/libgit2/include/git2/reset.h +43 -9
- data/vendor/libgit2/include/git2/revparse.h +48 -4
- data/vendor/libgit2/include/git2/revwalk.h +25 -10
- data/vendor/libgit2/include/git2/signature.h +20 -12
- data/vendor/libgit2/include/git2/stash.h +121 -0
- data/vendor/libgit2/include/git2/status.h +122 -53
- data/vendor/libgit2/include/git2/strarray.h +17 -11
- data/vendor/libgit2/include/git2/submodule.h +42 -7
- data/vendor/libgit2/include/git2/tag.h +72 -59
- data/vendor/libgit2/include/git2/threads.h +4 -2
- data/vendor/libgit2/include/git2/trace.h +68 -0
- data/vendor/libgit2/include/git2/transport.h +328 -0
- data/vendor/libgit2/include/git2/tree.h +149 -120
- data/vendor/libgit2/include/git2/types.h +13 -12
- data/vendor/libgit2/include/git2/version.h +3 -3
- data/vendor/libgit2/src/amiga/map.c +2 -2
- data/vendor/libgit2/src/attr.c +58 -48
- data/vendor/libgit2/src/attr.h +4 -18
- data/vendor/libgit2/src/attr_file.c +30 -6
- data/vendor/libgit2/src/attr_file.h +6 -8
- data/vendor/libgit2/src/attrcache.h +24 -0
- data/vendor/libgit2/src/blob.c +30 -7
- data/vendor/libgit2/src/blob.h +1 -1
- data/vendor/libgit2/src/branch.c +361 -68
- data/vendor/libgit2/src/branch.h +17 -0
- data/vendor/libgit2/src/bswap.h +1 -1
- data/vendor/libgit2/src/buf_text.c +291 -0
- data/vendor/libgit2/src/buf_text.h +122 -0
- data/vendor/libgit2/src/buffer.c +27 -101
- data/vendor/libgit2/src/buffer.h +54 -39
- data/vendor/libgit2/src/cache.c +15 -6
- data/vendor/libgit2/src/cache.h +1 -1
- data/vendor/libgit2/src/cc-compat.h +3 -1
- data/vendor/libgit2/src/checkout.c +1165 -222
- data/vendor/libgit2/src/checkout.h +24 -0
- data/vendor/libgit2/src/clone.c +171 -86
- data/vendor/libgit2/src/commit.c +44 -45
- data/vendor/libgit2/src/commit.h +3 -3
- data/vendor/libgit2/src/commit_list.c +194 -0
- data/vendor/libgit2/src/commit_list.h +49 -0
- data/vendor/libgit2/src/common.h +44 -10
- data/vendor/libgit2/src/compress.c +1 -1
- data/vendor/libgit2/src/compress.h +1 -1
- data/vendor/libgit2/src/config.c +211 -124
- data/vendor/libgit2/src/config.h +23 -4
- data/vendor/libgit2/src/config_cache.c +2 -2
- data/vendor/libgit2/src/config_file.c +129 -53
- data/vendor/libgit2/src/config_file.h +10 -8
- data/vendor/libgit2/src/crlf.c +66 -67
- data/vendor/libgit2/src/date.c +12 -12
- data/vendor/libgit2/src/delta-apply.c +14 -1
- data/vendor/libgit2/src/delta-apply.h +18 -1
- data/vendor/libgit2/src/delta.c +40 -107
- data/vendor/libgit2/src/delta.h +19 -17
- data/vendor/libgit2/src/diff.c +347 -496
- data/vendor/libgit2/src/diff.h +27 -1
- data/vendor/libgit2/src/diff_output.c +564 -249
- data/vendor/libgit2/src/diff_output.h +15 -8
- data/vendor/libgit2/src/diff_tform.c +687 -0
- data/vendor/libgit2/src/errors.c +27 -36
- data/vendor/libgit2/src/fetch.c +13 -351
- data/vendor/libgit2/src/fetch.h +13 -3
- data/vendor/libgit2/src/fetchhead.c +295 -0
- data/vendor/libgit2/src/fetchhead.h +34 -0
- data/vendor/libgit2/src/filebuf.c +42 -15
- data/vendor/libgit2/src/filebuf.h +4 -2
- data/vendor/libgit2/src/fileops.c +466 -113
- data/vendor/libgit2/src/fileops.h +154 -28
- data/vendor/libgit2/src/filter.c +3 -75
- data/vendor/libgit2/src/filter.h +1 -29
- data/vendor/libgit2/src/fnmatch.c +1 -1
- data/vendor/libgit2/src/fnmatch.h +1 -1
- data/vendor/libgit2/src/global.c +54 -10
- data/vendor/libgit2/src/global.h +10 -1
- data/vendor/libgit2/src/graph.c +178 -0
- data/vendor/libgit2/src/hash.c +25 -52
- data/vendor/libgit2/src/hash.h +21 -9
- data/vendor/libgit2/src/{sha1/sha1.c → hash/hash_generic.c} +20 -12
- data/vendor/libgit2/src/hash/hash_generic.h +24 -0
- data/vendor/libgit2/src/hash/hash_openssl.h +45 -0
- data/vendor/libgit2/src/hash/hash_win32.c +291 -0
- data/vendor/libgit2/src/hash/hash_win32.h +140 -0
- data/vendor/libgit2/src/hashsig.c +368 -0
- data/vendor/libgit2/src/hashsig.h +72 -0
- data/vendor/libgit2/src/ignore.c +22 -15
- data/vendor/libgit2/src/ignore.h +6 -1
- data/vendor/libgit2/src/index.c +770 -171
- data/vendor/libgit2/src/index.h +13 -5
- data/vendor/libgit2/src/indexer.c +286 -431
- data/vendor/libgit2/src/iterator.c +854 -466
- data/vendor/libgit2/src/iterator.h +134 -109
- data/vendor/libgit2/src/map.h +1 -1
- data/vendor/libgit2/src/merge.c +296 -0
- data/vendor/libgit2/src/merge.h +22 -0
- data/vendor/libgit2/src/message.c +1 -1
- data/vendor/libgit2/src/message.h +1 -1
- data/vendor/libgit2/src/mwindow.c +35 -30
- data/vendor/libgit2/src/mwindow.h +2 -2
- data/vendor/libgit2/src/netops.c +162 -98
- data/vendor/libgit2/src/netops.h +50 -15
- data/vendor/libgit2/src/notes.c +109 -58
- data/vendor/libgit2/src/notes.h +2 -1
- data/vendor/libgit2/src/object.c +46 -57
- data/vendor/libgit2/src/object.h +1 -8
- data/vendor/libgit2/src/odb.c +151 -40
- data/vendor/libgit2/src/odb.h +5 -1
- data/vendor/libgit2/src/odb_loose.c +4 -5
- data/vendor/libgit2/src/odb_pack.c +122 -80
- data/vendor/libgit2/src/offmap.h +65 -0
- data/vendor/libgit2/src/oid.c +12 -4
- data/vendor/libgit2/src/oidmap.h +1 -1
- data/vendor/libgit2/src/pack-objects.c +88 -61
- data/vendor/libgit2/src/pack-objects.h +8 -8
- data/vendor/libgit2/src/pack.c +293 -28
- data/vendor/libgit2/src/pack.h +49 -4
- data/vendor/libgit2/src/path.c +103 -14
- data/vendor/libgit2/src/path.h +23 -7
- data/vendor/libgit2/src/pathspec.c +168 -0
- data/vendor/libgit2/src/pathspec.h +40 -0
- data/vendor/libgit2/src/pool.c +29 -4
- data/vendor/libgit2/src/pool.h +8 -1
- data/vendor/libgit2/src/posix.c +26 -27
- data/vendor/libgit2/src/posix.h +2 -3
- data/vendor/libgit2/src/pqueue.c +23 -1
- data/vendor/libgit2/src/pqueue.h +23 -1
- data/vendor/libgit2/src/push.c +653 -0
- data/vendor/libgit2/src/push.h +51 -0
- data/vendor/libgit2/src/refdb.c +185 -0
- data/vendor/libgit2/src/refdb.h +46 -0
- data/vendor/libgit2/src/refdb_fs.c +1024 -0
- data/vendor/libgit2/src/refdb_fs.h +15 -0
- data/vendor/libgit2/src/reflog.c +77 -45
- data/vendor/libgit2/src/reflog.h +1 -3
- data/vendor/libgit2/src/refs.c +366 -1326
- data/vendor/libgit2/src/refs.h +22 -13
- data/vendor/libgit2/src/refspec.c +46 -7
- data/vendor/libgit2/src/refspec.h +11 -1
- data/vendor/libgit2/src/remote.c +758 -120
- data/vendor/libgit2/src/remote.h +10 -5
- data/vendor/libgit2/src/repo_template.h +6 -6
- data/vendor/libgit2/src/repository.c +315 -96
- data/vendor/libgit2/src/repository.h +5 -3
- data/vendor/libgit2/src/reset.c +99 -81
- data/vendor/libgit2/src/revparse.c +157 -84
- data/vendor/libgit2/src/revwalk.c +68 -470
- data/vendor/libgit2/src/revwalk.h +44 -0
- data/vendor/libgit2/src/sha1_lookup.c +1 -1
- data/vendor/libgit2/src/sha1_lookup.h +1 -1
- data/vendor/libgit2/src/signature.c +68 -200
- data/vendor/libgit2/src/signature.h +1 -1
- data/vendor/libgit2/src/stash.c +663 -0
- data/vendor/libgit2/src/status.c +101 -79
- data/vendor/libgit2/src/strmap.h +1 -1
- data/vendor/libgit2/src/submodule.c +67 -51
- data/vendor/libgit2/src/submodule.h +1 -1
- data/vendor/libgit2/src/tag.c +35 -29
- data/vendor/libgit2/src/tag.h +1 -1
- data/vendor/libgit2/src/thread-utils.c +1 -1
- data/vendor/libgit2/src/thread-utils.h +2 -2
- data/vendor/libgit2/src/trace.c +39 -0
- data/vendor/libgit2/src/trace.h +56 -0
- data/vendor/libgit2/src/transport.c +81 -34
- data/vendor/libgit2/src/transports/cred.c +60 -0
- data/vendor/libgit2/src/transports/cred_helpers.c +49 -0
- data/vendor/libgit2/src/transports/git.c +234 -127
- data/vendor/libgit2/src/transports/http.c +761 -433
- data/vendor/libgit2/src/transports/local.c +460 -64
- data/vendor/libgit2/src/transports/smart.c +345 -0
- data/vendor/libgit2/src/transports/smart.h +179 -0
- data/vendor/libgit2/src/{pkt.c → transports/smart_pkt.c} +131 -12
- data/vendor/libgit2/src/transports/smart_protocol.c +856 -0
- data/vendor/libgit2/src/transports/winhttp.c +1136 -0
- data/vendor/libgit2/src/tree-cache.c +2 -2
- data/vendor/libgit2/src/tree-cache.h +1 -1
- data/vendor/libgit2/src/tree.c +239 -166
- data/vendor/libgit2/src/tree.h +11 -2
- data/vendor/libgit2/src/tsort.c +39 -23
- data/vendor/libgit2/src/unix/map.c +1 -1
- data/vendor/libgit2/src/unix/posix.h +12 -2
- data/vendor/libgit2/src/unix/realpath.c +30 -0
- data/vendor/libgit2/src/util.c +250 -13
- data/vendor/libgit2/src/util.h +71 -14
- data/vendor/libgit2/src/vector.c +123 -60
- data/vendor/libgit2/src/vector.h +24 -22
- data/vendor/libgit2/src/win32/dir.c +1 -1
- data/vendor/libgit2/src/win32/dir.h +1 -1
- data/vendor/libgit2/src/win32/error.c +77 -0
- data/vendor/libgit2/src/win32/error.h +13 -0
- data/vendor/libgit2/src/win32/findfile.c +143 -54
- data/vendor/libgit2/src/win32/findfile.h +10 -6
- data/vendor/libgit2/src/win32/map.c +1 -1
- data/vendor/libgit2/src/win32/mingw-compat.h +1 -1
- data/vendor/libgit2/src/win32/msvc-compat.h +10 -1
- data/vendor/libgit2/src/win32/posix.h +10 -1
- data/vendor/libgit2/src/win32/posix_w32.c +132 -63
- data/vendor/libgit2/src/win32/precompiled.c +1 -1
- data/vendor/libgit2/src/win32/pthread.c +1 -1
- data/vendor/libgit2/src/win32/pthread.h +1 -1
- data/vendor/libgit2/src/win32/utf-conv.c +5 -5
- data/vendor/libgit2/src/win32/utf-conv.h +3 -3
- data/vendor/libgit2/src/win32/version.h +20 -0
- metadata +308 -252
- data/test/fixtures/testrepo.git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
- data/test/fixtures/testrepo.git/objects/7f/043268ea43ce18e3540acaabf9e090c91965b0 +0 -0
- data/test/fixtures/testrepo.git/objects/a3/e05719b428a2d0ed7a55c4ce53dcc5768c6d5e +0 -0
- data/test/index_test.rb~ +0 -218
- data/vendor/libgit2/src/pkt.h +0 -91
- data/vendor/libgit2/src/ppc/sha1.c +0 -70
- data/vendor/libgit2/src/ppc/sha1.h +0 -26
- data/vendor/libgit2/src/protocol.c +0 -110
- data/vendor/libgit2/src/protocol.h +0 -21
- data/vendor/libgit2/src/sha1.h +0 -33
- data/vendor/libgit2/src/transport.h +0 -148
@@ -0,0 +1,345 @@
|
|
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
|
+
#include "git2.h"
|
8
|
+
#include "smart.h"
|
9
|
+
#include "refs.h"
|
10
|
+
|
11
|
+
static int git_smart__recv_cb(gitno_buffer *buf)
|
12
|
+
{
|
13
|
+
transport_smart *t = (transport_smart *) buf->cb_data;
|
14
|
+
size_t old_len, bytes_read;
|
15
|
+
int error;
|
16
|
+
|
17
|
+
assert(t->current_stream);
|
18
|
+
|
19
|
+
old_len = buf->offset;
|
20
|
+
|
21
|
+
if ((error = t->current_stream->read(t->current_stream, buf->data + buf->offset, buf->len - buf->offset, &bytes_read)) < 0)
|
22
|
+
return error;
|
23
|
+
|
24
|
+
buf->offset += bytes_read;
|
25
|
+
|
26
|
+
if (t->packetsize_cb)
|
27
|
+
t->packetsize_cb(bytes_read, t->packetsize_payload);
|
28
|
+
|
29
|
+
return (int)(buf->offset - old_len);
|
30
|
+
}
|
31
|
+
|
32
|
+
GIT_INLINE(int) git_smart__reset_stream(transport_smart *t, bool close_subtransport)
|
33
|
+
{
|
34
|
+
if (t->current_stream) {
|
35
|
+
t->current_stream->free(t->current_stream);
|
36
|
+
t->current_stream = NULL;
|
37
|
+
}
|
38
|
+
|
39
|
+
if (close_subtransport &&
|
40
|
+
t->wrapped->close(t->wrapped) < 0)
|
41
|
+
return -1;
|
42
|
+
|
43
|
+
return 0;
|
44
|
+
}
|
45
|
+
|
46
|
+
static int git_smart__set_callbacks(
|
47
|
+
git_transport *transport,
|
48
|
+
git_transport_message_cb progress_cb,
|
49
|
+
git_transport_message_cb error_cb,
|
50
|
+
void *message_cb_payload)
|
51
|
+
{
|
52
|
+
transport_smart *t = (transport_smart *)transport;
|
53
|
+
|
54
|
+
t->progress_cb = progress_cb;
|
55
|
+
t->error_cb = error_cb;
|
56
|
+
t->message_cb_payload = message_cb_payload;
|
57
|
+
|
58
|
+
return 0;
|
59
|
+
}
|
60
|
+
|
61
|
+
static int git_smart__connect(
|
62
|
+
git_transport *transport,
|
63
|
+
const char *url,
|
64
|
+
git_cred_acquire_cb cred_acquire_cb,
|
65
|
+
void *cred_acquire_payload,
|
66
|
+
int direction,
|
67
|
+
int flags)
|
68
|
+
{
|
69
|
+
transport_smart *t = (transport_smart *)transport;
|
70
|
+
git_smart_subtransport_stream *stream;
|
71
|
+
int error;
|
72
|
+
git_pkt *pkt;
|
73
|
+
git_pkt_ref *first;
|
74
|
+
git_smart_service_t service;
|
75
|
+
|
76
|
+
if (git_smart__reset_stream(t, true) < 0)
|
77
|
+
return -1;
|
78
|
+
|
79
|
+
t->url = git__strdup(url);
|
80
|
+
GITERR_CHECK_ALLOC(t->url);
|
81
|
+
|
82
|
+
t->direction = direction;
|
83
|
+
t->flags = flags;
|
84
|
+
t->cred_acquire_cb = cred_acquire_cb;
|
85
|
+
t->cred_acquire_payload = cred_acquire_payload;
|
86
|
+
|
87
|
+
if (GIT_DIRECTION_FETCH == t->direction)
|
88
|
+
service = GIT_SERVICE_UPLOADPACK_LS;
|
89
|
+
else if (GIT_DIRECTION_PUSH == t->direction)
|
90
|
+
service = GIT_SERVICE_RECEIVEPACK_LS;
|
91
|
+
else {
|
92
|
+
giterr_set(GITERR_NET, "Invalid direction");
|
93
|
+
return -1;
|
94
|
+
}
|
95
|
+
|
96
|
+
if ((error = t->wrapped->action(&stream, t->wrapped, t->url, service)) < 0)
|
97
|
+
return error;
|
98
|
+
|
99
|
+
/* Save off the current stream (i.e. socket) that we are working with */
|
100
|
+
t->current_stream = stream;
|
101
|
+
|
102
|
+
gitno_buffer_setup_callback(NULL, &t->buffer, t->buffer_data, sizeof(t->buffer_data), git_smart__recv_cb, t);
|
103
|
+
|
104
|
+
/* 2 flushes for RPC; 1 for stateful */
|
105
|
+
if ((error = git_smart__store_refs(t, t->rpc ? 2 : 1)) < 0)
|
106
|
+
return error;
|
107
|
+
|
108
|
+
/* Strip the comment packet for RPC */
|
109
|
+
if (t->rpc) {
|
110
|
+
pkt = (git_pkt *)git_vector_get(&t->refs, 0);
|
111
|
+
|
112
|
+
if (!pkt || GIT_PKT_COMMENT != pkt->type) {
|
113
|
+
giterr_set(GITERR_NET, "Invalid response");
|
114
|
+
return -1;
|
115
|
+
} else {
|
116
|
+
/* Remove the comment pkt from the list */
|
117
|
+
git_vector_remove(&t->refs, 0);
|
118
|
+
git__free(pkt);
|
119
|
+
}
|
120
|
+
}
|
121
|
+
|
122
|
+
/* We now have loaded the refs. */
|
123
|
+
t->have_refs = 1;
|
124
|
+
|
125
|
+
first = (git_pkt_ref *)git_vector_get(&t->refs, 0);
|
126
|
+
|
127
|
+
/* Detect capabilities */
|
128
|
+
if (git_smart__detect_caps(first, &t->caps) < 0)
|
129
|
+
return -1;
|
130
|
+
|
131
|
+
/* If the only ref in the list is capabilities^{} with OID_ZERO, remove it */
|
132
|
+
if (1 == t->refs.length && !strcmp(first->head.name, "capabilities^{}") &&
|
133
|
+
git_oid_iszero(&first->head.oid)) {
|
134
|
+
git_vector_clear(&t->refs);
|
135
|
+
git_pkt_free((git_pkt *)first);
|
136
|
+
}
|
137
|
+
|
138
|
+
if (t->rpc && git_smart__reset_stream(t, false) < 0)
|
139
|
+
return -1;
|
140
|
+
|
141
|
+
/* We're now logically connected. */
|
142
|
+
t->connected = 1;
|
143
|
+
|
144
|
+
return 0;
|
145
|
+
}
|
146
|
+
|
147
|
+
static int git_smart__ls(git_transport *transport, git_headlist_cb list_cb, void *payload)
|
148
|
+
{
|
149
|
+
transport_smart *t = (transport_smart *)transport;
|
150
|
+
unsigned int i;
|
151
|
+
git_pkt *p = NULL;
|
152
|
+
|
153
|
+
if (!t->have_refs) {
|
154
|
+
giterr_set(GITERR_NET, "The transport has not yet loaded the refs");
|
155
|
+
return -1;
|
156
|
+
}
|
157
|
+
|
158
|
+
git_vector_foreach(&t->refs, i, p) {
|
159
|
+
git_pkt_ref *pkt = NULL;
|
160
|
+
|
161
|
+
if (p->type != GIT_PKT_REF)
|
162
|
+
continue;
|
163
|
+
|
164
|
+
pkt = (git_pkt_ref *)p;
|
165
|
+
|
166
|
+
if (list_cb(&pkt->head, payload))
|
167
|
+
return GIT_EUSER;
|
168
|
+
}
|
169
|
+
|
170
|
+
return 0;
|
171
|
+
}
|
172
|
+
|
173
|
+
int git_smart__negotiation_step(git_transport *transport, void *data, size_t len)
|
174
|
+
{
|
175
|
+
transport_smart *t = (transport_smart *)transport;
|
176
|
+
git_smart_subtransport_stream *stream;
|
177
|
+
int error;
|
178
|
+
|
179
|
+
if (t->rpc && git_smart__reset_stream(t, false) < 0)
|
180
|
+
return -1;
|
181
|
+
|
182
|
+
if (GIT_DIRECTION_FETCH != t->direction) {
|
183
|
+
giterr_set(GITERR_NET, "This operation is only valid for fetch");
|
184
|
+
return -1;
|
185
|
+
}
|
186
|
+
|
187
|
+
if ((error = t->wrapped->action(&stream, t->wrapped, t->url, GIT_SERVICE_UPLOADPACK)) < 0)
|
188
|
+
return error;
|
189
|
+
|
190
|
+
/* If this is a stateful implementation, the stream we get back should be the same */
|
191
|
+
assert(t->rpc || t->current_stream == stream);
|
192
|
+
|
193
|
+
/* Save off the current stream (i.e. socket) that we are working with */
|
194
|
+
t->current_stream = stream;
|
195
|
+
|
196
|
+
if ((error = stream->write(stream, (const char *)data, len)) < 0)
|
197
|
+
return error;
|
198
|
+
|
199
|
+
gitno_buffer_setup_callback(NULL, &t->buffer, t->buffer_data, sizeof(t->buffer_data), git_smart__recv_cb, t);
|
200
|
+
|
201
|
+
return 0;
|
202
|
+
}
|
203
|
+
|
204
|
+
int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream **stream)
|
205
|
+
{
|
206
|
+
int error;
|
207
|
+
|
208
|
+
if (t->rpc && git_smart__reset_stream(t, false) < 0)
|
209
|
+
return -1;
|
210
|
+
|
211
|
+
if (GIT_DIRECTION_PUSH != t->direction) {
|
212
|
+
giterr_set(GITERR_NET, "This operation is only valid for push");
|
213
|
+
return -1;
|
214
|
+
}
|
215
|
+
|
216
|
+
if ((error = t->wrapped->action(stream, t->wrapped, t->url, GIT_SERVICE_RECEIVEPACK)) < 0)
|
217
|
+
return error;
|
218
|
+
|
219
|
+
/* If this is a stateful implementation, the stream we get back should be the same */
|
220
|
+
assert(t->rpc || t->current_stream == *stream);
|
221
|
+
|
222
|
+
/* Save off the current stream (i.e. socket) that we are working with */
|
223
|
+
t->current_stream = *stream;
|
224
|
+
|
225
|
+
gitno_buffer_setup_callback(NULL, &t->buffer, t->buffer_data, sizeof(t->buffer_data), git_smart__recv_cb, t);
|
226
|
+
|
227
|
+
return 0;
|
228
|
+
}
|
229
|
+
|
230
|
+
static void git_smart__cancel(git_transport *transport)
|
231
|
+
{
|
232
|
+
transport_smart *t = (transport_smart *)transport;
|
233
|
+
|
234
|
+
git_atomic_set(&t->cancelled, 1);
|
235
|
+
}
|
236
|
+
|
237
|
+
static int git_smart__is_connected(git_transport *transport)
|
238
|
+
{
|
239
|
+
transport_smart *t = (transport_smart *)transport;
|
240
|
+
|
241
|
+
return t->connected;
|
242
|
+
}
|
243
|
+
|
244
|
+
static int git_smart__read_flags(git_transport *transport, int *flags)
|
245
|
+
{
|
246
|
+
transport_smart *t = (transport_smart *)transport;
|
247
|
+
|
248
|
+
*flags = t->flags;
|
249
|
+
|
250
|
+
return 0;
|
251
|
+
}
|
252
|
+
|
253
|
+
static int git_smart__close(git_transport *transport)
|
254
|
+
{
|
255
|
+
transport_smart *t = (transport_smart *)transport;
|
256
|
+
git_vector *common = &t->common;
|
257
|
+
unsigned int i;
|
258
|
+
git_pkt *p;
|
259
|
+
int ret;
|
260
|
+
|
261
|
+
ret = git_smart__reset_stream(t, true);
|
262
|
+
|
263
|
+
git_vector_foreach(common, i, p)
|
264
|
+
git_pkt_free(p);
|
265
|
+
|
266
|
+
git_vector_free(common);
|
267
|
+
|
268
|
+
if (t->url) {
|
269
|
+
git__free(t->url);
|
270
|
+
t->url = NULL;
|
271
|
+
}
|
272
|
+
|
273
|
+
t->connected = 0;
|
274
|
+
|
275
|
+
return ret;
|
276
|
+
}
|
277
|
+
|
278
|
+
static void git_smart__free(git_transport *transport)
|
279
|
+
{
|
280
|
+
transport_smart *t = (transport_smart *)transport;
|
281
|
+
git_vector *refs = &t->refs;
|
282
|
+
unsigned int i;
|
283
|
+
git_pkt *p;
|
284
|
+
|
285
|
+
/* Make sure that the current stream is closed, if we have one. */
|
286
|
+
git_smart__close(transport);
|
287
|
+
|
288
|
+
/* Free the subtransport */
|
289
|
+
t->wrapped->free(t->wrapped);
|
290
|
+
|
291
|
+
git_vector_foreach(refs, i, p)
|
292
|
+
git_pkt_free(p);
|
293
|
+
|
294
|
+
git_vector_free(refs);
|
295
|
+
|
296
|
+
git__free(t);
|
297
|
+
}
|
298
|
+
|
299
|
+
static int ref_name_cmp(const void *a, const void *b)
|
300
|
+
{
|
301
|
+
const git_pkt_ref *ref_a = a, *ref_b = b;
|
302
|
+
|
303
|
+
return strcmp(ref_a->head.name, ref_b->head.name);
|
304
|
+
}
|
305
|
+
|
306
|
+
int git_transport_smart(git_transport **out, git_remote *owner, void *param)
|
307
|
+
{
|
308
|
+
transport_smart *t;
|
309
|
+
git_smart_subtransport_definition *definition = (git_smart_subtransport_definition *)param;
|
310
|
+
|
311
|
+
if (!param)
|
312
|
+
return -1;
|
313
|
+
|
314
|
+
t = git__calloc(sizeof(transport_smart), 1);
|
315
|
+
GITERR_CHECK_ALLOC(t);
|
316
|
+
|
317
|
+
t->parent.version = GIT_TRANSPORT_VERSION;
|
318
|
+
t->parent.set_callbacks = git_smart__set_callbacks;
|
319
|
+
t->parent.connect = git_smart__connect;
|
320
|
+
t->parent.close = git_smart__close;
|
321
|
+
t->parent.free = git_smart__free;
|
322
|
+
t->parent.negotiate_fetch = git_smart__negotiate_fetch;
|
323
|
+
t->parent.download_pack = git_smart__download_pack;
|
324
|
+
t->parent.push = git_smart__push;
|
325
|
+
t->parent.ls = git_smart__ls;
|
326
|
+
t->parent.is_connected = git_smart__is_connected;
|
327
|
+
t->parent.read_flags = git_smart__read_flags;
|
328
|
+
t->parent.cancel = git_smart__cancel;
|
329
|
+
|
330
|
+
t->owner = owner;
|
331
|
+
t->rpc = definition->rpc;
|
332
|
+
|
333
|
+
if (git_vector_init(&t->refs, 16, ref_name_cmp) < 0) {
|
334
|
+
git__free(t);
|
335
|
+
return -1;
|
336
|
+
}
|
337
|
+
|
338
|
+
if (definition->callback(&t->wrapped, &t->parent) < 0) {
|
339
|
+
git__free(t);
|
340
|
+
return -1;
|
341
|
+
}
|
342
|
+
|
343
|
+
*out = (git_transport *) t;
|
344
|
+
return 0;
|
345
|
+
}
|
@@ -0,0 +1,179 @@
|
|
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
|
+
#include "git2.h"
|
8
|
+
#include "vector.h"
|
9
|
+
#include "netops.h"
|
10
|
+
#include "buffer.h"
|
11
|
+
#include "push.h"
|
12
|
+
|
13
|
+
#define GIT_SIDE_BAND_DATA 1
|
14
|
+
#define GIT_SIDE_BAND_PROGRESS 2
|
15
|
+
#define GIT_SIDE_BAND_ERROR 3
|
16
|
+
|
17
|
+
#define GIT_CAP_OFS_DELTA "ofs-delta"
|
18
|
+
#define GIT_CAP_MULTI_ACK "multi_ack"
|
19
|
+
#define GIT_CAP_SIDE_BAND "side-band"
|
20
|
+
#define GIT_CAP_SIDE_BAND_64K "side-band-64k"
|
21
|
+
#define GIT_CAP_INCLUDE_TAG "include-tag"
|
22
|
+
#define GIT_CAP_DELETE_REFS "delete-refs"
|
23
|
+
#define GIT_CAP_REPORT_STATUS "report-status"
|
24
|
+
|
25
|
+
enum git_pkt_type {
|
26
|
+
GIT_PKT_CMD,
|
27
|
+
GIT_PKT_FLUSH,
|
28
|
+
GIT_PKT_REF,
|
29
|
+
GIT_PKT_HAVE,
|
30
|
+
GIT_PKT_ACK,
|
31
|
+
GIT_PKT_NAK,
|
32
|
+
GIT_PKT_PACK,
|
33
|
+
GIT_PKT_COMMENT,
|
34
|
+
GIT_PKT_ERR,
|
35
|
+
GIT_PKT_DATA,
|
36
|
+
GIT_PKT_PROGRESS,
|
37
|
+
GIT_PKT_OK,
|
38
|
+
GIT_PKT_NG,
|
39
|
+
GIT_PKT_UNPACK,
|
40
|
+
};
|
41
|
+
|
42
|
+
/* Used for multi-ack */
|
43
|
+
enum git_ack_status {
|
44
|
+
GIT_ACK_NONE,
|
45
|
+
GIT_ACK_CONTINUE,
|
46
|
+
GIT_ACK_COMMON,
|
47
|
+
GIT_ACK_READY
|
48
|
+
};
|
49
|
+
|
50
|
+
/* This would be a flush pkt */
|
51
|
+
typedef struct {
|
52
|
+
enum git_pkt_type type;
|
53
|
+
} git_pkt;
|
54
|
+
|
55
|
+
struct git_pkt_cmd {
|
56
|
+
enum git_pkt_type type;
|
57
|
+
char *cmd;
|
58
|
+
char *path;
|
59
|
+
char *host;
|
60
|
+
};
|
61
|
+
|
62
|
+
/* This is a pkt-line with some info in it */
|
63
|
+
typedef struct {
|
64
|
+
enum git_pkt_type type;
|
65
|
+
git_remote_head head;
|
66
|
+
char *capabilities;
|
67
|
+
} git_pkt_ref;
|
68
|
+
|
69
|
+
/* Useful later */
|
70
|
+
typedef struct {
|
71
|
+
enum git_pkt_type type;
|
72
|
+
git_oid oid;
|
73
|
+
enum git_ack_status status;
|
74
|
+
} git_pkt_ack;
|
75
|
+
|
76
|
+
typedef struct {
|
77
|
+
enum git_pkt_type type;
|
78
|
+
char comment[GIT_FLEX_ARRAY];
|
79
|
+
} git_pkt_comment;
|
80
|
+
|
81
|
+
typedef struct {
|
82
|
+
enum git_pkt_type type;
|
83
|
+
int len;
|
84
|
+
char data[GIT_FLEX_ARRAY];
|
85
|
+
} git_pkt_data;
|
86
|
+
|
87
|
+
typedef git_pkt_data git_pkt_progress;
|
88
|
+
|
89
|
+
typedef struct {
|
90
|
+
enum git_pkt_type type;
|
91
|
+
int len;
|
92
|
+
char error[GIT_FLEX_ARRAY];
|
93
|
+
} git_pkt_err;
|
94
|
+
|
95
|
+
typedef struct {
|
96
|
+
enum git_pkt_type type;
|
97
|
+
char *ref;
|
98
|
+
} git_pkt_ok;
|
99
|
+
|
100
|
+
typedef struct {
|
101
|
+
enum git_pkt_type type;
|
102
|
+
char *ref;
|
103
|
+
char *msg;
|
104
|
+
} git_pkt_ng;
|
105
|
+
|
106
|
+
typedef struct {
|
107
|
+
enum git_pkt_type type;
|
108
|
+
int unpack_ok;
|
109
|
+
} git_pkt_unpack;
|
110
|
+
|
111
|
+
typedef struct transport_smart_caps {
|
112
|
+
int common:1,
|
113
|
+
ofs_delta:1,
|
114
|
+
multi_ack: 1,
|
115
|
+
side_band:1,
|
116
|
+
side_band_64k:1,
|
117
|
+
include_tag:1,
|
118
|
+
delete_refs:1,
|
119
|
+
report_status:1;
|
120
|
+
} transport_smart_caps;
|
121
|
+
|
122
|
+
typedef void (*packetsize_cb)(size_t received, void *payload);
|
123
|
+
|
124
|
+
typedef struct {
|
125
|
+
git_transport parent;
|
126
|
+
git_remote *owner;
|
127
|
+
char *url;
|
128
|
+
git_cred_acquire_cb cred_acquire_cb;
|
129
|
+
void *cred_acquire_payload;
|
130
|
+
int direction;
|
131
|
+
int flags;
|
132
|
+
git_transport_message_cb progress_cb;
|
133
|
+
git_transport_message_cb error_cb;
|
134
|
+
void *message_cb_payload;
|
135
|
+
git_smart_subtransport *wrapped;
|
136
|
+
git_smart_subtransport_stream *current_stream;
|
137
|
+
transport_smart_caps caps;
|
138
|
+
git_vector refs;
|
139
|
+
git_vector common;
|
140
|
+
git_atomic cancelled;
|
141
|
+
packetsize_cb packetsize_cb;
|
142
|
+
void *packetsize_payload;
|
143
|
+
unsigned rpc : 1,
|
144
|
+
have_refs : 1,
|
145
|
+
connected : 1;
|
146
|
+
gitno_buffer buffer;
|
147
|
+
char buffer_data[65536];
|
148
|
+
} transport_smart;
|
149
|
+
|
150
|
+
/* smart_protocol.c */
|
151
|
+
int git_smart__store_refs(transport_smart *t, int flushes);
|
152
|
+
int git_smart__detect_caps(git_pkt_ref *pkt, transport_smart_caps *caps);
|
153
|
+
int git_smart__push(git_transport *transport, git_push *push);
|
154
|
+
|
155
|
+
int git_smart__negotiate_fetch(
|
156
|
+
git_transport *transport,
|
157
|
+
git_repository *repo,
|
158
|
+
const git_remote_head * const *refs,
|
159
|
+
size_t count);
|
160
|
+
|
161
|
+
int git_smart__download_pack(
|
162
|
+
git_transport *transport,
|
163
|
+
git_repository *repo,
|
164
|
+
git_transfer_progress *stats,
|
165
|
+
git_transfer_progress_callback progress_cb,
|
166
|
+
void *progress_payload);
|
167
|
+
|
168
|
+
/* smart.c */
|
169
|
+
int git_smart__negotiation_step(git_transport *transport, void *data, size_t len);
|
170
|
+
int git_smart__get_push_stream(transport_smart *t, git_smart_subtransport_stream **out);
|
171
|
+
|
172
|
+
/* smart_pkt.c */
|
173
|
+
int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t len);
|
174
|
+
int git_pkt_buffer_flush(git_buf *buf);
|
175
|
+
int git_pkt_send_flush(GIT_SOCKET s);
|
176
|
+
int git_pkt_buffer_done(git_buf *buf);
|
177
|
+
int git_pkt_buffer_wants(const git_remote_head * const *refs, size_t count, transport_smart_caps *caps, git_buf *buf);
|
178
|
+
int git_pkt_buffer_have(git_oid *oid, git_buf *buf);
|
179
|
+
void git_pkt_free(git_pkt *pkt);
|