rugged 0.1.2 → 0.16.0b1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +25 -36
- data/Rakefile +20 -98
- data/ext/rugged/extconf.rb +44 -4
- data/ext/rugged/remote.c +215 -0
- data/ext/rugged/rugged.c +171 -0
- data/ext/rugged/rugged.h +126 -0
- data/ext/rugged/rugged_blob.c +99 -0
- data/ext/rugged/rugged_commit.c +224 -0
- data/ext/rugged/rugged_config.c +238 -0
- data/ext/rugged/rugged_index.c +440 -0
- data/ext/rugged/rugged_object.c +203 -0
- data/ext/rugged/rugged_reference.c +401 -0
- data/ext/rugged/rugged_repo.c +482 -0
- data/ext/rugged/rugged_revwalk.c +138 -0
- data/ext/rugged/rugged_signature.c +80 -0
- data/ext/rugged/rugged_tag.c +216 -0
- data/ext/rugged/rugged_tree.c +322 -0
- data/ext/rugged/vendor/libgit2-dist.tar.gz +0 -0
- data/ext/rugged/vendor/libgit2-dist/deps/http-parser/http_parser.c +1778 -0
- data/ext/rugged/vendor/libgit2-dist/deps/http-parser/http_parser.h +267 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/adler32.c +169 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/crc32.c +442 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/crc32.h +441 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/deflate.c +1834 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/deflate.h +342 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffast.c +340 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffast.h +11 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffixed.h +94 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inflate.c +1480 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inflate.h +122 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inftrees.c +330 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inftrees.h +62 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/trees.c +1244 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/trees.h +128 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/zconf.h +54 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/zlib.h +1613 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/zutil.c +318 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/zutil.h +274 -0
- data/ext/rugged/vendor/libgit2-dist/examples/general.c +451 -0
- data/ext/rugged/vendor/libgit2-dist/examples/network/common.h +14 -0
- data/ext/rugged/vendor/libgit2-dist/examples/network/fetch.c +97 -0
- data/ext/rugged/vendor/libgit2-dist/examples/network/git2.c +58 -0
- data/ext/rugged/vendor/libgit2-dist/examples/network/index-pack.c +47 -0
- data/ext/rugged/vendor/libgit2-dist/examples/network/ls-remote.c +76 -0
- data/ext/rugged/vendor/libgit2-dist/examples/showindex.c +43 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2.h +44 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/blob.h +120 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/branch.h +15 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/commit.h +263 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/common.h +103 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/config.h +278 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/errors.h +144 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/index.h +306 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/indexer.h +76 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/inttypes.h +305 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/net.h +51 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/object.h +173 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/odb.h +331 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/odb_backend.h +100 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/oid.h +218 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/reflog.h +128 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/refs.h +309 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/refspec.h +60 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/remote.h +176 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/repository.h +290 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/revwalk.h +169 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/signature.h +65 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/status.h +63 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/stdint.h +247 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/tag.h +279 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/threads.h +48 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/tree.h +318 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/types.h +169 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/version.h +15 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/windows.h +59 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/zlib.h +40 -0
- data/ext/rugged/vendor/libgit2-dist/src/blob.c +135 -0
- data/ext/rugged/vendor/libgit2-dist/src/blob.h +23 -0
- data/ext/rugged/vendor/libgit2-dist/src/bswap.h +97 -0
- data/ext/rugged/vendor/libgit2-dist/src/buffer.c +113 -0
- data/ext/rugged/vendor/libgit2-dist/src/buffer.h +32 -0
- data/ext/rugged/vendor/libgit2-dist/src/cache.c +111 -0
- data/ext/rugged/vendor/libgit2-dist/src/cache.h +64 -0
- data/ext/rugged/vendor/libgit2-dist/src/cc-compat.h +67 -0
- data/ext/rugged/vendor/libgit2-dist/src/commit.c +299 -0
- data/ext/rugged/vendor/libgit2-dist/src/commit.h +34 -0
- data/ext/rugged/vendor/libgit2-dist/src/common.h +64 -0
- data/ext/rugged/vendor/libgit2-dist/src/config.c +418 -0
- data/ext/rugged/vendor/libgit2-dist/src/config.h +24 -0
- data/ext/rugged/vendor/libgit2-dist/src/config_file.c +1210 -0
- data/ext/rugged/vendor/libgit2-dist/src/delta-apply.c +115 -0
- data/ext/rugged/vendor/libgit2-dist/src/delta-apply.h +33 -0
- data/ext/rugged/vendor/libgit2-dist/src/dir.h +47 -0
- data/ext/rugged/vendor/libgit2-dist/src/errors.c +104 -0
- data/ext/rugged/vendor/libgit2-dist/src/fetch.c +172 -0
- data/ext/rugged/vendor/libgit2-dist/src/fetch.h +18 -0
- data/ext/rugged/vendor/libgit2-dist/src/filebuf.c +400 -0
- data/ext/rugged/vendor/libgit2-dist/src/filebuf.h +72 -0
- data/ext/rugged/vendor/libgit2-dist/src/fileops.c +358 -0
- data/ext/rugged/vendor/libgit2-dist/src/fileops.h +151 -0
- data/ext/rugged/vendor/libgit2-dist/src/global.c +134 -0
- data/ext/rugged/vendor/libgit2-dist/src/global.h +24 -0
- data/ext/rugged/vendor/libgit2-dist/src/hash.c +74 -0
- data/ext/rugged/vendor/libgit2-dist/src/hash.h +29 -0
- data/ext/rugged/vendor/libgit2-dist/src/hashtable.c +243 -0
- data/ext/rugged/vendor/libgit2-dist/src/hashtable.h +80 -0
- data/ext/rugged/vendor/libgit2-dist/src/index.c +918 -0
- data/ext/rugged/vendor/libgit2-dist/src/index.h +34 -0
- data/ext/rugged/vendor/libgit2-dist/src/indexer.c +401 -0
- data/ext/rugged/vendor/libgit2-dist/src/map.h +37 -0
- data/ext/rugged/vendor/libgit2-dist/src/mwindow.c +272 -0
- data/ext/rugged/vendor/libgit2-dist/src/mwindow.h +45 -0
- data/ext/rugged/vendor/libgit2-dist/src/netops.c +198 -0
- data/ext/rugged/vendor/libgit2-dist/src/netops.h +36 -0
- data/ext/rugged/vendor/libgit2-dist/src/object.c +295 -0
- data/ext/rugged/vendor/libgit2-dist/src/odb.c +672 -0
- data/ext/rugged/vendor/libgit2-dist/src/odb.h +43 -0
- data/ext/rugged/vendor/libgit2-dist/src/odb_loose.c +855 -0
- data/ext/rugged/vendor/libgit2-dist/src/odb_pack.c +485 -0
- data/ext/rugged/vendor/libgit2-dist/src/oid.c +388 -0
- data/ext/rugged/vendor/libgit2-dist/src/pack.c +788 -0
- data/ext/rugged/vendor/libgit2-dist/src/pack.h +99 -0
- data/ext/rugged/vendor/libgit2-dist/src/path.c +270 -0
- data/ext/rugged/vendor/libgit2-dist/src/path.h +84 -0
- data/ext/rugged/vendor/libgit2-dist/src/pkt.c +426 -0
- data/ext/rugged/vendor/libgit2-dist/src/pkt.h +77 -0
- data/ext/rugged/vendor/libgit2-dist/src/posix.c +94 -0
- data/ext/rugged/vendor/libgit2-dist/src/posix.h +69 -0
- data/ext/rugged/vendor/libgit2-dist/src/ppc/sha1.c +70 -0
- data/ext/rugged/vendor/libgit2-dist/src/ppc/sha1.h +26 -0
- data/ext/rugged/vendor/libgit2-dist/src/pqueue.c +141 -0
- data/ext/rugged/vendor/libgit2-dist/src/pqueue.h +81 -0
- data/ext/rugged/vendor/libgit2-dist/src/protocol.c +50 -0
- data/ext/rugged/vendor/libgit2-dist/src/protocol.h +23 -0
- data/ext/rugged/vendor/libgit2-dist/src/reflog.c +318 -0
- data/ext/rugged/vendor/libgit2-dist/src/reflog.h +34 -0
- data/ext/rugged/vendor/libgit2-dist/src/refs.c +1693 -0
- data/ext/rugged/vendor/libgit2-dist/src/refs.h +58 -0
- data/ext/rugged/vendor/libgit2-dist/src/refspec.c +95 -0
- data/ext/rugged/vendor/libgit2-dist/src/refspec.h +23 -0
- data/ext/rugged/vendor/libgit2-dist/src/remote.c +339 -0
- data/ext/rugged/vendor/libgit2-dist/src/remote.h +25 -0
- data/ext/rugged/vendor/libgit2-dist/src/repository.c +849 -0
- data/ext/rugged/vendor/libgit2-dist/src/repository.h +60 -0
- data/ext/rugged/vendor/libgit2-dist/src/revwalk.c +569 -0
- data/ext/rugged/vendor/libgit2-dist/src/sha1.c +280 -0
- data/ext/rugged/vendor/libgit2-dist/src/sha1.h +21 -0
- data/ext/rugged/vendor/libgit2-dist/src/sha1_lookup.c +177 -0
- data/ext/rugged/vendor/libgit2-dist/src/sha1_lookup.h +18 -0
- data/ext/rugged/vendor/libgit2-dist/src/signature.c +335 -0
- data/ext/rugged/vendor/libgit2-dist/src/signature.h +18 -0
- data/ext/rugged/vendor/libgit2-dist/src/status.c +696 -0
- data/ext/rugged/vendor/libgit2-dist/src/tag.c +446 -0
- data/ext/rugged/vendor/libgit2-dist/src/tag.h +28 -0
- data/ext/rugged/vendor/libgit2-dist/src/thread-utils.c +55 -0
- data/ext/rugged/vendor/libgit2-dist/src/thread-utils.h +108 -0
- data/ext/rugged/vendor/libgit2-dist/src/transport.c +85 -0
- data/ext/rugged/vendor/libgit2-dist/src/transport.h +110 -0
- data/ext/rugged/vendor/libgit2-dist/src/transports/git.c +502 -0
- data/ext/rugged/vendor/libgit2-dist/src/transports/http.c +756 -0
- data/ext/rugged/vendor/libgit2-dist/src/transports/local.c +235 -0
- data/ext/rugged/vendor/libgit2-dist/src/tree-cache.c +201 -0
- data/ext/rugged/vendor/libgit2-dist/src/tree-cache.h +31 -0
- data/ext/rugged/vendor/libgit2-dist/src/tree.c +758 -0
- data/ext/rugged/vendor/libgit2-dist/src/tree.h +37 -0
- data/ext/rugged/vendor/libgit2-dist/src/tsort.c +365 -0
- data/ext/rugged/vendor/libgit2-dist/src/unix/map.c +70 -0
- data/ext/rugged/vendor/libgit2-dist/src/unix/posix.h +25 -0
- data/ext/rugged/vendor/libgit2-dist/src/util.c +381 -0
- data/ext/rugged/vendor/libgit2-dist/src/util.h +137 -0
- data/ext/rugged/vendor/libgit2-dist/src/vector.c +174 -0
- data/ext/rugged/vendor/libgit2-dist/src/vector.h +45 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/dir.c +115 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/fnmatch.c +180 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/fnmatch.h +27 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/map.c +131 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/mingw-compat.h +24 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/msvc-compat.h +38 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/posix.h +53 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/posix_w32.c +404 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/pthread.c +65 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/pthread.h +40 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/utf-conv.c +88 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/utf-conv.h +17 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/buf/basic.c +29 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/clay.h +187 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/clay_libgit2.h +28 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/clay_main.c +1073 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/config/add.c +37 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/config/new.c +36 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/config/read.c +209 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/config/stress.c +39 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/config/write.c +77 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/dirent.c +222 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/filebuf.c +106 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/oid.c +18 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/path.c +139 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/rmdir.c +50 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/string.c +28 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/strtol.c +37 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/vector.c +66 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/index/rename.c +60 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/network/remotes.c +50 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/chars.c +52 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/compare.c +124 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/convert.c +75 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/data.h +323 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/fromstr.c +30 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/hash.c +162 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/short.c +94 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/size.c +13 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/type2string.c +54 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/tree/frompath.c +75 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/loose.c +84 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/loose_data.h +522 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/pack_data.h +151 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/packed.c +78 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/sorting.c +71 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/getters.c +68 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/init.c +104 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/open.c +54 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/status/single.c +38 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/status/status_data.h +48 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/status/worktree.c +124 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t00-core.c +628 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t01-data.h +322 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t01-rawobj.c +638 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t03-data.h +344 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t03-objwrite.c +255 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t04-commit.c +788 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t05-revwalk.c +140 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t06-index.c +219 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t07-hashtable.c +192 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t08-tag.c +357 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t09-tree.c +221 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t10-refs.c +1294 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t12-repo.c +174 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t13-threads.c +41 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t17-bufs.c +61 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t18-status.c +448 -0
- data/ext/rugged/vendor/libgit2-dist/tests/test_helpers.c +310 -0
- data/ext/rugged/vendor/libgit2-dist/tests/test_helpers.h +83 -0
- data/ext/rugged/vendor/libgit2-dist/tests/test_lib.c +198 -0
- data/ext/rugged/vendor/libgit2-dist/tests/test_lib.h +54 -0
- data/ext/rugged/vendor/libgit2-dist/tests/test_main.c +89 -0
- data/lib/rugged.rb +4 -3
- data/lib/rugged/index.rb +0 -8
- data/lib/rugged/objects.rb +45 -0
- data/lib/rugged/repository.rb +29 -0
- data/lib/rugged/tree.rb +16 -6
- data/lib/rugged/version.rb +1 -1
- data/lib/rugged/walker.rb +5 -0
- data/test/blob_test.rb +18 -14
- data/test/commit_test.rb +28 -26
- data/test/coverage/HEAD.json +1 -0
- data/test/coverage/cover.rb +106 -0
- data/test/fixtures/testrepo.git/refs/heads/new_name +1 -0
- data/test/index_test.rb +101 -78
- data/test/lib_test.rb +4 -4
- data/test/object_test.rb +3 -3
- data/test/reference_test.rb +75 -0
- data/test/remote_test.rb +19 -0
- data/test/repo_pack_test.rb +4 -4
- data/test/repo_test.rb +44 -15
- data/test/tag_test.rb +7 -17
- data/test/test_helper.rb +24 -5
- data/test/tree_test.rb +30 -12
- data/test/walker_test.rb +40 -31
- metadata +273 -50
- data/lib/rugged/person.rb +0 -20
- data/lib/rugged/tree_entry.rb +0 -9
- data/test/fixtures/testrepo.git/objects/1d/83f106355e4309a293e42ad2a2c4b8bdbe77ae +0 -0
- data/test/fixtures/testrepo.git/objects/2f/3321418db5b2a841375b8b70880a8ab5a4148f +0 -0
- data/test/fixtures/testrepo.git/objects/36/9b00a7700cca3a506d79e301d6ad8bf735d9ee +0 -3
- data/test/fixtures/testrepo.git/objects/3d/b1b5ceace59ff65279757003763046fd4cbbe6 +0 -0
- data/test/fixtures/testrepo.git/objects/4c/d1604907792e2c43e03dcec1216f99d63e68c4 +0 -3
- data/test/fixtures/testrepo.git/objects/e0/f46d77041c149296549b01ed4a18b02c4b7400 +0 -0
@@ -0,0 +1,756 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2009-2011 the libgit2 contributors
|
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
|
+
|
8
|
+
#include <stdlib.h>
|
9
|
+
#include "git2.h"
|
10
|
+
#include "http_parser.h"
|
11
|
+
|
12
|
+
#include "transport.h"
|
13
|
+
#include "common.h"
|
14
|
+
#include "netops.h"
|
15
|
+
#include "buffer.h"
|
16
|
+
#include "pkt.h"
|
17
|
+
#include "refs.h"
|
18
|
+
#include "pack.h"
|
19
|
+
#include "fetch.h"
|
20
|
+
#include "filebuf.h"
|
21
|
+
#include "repository.h"
|
22
|
+
#include "protocol.h"
|
23
|
+
|
24
|
+
enum last_cb {
|
25
|
+
NONE,
|
26
|
+
FIELD,
|
27
|
+
VALUE
|
28
|
+
};
|
29
|
+
|
30
|
+
typedef struct {
|
31
|
+
git_transport parent;
|
32
|
+
git_protocol proto;
|
33
|
+
git_vector refs;
|
34
|
+
git_vector common;
|
35
|
+
int socket;
|
36
|
+
git_buf buf;
|
37
|
+
git_remote_head **heads;
|
38
|
+
int error;
|
39
|
+
int transfer_finished :1,
|
40
|
+
ct_found :1,
|
41
|
+
ct_finished :1,
|
42
|
+
pack_ready :1;
|
43
|
+
enum last_cb last_cb;
|
44
|
+
http_parser parser;
|
45
|
+
char *content_type;
|
46
|
+
char *host;
|
47
|
+
char *port;
|
48
|
+
char *service;
|
49
|
+
git_transport_caps caps;
|
50
|
+
#ifdef GIT_WIN32
|
51
|
+
WSADATA wsd;
|
52
|
+
#endif
|
53
|
+
} transport_http;
|
54
|
+
|
55
|
+
static int gen_request(git_buf *buf, const char *url, const char *host, const char *op,
|
56
|
+
const char *service, ssize_t content_length, int ls)
|
57
|
+
{
|
58
|
+
const char *path = url;
|
59
|
+
|
60
|
+
path = strchr(path, '/');
|
61
|
+
if (path == NULL) /* Is 'git fetch http://host.com/' valid? */
|
62
|
+
path = "/";
|
63
|
+
|
64
|
+
if (ls) {
|
65
|
+
git_buf_printf(buf, "%s %s/info/refs?service=git-%s HTTP/1.1\r\n", op, path, service);
|
66
|
+
} else {
|
67
|
+
git_buf_printf(buf, "%s %s/git-%s HTTP/1.1\r\n", op, path, service);
|
68
|
+
}
|
69
|
+
git_buf_puts(buf, "User-Agent: git/1.0 (libgit2 " LIBGIT2_VERSION ")\r\n");
|
70
|
+
git_buf_printf(buf, "Host: %s\r\n", host);
|
71
|
+
if (content_length > 0) {
|
72
|
+
git_buf_printf(buf, "Accept: application/x-git-%s-result\r\n", service);
|
73
|
+
git_buf_printf(buf, "Content-Type: application/x-git-%s-request\r\n", service);
|
74
|
+
git_buf_printf(buf, "Content-Length: %zd\r\n", content_length);
|
75
|
+
} else {
|
76
|
+
git_buf_puts(buf, "Accept: */*\r\n");
|
77
|
+
}
|
78
|
+
git_buf_puts(buf, "\r\n");
|
79
|
+
|
80
|
+
if (git_buf_oom(buf))
|
81
|
+
return GIT_ENOMEM;
|
82
|
+
|
83
|
+
return GIT_SUCCESS;
|
84
|
+
}
|
85
|
+
|
86
|
+
static int do_connect(transport_http *t, const char *host, const char *port)
|
87
|
+
{
|
88
|
+
GIT_SOCKET s = -1;
|
89
|
+
|
90
|
+
if (t->parent.connected && http_should_keep_alive(&t->parser))
|
91
|
+
return GIT_SUCCESS;
|
92
|
+
|
93
|
+
s = gitno_connect(host, port);
|
94
|
+
if (s < GIT_SUCCESS) {
|
95
|
+
return git__rethrow(s, "Failed to connect to host");
|
96
|
+
}
|
97
|
+
t->socket = s;
|
98
|
+
t->parent.connected = 1;
|
99
|
+
|
100
|
+
return GIT_SUCCESS;
|
101
|
+
}
|
102
|
+
|
103
|
+
/*
|
104
|
+
* The HTTP parser is streaming, so we need to wait until we're in the
|
105
|
+
* field handler before we can be sure that we can store the previous
|
106
|
+
* value. Right now, we only care about the
|
107
|
+
* Content-Type. on_header_{field,value} should be kept generic enough
|
108
|
+
* to work for any request.
|
109
|
+
*/
|
110
|
+
|
111
|
+
static const char *typestr = "Content-Type";
|
112
|
+
|
113
|
+
static int on_header_field(http_parser *parser, const char *str, size_t len)
|
114
|
+
{
|
115
|
+
transport_http *t = (transport_http *) parser->data;
|
116
|
+
git_buf *buf = &t->buf;
|
117
|
+
|
118
|
+
if (t->last_cb == VALUE && t->ct_found) {
|
119
|
+
t->ct_finished = 1;
|
120
|
+
t->ct_found = 0;
|
121
|
+
t->content_type = git__strdup(git_buf_cstr(buf));
|
122
|
+
if (t->content_type == NULL)
|
123
|
+
return t->error = GIT_ENOMEM;
|
124
|
+
git_buf_clear(buf);
|
125
|
+
}
|
126
|
+
|
127
|
+
if (t->ct_found) {
|
128
|
+
t->last_cb = FIELD;
|
129
|
+
return 0;
|
130
|
+
}
|
131
|
+
|
132
|
+
if (t->last_cb != FIELD)
|
133
|
+
git_buf_clear(buf);
|
134
|
+
|
135
|
+
git_buf_put(buf, str, len);
|
136
|
+
t->last_cb = FIELD;
|
137
|
+
|
138
|
+
return git_buf_oom(buf);
|
139
|
+
}
|
140
|
+
|
141
|
+
static int on_header_value(http_parser *parser, const char *str, size_t len)
|
142
|
+
{
|
143
|
+
transport_http *t = (transport_http *) parser->data;
|
144
|
+
git_buf *buf = &t->buf;
|
145
|
+
|
146
|
+
if (t->ct_finished) {
|
147
|
+
t->last_cb = VALUE;
|
148
|
+
return 0;
|
149
|
+
}
|
150
|
+
|
151
|
+
if (t->last_cb == VALUE)
|
152
|
+
git_buf_put(buf, str, len);
|
153
|
+
|
154
|
+
if (t->last_cb == FIELD && !strcmp(git_buf_cstr(buf), typestr)) {
|
155
|
+
t->ct_found = 1;
|
156
|
+
git_buf_clear(buf);
|
157
|
+
git_buf_put(buf, str, len);
|
158
|
+
}
|
159
|
+
|
160
|
+
t->last_cb = VALUE;
|
161
|
+
|
162
|
+
return git_buf_oom(buf);
|
163
|
+
}
|
164
|
+
|
165
|
+
static int on_headers_complete(http_parser *parser)
|
166
|
+
{
|
167
|
+
transport_http *t = (transport_http *) parser->data;
|
168
|
+
git_buf *buf = &t->buf;
|
169
|
+
|
170
|
+
if (t->content_type == NULL) {
|
171
|
+
t->content_type = git__strdup(git_buf_cstr(buf));
|
172
|
+
if (t->content_type == NULL)
|
173
|
+
return t->error = GIT_ENOMEM;
|
174
|
+
}
|
175
|
+
|
176
|
+
git_buf_clear(buf);
|
177
|
+
git_buf_printf(buf, "application/x-git-%s-advertisement", t->service);
|
178
|
+
if (git_buf_oom(buf))
|
179
|
+
return GIT_ENOMEM;
|
180
|
+
|
181
|
+
if (strcmp(t->content_type, git_buf_cstr(buf)))
|
182
|
+
return t->error = git__throw(GIT_EOBJCORRUPTED, "Content-Type '%s' is wrong", t->content_type);
|
183
|
+
|
184
|
+
git_buf_clear(buf);
|
185
|
+
return 0;
|
186
|
+
}
|
187
|
+
|
188
|
+
static int on_body_store_refs(http_parser *parser, const char *str, size_t len)
|
189
|
+
{
|
190
|
+
transport_http *t = (transport_http *) parser->data;
|
191
|
+
|
192
|
+
return git_protocol_store_refs(&t->proto, str, len);
|
193
|
+
}
|
194
|
+
|
195
|
+
static int on_message_complete(http_parser *parser)
|
196
|
+
{
|
197
|
+
transport_http *t = (transport_http *) parser->data;
|
198
|
+
|
199
|
+
t->transfer_finished = 1;
|
200
|
+
return 0;
|
201
|
+
}
|
202
|
+
|
203
|
+
static int store_refs(transport_http *t)
|
204
|
+
{
|
205
|
+
int error = GIT_SUCCESS;
|
206
|
+
http_parser_settings settings;
|
207
|
+
char buffer[1024];
|
208
|
+
gitno_buffer buf;
|
209
|
+
git_pkt *pkt;
|
210
|
+
|
211
|
+
http_parser_init(&t->parser, HTTP_RESPONSE);
|
212
|
+
t->parser.data = t;
|
213
|
+
memset(&settings, 0x0, sizeof(http_parser_settings));
|
214
|
+
settings.on_header_field = on_header_field;
|
215
|
+
settings.on_header_value = on_header_value;
|
216
|
+
settings.on_headers_complete = on_headers_complete;
|
217
|
+
settings.on_body = on_body_store_refs;
|
218
|
+
settings.on_message_complete = on_message_complete;
|
219
|
+
|
220
|
+
gitno_buffer_setup(&buf, buffer, sizeof(buffer), t->socket);
|
221
|
+
|
222
|
+
while(1) {
|
223
|
+
size_t parsed;
|
224
|
+
|
225
|
+
error = gitno_recv(&buf);
|
226
|
+
if (error < GIT_SUCCESS)
|
227
|
+
return git__rethrow(error, "Error receiving data from network");
|
228
|
+
|
229
|
+
parsed = http_parser_execute(&t->parser, &settings, buf.data, buf.offset);
|
230
|
+
/* Both should happen at the same time */
|
231
|
+
if (parsed != buf.offset || t->error < GIT_SUCCESS)
|
232
|
+
return git__rethrow(t->error, "Error parsing HTTP data");
|
233
|
+
|
234
|
+
gitno_consume_n(&buf, parsed);
|
235
|
+
|
236
|
+
if (error == 0 || t->transfer_finished)
|
237
|
+
return GIT_SUCCESS;
|
238
|
+
}
|
239
|
+
|
240
|
+
pkt = git_vector_get(&t->refs, 0);
|
241
|
+
if (pkt == NULL || pkt->type != GIT_PKT_COMMENT)
|
242
|
+
return t->error = git__throw(GIT_EOBJCORRUPTED, "Not a valid smart HTTP response");
|
243
|
+
else
|
244
|
+
git_vector_remove(&t->refs, 0);
|
245
|
+
|
246
|
+
return error;
|
247
|
+
}
|
248
|
+
|
249
|
+
static int http_connect(git_transport *transport, int direction)
|
250
|
+
{
|
251
|
+
transport_http *t = (transport_http *) transport;
|
252
|
+
int error;
|
253
|
+
git_buf request = GIT_BUF_INIT;
|
254
|
+
const char *service = "upload-pack";
|
255
|
+
const char *url = t->parent.url, *prefix = "http://";
|
256
|
+
|
257
|
+
if (direction == GIT_DIR_PUSH)
|
258
|
+
return git__throw(GIT_EINVALIDARGS, "Pushing over HTTP is not supported");
|
259
|
+
|
260
|
+
t->parent.direction = direction;
|
261
|
+
error = git_vector_init(&t->refs, 16, NULL);
|
262
|
+
if (error < GIT_SUCCESS)
|
263
|
+
return git__rethrow(error, "Failed to init refs vector");
|
264
|
+
|
265
|
+
if (!git__prefixcmp(url, prefix))
|
266
|
+
url += strlen(prefix);
|
267
|
+
|
268
|
+
error = gitno_extract_host_and_port(&t->host, &t->port, url, "80");
|
269
|
+
if (error < GIT_SUCCESS)
|
270
|
+
goto cleanup;
|
271
|
+
|
272
|
+
t->service = git__strdup(service);
|
273
|
+
if (t->service == NULL) {
|
274
|
+
error = GIT_ENOMEM;
|
275
|
+
goto cleanup;
|
276
|
+
}
|
277
|
+
|
278
|
+
error = do_connect(t, t->host, t->port);
|
279
|
+
if (error < GIT_SUCCESS) {
|
280
|
+
error = git__rethrow(error, "Failed to connect to host");
|
281
|
+
goto cleanup;
|
282
|
+
}
|
283
|
+
|
284
|
+
/* Generate and send the HTTP request */
|
285
|
+
error = gen_request(&request, url, t->host, "GET", service, 0, 1);
|
286
|
+
if (error < GIT_SUCCESS) {
|
287
|
+
error = git__throw(error, "Failed to generate request");
|
288
|
+
goto cleanup;
|
289
|
+
}
|
290
|
+
|
291
|
+
error = gitno_send(t->socket, request.ptr, request.size, 0);
|
292
|
+
if (error < GIT_SUCCESS)
|
293
|
+
error = git__rethrow(error, "Failed to send the HTTP request");
|
294
|
+
|
295
|
+
error = store_refs(t);
|
296
|
+
|
297
|
+
cleanup:
|
298
|
+
git_buf_free(&request);
|
299
|
+
git_buf_clear(&t->buf);
|
300
|
+
|
301
|
+
return error;
|
302
|
+
}
|
303
|
+
|
304
|
+
static int http_ls(git_transport *transport, git_headlist_cb list_cb, void *opaque)
|
305
|
+
{
|
306
|
+
transport_http *t = (transport_http *) transport;
|
307
|
+
git_vector *refs = &t->refs;
|
308
|
+
unsigned int i;
|
309
|
+
git_pkt_ref *p;
|
310
|
+
|
311
|
+
git_vector_foreach(refs, i, p) {
|
312
|
+
if (p->type != GIT_PKT_REF)
|
313
|
+
continue;
|
314
|
+
|
315
|
+
if (list_cb(&p->head, opaque) < 0)
|
316
|
+
return git__throw(GIT_ERROR,
|
317
|
+
"The user callback returned an error code");
|
318
|
+
}
|
319
|
+
|
320
|
+
return GIT_SUCCESS;
|
321
|
+
}
|
322
|
+
|
323
|
+
static int on_body_parse_response(http_parser *parser, const char *str, size_t len)
|
324
|
+
{
|
325
|
+
transport_http *t = (transport_http *) parser->data;
|
326
|
+
git_buf *buf = &t->buf;
|
327
|
+
git_vector *common = &t->common;
|
328
|
+
int error;
|
329
|
+
const char *line_end, *ptr;
|
330
|
+
|
331
|
+
if (len == 0) { /* EOF */
|
332
|
+
if (buf->size != 0)
|
333
|
+
return t->error = git__throw(GIT_ERROR, "EOF and unprocessed data");
|
334
|
+
else
|
335
|
+
return 0;
|
336
|
+
}
|
337
|
+
|
338
|
+
git_buf_put(buf, str, len);
|
339
|
+
ptr = buf->ptr;
|
340
|
+
while (1) {
|
341
|
+
git_pkt *pkt;
|
342
|
+
|
343
|
+
if (buf->size == 0)
|
344
|
+
return 0;
|
345
|
+
|
346
|
+
error = git_pkt_parse_line(&pkt, ptr, &line_end, buf->size);
|
347
|
+
if (error == GIT_ESHORTBUFFER) {
|
348
|
+
return 0; /* Ask for more */
|
349
|
+
}
|
350
|
+
if (error < GIT_SUCCESS)
|
351
|
+
return t->error = git__rethrow(error, "Failed to parse pkt-line");
|
352
|
+
|
353
|
+
git_buf_consume(buf, line_end);
|
354
|
+
|
355
|
+
if (pkt->type == GIT_PKT_PACK) {
|
356
|
+
git__free(pkt);
|
357
|
+
t->pack_ready = 1;
|
358
|
+
return 0;
|
359
|
+
}
|
360
|
+
|
361
|
+
if (pkt->type == GIT_PKT_NAK) {
|
362
|
+
git__free(pkt);
|
363
|
+
return 0;
|
364
|
+
}
|
365
|
+
|
366
|
+
if (pkt->type != GIT_PKT_ACK) {
|
367
|
+
git__free(pkt);
|
368
|
+
continue;
|
369
|
+
}
|
370
|
+
|
371
|
+
error = git_vector_insert(common, pkt);
|
372
|
+
if (error < GIT_SUCCESS)
|
373
|
+
return t->error = git__rethrow(error, "Failed to add pkt to list");
|
374
|
+
}
|
375
|
+
|
376
|
+
return error;
|
377
|
+
|
378
|
+
}
|
379
|
+
|
380
|
+
static int parse_response(transport_http *t)
|
381
|
+
{
|
382
|
+
int error = GIT_SUCCESS;
|
383
|
+
http_parser_settings settings;
|
384
|
+
char buffer[1024];
|
385
|
+
gitno_buffer buf;
|
386
|
+
|
387
|
+
http_parser_init(&t->parser, HTTP_RESPONSE);
|
388
|
+
t->parser.data = t;
|
389
|
+
t->transfer_finished = 0;
|
390
|
+
memset(&settings, 0x0, sizeof(http_parser_settings));
|
391
|
+
settings.on_header_field = on_header_field;
|
392
|
+
settings.on_header_value = on_header_value;
|
393
|
+
settings.on_headers_complete = on_headers_complete;
|
394
|
+
settings.on_body = on_body_parse_response;
|
395
|
+
settings.on_message_complete = on_message_complete;
|
396
|
+
|
397
|
+
gitno_buffer_setup(&buf, buffer, sizeof(buffer), t->socket);
|
398
|
+
|
399
|
+
while(1) {
|
400
|
+
size_t parsed;
|
401
|
+
|
402
|
+
error = gitno_recv(&buf);
|
403
|
+
if (error < GIT_SUCCESS)
|
404
|
+
return git__rethrow(error, "Error receiving data from network");
|
405
|
+
|
406
|
+
parsed = http_parser_execute(&t->parser, &settings, buf.data, buf.offset);
|
407
|
+
/* Both should happen at the same time */
|
408
|
+
if (parsed != buf.offset || t->error < GIT_SUCCESS)
|
409
|
+
return git__rethrow(t->error, "Error parsing HTTP data");
|
410
|
+
|
411
|
+
gitno_consume_n(&buf, parsed);
|
412
|
+
|
413
|
+
if (error == 0 || t->transfer_finished || t->pack_ready) {
|
414
|
+
return GIT_SUCCESS;
|
415
|
+
}
|
416
|
+
}
|
417
|
+
|
418
|
+
return error;
|
419
|
+
}
|
420
|
+
|
421
|
+
static int setup_walk(git_revwalk **out, git_repository *repo)
|
422
|
+
{
|
423
|
+
git_revwalk *walk;
|
424
|
+
git_strarray refs;
|
425
|
+
unsigned int i;
|
426
|
+
git_reference *ref;
|
427
|
+
int error;
|
428
|
+
|
429
|
+
error = git_reference_listall(&refs, repo, GIT_REF_LISTALL);
|
430
|
+
if (error < GIT_SUCCESS)
|
431
|
+
return git__rethrow(error, "Failed to list references");
|
432
|
+
|
433
|
+
error = git_revwalk_new(&walk, repo);
|
434
|
+
if (error < GIT_SUCCESS)
|
435
|
+
return git__rethrow(error, "Failed to setup walk");
|
436
|
+
|
437
|
+
git_revwalk_sorting(walk, GIT_SORT_TIME);
|
438
|
+
|
439
|
+
for (i = 0; i < refs.count; ++i) {
|
440
|
+
/* No tags */
|
441
|
+
if (!git__prefixcmp(refs.strings[i], GIT_REFS_TAGS_DIR))
|
442
|
+
continue;
|
443
|
+
|
444
|
+
error = git_reference_lookup(&ref, repo, refs.strings[i]);
|
445
|
+
if (error < GIT_ERROR) {
|
446
|
+
error = git__rethrow(error, "Failed to lookup %s", refs.strings[i]);
|
447
|
+
goto cleanup;
|
448
|
+
}
|
449
|
+
|
450
|
+
if (git_reference_type(ref) == GIT_REF_SYMBOLIC)
|
451
|
+
continue;
|
452
|
+
error = git_revwalk_push(walk, git_reference_oid(ref));
|
453
|
+
if (error < GIT_ERROR) {
|
454
|
+
error = git__rethrow(error, "Failed to push %s", refs.strings[i]);
|
455
|
+
goto cleanup;
|
456
|
+
}
|
457
|
+
}
|
458
|
+
|
459
|
+
*out = walk;
|
460
|
+
cleanup:
|
461
|
+
git_strarray_free(&refs);
|
462
|
+
|
463
|
+
return error;
|
464
|
+
}
|
465
|
+
|
466
|
+
static int http_negotiate_fetch(git_transport *transport, git_repository *repo, const git_vector *wants)
|
467
|
+
{
|
468
|
+
transport_http *t = (transport_http *) transport;
|
469
|
+
int error;
|
470
|
+
unsigned int i;
|
471
|
+
char buff[128];
|
472
|
+
gitno_buffer buf;
|
473
|
+
git_revwalk *walk = NULL;
|
474
|
+
git_oid oid;
|
475
|
+
git_pkt_ack *pkt;
|
476
|
+
git_vector *common = &t->common;
|
477
|
+
const char *prefix = "http://", *url = t->parent.url;
|
478
|
+
git_buf request = GIT_BUF_INIT, data = GIT_BUF_INIT;
|
479
|
+
gitno_buffer_setup(&buf, buff, sizeof(buff), t->socket);
|
480
|
+
|
481
|
+
/* TODO: Store url in the transport */
|
482
|
+
if (!git__prefixcmp(url, prefix))
|
483
|
+
url += strlen(prefix);
|
484
|
+
|
485
|
+
error = git_vector_init(common, 16, NULL);
|
486
|
+
if (error < GIT_SUCCESS)
|
487
|
+
return git__rethrow(error, "Failed to init common vector");
|
488
|
+
|
489
|
+
error = setup_walk(&walk, repo);
|
490
|
+
if (error < GIT_SUCCESS) {
|
491
|
+
error = git__rethrow(error, "Failed to setup walk");
|
492
|
+
goto cleanup;
|
493
|
+
}
|
494
|
+
|
495
|
+
do {
|
496
|
+
error = do_connect(t, t->host, t->port);
|
497
|
+
if (error < GIT_SUCCESS) {
|
498
|
+
error = git__rethrow(error, "Failed to connect to host");
|
499
|
+
goto cleanup;
|
500
|
+
}
|
501
|
+
|
502
|
+
error = git_pkt_buffer_wants(wants, &t->caps, &data);
|
503
|
+
if (error < GIT_SUCCESS) {
|
504
|
+
error = git__rethrow(error, "Failed to send wants");
|
505
|
+
goto cleanup;
|
506
|
+
}
|
507
|
+
|
508
|
+
/* We need to send these on each connection */
|
509
|
+
git_vector_foreach (common, i, pkt) {
|
510
|
+
error = git_pkt_buffer_have(&pkt->oid, &data);
|
511
|
+
if (error < GIT_SUCCESS) {
|
512
|
+
error = git__rethrow(error, "Failed to buffer common have");
|
513
|
+
goto cleanup;
|
514
|
+
}
|
515
|
+
}
|
516
|
+
|
517
|
+
i = 0;
|
518
|
+
while ((i < 20) && ((error = git_revwalk_next(&oid, walk)) == GIT_SUCCESS)) {
|
519
|
+
error = git_pkt_buffer_have(&oid, &data);
|
520
|
+
if (error < GIT_SUCCESS) {
|
521
|
+
error = git__rethrow(error, "Failed to buffer have");
|
522
|
+
goto cleanup;
|
523
|
+
}
|
524
|
+
i++;
|
525
|
+
}
|
526
|
+
|
527
|
+
git_pkt_buffer_done(&data);
|
528
|
+
|
529
|
+
error = gen_request(&request, url, t->host, "POST", "upload-pack", data.size, 0);
|
530
|
+
if (error < GIT_SUCCESS) {
|
531
|
+
error = git__rethrow(error, "Failed to generate request");
|
532
|
+
goto cleanup;
|
533
|
+
}
|
534
|
+
|
535
|
+
error = gitno_send(t->socket, request.ptr, request.size, 0);
|
536
|
+
if (error < GIT_SUCCESS) {
|
537
|
+
error = git__rethrow(error, "Failed to send request");
|
538
|
+
goto cleanup;
|
539
|
+
}
|
540
|
+
|
541
|
+
error = gitno_send(t->socket, data.ptr, data.size, 0);
|
542
|
+
if (error < GIT_SUCCESS) {
|
543
|
+
error = git__rethrow(error, "Failed to send data");
|
544
|
+
goto cleanup;
|
545
|
+
}
|
546
|
+
|
547
|
+
git_buf_clear(&request);
|
548
|
+
git_buf_clear(&data);
|
549
|
+
|
550
|
+
if (error < GIT_SUCCESS || i >= 256)
|
551
|
+
break;
|
552
|
+
|
553
|
+
error = parse_response(t);
|
554
|
+
if (error < GIT_SUCCESS) {
|
555
|
+
error = git__rethrow(error, "Error parsing the response");
|
556
|
+
goto cleanup;
|
557
|
+
}
|
558
|
+
|
559
|
+
if (t->pack_ready) {
|
560
|
+
error = GIT_SUCCESS;
|
561
|
+
goto cleanup;
|
562
|
+
}
|
563
|
+
|
564
|
+
} while(1);
|
565
|
+
|
566
|
+
cleanup:
|
567
|
+
git_buf_free(&request);
|
568
|
+
git_buf_free(&data);
|
569
|
+
git_revwalk_free(walk);
|
570
|
+
return error;
|
571
|
+
}
|
572
|
+
|
573
|
+
typedef struct {
|
574
|
+
git_filebuf *file;
|
575
|
+
transport_http *transport;
|
576
|
+
} download_pack_cbdata;
|
577
|
+
|
578
|
+
static int on_message_complete_download_pack(http_parser *parser)
|
579
|
+
{
|
580
|
+
download_pack_cbdata *data = (download_pack_cbdata *) parser->data;
|
581
|
+
|
582
|
+
data->transport->transfer_finished = 1;
|
583
|
+
|
584
|
+
return 0;
|
585
|
+
}
|
586
|
+
static int on_body_download_pack(http_parser *parser, const char *str, size_t len)
|
587
|
+
{
|
588
|
+
download_pack_cbdata *data = (download_pack_cbdata *) parser->data;
|
589
|
+
transport_http *t = data->transport;
|
590
|
+
git_filebuf *file = data->file;
|
591
|
+
|
592
|
+
|
593
|
+
return t->error = git_filebuf_write(file, str, len);
|
594
|
+
}
|
595
|
+
|
596
|
+
/*
|
597
|
+
* As the server is probably using Transfer-Encoding: chunked, we have
|
598
|
+
* to use the HTTP parser to download the pack instead of giving it to
|
599
|
+
* the simple downloader. Furthermore, we're using keep-alive
|
600
|
+
* connections, so the simple downloader would just hang.
|
601
|
+
*/
|
602
|
+
static int http_download_pack(char **out, git_transport *transport, git_repository *repo)
|
603
|
+
{
|
604
|
+
transport_http *t = (transport_http *) transport;
|
605
|
+
git_buf *oldbuf = &t->buf;
|
606
|
+
int error = GIT_SUCCESS;
|
607
|
+
http_parser_settings settings;
|
608
|
+
char buffer[1024];
|
609
|
+
gitno_buffer buf;
|
610
|
+
download_pack_cbdata data;
|
611
|
+
git_filebuf file;
|
612
|
+
char path[GIT_PATH_MAX], suff[] = "/objects/pack/pack-received\0";
|
613
|
+
|
614
|
+
/*
|
615
|
+
* This is part of the previous response, so we don't want to
|
616
|
+
* re-init the parser, just set these two callbacks.
|
617
|
+
*/
|
618
|
+
data.file = &file;
|
619
|
+
data.transport = t;
|
620
|
+
t->parser.data = &data;
|
621
|
+
t->transfer_finished = 0;
|
622
|
+
memset(&settings, 0x0, sizeof(settings));
|
623
|
+
settings.on_message_complete = on_message_complete_download_pack;
|
624
|
+
settings.on_body = on_body_download_pack;
|
625
|
+
|
626
|
+
gitno_buffer_setup(&buf, buffer, sizeof(buffer), t->socket);
|
627
|
+
|
628
|
+
git_path_join(path, repo->path_repository, suff);
|
629
|
+
|
630
|
+
if (memcmp(oldbuf->ptr, "PACK", strlen("PACK"))) {
|
631
|
+
return git__throw(GIT_ERROR, "The pack doesn't start with the signature");
|
632
|
+
}
|
633
|
+
|
634
|
+
error = git_filebuf_open(&file, path, GIT_FILEBUF_TEMPORARY);
|
635
|
+
if (error < GIT_SUCCESS)
|
636
|
+
goto cleanup;
|
637
|
+
|
638
|
+
/* Part of the packfile has been received, don't loose it */
|
639
|
+
error = git_filebuf_write(&file, oldbuf->ptr, oldbuf->size);
|
640
|
+
if (error < GIT_SUCCESS)
|
641
|
+
goto cleanup;
|
642
|
+
|
643
|
+
while(1) {
|
644
|
+
size_t parsed;
|
645
|
+
|
646
|
+
error = gitno_recv(&buf);
|
647
|
+
if (error < GIT_SUCCESS)
|
648
|
+
return git__rethrow(error, "Error receiving data from network");
|
649
|
+
|
650
|
+
parsed = http_parser_execute(&t->parser, &settings, buf.data, buf.offset);
|
651
|
+
/* Both should happen at the same time */
|
652
|
+
if (parsed != buf.offset || t->error < GIT_SUCCESS)
|
653
|
+
return git__rethrow(t->error, "Error parsing HTTP data");
|
654
|
+
|
655
|
+
gitno_consume_n(&buf, parsed);
|
656
|
+
|
657
|
+
if (error == 0 || t->transfer_finished) {
|
658
|
+
break;
|
659
|
+
}
|
660
|
+
}
|
661
|
+
|
662
|
+
*out = git__strdup(file.path_lock);
|
663
|
+
if (*out == NULL) {
|
664
|
+
error = GIT_ENOMEM;
|
665
|
+
goto cleanup;
|
666
|
+
}
|
667
|
+
|
668
|
+
/* A bit dodgy, but we need to keep the pack at the temporary path */
|
669
|
+
error = git_filebuf_commit_at(&file, file.path_lock, GIT_PACK_FILE_MODE);
|
670
|
+
|
671
|
+
cleanup:
|
672
|
+
if (error < GIT_SUCCESS)
|
673
|
+
git_filebuf_cleanup(&file);
|
674
|
+
|
675
|
+
return error;
|
676
|
+
}
|
677
|
+
|
678
|
+
static int http_close(git_transport *transport)
|
679
|
+
{
|
680
|
+
transport_http *t = (transport_http *) transport;
|
681
|
+
int error;
|
682
|
+
|
683
|
+
error = gitno_close(t->socket);
|
684
|
+
if (error < 0)
|
685
|
+
return git__throw(GIT_EOSERR, "Failed to close the socket: %s", strerror(errno));
|
686
|
+
|
687
|
+
return GIT_SUCCESS;
|
688
|
+
}
|
689
|
+
|
690
|
+
|
691
|
+
static void http_free(git_transport *transport)
|
692
|
+
{
|
693
|
+
transport_http *t = (transport_http *) transport;
|
694
|
+
git_vector *refs = &t->refs;
|
695
|
+
git_vector *common = &t->common;
|
696
|
+
unsigned int i;
|
697
|
+
git_pkt *p;
|
698
|
+
|
699
|
+
#ifdef GIT_WIN32
|
700
|
+
/* cleanup the WSA context. note that this context
|
701
|
+
* can be initialized more than once with WSAStartup(),
|
702
|
+
* and needs to be cleaned one time for each init call
|
703
|
+
*/
|
704
|
+
WSACleanup();
|
705
|
+
#endif
|
706
|
+
|
707
|
+
git_vector_foreach(refs, i, p) {
|
708
|
+
git_pkt_free(p);
|
709
|
+
}
|
710
|
+
git_vector_free(refs);
|
711
|
+
git_vector_foreach(common, i, p) {
|
712
|
+
git_pkt_free(p);
|
713
|
+
}
|
714
|
+
git_vector_free(common);
|
715
|
+
git_buf_free(&t->buf);
|
716
|
+
git_buf_free(&t->proto.buf);
|
717
|
+
git__free(t->heads);
|
718
|
+
git__free(t->content_type);
|
719
|
+
git__free(t->host);
|
720
|
+
git__free(t->port);
|
721
|
+
git__free(t->service);
|
722
|
+
git__free(t->parent.url);
|
723
|
+
git__free(t);
|
724
|
+
}
|
725
|
+
|
726
|
+
int git_transport_http(git_transport **out)
|
727
|
+
{
|
728
|
+
transport_http *t;
|
729
|
+
|
730
|
+
t = git__malloc(sizeof(transport_http));
|
731
|
+
if (t == NULL)
|
732
|
+
return GIT_ENOMEM;
|
733
|
+
|
734
|
+
memset(t, 0x0, sizeof(transport_http));
|
735
|
+
|
736
|
+
t->parent.connect = http_connect;
|
737
|
+
t->parent.ls = http_ls;
|
738
|
+
t->parent.negotiate_fetch = http_negotiate_fetch;
|
739
|
+
t->parent.download_pack = http_download_pack;
|
740
|
+
t->parent.close = http_close;
|
741
|
+
t->parent.free = http_free;
|
742
|
+
t->proto.refs = &t->refs;
|
743
|
+
t->proto.transport = (git_transport *) t;
|
744
|
+
|
745
|
+
#ifdef GIT_WIN32
|
746
|
+
/* on win32, the WSA context needs to be initialized
|
747
|
+
* before any socket calls can be performed */
|
748
|
+
if (WSAStartup(MAKEWORD(2,2), &t->wsd) != 0) {
|
749
|
+
http_free((git_transport *) t);
|
750
|
+
return git__throw(GIT_EOSERR, "Winsock init failed");
|
751
|
+
}
|
752
|
+
#endif
|
753
|
+
|
754
|
+
*out = (git_transport *) t;
|
755
|
+
return GIT_SUCCESS;
|
756
|
+
}
|