rugged 0.19.0 → 0.28.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/README.md +184 -33
- data/ext/rugged/extconf.rb +111 -28
- data/ext/rugged/rugged.c +327 -89
- data/ext/rugged/rugged.h +64 -28
- data/ext/rugged/rugged_allocator.c +89 -0
- data/ext/rugged/rugged_backend.c +17 -0
- data/ext/rugged/rugged_blame.c +278 -0
- data/ext/rugged/rugged_blob.c +301 -75
- data/ext/rugged/rugged_branch.c +92 -242
- data/ext/rugged/rugged_branch_collection.c +388 -0
- data/ext/rugged/rugged_commit.c +575 -79
- data/ext/rugged/rugged_config.c +129 -36
- data/ext/rugged/rugged_cred.c +131 -0
- data/ext/rugged/rugged_diff.c +291 -122
- data/ext/rugged/rugged_diff_delta.c +16 -22
- data/ext/rugged/rugged_diff_hunk.c +35 -51
- data/ext/rugged/rugged_diff_line.c +23 -36
- data/ext/rugged/rugged_index.c +289 -152
- data/ext/rugged/rugged_note.c +50 -60
- data/ext/rugged/rugged_object.c +13 -30
- data/ext/rugged/rugged_patch.c +400 -0
- data/ext/rugged/rugged_rebase.c +397 -0
- data/ext/rugged/rugged_reference.c +76 -346
- data/ext/rugged/rugged_reference_collection.c +423 -0
- data/ext/rugged/rugged_remote.c +438 -461
- data/ext/rugged/rugged_remote_collection.c +435 -0
- data/ext/rugged/rugged_repo.c +1548 -365
- data/ext/rugged/rugged_revwalk.c +378 -99
- data/ext/rugged/rugged_settings.c +86 -23
- data/ext/rugged/rugged_signature.c +47 -37
- data/ext/rugged/rugged_submodule.c +835 -0
- data/ext/rugged/rugged_submodule_collection.c +366 -0
- data/ext/rugged/rugged_tag.c +88 -210
- data/ext/rugged/rugged_tag_collection.c +326 -0
- data/ext/rugged/rugged_tree.c +460 -217
- data/lib/rugged/attributes.rb +46 -0
- data/lib/rugged/blob.rb +33 -0
- data/lib/rugged/branch.rb +12 -16
- data/lib/rugged/commit.rb +9 -0
- data/lib/rugged/console.rb +5 -0
- data/lib/rugged/credentials.rb +48 -0
- data/lib/rugged/diff/delta.rb +6 -2
- data/lib/rugged/diff/hunk.rb +9 -9
- data/lib/rugged/diff/line.rb +28 -5
- data/lib/rugged/diff.rb +7 -1
- data/lib/rugged/index.rb +120 -0
- data/lib/rugged/object.rb +5 -0
- data/lib/rugged/patch.rb +41 -0
- data/lib/rugged/reference.rb +6 -3
- data/lib/rugged/remote.rb +5 -9
- data/lib/rugged/repository.rb +126 -14
- data/lib/rugged/submodule_collection.rb +53 -0
- data/lib/rugged/tag.rb +45 -16
- data/lib/rugged/tree.rb +163 -1
- data/lib/rugged/version.rb +6 -1
- data/lib/rugged/walker.rb +5 -0
- data/lib/rugged.rb +16 -1
- data/vendor/libgit2/AUTHORS +77 -0
- data/vendor/libgit2/CMakeLists.txt +317 -0
- data/vendor/libgit2/COPYING +993 -0
- data/vendor/libgit2/cmake/Modules/AddCFlagIfSupported.cmake +30 -0
- data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.c.in +29 -0
- data/vendor/libgit2/cmake/Modules/CheckPrototypeDefinition.cmake +96 -0
- data/vendor/libgit2/cmake/Modules/EnableWarnings.cmake +11 -0
- data/vendor/libgit2/cmake/Modules/FindCoreFoundation.cmake +26 -0
- data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +324 -0
- data/vendor/libgit2/cmake/Modules/FindHTTP_Parser.cmake +39 -0
- data/vendor/libgit2/cmake/Modules/FindIconv.cmake +45 -0
- data/vendor/libgit2/cmake/Modules/FindPkgLibraries.cmake +28 -0
- data/vendor/libgit2/cmake/Modules/FindSecurity.cmake +28 -0
- data/vendor/libgit2/cmake/Modules/FindStatNsec.cmake +20 -0
- data/vendor/libgit2/cmake/Modules/FindmbedTLS.cmake +93 -0
- data/vendor/libgit2/cmake/Modules/IdeSplitSources.cmake +22 -0
- data/vendor/libgit2/deps/http-parser/CMakeLists.txt +5 -0
- data/vendor/libgit2/deps/http-parser/COPYING +23 -0
- data/vendor/libgit2/deps/http-parser/http_parser.c +5 -2
- data/vendor/libgit2/deps/http-parser/http_parser.h +2 -0
- data/vendor/libgit2/deps/regex/CMakeLists.txt +2 -0
- data/vendor/libgit2/deps/regex/COPYING +502 -0
- data/vendor/libgit2/deps/regex/regex.c +10 -3
- data/vendor/libgit2/deps/winhttp/CMakeLists.txt +26 -0
- data/vendor/libgit2/deps/winhttp/COPYING.GPL +993 -0
- data/vendor/libgit2/deps/winhttp/COPYING.LGPL +502 -0
- data/vendor/libgit2/deps/winhttp/urlmon.h +45 -0
- data/vendor/libgit2/deps/winhttp/winhttp.def +29 -0
- data/vendor/libgit2/deps/winhttp/winhttp.h +594 -0
- data/vendor/libgit2/deps/winhttp/winhttp64.def +29 -0
- data/vendor/libgit2/deps/zlib/CMakeLists.txt +5 -0
- data/vendor/libgit2/deps/zlib/COPYING +27 -0
- data/vendor/libgit2/deps/zlib/adler32.c +51 -34
- data/vendor/libgit2/deps/zlib/crc32.c +61 -61
- data/vendor/libgit2/deps/zlib/crc32.h +1 -1
- data/vendor/libgit2/deps/zlib/deflate.c +681 -352
- data/vendor/libgit2/deps/zlib/deflate.h +25 -18
- data/vendor/libgit2/deps/zlib/gzguts.h +218 -0
- data/vendor/libgit2/deps/zlib/infback.c +640 -0
- data/vendor/libgit2/deps/zlib/inffast.c +36 -53
- data/vendor/libgit2/deps/zlib/inffixed.h +3 -3
- data/vendor/libgit2/deps/zlib/inflate.c +167 -86
- data/vendor/libgit2/deps/zlib/inflate.h +7 -4
- data/vendor/libgit2/deps/zlib/inftrees.c +24 -50
- data/vendor/libgit2/deps/zlib/trees.c +55 -96
- data/vendor/libgit2/deps/zlib/zconf.h +499 -19
- data/vendor/libgit2/deps/zlib/zlib.h +526 -227
- data/vendor/libgit2/deps/zlib/zutil.c +39 -32
- data/vendor/libgit2/deps/zlib/zutil.h +75 -78
- data/vendor/libgit2/include/git2/annotated_commit.h +125 -0
- data/vendor/libgit2/include/git2/apply.h +129 -0
- data/vendor/libgit2/include/git2/attr.h +36 -21
- data/vendor/libgit2/include/git2/blame.h +229 -0
- data/vendor/libgit2/include/git2/blob.h +81 -44
- data/vendor/libgit2/include/git2/branch.h +81 -42
- data/vendor/libgit2/include/git2/buffer.h +128 -0
- data/vendor/libgit2/include/git2/checkout.h +141 -67
- data/vendor/libgit2/include/git2/cherrypick.h +92 -0
- data/vendor/libgit2/include/git2/clone.h +157 -58
- data/vendor/libgit2/include/git2/commit.h +231 -12
- data/vendor/libgit2/include/git2/common.h +216 -30
- data/vendor/libgit2/include/git2/config.h +274 -48
- data/vendor/libgit2/include/git2/cred_helpers.h +4 -4
- data/vendor/libgit2/include/git2/deprecated.h +253 -0
- data/vendor/libgit2/include/git2/describe.h +189 -0
- data/vendor/libgit2/include/git2/diff.h +985 -575
- data/vendor/libgit2/include/git2/errors.h +93 -52
- data/vendor/libgit2/include/git2/filter.h +217 -0
- data/vendor/libgit2/include/git2/global.h +44 -0
- data/vendor/libgit2/include/git2/graph.h +17 -0
- data/vendor/libgit2/include/git2/ignore.h +2 -2
- data/vendor/libgit2/include/git2/index.h +269 -94
- data/vendor/libgit2/include/git2/indexer.h +44 -12
- data/vendor/libgit2/include/git2/mailmap.h +115 -0
- data/vendor/libgit2/include/git2/merge.h +501 -64
- data/vendor/libgit2/include/git2/message.h +52 -17
- data/vendor/libgit2/include/git2/net.h +11 -5
- data/vendor/libgit2/include/git2/notes.h +120 -16
- data/vendor/libgit2/include/git2/object.h +62 -23
- data/vendor/libgit2/include/git2/odb.h +140 -24
- data/vendor/libgit2/include/git2/odb_backend.h +56 -12
- data/vendor/libgit2/include/git2/oid.h +17 -18
- data/vendor/libgit2/include/git2/oidarray.h +40 -0
- data/vendor/libgit2/include/git2/pack.h +86 -7
- data/vendor/libgit2/include/git2/patch.h +274 -0
- data/vendor/libgit2/include/git2/pathspec.h +280 -0
- data/vendor/libgit2/include/git2/proxy.h +96 -0
- data/vendor/libgit2/include/git2/rebase.h +323 -0
- data/vendor/libgit2/include/git2/reflog.h +12 -9
- data/vendor/libgit2/include/git2/refs.h +241 -46
- data/vendor/libgit2/include/git2/refspec.h +20 -4
- data/vendor/libgit2/include/git2/remote.h +636 -209
- data/vendor/libgit2/include/git2/repository.h +267 -57
- data/vendor/libgit2/include/git2/reset.h +36 -6
- data/vendor/libgit2/include/git2/revert.h +91 -0
- data/vendor/libgit2/include/git2/revparse.h +27 -16
- data/vendor/libgit2/include/git2/revwalk.h +78 -35
- data/vendor/libgit2/include/git2/signature.h +32 -5
- data/vendor/libgit2/include/git2/stash.h +160 -21
- data/vendor/libgit2/include/git2/status.h +92 -30
- data/vendor/libgit2/include/git2/submodule.h +226 -133
- data/vendor/libgit2/include/git2/sys/alloc.h +101 -0
- data/vendor/libgit2/include/git2/sys/commit.h +38 -4
- data/vendor/libgit2/include/git2/sys/config.h +68 -9
- data/vendor/libgit2/include/git2/sys/diff.h +94 -0
- data/vendor/libgit2/include/git2/sys/filter.h +332 -0
- data/vendor/libgit2/include/git2/sys/hashsig.h +106 -0
- data/vendor/libgit2/include/git2/sys/index.h +6 -5
- data/vendor/libgit2/include/git2/sys/mempack.h +86 -0
- data/vendor/libgit2/include/git2/sys/merge.h +182 -0
- data/vendor/libgit2/include/git2/sys/odb_backend.h +66 -28
- data/vendor/libgit2/include/git2/sys/openssl.h +38 -0
- data/vendor/libgit2/include/git2/sys/path.h +64 -0
- data/vendor/libgit2/include/git2/sys/refdb_backend.h +79 -19
- data/vendor/libgit2/include/git2/sys/reflog.h +21 -0
- data/vendor/libgit2/include/git2/sys/refs.h +13 -2
- data/vendor/libgit2/include/git2/sys/repository.h +64 -1
- data/vendor/libgit2/include/git2/sys/stream.h +138 -0
- data/vendor/libgit2/include/git2/sys/time.h +31 -0
- data/vendor/libgit2/include/git2/sys/transport.h +439 -0
- data/vendor/libgit2/include/git2/tag.h +11 -2
- data/vendor/libgit2/include/git2/trace.h +1 -1
- data/vendor/libgit2/include/git2/transaction.h +121 -0
- data/vendor/libgit2/include/git2/transport.h +261 -292
- data/vendor/libgit2/include/git2/tree.h +111 -21
- data/vendor/libgit2/include/git2/types.h +244 -32
- data/vendor/libgit2/include/git2/version.h +5 -2
- data/vendor/libgit2/include/git2/worktree.h +255 -0
- data/vendor/libgit2/include/git2.h +50 -40
- data/vendor/libgit2/libgit2.pc.in +13 -0
- data/vendor/libgit2/src/CMakeLists.txt +525 -0
- data/vendor/libgit2/src/alloc.c +55 -0
- data/vendor/libgit2/src/alloc.h +40 -0
- data/vendor/libgit2/src/annotated_commit.c +228 -0
- data/vendor/libgit2/src/annotated_commit.h +52 -0
- data/vendor/libgit2/src/apply.c +855 -0
- data/vendor/libgit2/src/apply.h +25 -0
- data/vendor/libgit2/src/array.h +74 -16
- data/vendor/libgit2/src/attr.c +239 -408
- data/vendor/libgit2/src/attr.h +3 -33
- data/vendor/libgit2/src/attr_file.c +424 -156
- data/vendor/libgit2/src/attr_file.h +95 -23
- data/vendor/libgit2/src/attrcache.c +469 -0
- data/vendor/libgit2/src/attrcache.h +37 -5
- data/vendor/libgit2/src/bitvec.h +75 -0
- data/vendor/libgit2/src/blame.c +532 -0
- data/vendor/libgit2/src/blame.h +95 -0
- data/vendor/libgit2/src/blame_git.c +668 -0
- data/vendor/libgit2/src/blame_git.h +22 -0
- data/vendor/libgit2/src/blob.c +233 -129
- data/vendor/libgit2/src/blob.h +29 -1
- data/vendor/libgit2/src/branch.c +295 -197
- data/vendor/libgit2/src/branch.h +2 -0
- data/vendor/libgit2/src/buf_text.c +52 -27
- data/vendor/libgit2/src/buf_text.h +7 -7
- data/vendor/libgit2/src/buffer.c +609 -52
- data/vendor/libgit2/src/buffer.h +68 -23
- data/vendor/libgit2/src/cache.c +48 -51
- data/vendor/libgit2/src/cache.h +6 -4
- data/vendor/libgit2/src/cc-compat.h +35 -7
- data/vendor/libgit2/src/checkout.c +1827 -483
- data/vendor/libgit2/src/checkout.h +4 -1
- data/vendor/libgit2/src/cherrypick.c +230 -0
- data/vendor/libgit2/src/clone.c +338 -258
- data/vendor/libgit2/src/{compress.h → clone.h} +5 -5
- data/vendor/libgit2/src/commit.c +711 -124
- data/vendor/libgit2/src/commit.h +10 -3
- data/vendor/libgit2/src/commit_list.c +21 -14
- data/vendor/libgit2/src/commit_list.h +9 -3
- data/vendor/libgit2/src/common.h +153 -13
- data/vendor/libgit2/src/config.c +871 -242
- data/vendor/libgit2/src/config.h +58 -14
- data/vendor/libgit2/src/config_backend.h +84 -0
- data/vendor/libgit2/src/config_cache.c +44 -18
- data/vendor/libgit2/src/config_entries.c +259 -0
- data/vendor/libgit2/src/config_entries.h +23 -0
- data/vendor/libgit2/src/config_file.c +837 -1113
- data/vendor/libgit2/src/config_mem.c +224 -0
- data/vendor/libgit2/src/config_parse.c +558 -0
- data/vendor/libgit2/src/config_parse.h +64 -0
- data/vendor/libgit2/src/crlf.c +290 -195
- data/vendor/libgit2/src/date.c +35 -7
- data/vendor/libgit2/src/delta.c +275 -71
- data/vendor/libgit2/src/delta.h +80 -58
- data/vendor/libgit2/src/describe.c +893 -0
- data/vendor/libgit2/src/diff.c +330 -1128
- data/vendor/libgit2/src/diff.h +25 -67
- data/vendor/libgit2/src/diff_driver.c +225 -109
- data/vendor/libgit2/src/diff_driver.h +5 -2
- data/vendor/libgit2/src/diff_file.c +128 -103
- data/vendor/libgit2/src/diff_file.h +17 -12
- data/vendor/libgit2/src/diff_generate.c +1622 -0
- data/vendor/libgit2/src/diff_generate.h +128 -0
- data/vendor/libgit2/src/diff_parse.c +108 -0
- data/vendor/libgit2/src/diff_parse.h +20 -0
- data/vendor/libgit2/src/diff_print.c +578 -218
- data/vendor/libgit2/src/diff_stats.c +362 -0
- data/vendor/libgit2/src/diff_tform.c +429 -257
- data/vendor/libgit2/src/diff_tform.h +25 -0
- data/vendor/libgit2/src/diff_xdiff.c +143 -46
- data/vendor/libgit2/src/diff_xdiff.h +12 -5
- data/vendor/libgit2/src/errors.c +150 -34
- data/vendor/libgit2/src/features.h.in +37 -0
- data/vendor/libgit2/src/fetch.c +69 -46
- data/vendor/libgit2/src/fetch.h +6 -12
- data/vendor/libgit2/src/fetchhead.c +40 -33
- data/vendor/libgit2/src/fetchhead.h +5 -4
- data/vendor/libgit2/src/filebuf.c +163 -61
- data/vendor/libgit2/src/filebuf.h +13 -7
- data/vendor/libgit2/src/fileops.c +549 -407
- data/vendor/libgit2/src/fileops.h +97 -106
- data/vendor/libgit2/src/filter.c +989 -46
- data/vendor/libgit2/src/filter.h +21 -70
- data/vendor/libgit2/src/fnmatch.c +67 -11
- data/vendor/libgit2/src/fnmatch.h +27 -7
- data/vendor/libgit2/src/global.c +257 -63
- data/vendor/libgit2/src/global.h +19 -0
- data/vendor/libgit2/src/graph.c +39 -23
- data/vendor/libgit2/src/hash/hash_collisiondetect.h +51 -0
- data/vendor/libgit2/src/hash/hash_common_crypto.h +61 -0
- data/vendor/libgit2/src/hash/hash_generic.c +3 -3
- data/vendor/libgit2/src/hash/hash_generic.h +10 -5
- data/vendor/libgit2/src/hash/hash_mbedtls.c +38 -0
- data/vendor/libgit2/src/hash/hash_mbedtls.h +24 -0
- data/vendor/libgit2/src/hash/hash_openssl.h +26 -8
- data/vendor/libgit2/src/hash/hash_win32.c +71 -43
- data/vendor/libgit2/src/hash/hash_win32.h +4 -3
- data/vendor/libgit2/src/hash/sha1dc/sha1.c +1900 -0
- data/vendor/libgit2/src/hash/sha1dc/sha1.h +110 -0
- data/vendor/libgit2/src/hash/sha1dc/ubc_check.c +372 -0
- data/vendor/libgit2/src/hash/sha1dc/ubc_check.h +52 -0
- data/vendor/libgit2/src/hash.c +0 -1
- data/vendor/libgit2/src/hash.h +13 -6
- data/vendor/libgit2/src/hashsig.c +121 -126
- data/vendor/libgit2/src/ident.c +129 -0
- data/vendor/libgit2/src/idxmap.c +153 -0
- data/vendor/libgit2/src/idxmap.h +41 -0
- data/vendor/libgit2/src/ignore.c +362 -123
- data/vendor/libgit2/src/ignore.h +16 -4
- data/vendor/libgit2/src/index.c +2131 -692
- data/vendor/libgit2/src/index.h +138 -6
- data/vendor/libgit2/src/indexer.c +866 -266
- data/vendor/libgit2/src/indexer.h +16 -0
- data/vendor/libgit2/src/integer.h +106 -0
- data/vendor/libgit2/src/iterator.c +1888 -967
- data/vendor/libgit2/src/iterator.h +130 -67
- data/vendor/libgit2/src/khash.h +43 -29
- data/vendor/libgit2/src/mailmap.c +485 -0
- data/vendor/libgit2/src/mailmap.h +35 -0
- data/vendor/libgit2/src/map.h +1 -1
- data/vendor/libgit2/src/merge.c +1679 -479
- data/vendor/libgit2/src/merge.h +89 -22
- data/vendor/libgit2/src/merge_driver.c +426 -0
- data/vendor/libgit2/src/merge_driver.h +62 -0
- data/vendor/libgit2/src/merge_file.c +238 -101
- data/vendor/libgit2/src/message.c +4 -28
- data/vendor/libgit2/src/message.h +3 -1
- data/vendor/libgit2/src/mwindow.c +123 -15
- data/vendor/libgit2/src/mwindow.h +10 -1
- data/vendor/libgit2/src/netops.c +178 -499
- data/vendor/libgit2/src/netops.h +51 -27
- data/vendor/libgit2/src/notes.c +251 -94
- data/vendor/libgit2/src/notes.h +5 -2
- data/vendor/libgit2/src/object.c +253 -67
- data/vendor/libgit2/src/object.h +40 -2
- data/vendor/libgit2/src/object_api.c +30 -11
- data/vendor/libgit2/src/odb.c +765 -201
- data/vendor/libgit2/src/odb.h +40 -8
- data/vendor/libgit2/src/odb_loose.c +560 -346
- data/vendor/libgit2/src/odb_mempack.c +185 -0
- data/vendor/libgit2/src/odb_pack.c +117 -73
- data/vendor/libgit2/src/offmap.c +113 -0
- data/vendor/libgit2/src/offmap.h +32 -42
- data/vendor/libgit2/src/oid.c +45 -25
- data/vendor/libgit2/src/oid.h +26 -8
- data/vendor/libgit2/src/oidarray.c +34 -0
- data/vendor/libgit2/src/oidarray.h +20 -0
- data/vendor/libgit2/src/oidmap.c +125 -0
- data/vendor/libgit2/src/oidmap.h +30 -17
- data/vendor/libgit2/src/pack-objects.c +688 -265
- data/vendor/libgit2/src/pack-objects.h +27 -13
- data/vendor/libgit2/src/pack.c +418 -202
- data/vendor/libgit2/src/pack.h +25 -16
- data/vendor/libgit2/src/parse.c +124 -0
- data/vendor/libgit2/src/parse.h +61 -0
- data/vendor/libgit2/src/patch.c +223 -0
- data/vendor/libgit2/src/patch.h +68 -0
- data/vendor/libgit2/src/patch_generate.c +901 -0
- data/vendor/libgit2/src/patch_generate.h +69 -0
- data/vendor/libgit2/src/patch_parse.c +1136 -0
- data/vendor/libgit2/src/patch_parse.h +51 -0
- data/vendor/libgit2/src/path.c +1247 -241
- data/vendor/libgit2/src/path.h +353 -57
- data/vendor/libgit2/src/pathspec.c +586 -58
- data/vendor/libgit2/src/pathspec.h +37 -15
- data/vendor/libgit2/src/pool.c +134 -221
- data/vendor/libgit2/src/pool.h +38 -50
- data/vendor/libgit2/src/posix.c +76 -10
- data/vendor/libgit2/src/posix.h +74 -32
- data/vendor/libgit2/src/pqueue.c +79 -117
- data/vendor/libgit2/src/pqueue.h +38 -82
- data/vendor/libgit2/src/proxy.c +39 -0
- data/vendor/libgit2/src/proxy.h +17 -0
- data/vendor/libgit2/src/push.c +178 -279
- data/vendor/libgit2/src/push.h +93 -4
- data/vendor/libgit2/src/reader.c +265 -0
- data/vendor/libgit2/src/reader.h +107 -0
- data/vendor/libgit2/src/rebase.c +1364 -0
- data/vendor/libgit2/src/refdb.c +74 -19
- data/vendor/libgit2/src/refdb.h +16 -3
- data/vendor/libgit2/src/refdb_fs.c +1472 -603
- data/vendor/libgit2/src/refdb_fs.h +4 -0
- data/vendor/libgit2/src/reflog.c +40 -330
- data/vendor/libgit2/src/reflog.h +8 -2
- data/vendor/libgit2/src/refs.c +641 -225
- data/vendor/libgit2/src/refs.h +53 -6
- data/vendor/libgit2/src/refspec.c +175 -62
- data/vendor/libgit2/src/refspec.h +10 -25
- data/vendor/libgit2/src/remote.c +1741 -723
- data/vendor/libgit2/src/remote.h +17 -5
- data/vendor/libgit2/src/repository.c +1505 -421
- data/vendor/libgit2/src/repository.h +95 -15
- data/vendor/libgit2/src/reset.c +63 -26
- data/vendor/libgit2/src/revert.c +232 -0
- data/vendor/libgit2/src/revparse.c +94 -80
- data/vendor/libgit2/src/revwalk.c +427 -194
- data/vendor/libgit2/src/revwalk.h +14 -5
- data/vendor/libgit2/src/settings.c +290 -0
- data/vendor/libgit2/src/sha1_lookup.c +16 -159
- data/vendor/libgit2/src/sha1_lookup.h +5 -4
- data/vendor/libgit2/src/signature.c +138 -26
- data/vendor/libgit2/src/signature.h +5 -0
- data/vendor/libgit2/src/sortedcache.c +395 -0
- data/vendor/libgit2/src/sortedcache.h +180 -0
- data/vendor/libgit2/src/stash.c +629 -168
- data/vendor/libgit2/src/status.c +125 -75
- data/vendor/libgit2/src/status.h +4 -2
- data/vendor/libgit2/src/stdalloc.c +120 -0
- data/vendor/libgit2/src/stdalloc.h +17 -0
- data/vendor/libgit2/src/stream.h +86 -0
- data/vendor/libgit2/src/streams/mbedtls.c +483 -0
- data/vendor/libgit2/src/streams/mbedtls.h +23 -0
- data/vendor/libgit2/src/streams/openssl.c +789 -0
- data/vendor/libgit2/src/streams/openssl.h +23 -0
- data/vendor/libgit2/src/streams/registry.c +118 -0
- data/vendor/libgit2/src/streams/registry.h +19 -0
- data/vendor/libgit2/src/streams/socket.c +235 -0
- data/vendor/libgit2/src/streams/socket.h +23 -0
- data/vendor/libgit2/src/streams/stransport.c +323 -0
- data/vendor/libgit2/src/streams/stransport.h +21 -0
- data/vendor/libgit2/src/streams/tls.c +73 -0
- data/vendor/libgit2/src/streams/tls.h +31 -0
- data/vendor/libgit2/src/strmap.c +147 -0
- data/vendor/libgit2/src/strmap.h +46 -51
- data/vendor/libgit2/src/strnlen.h +24 -0
- data/vendor/libgit2/src/submodule.c +1633 -877
- data/vendor/libgit2/src/submodule.h +83 -21
- data/vendor/libgit2/src/sysdir.c +355 -0
- data/vendor/libgit2/src/sysdir.h +119 -0
- data/vendor/libgit2/src/tag.c +87 -62
- data/vendor/libgit2/src/tag.h +4 -1
- data/vendor/libgit2/src/thread-utils.c +3 -0
- data/vendor/libgit2/src/thread-utils.h +71 -35
- data/vendor/libgit2/src/trace.c +4 -4
- data/vendor/libgit2/src/trace.h +11 -3
- data/vendor/libgit2/src/trailer.c +416 -0
- data/vendor/libgit2/src/transaction.c +382 -0
- data/vendor/libgit2/src/transaction.h +14 -0
- data/vendor/libgit2/src/transport.c +133 -67
- data/vendor/libgit2/src/transports/auth.c +75 -0
- data/vendor/libgit2/src/transports/auth.h +64 -0
- data/vendor/libgit2/src/transports/auth_negotiate.c +277 -0
- data/vendor/libgit2/src/transports/auth_negotiate.h +27 -0
- data/vendor/libgit2/src/transports/cred.c +296 -68
- data/vendor/libgit2/src/transports/cred.h +16 -0
- data/vendor/libgit2/src/transports/cred_helpers.c +4 -0
- data/vendor/libgit2/src/transports/git.c +108 -90
- data/vendor/libgit2/src/transports/http.c +803 -258
- data/vendor/libgit2/src/transports/http.h +25 -0
- data/vendor/libgit2/src/transports/local.c +265 -169
- data/vendor/libgit2/src/transports/smart.c +255 -45
- data/vendor/libgit2/src/transports/smart.h +42 -22
- data/vendor/libgit2/src/transports/smart_pkt.c +250 -159
- data/vendor/libgit2/src/transports/smart_protocol.c +414 -196
- data/vendor/libgit2/src/transports/ssh.c +645 -236
- data/vendor/libgit2/src/transports/ssh.h +14 -0
- data/vendor/libgit2/src/transports/winhttp.c +809 -353
- data/vendor/libgit2/src/tree-cache.c +138 -52
- data/vendor/libgit2/src/tree-cache.h +14 -7
- data/vendor/libgit2/src/tree.c +620 -259
- data/vendor/libgit2/src/tree.h +12 -19
- data/vendor/libgit2/src/tsort.c +3 -2
- data/vendor/libgit2/src/unix/map.c +25 -7
- data/vendor/libgit2/src/unix/posix.h +77 -12
- data/vendor/libgit2/src/unix/pthread.h +56 -0
- data/vendor/libgit2/src/unix/realpath.c +12 -8
- data/vendor/libgit2/src/userdiff.h +208 -0
- data/vendor/libgit2/src/util.c +349 -165
- data/vendor/libgit2/src/util.h +167 -85
- data/vendor/libgit2/src/varint.c +43 -0
- data/vendor/libgit2/src/varint.h +17 -0
- data/vendor/libgit2/src/vector.c +156 -33
- data/vendor/libgit2/src/vector.h +41 -5
- data/vendor/libgit2/src/win32/dir.c +22 -42
- data/vendor/libgit2/src/win32/dir.h +7 -5
- data/vendor/libgit2/src/win32/error.c +6 -32
- data/vendor/libgit2/src/win32/error.h +4 -2
- data/vendor/libgit2/src/win32/findfile.c +62 -69
- data/vendor/libgit2/src/win32/findfile.h +5 -13
- data/vendor/libgit2/src/win32/git2.rc +44 -0
- data/vendor/libgit2/src/win32/map.c +39 -11
- data/vendor/libgit2/src/win32/mingw-compat.h +10 -11
- data/vendor/libgit2/src/win32/msvc-compat.h +10 -33
- data/vendor/libgit2/src/win32/path_w32.c +476 -0
- data/vendor/libgit2/src/win32/path_w32.h +104 -0
- data/vendor/libgit2/src/win32/posix.h +35 -30
- data/vendor/libgit2/src/win32/posix_w32.c +659 -327
- data/vendor/libgit2/src/win32/precompiled.h +7 -2
- data/vendor/libgit2/src/win32/reparse.h +57 -0
- data/vendor/libgit2/src/win32/thread.c +258 -0
- data/vendor/libgit2/src/win32/thread.h +64 -0
- data/vendor/libgit2/src/win32/utf-conv.c +127 -62
- data/vendor/libgit2/src/win32/utf-conv.h +47 -6
- data/vendor/libgit2/src/win32/version.h +21 -4
- data/vendor/libgit2/src/win32/w32_buffer.c +54 -0
- data/vendor/libgit2/src/win32/w32_buffer.h +20 -0
- data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.c +438 -0
- data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +129 -0
- data/vendor/libgit2/src/win32/w32_stack.c +193 -0
- data/vendor/libgit2/src/win32/w32_stack.h +140 -0
- data/vendor/libgit2/src/win32/w32_util.c +95 -0
- data/vendor/libgit2/src/win32/w32_util.h +170 -0
- data/vendor/libgit2/src/win32/win32-compat.h +52 -0
- data/vendor/libgit2/src/worktree.c +578 -0
- data/vendor/libgit2/src/worktree.h +39 -0
- data/vendor/libgit2/src/xdiff/xdiff.h +33 -18
- data/vendor/libgit2/src/xdiff/xdiffi.c +578 -88
- data/vendor/libgit2/src/xdiff/xdiffi.h +3 -2
- data/vendor/libgit2/src/xdiff/xemit.c +106 -45
- data/vendor/libgit2/src/xdiff/xemit.h +3 -3
- data/vendor/libgit2/src/xdiff/xhistogram.c +5 -4
- data/vendor/libgit2/src/xdiff/xinclude.h +3 -2
- data/vendor/libgit2/src/xdiff/xmacros.h +2 -2
- data/vendor/libgit2/src/xdiff/xmerge.c +167 -48
- data/vendor/libgit2/src/xdiff/xpatience.c +42 -10
- data/vendor/libgit2/src/xdiff/xprepare.c +14 -14
- data/vendor/libgit2/src/xdiff/xprepare.h +2 -2
- data/vendor/libgit2/src/xdiff/xtypes.h +2 -2
- data/vendor/libgit2/src/xdiff/xutils.c +60 -56
- data/vendor/libgit2/src/xdiff/xutils.h +3 -5
- data/vendor/libgit2/src/zstream.c +205 -0
- data/vendor/libgit2/src/zstream.h +53 -0
- metadata +281 -233
- data/Rakefile +0 -61
- data/ext/rugged/rugged_diff_patch.c +0 -169
- data/lib/rugged/diff/patch.rb +0 -28
- data/test/blob_test.rb +0 -341
- data/test/branch_test.rb +0 -199
- data/test/commit_test.rb +0 -104
- data/test/config_test.rb +0 -45
- data/test/coverage/cover.rb +0 -133
- data/test/diff_test.rb +0 -777
- data/test/errors_test.rb +0 -34
- data/test/fixtures/alternate/objects/14/6ae76773c91e3b1d00cf7a338ec55ae58297e2 +0 -0
- data/test/fixtures/alternate/objects/14/9c32d47e99d0a3572ff1e70a2e0051bbf347a9 +0 -0
- data/test/fixtures/alternate/objects/14/fb3108588f9421bf764041e5e3ac305eb6277f +0 -0
- data/test/fixtures/archive.tar.gz +0 -0
- data/test/fixtures/attr/attr0 +0 -1
- data/test/fixtures/attr/attr1 +0 -29
- data/test/fixtures/attr/attr2 +0 -21
- data/test/fixtures/attr/attr3 +0 -4
- data/test/fixtures/attr/binfile +0 -1
- data/test/fixtures/attr/dir/file +0 -0
- data/test/fixtures/attr/file +0 -1
- data/test/fixtures/attr/gitattributes +0 -29
- data/test/fixtures/attr/gitignore +0 -2
- data/test/fixtures/attr/ign +0 -1
- data/test/fixtures/attr/macro_bad +0 -1
- data/test/fixtures/attr/macro_test +0 -1
- data/test/fixtures/attr/root_test1 +0 -1
- data/test/fixtures/attr/root_test2 +0 -6
- data/test/fixtures/attr/root_test3 +0 -19
- data/test/fixtures/attr/root_test4.txt +0 -14
- data/test/fixtures/attr/sub/abc +0 -37
- data/test/fixtures/attr/sub/dir/file +0 -0
- data/test/fixtures/attr/sub/file +0 -1
- data/test/fixtures/attr/sub/ign/file +0 -1
- data/test/fixtures/attr/sub/ign/sub/file +0 -1
- data/test/fixtures/attr/sub/sub/dir +0 -0
- data/test/fixtures/attr/sub/sub/file +0 -1
- data/test/fixtures/attr/sub/sub/subsub.txt +0 -1
- data/test/fixtures/attr/sub/subdir_test1 +0 -2
- data/test/fixtures/attr/sub/subdir_test2.txt +0 -1
- data/test/fixtures/diff/another.txt +0 -38
- data/test/fixtures/diff/readme.txt +0 -36
- data/test/fixtures/mergedrepo/conflicts-one.txt +0 -5
- data/test/fixtures/mergedrepo/conflicts-two.txt +0 -5
- data/test/fixtures/mergedrepo/one.txt +0 -10
- data/test/fixtures/mergedrepo/two.txt +0 -12
- data/test/fixtures/status/current_file +0 -1
- data/test/fixtures/status/ignored_file +0 -1
- data/test/fixtures/status/modified_file +0 -2
- data/test/fixtures/status/new_file +0 -1
- data/test/fixtures/status/staged_changes +0 -2
- data/test/fixtures/status/staged_changes_modified_file +0 -3
- data/test/fixtures/status/staged_delete_modified_file +0 -1
- data/test/fixtures/status/staged_new_file +0 -1
- data/test/fixtures/status/staged_new_file_modified_file +0 -2
- data/test/fixtures/status/subdir/current_file +0 -1
- data/test/fixtures/status/subdir/modified_file +0 -2
- data/test/fixtures/status/subdir/new_file +0 -1
- data/test/fixtures/status/subdir.txt +0 -2
- data/test/fixtures/status//350/277/231 +0 -1
- data/test/fixtures/testrepo.git/HEAD +0 -1
- data/test/fixtures/testrepo.git/config +0 -13
- data/test/fixtures/testrepo.git/description +0 -1
- data/test/fixtures/testrepo.git/index +0 -0
- data/test/fixtures/testrepo.git/info/exclude +0 -6
- data/test/fixtures/testrepo.git/logs/HEAD +0 -3
- data/test/fixtures/testrepo.git/logs/refs/heads/master +0 -3
- data/test/fixtures/testrepo.git/logs/refs/notes/commits +0 -1
- data/test/fixtures/testrepo.git/objects/0c/37a5391bbff43c37f0d0371823a5509eed5b1d +0 -0
- data/test/fixtures/testrepo.git/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08 +0 -0
- data/test/fixtures/testrepo.git/objects/18/1037049a54a1eb5fab404658a3a250b44335d7 +0 -0
- data/test/fixtures/testrepo.git/objects/18/10dff58d8a660512d4832e740f692884338ccd +0 -0
- data/test/fixtures/testrepo.git/objects/2d/2eff63372b08adf0a9eb84109ccf7d19e2f3a2 +0 -0
- data/test/fixtures/testrepo.git/objects/36/060c58702ed4c2a40832c51758d5344201d89a +0 -2
- data/test/fixtures/testrepo.git/objects/44/1034f860c1d5d90e4188d11ae0d325176869a8 +0 -1
- data/test/fixtures/testrepo.git/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 +0 -0
- data/test/fixtures/testrepo.git/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 +0 -2
- data/test/fixtures/testrepo.git/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644 +0 -2
- data/test/fixtures/testrepo.git/objects/60/d415052a33de2150bf68757f6461df4f563ae4 +0 -0
- data/test/fixtures/testrepo.git/objects/61/9f9935957e010c419cb9d15621916ddfcc0b96 +0 -0
- data/test/fixtures/testrepo.git/objects/68/8a8f4ef7496901d15322972f96e212a9e466cc +0 -1
- data/test/fixtures/testrepo.git/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a +0 -0
- data/test/fixtures/testrepo.git/objects/77/71329dfa3002caf8c61a0ceb62a31d09023f37 +0 -0
- data/test/fixtures/testrepo.git/objects/81/4889a078c031f61ed08ab5fa863aea9314344d +0 -0
- data/test/fixtures/testrepo.git/objects/84/96071c1b46c854b31185ea97743be6a8774479 +0 -0
- data/test/fixtures/testrepo.git/objects/94/eca2de348d5f672faf56b0decafa5937e3235e +0 -0
- data/test/fixtures/testrepo.git/objects/9b/7384fe1676186192842f5d3e129457b62db9e3 +0 -0
- data/test/fixtures/testrepo.git/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a +0 -3
- data/test/fixtures/testrepo.git/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f +0 -2
- data/test/fixtures/testrepo.git/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd +0 -0
- data/test/fixtures/testrepo.git/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 +0 -0
- data/test/fixtures/testrepo.git/objects/b7/4713326bc972cc15751ed504dca6f6f3b91f7a +0 -3
- data/test/fixtures/testrepo.git/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 +0 -3
- data/test/fixtures/testrepo.git/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd +0 -3
- data/test/fixtures/testrepo.git/objects/c4/dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b +0 -0
- data/test/fixtures/testrepo.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
- data/test/fixtures/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 +0 -0
- data/test/fixtures/testrepo.git/objects/fa/49b077972391ad58037050f2a75f74e3671e92 +0 -0
- data/test/fixtures/testrepo.git/objects/fd/093bff70906175335656e6ce6ae05783708765 +0 -0
- data/test/fixtures/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx +0 -0
- data/test/fixtures/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack +0 -0
- data/test/fixtures/testrepo.git/packed-refs +0 -2
- data/test/fixtures/testrepo.git/refs/heads/master +0 -1
- data/test/fixtures/testrepo.git/refs/notes/commits +0 -1
- data/test/fixtures/testrepo.git/refs/tags/v0.9 +0 -1
- data/test/fixtures/testrepo.git/refs/tags/v1.0 +0 -1
- data/test/fixtures/text_file.md +0 -464
- data/test/fixtures/unsymlinked.git/HEAD +0 -1
- data/test/fixtures/unsymlinked.git/config +0 -6
- data/test/fixtures/unsymlinked.git/description +0 -1
- data/test/fixtures/unsymlinked.git/info/exclude +0 -2
- data/test/fixtures/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf +0 -0
- data/test/fixtures/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30b +0 -0
- data/test/fixtures/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c +0 -0
- data/test/fixtures/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773 +0 -0
- data/test/fixtures/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c +0 -0
- data/test/fixtures/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 +0 -0
- data/test/fixtures/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d +0 -0
- data/test/fixtures/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3 +0 -0
- data/test/fixtures/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230 +0 -0
- data/test/fixtures/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b6 +0 -2
- data/test/fixtures/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7 +0 -0
- data/test/fixtures/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a +0 -0
- data/test/fixtures/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9 +0 -0
- data/test/fixtures/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006 +0 -0
- data/test/fixtures/unsymlinked.git/refs/heads/exe-file +0 -1
- data/test/fixtures/unsymlinked.git/refs/heads/master +0 -1
- data/test/fixtures/unsymlinked.git/refs/heads/reg-file +0 -1
- data/test/index_test.rb +0 -333
- data/test/lib_test.rb +0 -127
- data/test/note_test.rb +0 -158
- data/test/object_test.rb +0 -43
- data/test/reference_test.rb +0 -207
- data/test/remote_test.rb +0 -324
- data/test/repo_pack_test.rb +0 -24
- data/test/repo_reset_test.rb +0 -82
- data/test/repo_test.rb +0 -402
- data/test/tag_test.rb +0 -68
- data/test/test_helper.rb +0 -92
- data/test/tree_test.rb +0 -91
- data/test/walker_test.rb +0 -88
- data/vendor/libgit2/Makefile.embed +0 -42
- data/vendor/libgit2/include/git2/push.h +0 -131
- data/vendor/libgit2/include/git2/threads.h +0 -50
- data/vendor/libgit2/src/amiga/map.c +0 -48
- data/vendor/libgit2/src/bswap.h +0 -97
- data/vendor/libgit2/src/compress.c +0 -53
- data/vendor/libgit2/src/config_file.h +0 -60
- data/vendor/libgit2/src/delta-apply.c +0 -134
- data/vendor/libgit2/src/delta-apply.h +0 -50
- data/vendor/libgit2/src/diff_patch.c +0 -995
- data/vendor/libgit2/src/diff_patch.h +0 -46
- data/vendor/libgit2/src/hashsig.h +0 -72
- data/vendor/libgit2/src/merge_file.h +0 -71
- data/vendor/libgit2/src/win32/pthread.c +0 -144
- data/vendor/libgit2/src/win32/pthread.h +0 -50
@@ -6,20 +6,26 @@
|
|
6
6
|
*/
|
7
7
|
|
8
8
|
#include "common.h"
|
9
|
+
|
9
10
|
#include <zlib.h>
|
10
11
|
#include "git2/object.h"
|
11
12
|
#include "git2/sys/odb_backend.h"
|
12
13
|
#include "fileops.h"
|
13
14
|
#include "hash.h"
|
14
15
|
#include "odb.h"
|
15
|
-
#include "delta
|
16
|
+
#include "delta.h"
|
16
17
|
#include "filebuf.h"
|
18
|
+
#include "object.h"
|
19
|
+
#include "zstream.h"
|
17
20
|
|
18
21
|
#include "git2/odb_backend.h"
|
19
22
|
#include "git2/types.h"
|
20
23
|
|
24
|
+
/* maximum possible header length */
|
25
|
+
#define MAX_HEADER_LEN 64
|
26
|
+
|
21
27
|
typedef struct { /* object header data */
|
22
|
-
|
28
|
+
git_object_t type; /* object type */
|
23
29
|
size_t size; /* object size */
|
24
30
|
} obj_hdr;
|
25
31
|
|
@@ -28,11 +34,22 @@ typedef struct {
|
|
28
34
|
git_filebuf fbuf;
|
29
35
|
} loose_writestream;
|
30
36
|
|
37
|
+
typedef struct {
|
38
|
+
git_odb_stream stream;
|
39
|
+
git_map map;
|
40
|
+
char start[MAX_HEADER_LEN];
|
41
|
+
size_t start_len;
|
42
|
+
size_t start_read;
|
43
|
+
git_zstream zstream;
|
44
|
+
} loose_readstream;
|
45
|
+
|
31
46
|
typedef struct loose_backend {
|
32
47
|
git_odb_backend parent;
|
33
48
|
|
34
49
|
int object_zlib_level; /** loose object zlib compression level. */
|
35
50
|
int fsync_object_files; /** loose object file fsync flag. */
|
51
|
+
mode_t object_file_mode;
|
52
|
+
mode_t object_dir_mode;
|
36
53
|
|
37
54
|
size_t objects_dirlen;
|
38
55
|
char objects_dir[GIT_FLEX_ARRAY];
|
@@ -54,15 +71,19 @@ typedef struct {
|
|
54
71
|
|
55
72
|
/***********************************************************
|
56
73
|
*
|
57
|
-
*
|
74
|
+
* MISCELLANEOUS HELPER FUNCTIONS
|
58
75
|
*
|
59
76
|
***********************************************************/
|
60
77
|
|
61
78
|
static int object_file_name(
|
62
79
|
git_buf *name, const loose_backend *be, const git_oid *id)
|
63
80
|
{
|
81
|
+
size_t alloclen;
|
82
|
+
|
64
83
|
/* expand length for object root + 40 hex sha1 chars + 2 * '/' + '\0' */
|
65
|
-
|
84
|
+
GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, be->objects_dirlen, GIT_OID_HEXSZ);
|
85
|
+
GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 3);
|
86
|
+
if (git_buf_grow(name, alloclen) < 0)
|
66
87
|
return -1;
|
67
88
|
|
68
89
|
git_buf_set(name, be->objects_dir, be->objects_dirlen);
|
@@ -78,221 +99,122 @@ static int object_file_name(
|
|
78
99
|
|
79
100
|
static int object_mkdir(const git_buf *name, const loose_backend *be)
|
80
101
|
{
|
81
|
-
return
|
82
|
-
name->ptr + be->objects_dirlen, be->objects_dir,
|
83
|
-
GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR);
|
102
|
+
return git_futils_mkdir_relative(
|
103
|
+
name->ptr + be->objects_dirlen, be->objects_dir, be->object_dir_mode,
|
104
|
+
GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR, NULL);
|
84
105
|
}
|
85
106
|
|
86
|
-
static
|
107
|
+
static int parse_header_packlike(
|
108
|
+
obj_hdr *out, size_t *out_len, const unsigned char *data, size_t len)
|
87
109
|
{
|
88
|
-
unsigned
|
89
|
-
unsigned char *data = (unsigned char *)obj->ptr;
|
110
|
+
unsigned long c;
|
90
111
|
size_t shift, size, used = 0;
|
91
112
|
|
92
|
-
if (
|
93
|
-
|
113
|
+
if (len == 0)
|
114
|
+
goto on_error;
|
94
115
|
|
95
116
|
c = data[used++];
|
96
|
-
|
117
|
+
out->type = (c >> 4) & 7;
|
97
118
|
|
98
119
|
size = c & 15;
|
99
120
|
shift = 4;
|
100
121
|
while (c & 0x80) {
|
101
|
-
if (
|
102
|
-
|
122
|
+
if (len <= used)
|
123
|
+
goto on_error;
|
124
|
+
|
103
125
|
if (sizeof(size_t) * 8 <= shift)
|
104
|
-
|
126
|
+
goto on_error;
|
127
|
+
|
105
128
|
c = data[used++];
|
106
129
|
size += (c & 0x7f) << shift;
|
107
130
|
shift += 7;
|
108
131
|
}
|
109
|
-
hdr->size = size;
|
110
|
-
|
111
|
-
return used;
|
112
|
-
}
|
113
|
-
|
114
|
-
static size_t get_object_header(obj_hdr *hdr, unsigned char *data)
|
115
|
-
{
|
116
|
-
char c, typename[10];
|
117
|
-
size_t size, used = 0;
|
118
|
-
|
119
|
-
/*
|
120
|
-
* type name string followed by space.
|
121
|
-
*/
|
122
|
-
while ((c = data[used]) != ' ') {
|
123
|
-
typename[used++] = c;
|
124
|
-
if (used >= sizeof(typename))
|
125
|
-
return 0;
|
126
|
-
}
|
127
|
-
typename[used] = 0;
|
128
|
-
if (used == 0)
|
129
|
-
return 0;
|
130
|
-
hdr->type = git_object_string2type(typename);
|
131
|
-
used++; /* consume the space */
|
132
|
-
|
133
|
-
/*
|
134
|
-
* length follows immediately in decimal (without
|
135
|
-
* leading zeros).
|
136
|
-
*/
|
137
|
-
size = data[used++] - '0';
|
138
|
-
if (size > 9)
|
139
|
-
return 0;
|
140
|
-
if (size) {
|
141
|
-
while ((c = data[used]) != '\0') {
|
142
|
-
size_t d = c - '0';
|
143
|
-
if (d > 9)
|
144
|
-
break;
|
145
|
-
used++;
|
146
|
-
size = size * 10 + d;
|
147
|
-
}
|
148
|
-
}
|
149
|
-
hdr->size = size;
|
150
|
-
|
151
|
-
/*
|
152
|
-
* the length must be followed by a zero byte
|
153
|
-
*/
|
154
|
-
if (data[used++] != '\0')
|
155
|
-
return 0;
|
156
|
-
|
157
|
-
return used;
|
158
|
-
}
|
159
132
|
|
133
|
+
out->size = size;
|
160
134
|
|
135
|
+
if (out_len)
|
136
|
+
*out_len = used;
|
161
137
|
|
162
|
-
|
163
|
-
*
|
164
|
-
* ZLIB RELATED FUNCTIONS
|
165
|
-
*
|
166
|
-
***********************************************************/
|
167
|
-
|
168
|
-
static void init_stream(z_stream *s, void *out, size_t len)
|
169
|
-
{
|
170
|
-
memset(s, 0, sizeof(*s));
|
171
|
-
s->next_out = out;
|
172
|
-
s->avail_out = (uInt)len;
|
173
|
-
}
|
138
|
+
return 0;
|
174
139
|
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
s->avail_in = (uInt)len;
|
140
|
+
on_error:
|
141
|
+
git_error_set(GIT_ERROR_OBJECT, "failed to parse loose object: invalid header");
|
142
|
+
return -1;
|
179
143
|
}
|
180
144
|
|
181
|
-
static
|
145
|
+
static int parse_header(
|
146
|
+
obj_hdr *out,
|
147
|
+
size_t *out_len,
|
148
|
+
const unsigned char *_data,
|
149
|
+
size_t data_len)
|
182
150
|
{
|
183
|
-
|
184
|
-
|
185
|
-
|
151
|
+
const char *data = (char *)_data;
|
152
|
+
size_t i, typename_len, size_idx, size_len;
|
153
|
+
int64_t size;
|
186
154
|
|
155
|
+
*out_len = 0;
|
187
156
|
|
188
|
-
|
189
|
-
{
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
set_stream_input(s, obj->ptr, git_buf_len(obj));
|
157
|
+
/* find the object type name */
|
158
|
+
for (i = 0, typename_len = 0; i < data_len; i++, typename_len++) {
|
159
|
+
if (data[i] == ' ')
|
160
|
+
break;
|
161
|
+
}
|
194
162
|
|
195
|
-
if (
|
196
|
-
|
163
|
+
if (typename_len == data_len)
|
164
|
+
goto on_error;
|
197
165
|
|
198
|
-
|
199
|
-
}
|
166
|
+
out->type = git_object_stringn2type(data, typename_len);
|
200
167
|
|
201
|
-
|
202
|
-
{
|
203
|
-
|
168
|
+
size_idx = typename_len + 1;
|
169
|
+
for (i = size_idx, size_len = 0; i < data_len; i++, size_len++) {
|
170
|
+
if (data[i] == '\0')
|
171
|
+
break;
|
172
|
+
}
|
204
173
|
|
205
|
-
|
206
|
-
|
174
|
+
if (i == data_len)
|
175
|
+
goto on_error;
|
207
176
|
|
208
|
-
|
177
|
+
if (git__strntol64(&size, &data[size_idx], size_len, NULL, 10) < 0 ||
|
178
|
+
size < 0)
|
179
|
+
goto on_error;
|
209
180
|
|
210
|
-
if ((
|
211
|
-
|
181
|
+
if ((uint64_t)size > SIZE_MAX) {
|
182
|
+
git_error_set(GIT_ERROR_OBJECT, "object is larger than available memory");
|
212
183
|
return -1;
|
213
184
|
}
|
214
185
|
|
186
|
+
out->size = (size_t)size;
|
187
|
+
|
188
|
+
if (GIT_ADD_SIZET_OVERFLOW(out_len, i, 1))
|
189
|
+
goto on_error;
|
190
|
+
|
215
191
|
return 0;
|
192
|
+
|
193
|
+
on_error:
|
194
|
+
git_error_set(GIT_ERROR_OBJECT, "failed to parse loose object: invalid header");
|
195
|
+
return -1;
|
216
196
|
}
|
217
197
|
|
218
|
-
static int is_zlib_compressed_data(unsigned char *data)
|
198
|
+
static int is_zlib_compressed_data(unsigned char *data, size_t data_len)
|
219
199
|
{
|
220
200
|
unsigned int w;
|
221
201
|
|
202
|
+
if (data_len < 2)
|
203
|
+
return 0;
|
204
|
+
|
222
205
|
w = ((unsigned int)(data[0]) << 8) + data[1];
|
223
206
|
return (data[0] & 0x8F) == 0x08 && !(w % 31);
|
224
207
|
}
|
225
208
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
zs.avail_out = (uInt)outlen;
|
235
|
-
|
236
|
-
zs.next_in = in;
|
237
|
-
zs.avail_in = (uInt)inlen;
|
238
|
-
|
239
|
-
if (inflateInit(&zs) < Z_OK) {
|
240
|
-
giterr_set(GITERR_ZLIB, "Failed to inflate buffer");
|
241
|
-
return -1;
|
242
|
-
}
|
243
|
-
|
244
|
-
while (status == Z_OK)
|
245
|
-
status = inflate(&zs, Z_FINISH);
|
246
|
-
|
247
|
-
inflateEnd(&zs);
|
248
|
-
|
249
|
-
if (status != Z_STREAM_END /* || zs.avail_in != 0 */ ||
|
250
|
-
zs.total_out != outlen)
|
251
|
-
{
|
252
|
-
giterr_set(GITERR_ZLIB, "Failed to inflate buffer. Stream aborted prematurely");
|
253
|
-
return -1;
|
254
|
-
}
|
255
|
-
|
256
|
-
return 0;
|
257
|
-
}
|
258
|
-
|
259
|
-
static void *inflate_tail(z_stream *s, void *hb, size_t used, obj_hdr *hdr)
|
260
|
-
{
|
261
|
-
unsigned char *buf, *head = hb;
|
262
|
-
size_t tail;
|
263
|
-
|
264
|
-
/*
|
265
|
-
* allocate a buffer to hold the inflated data and copy the
|
266
|
-
* initial sequence of inflated data from the tail of the
|
267
|
-
* head buffer, if any.
|
268
|
-
*/
|
269
|
-
if ((buf = git__malloc(hdr->size + 1)) == NULL) {
|
270
|
-
inflateEnd(s);
|
271
|
-
return NULL;
|
272
|
-
}
|
273
|
-
tail = s->total_out - used;
|
274
|
-
if (used > 0 && tail > 0) {
|
275
|
-
if (tail > hdr->size)
|
276
|
-
tail = hdr->size;
|
277
|
-
memcpy(buf, head + used, tail);
|
278
|
-
}
|
279
|
-
used = tail;
|
280
|
-
|
281
|
-
/*
|
282
|
-
* inflate the remainder of the object data, if any
|
283
|
-
*/
|
284
|
-
if (hdr->size < used)
|
285
|
-
inflateEnd(s);
|
286
|
-
else {
|
287
|
-
set_stream_output(s, buf + used, hdr->size - used);
|
288
|
-
if (finish_inflate(s)) {
|
289
|
-
git__free(buf);
|
290
|
-
return NULL;
|
291
|
-
}
|
292
|
-
}
|
209
|
+
/***********************************************************
|
210
|
+
*
|
211
|
+
* ODB OBJECT READING & WRITING
|
212
|
+
*
|
213
|
+
* Backend for the public API; read headers and full objects
|
214
|
+
* from the ODB. Write raw data to the ODB.
|
215
|
+
*
|
216
|
+
***********************************************************/
|
293
217
|
|
294
|
-
return buf;
|
295
|
-
}
|
296
218
|
|
297
219
|
/*
|
298
220
|
* At one point, there was a loose object format that was intended to
|
@@ -300,96 +222,122 @@ static void *inflate_tail(z_stream *s, void *hb, size_t used, obj_hdr *hdr)
|
|
300
222
|
* of loose object data into packs. This format is no longer used, but
|
301
223
|
* we must still read it.
|
302
224
|
*/
|
303
|
-
static int
|
225
|
+
static int read_loose_packlike(git_rawobj *out, git_buf *obj)
|
304
226
|
{
|
305
|
-
|
227
|
+
git_buf body = GIT_BUF_INIT;
|
228
|
+
const unsigned char *obj_data;
|
306
229
|
obj_hdr hdr;
|
307
|
-
size_t
|
230
|
+
size_t obj_len, head_len, alloc_size;
|
231
|
+
int error;
|
232
|
+
|
233
|
+
obj_data = (unsigned char *)obj->ptr;
|
234
|
+
obj_len = obj->size;
|
308
235
|
|
309
236
|
/*
|
310
237
|
* read the object header, which is an (uncompressed)
|
311
238
|
* binary encoding of the object type and size.
|
312
239
|
*/
|
313
|
-
if ((
|
314
|
-
|
315
|
-
|
316
|
-
|
240
|
+
if ((error = parse_header_packlike(&hdr, &head_len, obj_data, obj_len)) < 0)
|
241
|
+
goto done;
|
242
|
+
|
243
|
+
if (!git_object_typeisloose(hdr.type) || head_len > obj_len) {
|
244
|
+
git_error_set(GIT_ERROR_ODB, "failed to inflate loose object");
|
245
|
+
error = -1;
|
246
|
+
goto done;
|
317
247
|
}
|
318
248
|
|
249
|
+
obj_data += head_len;
|
250
|
+
obj_len -= head_len;
|
251
|
+
|
319
252
|
/*
|
320
253
|
* allocate a buffer and inflate the data into it
|
321
254
|
*/
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
len = obj->size - used;
|
327
|
-
if (inflate_buffer(in, len, buf, hdr.size) < 0) {
|
328
|
-
git__free(buf);
|
329
|
-
return -1;
|
255
|
+
if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, hdr.size, 1) ||
|
256
|
+
git_buf_init(&body, alloc_size) < 0) {
|
257
|
+
error = -1;
|
258
|
+
goto done;
|
330
259
|
}
|
331
|
-
buf[hdr.size] = '\0';
|
332
260
|
|
333
|
-
|
261
|
+
if ((error = git_zstream_inflatebuf(&body, obj_data, obj_len)) < 0)
|
262
|
+
goto done;
|
263
|
+
|
334
264
|
out->len = hdr.size;
|
335
265
|
out->type = hdr.type;
|
266
|
+
out->data = git_buf_detach(&body);
|
336
267
|
|
337
|
-
|
268
|
+
done:
|
269
|
+
git_buf_dispose(&body);
|
270
|
+
return error;
|
338
271
|
}
|
339
272
|
|
340
|
-
static int
|
273
|
+
static int read_loose_standard(git_rawobj *out, git_buf *obj)
|
341
274
|
{
|
342
|
-
|
343
|
-
|
275
|
+
git_zstream zstream = GIT_ZSTREAM_INIT;
|
276
|
+
unsigned char head[MAX_HEADER_LEN], *body = NULL;
|
277
|
+
size_t decompressed, head_len, body_len, alloc_size;
|
344
278
|
obj_hdr hdr;
|
345
|
-
|
279
|
+
int error;
|
346
280
|
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
281
|
+
if ((error = git_zstream_init(&zstream, GIT_ZSTREAM_INFLATE)) < 0 ||
|
282
|
+
(error = git_zstream_set_input(&zstream, git_buf_cstr(obj), git_buf_len(obj))) < 0)
|
283
|
+
goto done;
|
284
|
+
|
285
|
+
decompressed = sizeof(head);
|
352
286
|
|
353
287
|
/*
|
354
|
-
* inflate the initial part of the
|
355
|
-
*
|
288
|
+
* inflate the initial part of the compressed buffer in order to
|
289
|
+
* parse the header; read the largest header possible, then push the
|
290
|
+
* remainder into the body buffer.
|
356
291
|
*/
|
357
|
-
if (
|
358
|
-
(
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
292
|
+
if ((error = git_zstream_get_output(head, &decompressed, &zstream)) < 0 ||
|
293
|
+
(error = parse_header(&hdr, &head_len, head, decompressed)) < 0)
|
294
|
+
goto done;
|
295
|
+
|
296
|
+
if (!git_object_typeisloose(hdr.type)) {
|
297
|
+
git_error_set(GIT_ERROR_ODB, "failed to inflate disk object");
|
298
|
+
error = -1;
|
299
|
+
goto done;
|
363
300
|
}
|
364
301
|
|
365
302
|
/*
|
366
303
|
* allocate a buffer and inflate the object data into it
|
367
304
|
* (including the initial sequence in the head buffer).
|
368
305
|
*/
|
369
|
-
if ((
|
370
|
-
|
371
|
-
|
306
|
+
if (GIT_ADD_SIZET_OVERFLOW(&alloc_size, hdr.size, 1) ||
|
307
|
+
(body = git__malloc(alloc_size)) == NULL) {
|
308
|
+
error = -1;
|
309
|
+
goto done;
|
310
|
+
}
|
372
311
|
|
373
|
-
|
374
|
-
|
375
|
-
out->type = hdr.type;
|
312
|
+
assert(decompressed >= head_len);
|
313
|
+
body_len = decompressed - head_len;
|
376
314
|
|
377
|
-
|
378
|
-
|
315
|
+
if (body_len)
|
316
|
+
memcpy(body, head + head_len, body_len);
|
379
317
|
|
318
|
+
decompressed = hdr.size - body_len;
|
319
|
+
if ((error = git_zstream_get_output(body + body_len, &decompressed, &zstream)) < 0)
|
320
|
+
goto done;
|
380
321
|
|
322
|
+
if (!git_zstream_done(&zstream)) {
|
323
|
+
git_error_set(GIT_ERROR_ZLIB, "failed to finish zlib inflation: stream aborted prematurely");
|
324
|
+
error = -1;
|
325
|
+
goto done;
|
326
|
+
}
|
381
327
|
|
328
|
+
body[hdr.size] = '\0';
|
382
329
|
|
330
|
+
out->data = body;
|
331
|
+
out->len = hdr.size;
|
332
|
+
out->type = hdr.type;
|
383
333
|
|
334
|
+
done:
|
335
|
+
if (error < 0)
|
336
|
+
git__free(body);
|
384
337
|
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
*
|
389
|
-
* Backend for the public API; read headers and full objects
|
390
|
-
* from the ODB. Write raw data to the ODB.
|
391
|
-
*
|
392
|
-
***********************************************************/
|
338
|
+
git_zstream_free(&zstream);
|
339
|
+
return error;
|
340
|
+
}
|
393
341
|
|
394
342
|
static int read_loose(git_rawobj *out, git_buf *loc)
|
395
343
|
{
|
@@ -403,23 +351,64 @@ static int read_loose(git_rawobj *out, git_buf *loc)
|
|
403
351
|
|
404
352
|
out->data = NULL;
|
405
353
|
out->len = 0;
|
406
|
-
out->type =
|
354
|
+
out->type = GIT_OBJECT_INVALID;
|
355
|
+
|
356
|
+
if ((error = git_futils_readbuffer(&obj, loc->ptr)) < 0)
|
357
|
+
goto done;
|
358
|
+
|
359
|
+
if (!is_zlib_compressed_data((unsigned char *)obj.ptr, obj.size))
|
360
|
+
error = read_loose_packlike(out, &obj);
|
361
|
+
else
|
362
|
+
error = read_loose_standard(out, &obj);
|
363
|
+
|
364
|
+
done:
|
365
|
+
git_buf_dispose(&obj);
|
366
|
+
return error;
|
367
|
+
}
|
407
368
|
|
408
|
-
|
409
|
-
|
369
|
+
static int read_header_loose_packlike(
|
370
|
+
git_rawobj *out, const unsigned char *data, size_t len)
|
371
|
+
{
|
372
|
+
obj_hdr hdr;
|
373
|
+
size_t header_len;
|
374
|
+
int error;
|
410
375
|
|
411
|
-
|
376
|
+
if ((error = parse_header_packlike(&hdr, &header_len, data, len)) < 0)
|
377
|
+
return error;
|
378
|
+
|
379
|
+
out->len = hdr.size;
|
380
|
+
out->type = hdr.type;
|
412
381
|
|
413
382
|
return error;
|
414
383
|
}
|
415
384
|
|
385
|
+
static int read_header_loose_standard(
|
386
|
+
git_rawobj *out, const unsigned char *data, size_t len)
|
387
|
+
{
|
388
|
+
git_zstream zs = GIT_ZSTREAM_INIT;
|
389
|
+
obj_hdr hdr;
|
390
|
+
unsigned char inflated[MAX_HEADER_LEN];
|
391
|
+
size_t header_len, inflated_len = sizeof(inflated);
|
392
|
+
int error;
|
393
|
+
|
394
|
+
if ((error = git_zstream_init(&zs, GIT_ZSTREAM_INFLATE)) < 0 ||
|
395
|
+
(error = git_zstream_set_input(&zs, data, len)) < 0 ||
|
396
|
+
(error = git_zstream_get_output_chunk(inflated, &inflated_len, &zs)) < 0 ||
|
397
|
+
(error = parse_header(&hdr, &header_len, inflated, inflated_len)) < 0)
|
398
|
+
goto done;
|
399
|
+
|
400
|
+
out->len = hdr.size;
|
401
|
+
out->type = hdr.type;
|
402
|
+
|
403
|
+
done:
|
404
|
+
git_zstream_free(&zs);
|
405
|
+
return error;
|
406
|
+
}
|
407
|
+
|
416
408
|
static int read_header_loose(git_rawobj *out, git_buf *loc)
|
417
409
|
{
|
418
|
-
|
419
|
-
|
420
|
-
z_stream zs;
|
421
|
-
obj_hdr header_obj;
|
422
|
-
unsigned char raw_buffer[16], inflated_buffer[64];
|
410
|
+
unsigned char obj[1024];
|
411
|
+
int fd, obj_len, error;
|
423
412
|
|
424
413
|
assert(out && loc);
|
425
414
|
|
@@ -428,35 +417,24 @@ static int read_header_loose(git_rawobj *out, git_buf *loc)
|
|
428
417
|
|
429
418
|
out->data = NULL;
|
430
419
|
|
431
|
-
if ((fd = git_futils_open_ro(loc->ptr)) < 0
|
432
|
-
|
433
|
-
|
434
|
-
init_stream(&zs, inflated_buffer, sizeof(inflated_buffer));
|
435
|
-
|
436
|
-
z_return = inflateInit(&zs);
|
420
|
+
if ((error = fd = git_futils_open_ro(loc->ptr)) < 0 ||
|
421
|
+
(error = obj_len = p_read(fd, obj, sizeof(obj))) < 0)
|
422
|
+
goto done;
|
437
423
|
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
} else
|
443
|
-
z_return = Z_STREAM_END;
|
444
|
-
}
|
424
|
+
if (!is_zlib_compressed_data(obj, (size_t)obj_len))
|
425
|
+
error = read_header_loose_packlike(out, obj, (size_t)obj_len);
|
426
|
+
else
|
427
|
+
error = read_header_loose_standard(out, obj, (size_t)obj_len);
|
445
428
|
|
446
|
-
if (
|
447
|
-
|
448
|
-
|| git_object_typeisloose(header_obj.type) == 0)
|
449
|
-
{
|
450
|
-
giterr_set(GITERR_ZLIB, "Failed to read loose object header");
|
429
|
+
if (!error && !git_object_typeisloose(out->type)) {
|
430
|
+
git_error_set(GIT_ERROR_ZLIB, "failed to read loose object header");
|
451
431
|
error = -1;
|
452
|
-
|
453
|
-
out->len = header_obj.size;
|
454
|
-
out->type = header_obj.type;
|
432
|
+
goto done;
|
455
433
|
}
|
456
434
|
|
457
|
-
|
458
|
-
|
459
|
-
|
435
|
+
done:
|
436
|
+
if (fd >= 0)
|
437
|
+
p_close(fd);
|
460
438
|
return error;
|
461
439
|
}
|
462
440
|
|
@@ -499,7 +477,7 @@ static int fn_locate_object_short_oid(void *state, git_buf *pathbuf) {
|
|
499
477
|
}
|
500
478
|
|
501
479
|
if (sstate->found > 1)
|
502
|
-
return
|
480
|
+
return GIT_EAMBIGUOUS;
|
503
481
|
|
504
482
|
return 0;
|
505
483
|
}
|
@@ -513,15 +491,17 @@ static int locate_object_short_oid(
|
|
513
491
|
size_t len)
|
514
492
|
{
|
515
493
|
char *objects_dir = backend->objects_dir;
|
516
|
-
size_t dir_len = strlen(objects_dir);
|
494
|
+
size_t dir_len = strlen(objects_dir), alloc_len;
|
517
495
|
loose_locate_object_state state;
|
518
496
|
int error;
|
519
497
|
|
520
|
-
/* prealloc memory for OBJ_DIR/xx/ */
|
521
|
-
|
498
|
+
/* prealloc memory for OBJ_DIR/xx/xx..38x..xx */
|
499
|
+
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, GIT_OID_HEXSZ);
|
500
|
+
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 3);
|
501
|
+
if (git_buf_grow(object_location, alloc_len) < 0)
|
522
502
|
return -1;
|
523
503
|
|
524
|
-
|
504
|
+
git_buf_set(object_location, objects_dir, dir_len);
|
525
505
|
git_path_to_dir(object_location);
|
526
506
|
|
527
507
|
/* save adjusted position at end of dir so it can be restored later */
|
@@ -531,12 +511,14 @@ static int locate_object_short_oid(
|
|
531
511
|
git_oid_fmt((char *)state.short_oid, short_oid);
|
532
512
|
|
533
513
|
/* Explore OBJ_DIR/xx/ where xx is the beginning of hex formatted short oid */
|
534
|
-
if (
|
514
|
+
if (git_buf_put(object_location, (char *)state.short_oid, 3) < 0)
|
535
515
|
return -1;
|
516
|
+
object_location->ptr[object_location->size - 1] = '/';
|
536
517
|
|
537
518
|
/* Check that directory exists */
|
538
519
|
if (git_path_isdir(object_location->ptr) == false)
|
539
|
-
return git_odb__error_notfound("no matching loose object for prefix",
|
520
|
+
return git_odb__error_notfound("no matching loose object for prefix",
|
521
|
+
short_oid, len);
|
540
522
|
|
541
523
|
state.dir_len = git_buf_len(object_location);
|
542
524
|
state.short_oid_len = len;
|
@@ -544,12 +526,16 @@ static int locate_object_short_oid(
|
|
544
526
|
|
545
527
|
/* Explore directory to find a unique object matching short_oid */
|
546
528
|
error = git_path_direach(
|
547
|
-
object_location, fn_locate_object_short_oid, &state);
|
548
|
-
if (error)
|
529
|
+
object_location, 0, fn_locate_object_short_oid, &state);
|
530
|
+
if (error < 0 && error != GIT_EAMBIGUOUS)
|
549
531
|
return error;
|
550
532
|
|
551
533
|
if (!state.found)
|
552
|
-
return git_odb__error_notfound("no matching loose object for prefix",
|
534
|
+
return git_odb__error_notfound("no matching loose object for prefix",
|
535
|
+
short_oid, len);
|
536
|
+
|
537
|
+
if (state.found > 1)
|
538
|
+
return git_odb__error_ambiguous("multiple matches in loose objects");
|
553
539
|
|
554
540
|
/* Convert obtained hex formatted oid to raw */
|
555
541
|
error = git_oid_fromstr(res_oid, (char *)state.res_oid);
|
@@ -557,9 +543,11 @@ static int locate_object_short_oid(
|
|
557
543
|
return error;
|
558
544
|
|
559
545
|
/* Update the location according to the oid obtained */
|
546
|
+
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, dir_len, GIT_OID_HEXSZ);
|
547
|
+
GIT_ERROR_CHECK_ALLOC_ADD(&alloc_len, alloc_len, 2);
|
560
548
|
|
561
549
|
git_buf_truncate(object_location, dir_len);
|
562
|
-
if (git_buf_grow(object_location,
|
550
|
+
if (git_buf_grow(object_location, alloc_len) < 0)
|
563
551
|
return -1;
|
564
552
|
|
565
553
|
git_oid_pathfmt(object_location->ptr + dir_len, res_oid);
|
@@ -586,7 +574,7 @@ static int locate_object_short_oid(
|
|
586
574
|
*
|
587
575
|
***********************************************************/
|
588
576
|
|
589
|
-
static int loose_backend__read_header(size_t *len_p,
|
577
|
+
static int loose_backend__read_header(size_t *len_p, git_object_t *type_p, git_odb_backend *backend, const git_oid *oid)
|
590
578
|
{
|
591
579
|
git_buf object_path = GIT_BUF_INIT;
|
592
580
|
git_rawobj raw;
|
@@ -595,21 +583,22 @@ static int loose_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_
|
|
595
583
|
assert(backend && oid);
|
596
584
|
|
597
585
|
raw.len = 0;
|
598
|
-
raw.type =
|
586
|
+
raw.type = GIT_OBJECT_INVALID;
|
599
587
|
|
600
|
-
if (locate_object(&object_path, (loose_backend *)backend, oid) < 0)
|
601
|
-
error = git_odb__error_notfound("no matching loose object",
|
602
|
-
|
588
|
+
if (locate_object(&object_path, (loose_backend *)backend, oid) < 0) {
|
589
|
+
error = git_odb__error_notfound("no matching loose object",
|
590
|
+
oid, GIT_OID_HEXSZ);
|
591
|
+
} else if ((error = read_header_loose(&raw, &object_path)) == 0) {
|
603
592
|
*len_p = raw.len;
|
604
593
|
*type_p = raw.type;
|
605
594
|
}
|
606
595
|
|
607
|
-
|
596
|
+
git_buf_dispose(&object_path);
|
608
597
|
|
609
598
|
return error;
|
610
599
|
}
|
611
600
|
|
612
|
-
static int loose_backend__read(void **buffer_p, size_t *len_p,
|
601
|
+
static int loose_backend__read(void **buffer_p, size_t *len_p, git_object_t *type_p, git_odb_backend *backend, const git_oid *oid)
|
613
602
|
{
|
614
603
|
git_buf object_path = GIT_BUF_INIT;
|
615
604
|
git_rawobj raw;
|
@@ -617,15 +606,16 @@ static int loose_backend__read(void **buffer_p, size_t *len_p, git_otype *type_p
|
|
617
606
|
|
618
607
|
assert(backend && oid);
|
619
608
|
|
620
|
-
if (locate_object(&object_path, (loose_backend *)backend, oid) < 0)
|
621
|
-
error = git_odb__error_notfound("no matching loose object",
|
622
|
-
|
609
|
+
if (locate_object(&object_path, (loose_backend *)backend, oid) < 0) {
|
610
|
+
error = git_odb__error_notfound("no matching loose object",
|
611
|
+
oid, GIT_OID_HEXSZ);
|
612
|
+
} else if ((error = read_loose(&raw, &object_path)) == 0) {
|
623
613
|
*buffer_p = raw.data;
|
624
614
|
*len_p = raw.len;
|
625
615
|
*type_p = raw.type;
|
626
616
|
}
|
627
617
|
|
628
|
-
|
618
|
+
git_buf_dispose(&object_path);
|
629
619
|
|
630
620
|
return error;
|
631
621
|
}
|
@@ -634,17 +624,16 @@ static int loose_backend__read_prefix(
|
|
634
624
|
git_oid *out_oid,
|
635
625
|
void **buffer_p,
|
636
626
|
size_t *len_p,
|
637
|
-
|
627
|
+
git_object_t *type_p,
|
638
628
|
git_odb_backend *backend,
|
639
629
|
const git_oid *short_oid,
|
640
630
|
size_t len)
|
641
631
|
{
|
642
632
|
int error = 0;
|
643
633
|
|
644
|
-
|
645
|
-
error = git_odb__error_ambiguous("prefix length too short");
|
634
|
+
assert(len >= GIT_OID_MINPREFIXLEN && len <= GIT_OID_HEXSZ);
|
646
635
|
|
647
|
-
|
636
|
+
if (len == GIT_OID_HEXSZ) {
|
648
637
|
/* We can fall back to regular read method */
|
649
638
|
error = loose_backend__read(buffer_p, len_p, type_p, backend, short_oid);
|
650
639
|
if (!error)
|
@@ -664,7 +653,7 @@ static int loose_backend__read_prefix(
|
|
664
653
|
*type_p = raw.type;
|
665
654
|
}
|
666
655
|
|
667
|
-
|
656
|
+
git_buf_dispose(&object_path);
|
668
657
|
}
|
669
658
|
|
670
659
|
return error;
|
@@ -679,22 +668,37 @@ static int loose_backend__exists(git_odb_backend *backend, const git_oid *oid)
|
|
679
668
|
|
680
669
|
error = locate_object(&object_path, (loose_backend *)backend, oid);
|
681
670
|
|
682
|
-
|
671
|
+
git_buf_dispose(&object_path);
|
683
672
|
|
684
673
|
return !error;
|
685
674
|
}
|
686
675
|
|
676
|
+
static int loose_backend__exists_prefix(
|
677
|
+
git_oid *out, git_odb_backend *backend, const git_oid *short_id, size_t len)
|
678
|
+
{
|
679
|
+
git_buf object_path = GIT_BUF_INIT;
|
680
|
+
int error;
|
681
|
+
|
682
|
+
assert(backend && out && short_id && len >= GIT_OID_MINPREFIXLEN);
|
683
|
+
|
684
|
+
error = locate_object_short_oid(
|
685
|
+
&object_path, out, (loose_backend *)backend, short_id, len);
|
686
|
+
|
687
|
+
git_buf_dispose(&object_path);
|
688
|
+
|
689
|
+
return error;
|
690
|
+
}
|
691
|
+
|
687
692
|
struct foreach_state {
|
688
693
|
size_t dir_len;
|
689
694
|
git_odb_foreach_cb cb;
|
690
695
|
void *data;
|
691
|
-
int cb_error;
|
692
696
|
};
|
693
697
|
|
694
698
|
GIT_INLINE(int) filename_to_oid(git_oid *oid, const char *ptr)
|
695
699
|
{
|
696
700
|
int v, i = 0;
|
697
|
-
if (strlen(ptr) !=
|
701
|
+
if (strlen(ptr) != GIT_OID_HEXSZ+1)
|
698
702
|
return -1;
|
699
703
|
|
700
704
|
if (ptr[2] != '/') {
|
@@ -727,19 +731,19 @@ static int foreach_object_dir_cb(void *_state, git_buf *path)
|
|
727
731
|
if (filename_to_oid(&oid, path->ptr + state->dir_len) < 0)
|
728
732
|
return 0;
|
729
733
|
|
730
|
-
|
731
|
-
state->
|
732
|
-
return -1;
|
733
|
-
}
|
734
|
-
|
735
|
-
return 0;
|
734
|
+
return git_error_set_after_callback_function(
|
735
|
+
state->cb(&oid, state->data), "git_odb_foreach");
|
736
736
|
}
|
737
737
|
|
738
738
|
static int foreach_cb(void *_state, git_buf *path)
|
739
739
|
{
|
740
740
|
struct foreach_state *state = (struct foreach_state *) _state;
|
741
741
|
|
742
|
-
|
742
|
+
/* non-dir is some stray file, ignore it */
|
743
|
+
if (!git_path_isdir(git_buf_cstr(path)))
|
744
|
+
return 0;
|
745
|
+
|
746
|
+
return git_path_direach(path, 0, foreach_object_dir_cb, state);
|
743
747
|
}
|
744
748
|
|
745
749
|
static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb cb, void *data)
|
@@ -756,53 +760,47 @@ static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb
|
|
756
760
|
|
757
761
|
git_buf_sets(&buf, objects_dir);
|
758
762
|
git_path_to_dir(&buf);
|
763
|
+
if (git_buf_oom(&buf))
|
764
|
+
return -1;
|
759
765
|
|
760
766
|
memset(&state, 0, sizeof(state));
|
761
767
|
state.cb = cb;
|
762
768
|
state.data = data;
|
763
769
|
state.dir_len = git_buf_len(&buf);
|
764
770
|
|
765
|
-
error = git_path_direach(&buf, foreach_cb, &state);
|
771
|
+
error = git_path_direach(&buf, 0, foreach_cb, &state);
|
766
772
|
|
767
|
-
|
773
|
+
git_buf_dispose(&buf);
|
768
774
|
|
769
|
-
return
|
775
|
+
return error;
|
770
776
|
}
|
771
777
|
|
772
|
-
static int
|
778
|
+
static int loose_backend__writestream_finalize(git_odb_stream *_stream, const git_oid *oid)
|
773
779
|
{
|
774
780
|
loose_writestream *stream = (loose_writestream *)_stream;
|
775
781
|
loose_backend *backend = (loose_backend *)_stream->backend;
|
776
782
|
git_buf final_path = GIT_BUF_INIT;
|
777
783
|
int error = 0;
|
778
784
|
|
779
|
-
if (
|
780
|
-
object_file_name(&final_path, backend, oid) < 0 ||
|
785
|
+
if (object_file_name(&final_path, backend, oid) < 0 ||
|
781
786
|
object_mkdir(&final_path, backend) < 0)
|
782
787
|
error = -1;
|
783
|
-
/*
|
784
|
-
* Don't try to add an existing object to the repository. This
|
785
|
-
* is what git does and allows us to sidestep the fact that
|
786
|
-
* we're not allowed to overwrite a read-only file on Windows.
|
787
|
-
*/
|
788
|
-
else if (git_path_exists(final_path.ptr) == true)
|
789
|
-
git_filebuf_cleanup(&stream->fbuf);
|
790
788
|
else
|
791
789
|
error = git_filebuf_commit_at(
|
792
|
-
&stream->fbuf, final_path.ptr
|
790
|
+
&stream->fbuf, final_path.ptr);
|
793
791
|
|
794
|
-
|
792
|
+
git_buf_dispose(&final_path);
|
795
793
|
|
796
794
|
return error;
|
797
795
|
}
|
798
796
|
|
799
|
-
static int
|
797
|
+
static int loose_backend__writestream_write(git_odb_stream *_stream, const char *data, size_t len)
|
800
798
|
{
|
801
799
|
loose_writestream *stream = (loose_writestream *)_stream;
|
802
800
|
return git_filebuf_write(&stream->fbuf, data, len);
|
803
801
|
}
|
804
802
|
|
805
|
-
static void
|
803
|
+
static void loose_backend__writestream_free(git_odb_stream *_stream)
|
806
804
|
{
|
807
805
|
loose_writestream *stream = (loose_writestream *)_stream;
|
808
806
|
|
@@ -810,76 +808,260 @@ static void loose_backend__stream_free(git_odb_stream *_stream)
|
|
810
808
|
git__free(stream);
|
811
809
|
}
|
812
810
|
|
813
|
-
static int
|
811
|
+
static int filebuf_flags(loose_backend *backend)
|
814
812
|
{
|
815
|
-
|
816
|
-
|
813
|
+
int flags = GIT_FILEBUF_TEMPORARY |
|
814
|
+
(backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT);
|
817
815
|
|
818
|
-
|
819
|
-
|
816
|
+
if (backend->fsync_object_files || git_repository__fsync_gitdir)
|
817
|
+
flags |= GIT_FILEBUF_FSYNC;
|
820
818
|
|
821
|
-
return
|
819
|
+
return flags;
|
822
820
|
}
|
823
821
|
|
824
|
-
static int
|
822
|
+
static int loose_backend__writestream(git_odb_stream **stream_out, git_odb_backend *_backend, git_off_t length, git_object_t type)
|
825
823
|
{
|
826
824
|
loose_backend *backend;
|
827
825
|
loose_writestream *stream = NULL;
|
828
|
-
char hdr[
|
826
|
+
char hdr[MAX_HEADER_LEN];
|
829
827
|
git_buf tmp_path = GIT_BUF_INIT;
|
830
|
-
|
828
|
+
size_t hdrlen;
|
829
|
+
int error;
|
831
830
|
|
832
|
-
assert(_backend);
|
831
|
+
assert(_backend && length >= 0);
|
833
832
|
|
834
833
|
backend = (loose_backend *)_backend;
|
835
834
|
*stream_out = NULL;
|
836
835
|
|
837
|
-
|
836
|
+
if ((error = git_odb__format_object_header(&hdrlen,
|
837
|
+
hdr, sizeof(hdr), length, type)) < 0)
|
838
|
+
return error;
|
838
839
|
|
839
840
|
stream = git__calloc(1, sizeof(loose_writestream));
|
840
|
-
|
841
|
+
GIT_ERROR_CHECK_ALLOC(stream);
|
841
842
|
|
842
843
|
stream->stream.backend = _backend;
|
843
844
|
stream->stream.read = NULL; /* read only */
|
844
|
-
stream->stream.write = &
|
845
|
-
stream->stream.finalize_write = &
|
846
|
-
stream->stream.free = &
|
845
|
+
stream->stream.write = &loose_backend__writestream_write;
|
846
|
+
stream->stream.finalize_write = &loose_backend__writestream_finalize;
|
847
|
+
stream->stream.free = &loose_backend__writestream_free;
|
847
848
|
stream->stream.mode = GIT_STREAM_WRONLY;
|
848
849
|
|
849
850
|
if (git_buf_joinpath(&tmp_path, backend->objects_dir, "tmp_object") < 0 ||
|
850
|
-
git_filebuf_open(&stream->fbuf, tmp_path.ptr,
|
851
|
-
|
852
|
-
GIT_FILEBUF_TEMPORARY |
|
853
|
-
(backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT)) < 0 ||
|
851
|
+
git_filebuf_open(&stream->fbuf, tmp_path.ptr, filebuf_flags(backend),
|
852
|
+
backend->object_file_mode) < 0 ||
|
854
853
|
stream->stream.write((git_odb_stream *)stream, hdr, hdrlen) < 0)
|
855
854
|
{
|
856
855
|
git_filebuf_cleanup(&stream->fbuf);
|
857
856
|
git__free(stream);
|
858
857
|
stream = NULL;
|
859
858
|
}
|
860
|
-
|
859
|
+
git_buf_dispose(&tmp_path);
|
861
860
|
*stream_out = (git_odb_stream *)stream;
|
862
861
|
|
863
862
|
return !stream ? -1 : 0;
|
864
863
|
}
|
865
864
|
|
866
|
-
static int
|
865
|
+
static int loose_backend__readstream_read(
|
866
|
+
git_odb_stream *_stream,
|
867
|
+
char *buffer,
|
868
|
+
size_t buffer_len)
|
869
|
+
{
|
870
|
+
loose_readstream *stream = (loose_readstream *)_stream;
|
871
|
+
size_t start_remain = stream->start_len - stream->start_read;
|
872
|
+
int total = 0, error;
|
873
|
+
|
874
|
+
/*
|
875
|
+
* if we read more than just the header in the initial read, play
|
876
|
+
* that back for the caller.
|
877
|
+
*/
|
878
|
+
if (start_remain && buffer_len) {
|
879
|
+
size_t chunk = min(start_remain, buffer_len);
|
880
|
+
memcpy(buffer, stream->start + stream->start_read, chunk);
|
881
|
+
|
882
|
+
buffer += chunk;
|
883
|
+
stream->start_read += chunk;
|
884
|
+
|
885
|
+
total += chunk;
|
886
|
+
buffer_len -= chunk;
|
887
|
+
}
|
888
|
+
|
889
|
+
if (buffer_len) {
|
890
|
+
size_t chunk = min(buffer_len, INT_MAX);
|
891
|
+
|
892
|
+
if ((error = git_zstream_get_output(buffer, &chunk, &stream->zstream)) < 0)
|
893
|
+
return error;
|
894
|
+
|
895
|
+
total += chunk;
|
896
|
+
}
|
897
|
+
|
898
|
+
return total;
|
899
|
+
}
|
900
|
+
|
901
|
+
static void loose_backend__readstream_free(git_odb_stream *_stream)
|
902
|
+
{
|
903
|
+
loose_readstream *stream = (loose_readstream *)_stream;
|
904
|
+
|
905
|
+
git_futils_mmap_free(&stream->map);
|
906
|
+
git_zstream_free(&stream->zstream);
|
907
|
+
git__free(stream);
|
908
|
+
}
|
909
|
+
|
910
|
+
static int loose_backend__readstream_packlike(
|
911
|
+
obj_hdr *hdr,
|
912
|
+
loose_readstream *stream)
|
867
913
|
{
|
868
|
-
|
914
|
+
const unsigned char *data;
|
915
|
+
size_t data_len, head_len;
|
916
|
+
int error;
|
917
|
+
|
918
|
+
data = stream->map.data;
|
919
|
+
data_len = stream->map.len;
|
920
|
+
|
921
|
+
/*
|
922
|
+
* read the object header, which is an (uncompressed)
|
923
|
+
* binary encoding of the object type and size.
|
924
|
+
*/
|
925
|
+
if ((error = parse_header_packlike(hdr, &head_len, data, data_len)) < 0)
|
926
|
+
return error;
|
927
|
+
|
928
|
+
if (!git_object_typeisloose(hdr->type)) {
|
929
|
+
git_error_set(GIT_ERROR_ODB, "failed to inflate loose object");
|
930
|
+
return -1;
|
931
|
+
}
|
932
|
+
|
933
|
+
return git_zstream_set_input(&stream->zstream,
|
934
|
+
data + head_len, data_len - head_len);
|
935
|
+
}
|
936
|
+
|
937
|
+
static int loose_backend__readstream_standard(
|
938
|
+
obj_hdr *hdr,
|
939
|
+
loose_readstream *stream)
|
940
|
+
{
|
941
|
+
unsigned char head[MAX_HEADER_LEN];
|
942
|
+
size_t init, head_len;
|
943
|
+
int error;
|
944
|
+
|
945
|
+
if ((error = git_zstream_set_input(&stream->zstream,
|
946
|
+
stream->map.data, stream->map.len)) < 0)
|
947
|
+
return error;
|
948
|
+
|
949
|
+
init = sizeof(head);
|
950
|
+
|
951
|
+
/*
|
952
|
+
* inflate the initial part of the compressed buffer in order to
|
953
|
+
* parse the header; read the largest header possible, then store
|
954
|
+
* it in the `start` field of the stream object.
|
955
|
+
*/
|
956
|
+
if ((error = git_zstream_get_output(head, &init, &stream->zstream)) < 0 ||
|
957
|
+
(error = parse_header(hdr, &head_len, head, init)) < 0)
|
958
|
+
return error;
|
959
|
+
|
960
|
+
if (!git_object_typeisloose(hdr->type)) {
|
961
|
+
git_error_set(GIT_ERROR_ODB, "failed to inflate disk object");
|
962
|
+
return -1;
|
963
|
+
}
|
964
|
+
|
965
|
+
if (init > head_len) {
|
966
|
+
stream->start_len = init - head_len;
|
967
|
+
memcpy(stream->start, head + head_len, init - head_len);
|
968
|
+
}
|
969
|
+
|
970
|
+
return 0;
|
971
|
+
}
|
972
|
+
|
973
|
+
static int loose_backend__readstream(
|
974
|
+
git_odb_stream **stream_out,
|
975
|
+
size_t *len_out,
|
976
|
+
git_object_t *type_out,
|
977
|
+
git_odb_backend *_backend,
|
978
|
+
const git_oid *oid)
|
979
|
+
{
|
980
|
+
loose_backend *backend;
|
981
|
+
loose_readstream *stream = NULL;
|
982
|
+
git_hash_ctx *hash_ctx = NULL;
|
983
|
+
git_buf object_path = GIT_BUF_INIT;
|
984
|
+
obj_hdr hdr;
|
985
|
+
int error = 0;
|
986
|
+
|
987
|
+
assert(stream_out && len_out && type_out && _backend && oid);
|
988
|
+
|
989
|
+
backend = (loose_backend *)_backend;
|
990
|
+
*stream_out = NULL;
|
991
|
+
*len_out = 0;
|
992
|
+
*type_out = GIT_OBJECT_INVALID;
|
993
|
+
|
994
|
+
if (locate_object(&object_path, backend, oid) < 0) {
|
995
|
+
error = git_odb__error_notfound("no matching loose object",
|
996
|
+
oid, GIT_OID_HEXSZ);
|
997
|
+
goto done;
|
998
|
+
}
|
999
|
+
|
1000
|
+
stream = git__calloc(1, sizeof(loose_readstream));
|
1001
|
+
GIT_ERROR_CHECK_ALLOC(stream);
|
1002
|
+
|
1003
|
+
hash_ctx = git__malloc(sizeof(git_hash_ctx));
|
1004
|
+
GIT_ERROR_CHECK_ALLOC(hash_ctx);
|
1005
|
+
|
1006
|
+
if ((error = git_hash_ctx_init(hash_ctx)) < 0 ||
|
1007
|
+
(error = git_futils_mmap_ro_file(&stream->map, object_path.ptr)) < 0 ||
|
1008
|
+
(error = git_zstream_init(&stream->zstream, GIT_ZSTREAM_INFLATE)) < 0)
|
1009
|
+
goto done;
|
1010
|
+
|
1011
|
+
/* check for a packlike loose object */
|
1012
|
+
if (!is_zlib_compressed_data(stream->map.data, stream->map.len))
|
1013
|
+
error = loose_backend__readstream_packlike(&hdr, stream);
|
1014
|
+
else
|
1015
|
+
error = loose_backend__readstream_standard(&hdr, stream);
|
1016
|
+
|
1017
|
+
if (error < 0)
|
1018
|
+
goto done;
|
1019
|
+
|
1020
|
+
stream->stream.backend = _backend;
|
1021
|
+
stream->stream.hash_ctx = hash_ctx;
|
1022
|
+
stream->stream.read = &loose_backend__readstream_read;
|
1023
|
+
stream->stream.free = &loose_backend__readstream_free;
|
1024
|
+
|
1025
|
+
*stream_out = (git_odb_stream *)stream;
|
1026
|
+
*len_out = hdr.size;
|
1027
|
+
*type_out = hdr.type;
|
1028
|
+
|
1029
|
+
done:
|
1030
|
+
if (error < 0) {
|
1031
|
+
if (stream) {
|
1032
|
+
git_futils_mmap_free(&stream->map);
|
1033
|
+
git_zstream_free(&stream->zstream);
|
1034
|
+
git__free(stream);
|
1035
|
+
}
|
1036
|
+
if (hash_ctx) {
|
1037
|
+
git_hash_ctx_cleanup(hash_ctx);
|
1038
|
+
git__free(hash_ctx);
|
1039
|
+
}
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
git_buf_dispose(&object_path);
|
1043
|
+
return error;
|
1044
|
+
}
|
1045
|
+
|
1046
|
+
static int loose_backend__write(git_odb_backend *_backend, const git_oid *oid, const void *data, size_t len, git_object_t type)
|
1047
|
+
{
|
1048
|
+
int error = 0;
|
869
1049
|
git_buf final_path = GIT_BUF_INIT;
|
870
|
-
char header[
|
1050
|
+
char header[MAX_HEADER_LEN];
|
1051
|
+
size_t header_len;
|
871
1052
|
git_filebuf fbuf = GIT_FILEBUF_INIT;
|
872
1053
|
loose_backend *backend;
|
873
1054
|
|
874
1055
|
backend = (loose_backend *)_backend;
|
875
1056
|
|
876
1057
|
/* prepare the header for the file */
|
877
|
-
|
1058
|
+
if ((error = git_odb__format_object_header(&header_len,
|
1059
|
+
header, sizeof(header), len, type)) < 0)
|
1060
|
+
goto cleanup;
|
878
1061
|
|
879
1062
|
if (git_buf_joinpath(&final_path, backend->objects_dir, "tmp_object") < 0 ||
|
880
|
-
git_filebuf_open(&fbuf, final_path.ptr,
|
881
|
-
|
882
|
-
(backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT)) < 0)
|
1063
|
+
git_filebuf_open(&fbuf, final_path.ptr, filebuf_flags(backend),
|
1064
|
+
backend->object_file_mode) < 0)
|
883
1065
|
{
|
884
1066
|
error = -1;
|
885
1067
|
goto cleanup;
|
@@ -890,13 +1072,30 @@ static int loose_backend__write(git_oid *oid, git_odb_backend *_backend, const v
|
|
890
1072
|
|
891
1073
|
if (object_file_name(&final_path, backend, oid) < 0 ||
|
892
1074
|
object_mkdir(&final_path, backend) < 0 ||
|
893
|
-
git_filebuf_commit_at(&fbuf, final_path.ptr
|
1075
|
+
git_filebuf_commit_at(&fbuf, final_path.ptr) < 0)
|
894
1076
|
error = -1;
|
895
1077
|
|
896
1078
|
cleanup:
|
897
1079
|
if (error < 0)
|
898
1080
|
git_filebuf_cleanup(&fbuf);
|
899
|
-
|
1081
|
+
git_buf_dispose(&final_path);
|
1082
|
+
return error;
|
1083
|
+
}
|
1084
|
+
|
1085
|
+
static int loose_backend__freshen(
|
1086
|
+
git_odb_backend *_backend,
|
1087
|
+
const git_oid *oid)
|
1088
|
+
{
|
1089
|
+
loose_backend *backend = (loose_backend *)_backend;
|
1090
|
+
git_buf path = GIT_BUF_INIT;
|
1091
|
+
int error;
|
1092
|
+
|
1093
|
+
if (object_file_name(&path, backend, oid) < 0)
|
1094
|
+
return -1;
|
1095
|
+
|
1096
|
+
error = git_futils_touch(path.ptr, NULL);
|
1097
|
+
git_buf_dispose(&path);
|
1098
|
+
|
900
1099
|
return error;
|
901
1100
|
}
|
902
1101
|
|
@@ -913,17 +1112,21 @@ int git_odb_backend_loose(
|
|
913
1112
|
git_odb_backend **backend_out,
|
914
1113
|
const char *objects_dir,
|
915
1114
|
int compression_level,
|
916
|
-
int do_fsync
|
1115
|
+
int do_fsync,
|
1116
|
+
unsigned int dir_mode,
|
1117
|
+
unsigned int file_mode)
|
917
1118
|
{
|
918
1119
|
loose_backend *backend;
|
919
|
-
size_t objects_dirlen;
|
1120
|
+
size_t objects_dirlen, alloclen;
|
920
1121
|
|
921
1122
|
assert(backend_out && objects_dir);
|
922
1123
|
|
923
1124
|
objects_dirlen = strlen(objects_dir);
|
924
1125
|
|
925
|
-
|
926
|
-
|
1126
|
+
GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, sizeof(loose_backend), objects_dirlen);
|
1127
|
+
GIT_ERROR_CHECK_ALLOC_ADD(&alloclen, alloclen, 2);
|
1128
|
+
backend = git__calloc(1, alloclen);
|
1129
|
+
GIT_ERROR_CHECK_ALLOC(backend);
|
927
1130
|
|
928
1131
|
backend->parent.version = GIT_ODB_BACKEND_VERSION;
|
929
1132
|
backend->objects_dirlen = objects_dirlen;
|
@@ -934,16 +1137,27 @@ int git_odb_backend_loose(
|
|
934
1137
|
if (compression_level < 0)
|
935
1138
|
compression_level = Z_BEST_SPEED;
|
936
1139
|
|
1140
|
+
if (dir_mode == 0)
|
1141
|
+
dir_mode = GIT_OBJECT_DIR_MODE;
|
1142
|
+
|
1143
|
+
if (file_mode == 0)
|
1144
|
+
file_mode = GIT_OBJECT_FILE_MODE;
|
1145
|
+
|
937
1146
|
backend->object_zlib_level = compression_level;
|
938
1147
|
backend->fsync_object_files = do_fsync;
|
1148
|
+
backend->object_dir_mode = dir_mode;
|
1149
|
+
backend->object_file_mode = file_mode;
|
939
1150
|
|
940
1151
|
backend->parent.read = &loose_backend__read;
|
941
1152
|
backend->parent.write = &loose_backend__write;
|
942
1153
|
backend->parent.read_prefix = &loose_backend__read_prefix;
|
943
1154
|
backend->parent.read_header = &loose_backend__read_header;
|
944
|
-
backend->parent.writestream = &
|
1155
|
+
backend->parent.writestream = &loose_backend__writestream;
|
1156
|
+
backend->parent.readstream = &loose_backend__readstream;
|
945
1157
|
backend->parent.exists = &loose_backend__exists;
|
1158
|
+
backend->parent.exists_prefix = &loose_backend__exists_prefix;
|
946
1159
|
backend->parent.foreach = &loose_backend__foreach;
|
1160
|
+
backend->parent.freshen = &loose_backend__freshen;
|
947
1161
|
backend->parent.free = &loose_backend__free;
|
948
1162
|
|
949
1163
|
*backend_out = (git_odb_backend *)backend;
|