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,55 @@
|
|
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
|
+
#include "common.h"
|
8
|
+
#include "thread-utils.h"
|
9
|
+
|
10
|
+
#ifdef _WIN32
|
11
|
+
# define WIN32_LEAN_AND_MEAN
|
12
|
+
# include <windows.h>
|
13
|
+
#elif defined(hpux) || defined(__hpux) || defined(_hpux)
|
14
|
+
# include <sys/pstat.h>
|
15
|
+
#endif
|
16
|
+
|
17
|
+
/*
|
18
|
+
* By doing this in two steps we can at least get
|
19
|
+
* the function to be somewhat coherent, even
|
20
|
+
* with this disgusting nest of #ifdefs.
|
21
|
+
*/
|
22
|
+
#ifndef _SC_NPROCESSORS_ONLN
|
23
|
+
# ifdef _SC_NPROC_ONLN
|
24
|
+
# define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN
|
25
|
+
# elif defined _SC_CRAY_NCPU
|
26
|
+
# define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU
|
27
|
+
# endif
|
28
|
+
#endif
|
29
|
+
|
30
|
+
int git_online_cpus(void)
|
31
|
+
{
|
32
|
+
#ifdef _SC_NPROCESSORS_ONLN
|
33
|
+
long ncpus;
|
34
|
+
#endif
|
35
|
+
|
36
|
+
#ifdef _WIN32
|
37
|
+
SYSTEM_INFO info;
|
38
|
+
GetSystemInfo(&info);
|
39
|
+
|
40
|
+
if ((int)info.dwNumberOfProcessors > 0)
|
41
|
+
return (int)info.dwNumberOfProcessors;
|
42
|
+
#elif defined(hpux) || defined(__hpux) || defined(_hpux)
|
43
|
+
struct pst_dynamic psd;
|
44
|
+
|
45
|
+
if (!pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0))
|
46
|
+
return (int)psd.psd_proc_cnt;
|
47
|
+
#endif
|
48
|
+
|
49
|
+
#ifdef _SC_NPROCESSORS_ONLN
|
50
|
+
if ((ncpus = (long)sysconf(_SC_NPROCESSORS_ONLN)) > 0)
|
51
|
+
return (int)ncpus;
|
52
|
+
#endif
|
53
|
+
|
54
|
+
return 1;
|
55
|
+
}
|
@@ -0,0 +1,108 @@
|
|
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
|
+
#ifndef INCLUDE_thread_utils_h__
|
8
|
+
#define INCLUDE_thread_utils_h__
|
9
|
+
|
10
|
+
#include "common.h"
|
11
|
+
|
12
|
+
/* Common operations even if threading has been disabled */
|
13
|
+
typedef struct {
|
14
|
+
#if defined(_MSC_VER)
|
15
|
+
volatile long val;
|
16
|
+
#else
|
17
|
+
volatile int val;
|
18
|
+
#endif
|
19
|
+
} git_atomic;
|
20
|
+
|
21
|
+
GIT_INLINE(void) git_atomic_set(git_atomic *a, int val)
|
22
|
+
{
|
23
|
+
a->val = val;
|
24
|
+
}
|
25
|
+
|
26
|
+
#ifdef GIT_THREADS
|
27
|
+
|
28
|
+
#define git_thread pthread_t
|
29
|
+
#define git_thread_create(thread, attr, start_routine, arg) pthread_create(thread, attr, start_routine, arg)
|
30
|
+
#define git_thread_kill(thread) pthread_cancel(thread)
|
31
|
+
#define git_thread_exit(status) pthread_exit(status)
|
32
|
+
#define git_thread_join(id, status) pthread_join(id, status)
|
33
|
+
|
34
|
+
/* Pthreads Mutex */
|
35
|
+
#define git_mutex pthread_mutex_t
|
36
|
+
#define git_mutex_init(a) pthread_mutex_init(a, NULL)
|
37
|
+
#define git_mutex_lock(a) pthread_mutex_lock(a)
|
38
|
+
#define git_mutex_unlock(a) pthread_mutex_unlock(a)
|
39
|
+
#define git_mutex_free(a) pthread_mutex_destroy(a)
|
40
|
+
|
41
|
+
/* Pthreads condition vars -- disabled by now */
|
42
|
+
#define git_cond unsigned int //pthread_cond_t
|
43
|
+
#define git_cond_init(c, a) (void)0 //pthread_cond_init(c, a)
|
44
|
+
#define git_cond_free(c) (void)0 //pthread_cond_destroy(c)
|
45
|
+
#define git_cond_wait(c, l) (void)0 //pthread_cond_wait(c, l)
|
46
|
+
#define git_cond_signal(c) (void)0 //pthread_cond_signal(c)
|
47
|
+
#define git_cond_broadcast(c) (void)0 //pthread_cond_broadcast(c)
|
48
|
+
|
49
|
+
GIT_INLINE(int) git_atomic_inc(git_atomic *a)
|
50
|
+
{
|
51
|
+
#ifdef __GNUC__
|
52
|
+
return __sync_add_and_fetch(&a->val, 1);
|
53
|
+
#elif defined(_MSC_VER)
|
54
|
+
return InterlockedIncrement(&a->val);
|
55
|
+
#else
|
56
|
+
# error "Unsupported architecture for atomic operations"
|
57
|
+
#endif
|
58
|
+
}
|
59
|
+
|
60
|
+
GIT_INLINE(int) git_atomic_dec(git_atomic *a)
|
61
|
+
{
|
62
|
+
#ifdef __GNUC__
|
63
|
+
return __sync_sub_and_fetch(&a->val, 1);
|
64
|
+
#elif defined(_MSC_VER)
|
65
|
+
return InterlockedDecrement(&a->val);
|
66
|
+
#else
|
67
|
+
# error "Unsupported architecture for atomic operations"
|
68
|
+
#endif
|
69
|
+
}
|
70
|
+
|
71
|
+
#else
|
72
|
+
|
73
|
+
#define git_thread unsigned int
|
74
|
+
#define git_thread_create(thread, attr, start_routine, arg) (void)0
|
75
|
+
#define git_thread_kill(thread) (void)0
|
76
|
+
#define git_thread_exit(status) (void)0
|
77
|
+
#define git_thread_join(id, status) (void)0
|
78
|
+
|
79
|
+
/* Pthreads Mutex */
|
80
|
+
#define git_mutex unsigned int
|
81
|
+
#define git_mutex_init(a) (void)0
|
82
|
+
#define git_mutex_lock(a) (void)0
|
83
|
+
#define git_mutex_unlock(a) (void)0
|
84
|
+
#define git_mutex_free(a) (void)0
|
85
|
+
|
86
|
+
/* Pthreads condition vars */
|
87
|
+
#define git_cond unsigned int
|
88
|
+
#define git_cond_init(c, a) (void)0
|
89
|
+
#define git_cond_free(c) (void)0
|
90
|
+
#define git_cond_wait(c, l) (void)0
|
91
|
+
#define git_cond_signal(c) (void)0
|
92
|
+
#define git_cond_broadcast(c) (void)0
|
93
|
+
|
94
|
+
GIT_INLINE(int) git_atomic_inc(git_atomic *a)
|
95
|
+
{
|
96
|
+
return ++a->val;
|
97
|
+
}
|
98
|
+
|
99
|
+
GIT_INLINE(int) git_atomic_dec(git_atomic *a)
|
100
|
+
{
|
101
|
+
return --a->val;
|
102
|
+
}
|
103
|
+
|
104
|
+
#endif
|
105
|
+
|
106
|
+
extern int git_online_cpus(void);
|
107
|
+
|
108
|
+
#endif /* INCLUDE_thread_utils_h__ */
|
@@ -0,0 +1,85 @@
|
|
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
|
+
#include "common.h"
|
8
|
+
#include "git2/types.h"
|
9
|
+
#include "git2/remote.h"
|
10
|
+
#include "git2/net.h"
|
11
|
+
#include "transport.h"
|
12
|
+
|
13
|
+
static struct {
|
14
|
+
char *prefix;
|
15
|
+
git_transport_cb fn;
|
16
|
+
} transports[] = {
|
17
|
+
{"git://", git_transport_git},
|
18
|
+
{"http://", git_transport_http},
|
19
|
+
{"https://", git_transport_dummy},
|
20
|
+
{"file://", git_transport_local},
|
21
|
+
{"git+ssh://", git_transport_dummy},
|
22
|
+
{"ssh+git://", git_transport_dummy},
|
23
|
+
{NULL, 0}
|
24
|
+
};
|
25
|
+
|
26
|
+
#define GIT_TRANSPORT_COUNT (sizeof(transports)/sizeof(transports[0]))
|
27
|
+
|
28
|
+
static git_transport_cb transport_find_fn(const char *url)
|
29
|
+
{
|
30
|
+
size_t i = 0;
|
31
|
+
|
32
|
+
/* TODO: Parse "example.com:project.git" as an SSH URL */
|
33
|
+
|
34
|
+
for (i = 0; i < GIT_TRANSPORT_COUNT; ++i) {
|
35
|
+
if (!strncasecmp(url, transports[i].prefix, strlen(transports[i].prefix)))
|
36
|
+
return transports[i].fn;
|
37
|
+
}
|
38
|
+
|
39
|
+
return NULL;
|
40
|
+
}
|
41
|
+
|
42
|
+
/**************
|
43
|
+
* Public API *
|
44
|
+
**************/
|
45
|
+
|
46
|
+
int git_transport_dummy(git_transport **GIT_UNUSED(transport))
|
47
|
+
{
|
48
|
+
GIT_UNUSED_ARG(transport);
|
49
|
+
return git__throw(GIT_ENOTIMPLEMENTED, "This protocol isn't implemented. Sorry");
|
50
|
+
}
|
51
|
+
|
52
|
+
int git_transport_new(git_transport **out, const char *url)
|
53
|
+
{
|
54
|
+
git_transport_cb fn;
|
55
|
+
git_transport *transport;
|
56
|
+
int error;
|
57
|
+
|
58
|
+
fn = transport_find_fn(url);
|
59
|
+
|
60
|
+
/*
|
61
|
+
* If we haven't found the transport, we assume we mean a
|
62
|
+
* local file.
|
63
|
+
*/
|
64
|
+
if (fn == NULL)
|
65
|
+
fn = &git_transport_local;
|
66
|
+
|
67
|
+
error = fn(&transport);
|
68
|
+
if (error < GIT_SUCCESS)
|
69
|
+
return git__rethrow(error, "Failed to create new transport");
|
70
|
+
|
71
|
+
transport->url = git__strdup(url);
|
72
|
+
if (transport->url == NULL)
|
73
|
+
return GIT_ENOMEM;
|
74
|
+
|
75
|
+
*out = transport;
|
76
|
+
|
77
|
+
return GIT_SUCCESS;
|
78
|
+
}
|
79
|
+
|
80
|
+
/* from remote.h */
|
81
|
+
int git_remote_valid_url(const char *url)
|
82
|
+
{
|
83
|
+
return transport_find_fn(url) != NULL;
|
84
|
+
}
|
85
|
+
|
@@ -0,0 +1,110 @@
|
|
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
|
+
#ifndef INCLUDE_transport_h__
|
8
|
+
#define INCLUDE_transport_h__
|
9
|
+
|
10
|
+
#include "git2/net.h"
|
11
|
+
#include "vector.h"
|
12
|
+
|
13
|
+
#define GIT_CAP_OFS_DELTA "ofs-delta"
|
14
|
+
|
15
|
+
typedef struct git_transport_caps {
|
16
|
+
int common:1,
|
17
|
+
ofs_delta:1;
|
18
|
+
} git_transport_caps;
|
19
|
+
|
20
|
+
/*
|
21
|
+
* A day in the life of a network operation
|
22
|
+
* ========================================
|
23
|
+
*
|
24
|
+
* The library gets told to ls-remote/push/fetch on/to/from some
|
25
|
+
* remote. We look at the URL of the remote and fill the function
|
26
|
+
* table with whatever is appropriate (the remote may be git over git,
|
27
|
+
* ssh or http(s). It may even be an hg or svn repository, the library
|
28
|
+
* at this level doesn't care, it just calls the helpers.
|
29
|
+
*
|
30
|
+
* The first call is to ->connect() which connects to the remote,
|
31
|
+
* making use of the direction if necessary. This function must also
|
32
|
+
* store the remote heads and any other information it needs.
|
33
|
+
*
|
34
|
+
* The next useful step is to call ->ls() to get the list of
|
35
|
+
* references available to the remote. These references may have been
|
36
|
+
* collected on connect, or we may build them now. For ls-remote,
|
37
|
+
* nothing else is needed other than closing the connection.
|
38
|
+
* Otherwise, the higher leves decide which objects we want to
|
39
|
+
* have. ->send_have() is used to tell the other end what we have. If
|
40
|
+
* we do need to download a pack, ->download_pack() is called.
|
41
|
+
*
|
42
|
+
* When we're done, we call ->close() to close the
|
43
|
+
* connection. ->free() takes care of freeing all the resources.
|
44
|
+
*/
|
45
|
+
|
46
|
+
struct git_transport {
|
47
|
+
/**
|
48
|
+
* Where the repo lives
|
49
|
+
*/
|
50
|
+
char *url;
|
51
|
+
/**
|
52
|
+
* Whether we want to push or fetch
|
53
|
+
*/
|
54
|
+
int direction : 1, /* 0 fetch, 1 push */
|
55
|
+
connected : 1;
|
56
|
+
/**
|
57
|
+
* Connect and store the remote heads
|
58
|
+
*/
|
59
|
+
int (*connect)(struct git_transport *transport, int dir);
|
60
|
+
/**
|
61
|
+
* Give a list of references, useful for ls-remote
|
62
|
+
*/
|
63
|
+
int (*ls)(struct git_transport *transport, git_headlist_cb list_cb, void *opaque);
|
64
|
+
/**
|
65
|
+
* Push the changes over
|
66
|
+
*/
|
67
|
+
int (*push)(struct git_transport *transport);
|
68
|
+
/**
|
69
|
+
* Send a 'done' message
|
70
|
+
*/
|
71
|
+
int (*send_done)(struct git_transport *transport);
|
72
|
+
/**
|
73
|
+
* Negotiate the minimal amount of objects that need to be
|
74
|
+
* retrieved
|
75
|
+
*/
|
76
|
+
int (*negotiate_fetch)(struct git_transport *transport, git_repository *repo, const git_vector *wants);
|
77
|
+
/**
|
78
|
+
* Send a flush
|
79
|
+
*/
|
80
|
+
int (*send_flush)(struct git_transport *transport);
|
81
|
+
/**
|
82
|
+
* Download the packfile
|
83
|
+
*/
|
84
|
+
int (*download_pack)(char **out, struct git_transport *transport, git_repository *repo);
|
85
|
+
/**
|
86
|
+
* Fetch the changes
|
87
|
+
*/
|
88
|
+
int (*fetch)(struct git_transport *transport);
|
89
|
+
/**
|
90
|
+
* Close the connection
|
91
|
+
*/
|
92
|
+
int (*close)(struct git_transport *transport);
|
93
|
+
/**
|
94
|
+
* Free the associated resources
|
95
|
+
*/
|
96
|
+
void (*free)(struct git_transport *transport);
|
97
|
+
};
|
98
|
+
|
99
|
+
|
100
|
+
int git_transport_new(struct git_transport **transport, const char *url);
|
101
|
+
int git_transport_local(struct git_transport **transport);
|
102
|
+
int git_transport_git(struct git_transport **transport);
|
103
|
+
int git_transport_http(struct git_transport **transport);
|
104
|
+
int git_transport_dummy(struct git_transport **transport);
|
105
|
+
int git_transport_valid_url(const char *url);
|
106
|
+
|
107
|
+
typedef struct git_transport git_transport;
|
108
|
+
typedef int (*git_transport_cb)(git_transport **transport);
|
109
|
+
|
110
|
+
#endif
|
@@ -0,0 +1,502 @@
|
|
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 "git2/net.h"
|
9
|
+
#include "git2/common.h"
|
10
|
+
#include "git2/types.h"
|
11
|
+
#include "git2/errors.h"
|
12
|
+
#include "git2/net.h"
|
13
|
+
#include "git2/revwalk.h"
|
14
|
+
|
15
|
+
#include "vector.h"
|
16
|
+
#include "transport.h"
|
17
|
+
#include "pkt.h"
|
18
|
+
#include "common.h"
|
19
|
+
#include "netops.h"
|
20
|
+
#include "filebuf.h"
|
21
|
+
#include "repository.h"
|
22
|
+
#include "fetch.h"
|
23
|
+
#include "protocol.h"
|
24
|
+
|
25
|
+
typedef struct {
|
26
|
+
git_transport parent;
|
27
|
+
git_protocol proto;
|
28
|
+
GIT_SOCKET socket;
|
29
|
+
git_vector refs;
|
30
|
+
git_remote_head **heads;
|
31
|
+
git_transport_caps caps;
|
32
|
+
char buff[1024];
|
33
|
+
gitno_buffer buf;
|
34
|
+
#ifdef GIT_WIN32
|
35
|
+
WSADATA wsd;
|
36
|
+
#endif
|
37
|
+
} transport_git;
|
38
|
+
|
39
|
+
/*
|
40
|
+
* Create a git procol request.
|
41
|
+
*
|
42
|
+
* For example: 0035git-upload-pack /libgit2/libgit2\0host=github.com\0
|
43
|
+
*/
|
44
|
+
static int gen_proto(git_buf *request, const char *cmd, const char *url)
|
45
|
+
{
|
46
|
+
char *delim, *repo;
|
47
|
+
char default_command[] = "git-upload-pack";
|
48
|
+
char host[] = "host=";
|
49
|
+
int len;
|
50
|
+
|
51
|
+
delim = strchr(url, '/');
|
52
|
+
if (delim == NULL)
|
53
|
+
return git__throw(GIT_EOBJCORRUPTED, "Failed to create proto-request: malformed URL");
|
54
|
+
|
55
|
+
repo = delim;
|
56
|
+
|
57
|
+
delim = strchr(url, ':');
|
58
|
+
if (delim == NULL)
|
59
|
+
delim = strchr(url, '/');
|
60
|
+
|
61
|
+
if (cmd == NULL)
|
62
|
+
cmd = default_command;
|
63
|
+
|
64
|
+
len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + strlen(host) + (delim - url) + 1;
|
65
|
+
|
66
|
+
git_buf_grow(request, len);
|
67
|
+
git_buf_printf(request, "%04x%s %s%c%s", len, cmd, repo, 0, host);
|
68
|
+
git_buf_put(request, url, delim - url);
|
69
|
+
git_buf_putc(request, '\0');
|
70
|
+
|
71
|
+
return git_buf_oom(request);
|
72
|
+
}
|
73
|
+
|
74
|
+
static int send_request(GIT_SOCKET s, const char *cmd, const char *url)
|
75
|
+
{
|
76
|
+
int error;
|
77
|
+
git_buf request = GIT_BUF_INIT;
|
78
|
+
|
79
|
+
error = gen_proto(&request, cmd, url);
|
80
|
+
if (error < GIT_SUCCESS)
|
81
|
+
goto cleanup;
|
82
|
+
|
83
|
+
error = gitno_send(s, request.ptr, request.size, 0);
|
84
|
+
|
85
|
+
cleanup:
|
86
|
+
git_buf_free(&request);
|
87
|
+
return error;
|
88
|
+
}
|
89
|
+
|
90
|
+
/*
|
91
|
+
* Parse the URL and connect to a server, storing the socket in
|
92
|
+
* out. For convenience this also takes care of asking for the remote
|
93
|
+
* refs
|
94
|
+
*/
|
95
|
+
static int do_connect(transport_git *t, const char *url)
|
96
|
+
{
|
97
|
+
GIT_SOCKET s;
|
98
|
+
char *host, *port;
|
99
|
+
const char prefix[] = "git://";
|
100
|
+
int error, connected = 0;
|
101
|
+
|
102
|
+
if (!git__prefixcmp(url, prefix))
|
103
|
+
url += strlen(prefix);
|
104
|
+
|
105
|
+
error = gitno_extract_host_and_port(&host, &port, url, GIT_DEFAULT_PORT);
|
106
|
+
if (error < GIT_SUCCESS)
|
107
|
+
return error;
|
108
|
+
|
109
|
+
s = gitno_connect(host, port);
|
110
|
+
connected = 1;
|
111
|
+
error = send_request(s, NULL, url);
|
112
|
+
t->socket = s;
|
113
|
+
|
114
|
+
git__free(host);
|
115
|
+
git__free(port);
|
116
|
+
|
117
|
+
if (error < GIT_SUCCESS && s > 0)
|
118
|
+
close(s);
|
119
|
+
if (!connected)
|
120
|
+
error = git__throw(GIT_EOSERR, "Failed to connect to any of the addresses");
|
121
|
+
|
122
|
+
return error;
|
123
|
+
}
|
124
|
+
|
125
|
+
/*
|
126
|
+
* Read from the socket and store the references in the vector
|
127
|
+
*/
|
128
|
+
static int store_refs(transport_git *t)
|
129
|
+
{
|
130
|
+
gitno_buffer *buf = &t->buf;
|
131
|
+
int error = GIT_SUCCESS;
|
132
|
+
|
133
|
+
while (1) {
|
134
|
+
error = gitno_recv(buf);
|
135
|
+
if (error < GIT_SUCCESS)
|
136
|
+
return git__rethrow(GIT_EOSERR, "Failed to receive data");
|
137
|
+
if (error == GIT_SUCCESS) /* Orderly shutdown, so exit */
|
138
|
+
return GIT_SUCCESS;
|
139
|
+
|
140
|
+
error = git_protocol_store_refs(&t->proto, buf->data, buf->offset);
|
141
|
+
if (error == GIT_ESHORTBUFFER) {
|
142
|
+
gitno_consume_n(buf, buf->len);
|
143
|
+
continue;
|
144
|
+
}
|
145
|
+
|
146
|
+
if (error < GIT_SUCCESS)
|
147
|
+
return git__rethrow(error, "Failed to store refs");
|
148
|
+
|
149
|
+
gitno_consume_n(buf, buf->offset);
|
150
|
+
|
151
|
+
if (t->proto.flush) { /* No more refs */
|
152
|
+
t->proto.flush = 0;
|
153
|
+
return GIT_SUCCESS;
|
154
|
+
}
|
155
|
+
}
|
156
|
+
|
157
|
+
return error;
|
158
|
+
}
|
159
|
+
|
160
|
+
static int detect_caps(transport_git *t)
|
161
|
+
{
|
162
|
+
git_vector *refs = &t->refs;
|
163
|
+
git_pkt_ref *pkt;
|
164
|
+
git_transport_caps *caps = &t->caps;
|
165
|
+
const char *ptr;
|
166
|
+
|
167
|
+
pkt = git_vector_get(refs, 0);
|
168
|
+
/* No refs or capabilites, odd but not a problem */
|
169
|
+
if (pkt == NULL || pkt->capabilities == NULL)
|
170
|
+
return GIT_SUCCESS;
|
171
|
+
|
172
|
+
ptr = pkt->capabilities;
|
173
|
+
while (ptr != NULL && *ptr != '\0') {
|
174
|
+
if (*ptr == ' ')
|
175
|
+
ptr++;
|
176
|
+
|
177
|
+
if(!git__prefixcmp(ptr, GIT_CAP_OFS_DELTA)) {
|
178
|
+
caps->common = caps->ofs_delta = 1;
|
179
|
+
ptr += strlen(GIT_CAP_OFS_DELTA);
|
180
|
+
continue;
|
181
|
+
}
|
182
|
+
|
183
|
+
/* We don't know this capability, so skip it */
|
184
|
+
ptr = strchr(ptr, ' ');
|
185
|
+
}
|
186
|
+
|
187
|
+
return GIT_SUCCESS;
|
188
|
+
}
|
189
|
+
|
190
|
+
/*
|
191
|
+
* Since this is a network connection, we need to parse and store the
|
192
|
+
* pkt-lines at this stage and keep them there.
|
193
|
+
*/
|
194
|
+
static int git_connect(git_transport *transport, int direction)
|
195
|
+
{
|
196
|
+
transport_git *t = (transport_git *) transport;
|
197
|
+
int error = GIT_SUCCESS;
|
198
|
+
|
199
|
+
if (direction == GIT_DIR_PUSH)
|
200
|
+
return git__throw(GIT_EINVALIDARGS, "Pushing is not supported with the git protocol");
|
201
|
+
|
202
|
+
t->parent.direction = direction;
|
203
|
+
error = git_vector_init(&t->refs, 16, NULL);
|
204
|
+
if (error < GIT_SUCCESS)
|
205
|
+
goto cleanup;
|
206
|
+
|
207
|
+
/* Connect and ask for the refs */
|
208
|
+
error = do_connect(t, transport->url);
|
209
|
+
if (error < GIT_SUCCESS)
|
210
|
+
return error;
|
211
|
+
|
212
|
+
gitno_buffer_setup(&t->buf, t->buff, sizeof(t->buff), t->socket);
|
213
|
+
|
214
|
+
t->parent.connected = 1;
|
215
|
+
error = store_refs(t);
|
216
|
+
if (error < GIT_SUCCESS)
|
217
|
+
return error;
|
218
|
+
|
219
|
+
error = detect_caps(t);
|
220
|
+
|
221
|
+
cleanup:
|
222
|
+
if (error < GIT_SUCCESS) {
|
223
|
+
git_vector_free(&t->refs);
|
224
|
+
}
|
225
|
+
|
226
|
+
return error;
|
227
|
+
}
|
228
|
+
|
229
|
+
static int git_ls(git_transport *transport, git_headlist_cb list_cb, void *opaque)
|
230
|
+
{
|
231
|
+
transport_git *t = (transport_git *) transport;
|
232
|
+
git_vector *refs = &t->refs;
|
233
|
+
unsigned int i;
|
234
|
+
git_pkt *p = NULL;
|
235
|
+
|
236
|
+
git_vector_foreach(refs, i, p) {
|
237
|
+
git_pkt_ref *pkt = NULL;
|
238
|
+
|
239
|
+
if (p->type != GIT_PKT_REF)
|
240
|
+
continue;
|
241
|
+
|
242
|
+
pkt = (git_pkt_ref *)p;
|
243
|
+
|
244
|
+
if (list_cb(&pkt->head, opaque) < 0)
|
245
|
+
return git__throw(GIT_ERROR,
|
246
|
+
"The user callback returned an error code");
|
247
|
+
}
|
248
|
+
|
249
|
+
return GIT_SUCCESS;
|
250
|
+
}
|
251
|
+
|
252
|
+
static int git_negotiate_fetch(git_transport *transport, git_repository *repo, const git_vector *wants)
|
253
|
+
{
|
254
|
+
transport_git *t = (transport_git *) transport;
|
255
|
+
git_revwalk *walk;
|
256
|
+
git_reference *ref;
|
257
|
+
git_strarray refs;
|
258
|
+
git_oid oid;
|
259
|
+
int error;
|
260
|
+
unsigned int i;
|
261
|
+
gitno_buffer *buf = &t->buf;
|
262
|
+
|
263
|
+
error = git_pkt_send_wants(wants, &t->caps, t->socket);
|
264
|
+
if (error < GIT_SUCCESS)
|
265
|
+
return git__rethrow(error, "Failed to send wants list");
|
266
|
+
|
267
|
+
error = git_reference_listall(&refs, repo, GIT_REF_LISTALL);
|
268
|
+
if (error < GIT_ERROR)
|
269
|
+
return git__rethrow(error, "Failed to list all references");
|
270
|
+
|
271
|
+
error = git_revwalk_new(&walk, repo);
|
272
|
+
if (error < GIT_ERROR) {
|
273
|
+
error = git__rethrow(error, "Failed to list all references");
|
274
|
+
goto cleanup;
|
275
|
+
}
|
276
|
+
git_revwalk_sorting(walk, GIT_SORT_TIME);
|
277
|
+
|
278
|
+
for (i = 0; i < refs.count; ++i) {
|
279
|
+
/* No tags */
|
280
|
+
if (!git__prefixcmp(refs.strings[i], GIT_REFS_TAGS_DIR))
|
281
|
+
continue;
|
282
|
+
|
283
|
+
error = git_reference_lookup(&ref, repo, refs.strings[i]);
|
284
|
+
if (error < GIT_ERROR) {
|
285
|
+
error = git__rethrow(error, "Failed to lookup %s", refs.strings[i]);
|
286
|
+
goto cleanup;
|
287
|
+
}
|
288
|
+
|
289
|
+
if (git_reference_type(ref) == GIT_REF_SYMBOLIC)
|
290
|
+
continue;
|
291
|
+
|
292
|
+
error = git_revwalk_push(walk, git_reference_oid(ref));
|
293
|
+
if (error < GIT_ERROR) {
|
294
|
+
error = git__rethrow(error, "Failed to push %s", refs.strings[i]);
|
295
|
+
goto cleanup;
|
296
|
+
}
|
297
|
+
}
|
298
|
+
git_strarray_free(&refs);
|
299
|
+
|
300
|
+
/*
|
301
|
+
* We don't support any kind of ACK extensions, so the negotiation
|
302
|
+
* boils down to sending what we have and listening for an ACK
|
303
|
+
* every once in a while.
|
304
|
+
*/
|
305
|
+
i = 0;
|
306
|
+
while ((error = git_revwalk_next(&oid, walk)) == GIT_SUCCESS) {
|
307
|
+
error = git_pkt_send_have(&oid, t->socket);
|
308
|
+
i++;
|
309
|
+
if (i % 20 == 0) {
|
310
|
+
const char *ptr = buf->data, *line_end;
|
311
|
+
git_pkt *pkt;
|
312
|
+
git_pkt_send_flush(t->socket);
|
313
|
+
while (1) {
|
314
|
+
/* Wait for max. 1 second */
|
315
|
+
error = gitno_select_in(buf, 1, 0);
|
316
|
+
if (error < GIT_SUCCESS) {
|
317
|
+
error = git__throw(GIT_EOSERR, "Error in select");
|
318
|
+
} else if (error == 0) {
|
319
|
+
/*
|
320
|
+
* Some servers don't respond immediately, so if this
|
321
|
+
* happens, we keep sending information until it
|
322
|
+
* answers.
|
323
|
+
*/
|
324
|
+
break;
|
325
|
+
}
|
326
|
+
|
327
|
+
error = gitno_recv(buf);
|
328
|
+
if (error < GIT_SUCCESS) {
|
329
|
+
error = git__rethrow(error, "Error receiving data");
|
330
|
+
goto cleanup;
|
331
|
+
}
|
332
|
+
error = git_pkt_parse_line(&pkt, ptr, &line_end, buf->offset);
|
333
|
+
if (error == GIT_ESHORTBUFFER)
|
334
|
+
continue;
|
335
|
+
if (error < GIT_SUCCESS) {
|
336
|
+
error = git__rethrow(error, "Failed to get answer");
|
337
|
+
goto cleanup;
|
338
|
+
}
|
339
|
+
|
340
|
+
gitno_consume(buf, line_end);
|
341
|
+
|
342
|
+
if (pkt->type == GIT_PKT_ACK) {
|
343
|
+
git__free(pkt);
|
344
|
+
error = GIT_SUCCESS;
|
345
|
+
goto done;
|
346
|
+
} else if (pkt->type == GIT_PKT_NAK) {
|
347
|
+
git__free(pkt);
|
348
|
+
break;
|
349
|
+
} else {
|
350
|
+
error = git__throw(GIT_ERROR, "Got unexpected pkt type");
|
351
|
+
goto cleanup;
|
352
|
+
}
|
353
|
+
}
|
354
|
+
}
|
355
|
+
}
|
356
|
+
if (error == GIT_EREVWALKOVER)
|
357
|
+
error = GIT_SUCCESS;
|
358
|
+
|
359
|
+
done:
|
360
|
+
git_pkt_send_flush(t->socket);
|
361
|
+
git_pkt_send_done(t->socket);
|
362
|
+
|
363
|
+
cleanup:
|
364
|
+
git_revwalk_free(walk);
|
365
|
+
|
366
|
+
return error;
|
367
|
+
}
|
368
|
+
|
369
|
+
static int git_send_flush(git_transport *transport)
|
370
|
+
{
|
371
|
+
transport_git *t = (transport_git *) transport;
|
372
|
+
|
373
|
+
return git_pkt_send_flush(t->socket);
|
374
|
+
}
|
375
|
+
|
376
|
+
static int git_send_done(git_transport *transport)
|
377
|
+
{
|
378
|
+
transport_git *t = (transport_git *) transport;
|
379
|
+
|
380
|
+
return git_pkt_send_done(t->socket);
|
381
|
+
}
|
382
|
+
|
383
|
+
static int git_download_pack(char **out, git_transport *transport, git_repository *repo)
|
384
|
+
{
|
385
|
+
transport_git *t = (transport_git *) transport;
|
386
|
+
int error = GIT_SUCCESS;
|
387
|
+
gitno_buffer *buf = &t->buf;
|
388
|
+
git_pkt *pkt;
|
389
|
+
const char *line_end, *ptr;
|
390
|
+
|
391
|
+
/*
|
392
|
+
* For now, we ignore everything and wait for the pack
|
393
|
+
*/
|
394
|
+
while (1) {
|
395
|
+
ptr = buf->data;
|
396
|
+
/* Whilst we're searching for the pack */
|
397
|
+
while (1) {
|
398
|
+
if (buf->offset == 0) {
|
399
|
+
break;
|
400
|
+
}
|
401
|
+
|
402
|
+
error = git_pkt_parse_line(&pkt, ptr, &line_end, buf->offset);
|
403
|
+
if (error == GIT_ESHORTBUFFER)
|
404
|
+
break;
|
405
|
+
|
406
|
+
if (error < GIT_SUCCESS)
|
407
|
+
return error;
|
408
|
+
|
409
|
+
if (pkt->type == GIT_PKT_PACK) {
|
410
|
+
git__free(pkt);
|
411
|
+
return git_fetch__download_pack(out, buf->data, buf->offset, t->socket, repo);
|
412
|
+
}
|
413
|
+
|
414
|
+
/* For now we don't care about anything */
|
415
|
+
git__free(pkt);
|
416
|
+
gitno_consume(buf, line_end);
|
417
|
+
}
|
418
|
+
|
419
|
+
error = gitno_recv(buf);
|
420
|
+
if (error < GIT_SUCCESS)
|
421
|
+
return git__rethrow(GIT_EOSERR, "Failed to receive data");
|
422
|
+
if (error == 0) { /* Orderly shutdown */
|
423
|
+
return GIT_SUCCESS;
|
424
|
+
}
|
425
|
+
|
426
|
+
}
|
427
|
+
}
|
428
|
+
|
429
|
+
|
430
|
+
static int git_close(git_transport *transport)
|
431
|
+
{
|
432
|
+
transport_git *t = (transport_git*) transport;
|
433
|
+
int error;
|
434
|
+
|
435
|
+
/* Can't do anything if there's an error, so don't bother checking */
|
436
|
+
git_pkt_send_flush(t->socket);
|
437
|
+
error = gitno_close(t->socket);
|
438
|
+
|
439
|
+
if (error < 0)
|
440
|
+
error = git__throw(GIT_EOSERR, "Failed to close socket");
|
441
|
+
|
442
|
+
#ifdef GIT_WIN32
|
443
|
+
WSACleanup();
|
444
|
+
#endif
|
445
|
+
|
446
|
+
return error;
|
447
|
+
}
|
448
|
+
|
449
|
+
static void git_free(git_transport *transport)
|
450
|
+
{
|
451
|
+
transport_git *t = (transport_git *) transport;
|
452
|
+
git_vector *refs = &t->refs;
|
453
|
+
unsigned int i;
|
454
|
+
|
455
|
+
for (i = 0; i < refs->length; ++i) {
|
456
|
+
git_pkt *p = git_vector_get(refs, i);
|
457
|
+
git_pkt_free(p);
|
458
|
+
}
|
459
|
+
|
460
|
+
git_vector_free(refs);
|
461
|
+
git__free(t->heads);
|
462
|
+
git_buf_free(&t->proto.buf);
|
463
|
+
git__free(t->parent.url);
|
464
|
+
git__free(t);
|
465
|
+
}
|
466
|
+
|
467
|
+
int git_transport_git(git_transport **out)
|
468
|
+
{
|
469
|
+
transport_git *t;
|
470
|
+
#ifdef GIT_WIN32
|
471
|
+
int ret;
|
472
|
+
#endif
|
473
|
+
|
474
|
+
t = git__malloc(sizeof(transport_git));
|
475
|
+
if (t == NULL)
|
476
|
+
return GIT_ENOMEM;
|
477
|
+
|
478
|
+
memset(t, 0x0, sizeof(transport_git));
|
479
|
+
|
480
|
+
t->parent.connect = git_connect;
|
481
|
+
t->parent.ls = git_ls;
|
482
|
+
t->parent.negotiate_fetch = git_negotiate_fetch;
|
483
|
+
t->parent.send_flush = git_send_flush;
|
484
|
+
t->parent.send_done = git_send_done;
|
485
|
+
t->parent.download_pack = git_download_pack;
|
486
|
+
t->parent.close = git_close;
|
487
|
+
t->parent.free = git_free;
|
488
|
+
t->proto.refs = &t->refs;
|
489
|
+
t->proto.transport = (git_transport *) t;
|
490
|
+
|
491
|
+
*out = (git_transport *) t;
|
492
|
+
|
493
|
+
#ifdef GIT_WIN32
|
494
|
+
ret = WSAStartup(MAKEWORD(2,2), &t->wsd);
|
495
|
+
if (ret != 0) {
|
496
|
+
git_free(*out);
|
497
|
+
return git__throw(GIT_EOSERR, "Winsock init failed");
|
498
|
+
}
|
499
|
+
#endif
|
500
|
+
|
501
|
+
return GIT_SUCCESS;
|
502
|
+
}
|