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,18 @@
|
|
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_fetch_h__
|
8
|
+
#define INCLUDE_fetch_h__
|
9
|
+
|
10
|
+
#include "netops.h"
|
11
|
+
|
12
|
+
int git_fetch_negotiate(git_remote *remote);
|
13
|
+
int git_fetch_download_pack(char **out, git_remote *remote);
|
14
|
+
|
15
|
+
int git_fetch__download_pack(char **out, const char *buffered, size_t buffered_size,
|
16
|
+
GIT_SOCKET fd, git_repository *repo);
|
17
|
+
|
18
|
+
#endif
|
@@ -0,0 +1,400 @@
|
|
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 <stdarg.h>
|
8
|
+
|
9
|
+
#include "common.h"
|
10
|
+
#include "filebuf.h"
|
11
|
+
#include "fileops.h"
|
12
|
+
|
13
|
+
#define GIT_LOCK_FILE_MODE 0644
|
14
|
+
|
15
|
+
static const size_t WRITE_BUFFER_SIZE = (4096 * 2);
|
16
|
+
|
17
|
+
static int lock_file(git_filebuf *file, int flags)
|
18
|
+
{
|
19
|
+
if (git_futils_exists(file->path_lock) == 0) {
|
20
|
+
if (flags & GIT_FILEBUF_FORCE)
|
21
|
+
p_unlink(file->path_lock);
|
22
|
+
else
|
23
|
+
return git__throw(GIT_EOSERR, "Failed to lock file");
|
24
|
+
}
|
25
|
+
|
26
|
+
/* create path to the file buffer is required */
|
27
|
+
if (flags & GIT_FILEBUF_FORCE) {
|
28
|
+
/* XXX: Should dirmode here be configurable? Or is 0777 always fine? */
|
29
|
+
file->fd = git_futils_creat_locked_withpath(file->path_lock, 0777, GIT_LOCK_FILE_MODE);
|
30
|
+
} else {
|
31
|
+
file->fd = git_futils_creat_locked(file->path_lock, GIT_LOCK_FILE_MODE);
|
32
|
+
}
|
33
|
+
|
34
|
+
if (file->fd < 0)
|
35
|
+
return git__throw(GIT_EOSERR, "Failed to create lock");
|
36
|
+
|
37
|
+
if ((flags & GIT_FILEBUF_APPEND) && git_futils_exists(file->path_original) == 0) {
|
38
|
+
git_file source;
|
39
|
+
char buffer[2048];
|
40
|
+
size_t read_bytes;
|
41
|
+
|
42
|
+
source = p_open(file->path_original, O_RDONLY);
|
43
|
+
if (source < 0)
|
44
|
+
return git__throw(GIT_EOSERR, "Failed to lock file. Could not open %s", file->path_original);
|
45
|
+
|
46
|
+
while ((read_bytes = p_read(source, buffer, 2048)) > 0) {
|
47
|
+
p_write(file->fd, buffer, read_bytes);
|
48
|
+
if (file->digest)
|
49
|
+
git_hash_update(file->digest, buffer, read_bytes);
|
50
|
+
}
|
51
|
+
|
52
|
+
p_close(source);
|
53
|
+
}
|
54
|
+
|
55
|
+
return GIT_SUCCESS;
|
56
|
+
}
|
57
|
+
|
58
|
+
void git_filebuf_cleanup(git_filebuf *file)
|
59
|
+
{
|
60
|
+
if (file->fd >= 0)
|
61
|
+
p_close(file->fd);
|
62
|
+
|
63
|
+
if (file->fd >= 0 && file->path_lock && git_futils_exists(file->path_lock) == GIT_SUCCESS)
|
64
|
+
p_unlink(file->path_lock);
|
65
|
+
|
66
|
+
if (file->digest)
|
67
|
+
git_hash_free_ctx(file->digest);
|
68
|
+
|
69
|
+
if (file->buffer)
|
70
|
+
git__free(file->buffer);
|
71
|
+
|
72
|
+
/* use the presence of z_buf to decide if we need to deflateEnd */
|
73
|
+
if (file->z_buf) {
|
74
|
+
git__free(file->z_buf);
|
75
|
+
deflateEnd(&file->zs);
|
76
|
+
}
|
77
|
+
|
78
|
+
if (file->path_original)
|
79
|
+
git__free(file->path_original);
|
80
|
+
if (file->path_lock)
|
81
|
+
git__free(file->path_lock);
|
82
|
+
|
83
|
+
memset(file, 0x0, sizeof(git_filebuf));
|
84
|
+
file->fd = -1;
|
85
|
+
}
|
86
|
+
|
87
|
+
GIT_INLINE(int) flush_buffer(git_filebuf *file)
|
88
|
+
{
|
89
|
+
int result = file->write(file, file->buffer, file->buf_pos);
|
90
|
+
file->buf_pos = 0;
|
91
|
+
return result;
|
92
|
+
}
|
93
|
+
|
94
|
+
static int write_normal(git_filebuf *file, void *source, size_t len)
|
95
|
+
{
|
96
|
+
int result = 0;
|
97
|
+
|
98
|
+
if (len > 0) {
|
99
|
+
result = p_write(file->fd, (void *)source, len);
|
100
|
+
if (file->digest)
|
101
|
+
git_hash_update(file->digest, source, len);
|
102
|
+
}
|
103
|
+
|
104
|
+
return result;
|
105
|
+
}
|
106
|
+
|
107
|
+
static int write_deflate(git_filebuf *file, void *source, size_t len)
|
108
|
+
{
|
109
|
+
int result = Z_OK;
|
110
|
+
z_stream *zs = &file->zs;
|
111
|
+
|
112
|
+
if (len > 0 || file->flush_mode == Z_FINISH) {
|
113
|
+
zs->next_in = source;
|
114
|
+
zs->avail_in = (uInt)len;
|
115
|
+
|
116
|
+
do {
|
117
|
+
size_t have;
|
118
|
+
|
119
|
+
zs->next_out = file->z_buf;
|
120
|
+
zs->avail_out = (uInt)file->buf_size;
|
121
|
+
|
122
|
+
result = deflate(zs, file->flush_mode);
|
123
|
+
if (result == Z_STREAM_ERROR)
|
124
|
+
return git__throw(GIT_ERROR, "Failed to deflate input");
|
125
|
+
|
126
|
+
have = file->buf_size - (size_t)zs->avail_out;
|
127
|
+
|
128
|
+
if (p_write(file->fd, file->z_buf, have) < GIT_SUCCESS)
|
129
|
+
return git__throw(GIT_EOSERR, "Failed to write to file");
|
130
|
+
|
131
|
+
} while (zs->avail_out == 0);
|
132
|
+
|
133
|
+
assert(zs->avail_in == 0);
|
134
|
+
|
135
|
+
if (file->digest)
|
136
|
+
git_hash_update(file->digest, source, len);
|
137
|
+
}
|
138
|
+
|
139
|
+
return GIT_SUCCESS;
|
140
|
+
}
|
141
|
+
|
142
|
+
int git_filebuf_open(git_filebuf *file, const char *path, int flags)
|
143
|
+
{
|
144
|
+
int error, compression;
|
145
|
+
size_t path_len;
|
146
|
+
|
147
|
+
assert(file && path);
|
148
|
+
|
149
|
+
if (file->buffer)
|
150
|
+
return git__throw(GIT_EINVALIDARGS, "Tried to reopen an open filebuf");
|
151
|
+
|
152
|
+
memset(file, 0x0, sizeof(git_filebuf));
|
153
|
+
|
154
|
+
file->buf_size = WRITE_BUFFER_SIZE;
|
155
|
+
file->buf_pos = 0;
|
156
|
+
file->fd = -1;
|
157
|
+
|
158
|
+
/* Allocate the main cache buffer */
|
159
|
+
file->buffer = git__malloc(file->buf_size);
|
160
|
+
if (file->buffer == NULL){
|
161
|
+
error = GIT_ENOMEM;
|
162
|
+
goto cleanup;
|
163
|
+
}
|
164
|
+
|
165
|
+
/* If we are hashing on-write, allocate a new hash context */
|
166
|
+
if (flags & GIT_FILEBUF_HASH_CONTENTS) {
|
167
|
+
if ((file->digest = git_hash_new_ctx()) == NULL) {
|
168
|
+
error = GIT_ENOMEM;
|
169
|
+
goto cleanup;
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
compression = flags >> GIT_FILEBUF_DEFLATE_SHIFT;
|
174
|
+
|
175
|
+
/* If we are deflating on-write, */
|
176
|
+
if (compression != 0) {
|
177
|
+
/* Initialize the ZLib stream */
|
178
|
+
if (deflateInit(&file->zs, compression) != Z_OK) {
|
179
|
+
error = git__throw(GIT_EZLIB, "Failed to initialize zlib");
|
180
|
+
goto cleanup;
|
181
|
+
}
|
182
|
+
|
183
|
+
/* Allocate the Zlib cache buffer */
|
184
|
+
file->z_buf = git__malloc(file->buf_size);
|
185
|
+
if (file->z_buf == NULL){
|
186
|
+
error = GIT_ENOMEM;
|
187
|
+
goto cleanup;
|
188
|
+
}
|
189
|
+
|
190
|
+
/* Never flush */
|
191
|
+
file->flush_mode = Z_NO_FLUSH;
|
192
|
+
file->write = &write_deflate;
|
193
|
+
} else {
|
194
|
+
file->write = &write_normal;
|
195
|
+
}
|
196
|
+
|
197
|
+
/* If we are writing to a temp file */
|
198
|
+
if (flags & GIT_FILEBUF_TEMPORARY) {
|
199
|
+
char tmp_path[GIT_PATH_MAX];
|
200
|
+
|
201
|
+
/* Open the file as temporary for locking */
|
202
|
+
file->fd = git_futils_mktmp(tmp_path, path);
|
203
|
+
if (file->fd < 0) {
|
204
|
+
error = GIT_EOSERR;
|
205
|
+
goto cleanup;
|
206
|
+
}
|
207
|
+
|
208
|
+
/* No original path */
|
209
|
+
file->path_original = NULL;
|
210
|
+
file->path_lock = git__strdup(tmp_path);
|
211
|
+
|
212
|
+
if (file->path_lock == NULL) {
|
213
|
+
error = GIT_ENOMEM;
|
214
|
+
goto cleanup;
|
215
|
+
}
|
216
|
+
} else {
|
217
|
+
path_len = strlen(path);
|
218
|
+
|
219
|
+
/* Save the original path of the file */
|
220
|
+
file->path_original = git__strdup(path);
|
221
|
+
if (file->path_original == NULL) {
|
222
|
+
error = GIT_ENOMEM;
|
223
|
+
goto cleanup;
|
224
|
+
}
|
225
|
+
|
226
|
+
/* create the locking path by appending ".lock" to the original */
|
227
|
+
file->path_lock = git__malloc(path_len + GIT_FILELOCK_EXTLENGTH);
|
228
|
+
if (file->path_lock == NULL) {
|
229
|
+
error = GIT_ENOMEM;
|
230
|
+
goto cleanup;
|
231
|
+
}
|
232
|
+
|
233
|
+
memcpy(file->path_lock, file->path_original, path_len);
|
234
|
+
memcpy(file->path_lock + path_len, GIT_FILELOCK_EXTENSION, GIT_FILELOCK_EXTLENGTH);
|
235
|
+
|
236
|
+
/* open the file for locking */
|
237
|
+
if ((error = lock_file(file, flags)) < GIT_SUCCESS)
|
238
|
+
goto cleanup;
|
239
|
+
}
|
240
|
+
|
241
|
+
return GIT_SUCCESS;
|
242
|
+
|
243
|
+
cleanup:
|
244
|
+
git_filebuf_cleanup(file);
|
245
|
+
return git__rethrow(error, "Failed to open file buffer for '%s'", path);
|
246
|
+
}
|
247
|
+
|
248
|
+
int git_filebuf_hash(git_oid *oid, git_filebuf *file)
|
249
|
+
{
|
250
|
+
int error;
|
251
|
+
|
252
|
+
assert(oid && file && file->digest);
|
253
|
+
|
254
|
+
if ((error = flush_buffer(file)) < GIT_SUCCESS)
|
255
|
+
return git__rethrow(error, "Failed to get hash for file");
|
256
|
+
|
257
|
+
git_hash_final(oid, file->digest);
|
258
|
+
git_hash_free_ctx(file->digest);
|
259
|
+
file->digest = NULL;
|
260
|
+
|
261
|
+
return GIT_SUCCESS;
|
262
|
+
}
|
263
|
+
|
264
|
+
int git_filebuf_commit_at(git_filebuf *file, const char *path, mode_t mode)
|
265
|
+
{
|
266
|
+
git__free(file->path_original);
|
267
|
+
file->path_original = git__strdup(path);
|
268
|
+
if (file->path_original == NULL)
|
269
|
+
return GIT_ENOMEM;
|
270
|
+
|
271
|
+
return git_filebuf_commit(file, mode);
|
272
|
+
}
|
273
|
+
|
274
|
+
int git_filebuf_commit(git_filebuf *file, mode_t mode)
|
275
|
+
{
|
276
|
+
int error;
|
277
|
+
|
278
|
+
/* temporary files cannot be committed */
|
279
|
+
assert(file && file->path_original);
|
280
|
+
|
281
|
+
file->flush_mode = Z_FINISH;
|
282
|
+
if ((error = flush_buffer(file)) < GIT_SUCCESS)
|
283
|
+
goto cleanup;
|
284
|
+
|
285
|
+
p_close(file->fd);
|
286
|
+
file->fd = -1;
|
287
|
+
|
288
|
+
if (p_chmod(file->path_lock, mode)) {
|
289
|
+
error = git__throw(GIT_EOSERR, "Failed to chmod locked file before committing");
|
290
|
+
goto cleanup;
|
291
|
+
}
|
292
|
+
|
293
|
+
error = p_rename(file->path_lock, file->path_original);
|
294
|
+
|
295
|
+
cleanup:
|
296
|
+
git_filebuf_cleanup(file);
|
297
|
+
if (error < GIT_SUCCESS)
|
298
|
+
return git__rethrow(error, "Failed to commit locked file from buffer");
|
299
|
+
return GIT_SUCCESS;
|
300
|
+
}
|
301
|
+
|
302
|
+
GIT_INLINE(void) add_to_cache(git_filebuf *file, const void *buf, size_t len)
|
303
|
+
{
|
304
|
+
memcpy(file->buffer + file->buf_pos, buf, len);
|
305
|
+
file->buf_pos += len;
|
306
|
+
}
|
307
|
+
|
308
|
+
int git_filebuf_write(git_filebuf *file, const void *buff, size_t len)
|
309
|
+
{
|
310
|
+
int error;
|
311
|
+
const unsigned char *buf = buff;
|
312
|
+
|
313
|
+
for (;;) {
|
314
|
+
size_t space_left = file->buf_size - file->buf_pos;
|
315
|
+
|
316
|
+
/* cache if it's small */
|
317
|
+
if (space_left > len) {
|
318
|
+
add_to_cache(file, buf, len);
|
319
|
+
return GIT_SUCCESS;
|
320
|
+
}
|
321
|
+
|
322
|
+
add_to_cache(file, buf, space_left);
|
323
|
+
|
324
|
+
if ((error = flush_buffer(file)) < GIT_SUCCESS)
|
325
|
+
return git__rethrow(error, "Failed to write to buffer");
|
326
|
+
|
327
|
+
len -= space_left;
|
328
|
+
buf += space_left;
|
329
|
+
}
|
330
|
+
}
|
331
|
+
|
332
|
+
int git_filebuf_reserve(git_filebuf *file, void **buffer, size_t len)
|
333
|
+
{
|
334
|
+
int error;
|
335
|
+
size_t space_left = file->buf_size - file->buf_pos;
|
336
|
+
|
337
|
+
*buffer = NULL;
|
338
|
+
|
339
|
+
if (len > file->buf_size)
|
340
|
+
return GIT_ENOMEM;
|
341
|
+
|
342
|
+
if (space_left <= len) {
|
343
|
+
if ((error = flush_buffer(file)) < GIT_SUCCESS)
|
344
|
+
return git__rethrow(error, "Failed to reserve buffer");
|
345
|
+
}
|
346
|
+
|
347
|
+
*buffer = (file->buffer + file->buf_pos);
|
348
|
+
file->buf_pos += len;
|
349
|
+
|
350
|
+
return GIT_SUCCESS;
|
351
|
+
}
|
352
|
+
|
353
|
+
int git_filebuf_printf(git_filebuf *file, const char *format, ...)
|
354
|
+
{
|
355
|
+
va_list arglist;
|
356
|
+
size_t space_left;
|
357
|
+
int len, error;
|
358
|
+
char *tmp_buffer;
|
359
|
+
|
360
|
+
space_left = file->buf_size - file->buf_pos;
|
361
|
+
|
362
|
+
do {
|
363
|
+
va_start(arglist, format);
|
364
|
+
len = p_vsnprintf((char *)file->buffer + file->buf_pos, space_left, format, arglist);
|
365
|
+
va_end(arglist);
|
366
|
+
|
367
|
+
if (len < 0)
|
368
|
+
return git__throw(GIT_EOSERR, "Failed to format string");
|
369
|
+
|
370
|
+
if ((size_t)len + 1 <= space_left) {
|
371
|
+
file->buf_pos += len;
|
372
|
+
return GIT_SUCCESS;
|
373
|
+
}
|
374
|
+
|
375
|
+
if ((error = flush_buffer(file)) < GIT_SUCCESS)
|
376
|
+
return git__rethrow(error, "Failed to output to buffer");
|
377
|
+
|
378
|
+
space_left = file->buf_size - file->buf_pos;
|
379
|
+
|
380
|
+
} while ((size_t)len + 1 <= space_left);
|
381
|
+
|
382
|
+
tmp_buffer = git__malloc(len + 1);
|
383
|
+
if (!tmp_buffer)
|
384
|
+
return GIT_ENOMEM;
|
385
|
+
|
386
|
+
va_start(arglist, format);
|
387
|
+
len = p_vsnprintf(tmp_buffer, len + 1, format, arglist);
|
388
|
+
va_end(arglist);
|
389
|
+
|
390
|
+
if (len < 0) {
|
391
|
+
git__free(tmp_buffer);
|
392
|
+
return git__throw(GIT_EOSERR, "Failed to format string");
|
393
|
+
}
|
394
|
+
|
395
|
+
error = git_filebuf_write(file, tmp_buffer, len);
|
396
|
+
git__free(tmp_buffer);
|
397
|
+
|
398
|
+
return error;
|
399
|
+
}
|
400
|
+
|
@@ -0,0 +1,72 @@
|
|
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_filebuf_h__
|
8
|
+
#define INCLUDE_filebuf_h__
|
9
|
+
|
10
|
+
#include "fileops.h"
|
11
|
+
#include "hash.h"
|
12
|
+
#include "git2/zlib.h"
|
13
|
+
|
14
|
+
#ifdef GIT_THREADS
|
15
|
+
# define GIT_FILEBUF_THREADS
|
16
|
+
#endif
|
17
|
+
|
18
|
+
#define GIT_FILEBUF_HASH_CONTENTS (1 << 0)
|
19
|
+
#define GIT_FILEBUF_APPEND (1 << 2)
|
20
|
+
#define GIT_FILEBUF_FORCE (1 << 3)
|
21
|
+
#define GIT_FILEBUF_TEMPORARY (1 << 4)
|
22
|
+
#define GIT_FILEBUF_DEFLATE_SHIFT (5)
|
23
|
+
|
24
|
+
#define GIT_FILELOCK_EXTENSION ".lock\0"
|
25
|
+
#define GIT_FILELOCK_EXTLENGTH 6
|
26
|
+
|
27
|
+
struct git_filebuf {
|
28
|
+
char *path_original;
|
29
|
+
char *path_lock;
|
30
|
+
|
31
|
+
int (*write)(struct git_filebuf *file, void *source, size_t len);
|
32
|
+
|
33
|
+
git_hash_ctx *digest;
|
34
|
+
|
35
|
+
unsigned char *buffer;
|
36
|
+
unsigned char *z_buf;
|
37
|
+
|
38
|
+
z_stream zs;
|
39
|
+
int flush_mode;
|
40
|
+
|
41
|
+
size_t buf_size, buf_pos;
|
42
|
+
git_file fd;
|
43
|
+
};
|
44
|
+
|
45
|
+
typedef struct git_filebuf git_filebuf;
|
46
|
+
|
47
|
+
#define GIT_FILEBUF_INIT {0}
|
48
|
+
|
49
|
+
/* The git_filebuf object lifecycle is:
|
50
|
+
* - Allocate git_filebuf, preferably using GIT_FILEBUF_INIT.
|
51
|
+
* - Call git_filebuf_open() to initialize the filebuf for use.
|
52
|
+
* - Make as many calls to git_filebuf_write(), git_filebuf_printf(),
|
53
|
+
* git_filebuf_reserve() as you like.
|
54
|
+
* - While you are writing, you may call git_filebuf_hash() to get
|
55
|
+
* the hash of all you have written so far.
|
56
|
+
* - To close the git_filebuf, you may call git_filebuf_commit() or
|
57
|
+
* git_filebuf_commit_at() to save the file, or
|
58
|
+
* git_filebuf_cleanup() to abandon the file. All of these will
|
59
|
+
* clear the git_filebuf object.
|
60
|
+
*/
|
61
|
+
|
62
|
+
int git_filebuf_write(git_filebuf *lock, const void *buff, size_t len);
|
63
|
+
int git_filebuf_reserve(git_filebuf *file, void **buff, size_t len);
|
64
|
+
int git_filebuf_printf(git_filebuf *file, const char *format, ...) GIT_FORMAT_PRINTF(2, 3);
|
65
|
+
|
66
|
+
int git_filebuf_open(git_filebuf *lock, const char *path, int flags);
|
67
|
+
int git_filebuf_commit(git_filebuf *lock, mode_t mode);
|
68
|
+
int git_filebuf_commit_at(git_filebuf *lock, const char *path, mode_t mode);
|
69
|
+
void git_filebuf_cleanup(git_filebuf *lock);
|
70
|
+
int git_filebuf_hash(git_oid *oid, git_filebuf *file);
|
71
|
+
|
72
|
+
#endif
|