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,272 @@
|
|
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 "common.h"
|
9
|
+
#include "mwindow.h"
|
10
|
+
#include "vector.h"
|
11
|
+
#include "fileops.h"
|
12
|
+
#include "map.h"
|
13
|
+
#include "global.h"
|
14
|
+
|
15
|
+
#define DEFAULT_WINDOW_SIZE \
|
16
|
+
(sizeof(void*) >= 8 \
|
17
|
+
? 1 * 1024 * 1024 * 1024 \
|
18
|
+
: 32 * 1024 * 1024)
|
19
|
+
|
20
|
+
#define DEFAULT_MAPPED_LIMIT \
|
21
|
+
((1024 * 1024) * (sizeof(void*) >= 8 ? 8192ULL : 256UL))
|
22
|
+
|
23
|
+
/*
|
24
|
+
* These are the global options for mmmap limits.
|
25
|
+
* TODO: allow the user to change these
|
26
|
+
*/
|
27
|
+
static struct {
|
28
|
+
size_t window_size;
|
29
|
+
size_t mapped_limit;
|
30
|
+
} _mw_options = {
|
31
|
+
DEFAULT_WINDOW_SIZE,
|
32
|
+
DEFAULT_MAPPED_LIMIT,
|
33
|
+
};
|
34
|
+
|
35
|
+
/*
|
36
|
+
* Free all the windows in a sequence, typically because we're done
|
37
|
+
* with the file
|
38
|
+
*/
|
39
|
+
void git_mwindow_free_all(git_mwindow_file *mwf)
|
40
|
+
{
|
41
|
+
git_mwindow_ctl *ctl = &GIT_GLOBAL->mem_ctl;
|
42
|
+
unsigned int i;
|
43
|
+
/*
|
44
|
+
* Remove these windows from the global list
|
45
|
+
*/
|
46
|
+
for (i = 0; i < ctl->windowfiles.length; ++i){
|
47
|
+
if (git_vector_get(&ctl->windowfiles, i) == mwf) {
|
48
|
+
git_vector_remove(&ctl->windowfiles, i);
|
49
|
+
break;
|
50
|
+
}
|
51
|
+
}
|
52
|
+
|
53
|
+
if (ctl->windowfiles.length == 0) {
|
54
|
+
git_vector_free(&ctl->windowfiles);
|
55
|
+
ctl->windowfiles.contents = NULL;
|
56
|
+
}
|
57
|
+
|
58
|
+
while (mwf->windows) {
|
59
|
+
git_mwindow *w = mwf->windows;
|
60
|
+
assert(w->inuse_cnt == 0);
|
61
|
+
|
62
|
+
ctl->mapped -= w->window_map.len;
|
63
|
+
ctl->open_windows--;
|
64
|
+
|
65
|
+
git_futils_mmap_free(&w->window_map);
|
66
|
+
|
67
|
+
mwf->windows = w->next;
|
68
|
+
git__free(w);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
/*
|
73
|
+
* Check if a window 'win' contains the address 'offset'
|
74
|
+
*/
|
75
|
+
int git_mwindow_contains(git_mwindow *win, git_off_t offset)
|
76
|
+
{
|
77
|
+
git_off_t win_off = win->offset;
|
78
|
+
return win_off <= offset
|
79
|
+
&& offset <= (git_off_t)(win_off + win->window_map.len);
|
80
|
+
}
|
81
|
+
|
82
|
+
/*
|
83
|
+
* Find the least-recently-used window in a file
|
84
|
+
*/
|
85
|
+
void git_mwindow_scan_lru(
|
86
|
+
git_mwindow_file *mwf,
|
87
|
+
git_mwindow **lru_w,
|
88
|
+
git_mwindow **lru_l)
|
89
|
+
{
|
90
|
+
git_mwindow *w, *w_l;
|
91
|
+
|
92
|
+
for (w_l = NULL, w = mwf->windows; w; w = w->next) {
|
93
|
+
if (!w->inuse_cnt) {
|
94
|
+
/*
|
95
|
+
* If the current one is more recent than the last one,
|
96
|
+
* store it in the output parameter. If lru_w is NULL,
|
97
|
+
* it's the first loop, so store it as well.
|
98
|
+
*/
|
99
|
+
if (!*lru_w || w->last_used < (*lru_w)->last_used) {
|
100
|
+
*lru_w = w;
|
101
|
+
*lru_l = w_l;
|
102
|
+
}
|
103
|
+
}
|
104
|
+
w_l = w;
|
105
|
+
}
|
106
|
+
}
|
107
|
+
|
108
|
+
/*
|
109
|
+
* Close the least recently used window. You should check to see if
|
110
|
+
* the file descriptors need closing from time to time.
|
111
|
+
*/
|
112
|
+
static int git_mwindow_close_lru(git_mwindow_file *mwf)
|
113
|
+
{
|
114
|
+
git_mwindow_ctl *ctl = &GIT_GLOBAL->mem_ctl;
|
115
|
+
unsigned int i;
|
116
|
+
git_mwindow *lru_w = NULL, *lru_l = NULL, **list = &mwf->windows;
|
117
|
+
|
118
|
+
/* FIMXE: Does this give us any advantage? */
|
119
|
+
if(mwf->windows)
|
120
|
+
git_mwindow_scan_lru(mwf, &lru_w, &lru_l);
|
121
|
+
|
122
|
+
for (i = 0; i < ctl->windowfiles.length; ++i) {
|
123
|
+
git_mwindow *last = lru_w;
|
124
|
+
git_mwindow_file *cur = git_vector_get(&ctl->windowfiles, i);
|
125
|
+
git_mwindow_scan_lru(cur, &lru_w, &lru_l);
|
126
|
+
if (lru_w != last)
|
127
|
+
list = &cur->windows;
|
128
|
+
}
|
129
|
+
|
130
|
+
if (lru_w) {
|
131
|
+
ctl->mapped -= lru_w->window_map.len;
|
132
|
+
git_futils_mmap_free(&lru_w->window_map);
|
133
|
+
|
134
|
+
if (lru_l)
|
135
|
+
lru_l->next = lru_w->next;
|
136
|
+
else
|
137
|
+
*list = lru_w->next;
|
138
|
+
|
139
|
+
git__free(lru_w);
|
140
|
+
ctl->open_windows--;
|
141
|
+
|
142
|
+
return GIT_SUCCESS;
|
143
|
+
}
|
144
|
+
|
145
|
+
return git__throw(GIT_ERROR, "Failed to close memory window. Couln't find LRU");
|
146
|
+
}
|
147
|
+
|
148
|
+
static git_mwindow *new_window(
|
149
|
+
git_mwindow_file *mwf,
|
150
|
+
git_file fd,
|
151
|
+
git_off_t size,
|
152
|
+
git_off_t offset)
|
153
|
+
{
|
154
|
+
git_mwindow_ctl *ctl = &GIT_GLOBAL->mem_ctl;
|
155
|
+
size_t walign = _mw_options.window_size / 2;
|
156
|
+
git_off_t len;
|
157
|
+
git_mwindow *w;
|
158
|
+
|
159
|
+
w = git__malloc(sizeof(*w));
|
160
|
+
if (w == NULL)
|
161
|
+
return w;
|
162
|
+
|
163
|
+
memset(w, 0x0, sizeof(*w));
|
164
|
+
w->offset = (offset / walign) * walign;
|
165
|
+
|
166
|
+
len = size - w->offset;
|
167
|
+
if (len > (git_off_t)_mw_options.window_size)
|
168
|
+
len = (git_off_t)_mw_options.window_size;
|
169
|
+
|
170
|
+
ctl->mapped += (size_t)len;
|
171
|
+
|
172
|
+
while (_mw_options.mapped_limit < ctl->mapped &&
|
173
|
+
git_mwindow_close_lru(mwf) == GIT_SUCCESS) /* nop */;
|
174
|
+
|
175
|
+
/*
|
176
|
+
* We treat _mw_options.mapped_limit as a soft limit. If we can't find a
|
177
|
+
* window to close and are above the limit, we still mmap the new
|
178
|
+
* window.
|
179
|
+
*/
|
180
|
+
|
181
|
+
if (git_futils_mmap_ro(&w->window_map, fd, w->offset, (size_t)len) < GIT_SUCCESS)
|
182
|
+
goto cleanup;
|
183
|
+
|
184
|
+
ctl->mmap_calls++;
|
185
|
+
ctl->open_windows++;
|
186
|
+
|
187
|
+
if (ctl->mapped > ctl->peak_mapped)
|
188
|
+
ctl->peak_mapped = ctl->mapped;
|
189
|
+
|
190
|
+
if (ctl->open_windows > ctl->peak_open_windows)
|
191
|
+
ctl->peak_open_windows = ctl->open_windows;
|
192
|
+
|
193
|
+
return w;
|
194
|
+
|
195
|
+
cleanup:
|
196
|
+
git__free(w);
|
197
|
+
return NULL;
|
198
|
+
}
|
199
|
+
|
200
|
+
/*
|
201
|
+
* Open a new window, closing the least recenty used until we have
|
202
|
+
* enough space. Don't forget to add it to your list
|
203
|
+
*/
|
204
|
+
unsigned char *git_mwindow_open(
|
205
|
+
git_mwindow_file *mwf,
|
206
|
+
git_mwindow **cursor,
|
207
|
+
git_off_t offset,
|
208
|
+
int extra,
|
209
|
+
unsigned int *left)
|
210
|
+
{
|
211
|
+
git_mwindow_ctl *ctl = &GIT_GLOBAL->mem_ctl;
|
212
|
+
git_mwindow *w = *cursor;
|
213
|
+
|
214
|
+
if (!w || !git_mwindow_contains(w, offset + extra)) {
|
215
|
+
if (w) {
|
216
|
+
w->inuse_cnt--;
|
217
|
+
}
|
218
|
+
|
219
|
+
for (w = mwf->windows; w; w = w->next) {
|
220
|
+
if (git_mwindow_contains(w, offset + extra))
|
221
|
+
break;
|
222
|
+
}
|
223
|
+
|
224
|
+
/*
|
225
|
+
* If there isn't a suitable window, we need to create a new
|
226
|
+
* one.
|
227
|
+
*/
|
228
|
+
if (!w) {
|
229
|
+
w = new_window(mwf, mwf->fd, mwf->size, offset);
|
230
|
+
if (w == NULL)
|
231
|
+
return NULL;
|
232
|
+
w->next = mwf->windows;
|
233
|
+
mwf->windows = w;
|
234
|
+
}
|
235
|
+
}
|
236
|
+
|
237
|
+
/* If we changed w, store it in the cursor */
|
238
|
+
if (w != *cursor) {
|
239
|
+
w->last_used = ctl->used_ctr++;
|
240
|
+
w->inuse_cnt++;
|
241
|
+
*cursor = w;
|
242
|
+
}
|
243
|
+
|
244
|
+
offset -= w->offset;
|
245
|
+
assert(git__is_sizet(offset));
|
246
|
+
|
247
|
+
if (left)
|
248
|
+
*left = (unsigned int)(w->window_map.len - offset);
|
249
|
+
|
250
|
+
return (unsigned char *) w->window_map.data + offset;
|
251
|
+
}
|
252
|
+
|
253
|
+
int git_mwindow_file_register(git_mwindow_file *mwf)
|
254
|
+
{
|
255
|
+
git_mwindow_ctl *ctl = &GIT_GLOBAL->mem_ctl;
|
256
|
+
int error;
|
257
|
+
|
258
|
+
if (ctl->windowfiles.length == 0 &&
|
259
|
+
(error = git_vector_init(&ctl->windowfiles, 8, NULL)) < GIT_SUCCESS)
|
260
|
+
return error;
|
261
|
+
|
262
|
+
return git_vector_insert(&ctl->windowfiles, mwf);
|
263
|
+
}
|
264
|
+
|
265
|
+
void git_mwindow_close(git_mwindow **window)
|
266
|
+
{
|
267
|
+
git_mwindow *w = *window;
|
268
|
+
if (w) {
|
269
|
+
w->inuse_cnt--;
|
270
|
+
*window = NULL;
|
271
|
+
}
|
272
|
+
}
|
@@ -0,0 +1,45 @@
|
|
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
|
+
#ifndef INCLUDE_mwindow__
|
9
|
+
#define INCLUDE_mwindow__
|
10
|
+
|
11
|
+
#include "map.h"
|
12
|
+
#include "vector.h"
|
13
|
+
|
14
|
+
typedef struct git_mwindow {
|
15
|
+
struct git_mwindow *next;
|
16
|
+
git_map window_map;
|
17
|
+
git_off_t offset;
|
18
|
+
unsigned int last_used;
|
19
|
+
unsigned int inuse_cnt;
|
20
|
+
} git_mwindow;
|
21
|
+
|
22
|
+
typedef struct git_mwindow_file {
|
23
|
+
git_mwindow *windows;
|
24
|
+
int fd;
|
25
|
+
git_off_t size;
|
26
|
+
} git_mwindow_file;
|
27
|
+
|
28
|
+
typedef struct git_mwindow_ctl {
|
29
|
+
size_t mapped;
|
30
|
+
unsigned int open_windows;
|
31
|
+
unsigned int mmap_calls;
|
32
|
+
unsigned int peak_open_windows;
|
33
|
+
size_t peak_mapped;
|
34
|
+
size_t used_ctr;
|
35
|
+
git_vector windowfiles;
|
36
|
+
} git_mwindow_ctl;
|
37
|
+
|
38
|
+
int git_mwindow_contains(git_mwindow *win, git_off_t offset);
|
39
|
+
void git_mwindow_free_all(git_mwindow_file *mwf);
|
40
|
+
unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor, git_off_t offset, int extra, unsigned int *left);
|
41
|
+
void git_mwindow_scan_lru(git_mwindow_file *mwf, git_mwindow **lru_w, git_mwindow **lru_l);
|
42
|
+
int git_mwindow_file_register(git_mwindow_file *mwf);
|
43
|
+
void git_mwindow_close(git_mwindow **w_cursor);
|
44
|
+
|
45
|
+
#endif
|
@@ -0,0 +1,198 @@
|
|
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 _WIN32
|
8
|
+
# include <sys/types.h>
|
9
|
+
# include <sys/socket.h>
|
10
|
+
# include <sys/select.h>
|
11
|
+
# include <netdb.h>
|
12
|
+
#else
|
13
|
+
# define _WIN32_WINNT 0x0501
|
14
|
+
# include <winsock2.h>
|
15
|
+
# include <Ws2tcpip.h>
|
16
|
+
# ifdef _MSC_VER
|
17
|
+
# pragma comment(lib, "Ws2_32.lib")
|
18
|
+
# endif
|
19
|
+
#endif
|
20
|
+
|
21
|
+
|
22
|
+
#include "git2/errors.h"
|
23
|
+
|
24
|
+
#include "common.h"
|
25
|
+
#include "netops.h"
|
26
|
+
#include "posix.h"
|
27
|
+
|
28
|
+
void gitno_buffer_setup(gitno_buffer *buf, char *data, unsigned int len, int fd)
|
29
|
+
{
|
30
|
+
memset(buf, 0x0, sizeof(gitno_buffer));
|
31
|
+
memset(data, 0x0, len);
|
32
|
+
buf->data = data;
|
33
|
+
buf->len = len;
|
34
|
+
buf->offset = 0;
|
35
|
+
buf->fd = fd;
|
36
|
+
}
|
37
|
+
|
38
|
+
int gitno_recv(gitno_buffer *buf)
|
39
|
+
{
|
40
|
+
int ret;
|
41
|
+
|
42
|
+
ret = recv(buf->fd, buf->data + buf->offset, buf->len - buf->offset, 0);
|
43
|
+
if (ret < 0)
|
44
|
+
return git__throw(GIT_EOSERR, "Failed to receive data: %s", strerror(errno));
|
45
|
+
if (ret == 0) /* Orderly shutdown, so exit */
|
46
|
+
return GIT_SUCCESS;
|
47
|
+
|
48
|
+
buf->offset += ret;
|
49
|
+
|
50
|
+
return ret;
|
51
|
+
}
|
52
|
+
|
53
|
+
/* Consume up to ptr and move the rest of the buffer to the beginning */
|
54
|
+
void gitno_consume(gitno_buffer *buf, const char *ptr)
|
55
|
+
{
|
56
|
+
size_t consumed;
|
57
|
+
|
58
|
+
assert(ptr - buf->data >= 0);
|
59
|
+
assert(ptr - buf->data <= (int) buf->len);
|
60
|
+
|
61
|
+
consumed = ptr - buf->data;
|
62
|
+
|
63
|
+
memmove(buf->data, ptr, buf->offset - consumed);
|
64
|
+
memset(buf->data + buf->offset, 0x0, buf->len - buf->offset);
|
65
|
+
buf->offset -= consumed;
|
66
|
+
}
|
67
|
+
|
68
|
+
/* Consume const bytes and move the rest of the buffer to the beginning */
|
69
|
+
void gitno_consume_n(gitno_buffer *buf, size_t cons)
|
70
|
+
{
|
71
|
+
memmove(buf->data, buf->data + cons, buf->len - buf->offset);
|
72
|
+
memset(buf->data + cons, 0x0, buf->len - buf->offset);
|
73
|
+
buf->offset -= cons;
|
74
|
+
}
|
75
|
+
|
76
|
+
int gitno_connect(const char *host, const char *port)
|
77
|
+
{
|
78
|
+
struct addrinfo *info, *p;
|
79
|
+
struct addrinfo hints;
|
80
|
+
int ret, error = GIT_SUCCESS;
|
81
|
+
GIT_SOCKET s;
|
82
|
+
|
83
|
+
memset(&hints, 0x0, sizeof(struct addrinfo));
|
84
|
+
hints.ai_family = AF_UNSPEC;
|
85
|
+
hints.ai_socktype = SOCK_STREAM;
|
86
|
+
|
87
|
+
ret = getaddrinfo(host, port, &hints, &info);
|
88
|
+
if (ret != 0) {
|
89
|
+
error = GIT_EOSERR;
|
90
|
+
info = NULL;
|
91
|
+
goto cleanup;
|
92
|
+
}
|
93
|
+
|
94
|
+
for (p = info; p != NULL; p = p->ai_next) {
|
95
|
+
s = socket(p->ai_family, p->ai_socktype, p->ai_protocol);
|
96
|
+
#ifdef GIT_WIN32
|
97
|
+
if (s == INVALID_SOCKET) {
|
98
|
+
#else
|
99
|
+
if (s < 0) {
|
100
|
+
#endif
|
101
|
+
error = GIT_EOSERR;
|
102
|
+
goto cleanup;
|
103
|
+
}
|
104
|
+
|
105
|
+
ret = connect(s, p->ai_addr, p->ai_addrlen);
|
106
|
+
/* If we can't connect, try the next one */
|
107
|
+
if (ret < 0) {
|
108
|
+
continue;
|
109
|
+
}
|
110
|
+
|
111
|
+
/* Return the socket */
|
112
|
+
error = s;
|
113
|
+
goto cleanup;
|
114
|
+
}
|
115
|
+
|
116
|
+
/* Oops, we couldn't connect to any address */
|
117
|
+
error = git__throw(GIT_EOSERR, "Failed to connect: %s", strerror(errno));
|
118
|
+
|
119
|
+
cleanup:
|
120
|
+
freeaddrinfo(info);
|
121
|
+
return error;
|
122
|
+
}
|
123
|
+
|
124
|
+
int gitno_send(GIT_SOCKET s, const char *msg, size_t len, int flags)
|
125
|
+
{
|
126
|
+
int ret;
|
127
|
+
size_t off = 0;
|
128
|
+
|
129
|
+
while (off < len) {
|
130
|
+
errno = 0;
|
131
|
+
|
132
|
+
ret = send(s, msg + off, len - off, flags);
|
133
|
+
if (ret < 0)
|
134
|
+
return git__throw(GIT_EOSERR, "Error sending data: %s", strerror(errno));
|
135
|
+
|
136
|
+
off += ret;
|
137
|
+
}
|
138
|
+
|
139
|
+
return off;
|
140
|
+
}
|
141
|
+
|
142
|
+
|
143
|
+
#ifdef GIT_WIN32
|
144
|
+
int gitno_close(GIT_SOCKET s)
|
145
|
+
{
|
146
|
+
return closesocket(s) == SOCKET_ERROR ? -1 : 0;
|
147
|
+
}
|
148
|
+
#else
|
149
|
+
int gitno_close(GIT_SOCKET s)
|
150
|
+
{
|
151
|
+
return close(s);
|
152
|
+
}
|
153
|
+
#endif
|
154
|
+
|
155
|
+
int gitno_select_in(gitno_buffer *buf, long int sec, long int usec)
|
156
|
+
{
|
157
|
+
fd_set fds;
|
158
|
+
struct timeval tv;
|
159
|
+
|
160
|
+
tv.tv_sec = sec;
|
161
|
+
tv.tv_usec = usec;
|
162
|
+
|
163
|
+
FD_ZERO(&fds);
|
164
|
+
FD_SET(buf->fd, &fds);
|
165
|
+
|
166
|
+
/* The select(2) interface is silly */
|
167
|
+
return select(buf->fd + 1, &fds, NULL, NULL, &tv);
|
168
|
+
}
|
169
|
+
|
170
|
+
int gitno_extract_host_and_port(char **host, char **port, const char *url, const char *default_port)
|
171
|
+
{
|
172
|
+
char *colon, *slash, *delim;
|
173
|
+
int error = GIT_SUCCESS;
|
174
|
+
|
175
|
+
colon = strchr(url, ':');
|
176
|
+
slash = strchr(url, '/');
|
177
|
+
|
178
|
+
if (slash == NULL)
|
179
|
+
return git__throw(GIT_EOBJCORRUPTED, "Malformed URL: missing /");
|
180
|
+
|
181
|
+
if (colon == NULL) {
|
182
|
+
*port = git__strdup(default_port);
|
183
|
+
} else {
|
184
|
+
*port = git__strndup(colon + 1, slash - colon - 1);
|
185
|
+
}
|
186
|
+
if (*port == NULL)
|
187
|
+
return GIT_ENOMEM;;
|
188
|
+
|
189
|
+
|
190
|
+
delim = colon == NULL ? slash : colon;
|
191
|
+
*host = git__strndup(url, delim - url);
|
192
|
+
if (*host == NULL) {
|
193
|
+
git__free(*port);
|
194
|
+
error = GIT_ENOMEM;
|
195
|
+
}
|
196
|
+
|
197
|
+
return error;
|
198
|
+
}
|