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
@@ -7,13 +7,16 @@
|
|
7
7
|
|
8
8
|
#include "pack-objects.h"
|
9
9
|
|
10
|
-
#include "
|
10
|
+
#include "zstream.h"
|
11
11
|
#include "delta.h"
|
12
12
|
#include "iterator.h"
|
13
13
|
#include "netops.h"
|
14
14
|
#include "pack.h"
|
15
15
|
#include "thread-utils.h"
|
16
16
|
#include "tree.h"
|
17
|
+
#include "util.h"
|
18
|
+
#include "revwalk.h"
|
19
|
+
#include "commit_list.h"
|
17
20
|
|
18
21
|
#include "git2/pack.h"
|
19
22
|
#include "git2/commit.h"
|
@@ -25,7 +28,7 @@ struct unpacked {
|
|
25
28
|
git_pobject *object;
|
26
29
|
void *data;
|
27
30
|
struct git_delta_index *index;
|
28
|
-
|
31
|
+
size_t depth;
|
29
32
|
};
|
30
33
|
|
31
34
|
struct tree_walk_context {
|
@@ -34,10 +37,16 @@ struct tree_walk_context {
|
|
34
37
|
};
|
35
38
|
|
36
39
|
struct pack_write_context {
|
37
|
-
|
40
|
+
git_indexer *indexer;
|
38
41
|
git_transfer_progress *stats;
|
39
42
|
};
|
40
43
|
|
44
|
+
struct walk_object {
|
45
|
+
git_oid id;
|
46
|
+
unsigned int uninteresting:1,
|
47
|
+
seen:1;
|
48
|
+
};
|
49
|
+
|
41
50
|
#ifdef GIT_THREADS
|
42
51
|
|
43
52
|
#define GIT_PACKBUILDER__MUTEX_OP(pb, mtx, op) do { \
|
@@ -57,6 +66,12 @@ struct pack_write_context {
|
|
57
66
|
#define git_packbuilder__progress_lock(pb) GIT_PACKBUILDER__MUTEX_OP(pb, progress_mutex, lock)
|
58
67
|
#define git_packbuilder__progress_unlock(pb) GIT_PACKBUILDER__MUTEX_OP(pb, progress_mutex, unlock)
|
59
68
|
|
69
|
+
/* The minimal interval between progress updates (in seconds). */
|
70
|
+
#define MIN_PROGRESS_UPDATE_INTERVAL 0.5
|
71
|
+
|
72
|
+
/* Size of the buffer to feed to zlib */
|
73
|
+
#define COMPRESS_BUFLEN (1024 * 1024)
|
74
|
+
|
60
75
|
static unsigned name_hash(const char *name)
|
61
76
|
{
|
62
77
|
unsigned c, hash = 0;
|
@@ -80,17 +95,26 @@ static unsigned name_hash(const char *name)
|
|
80
95
|
static int packbuilder_config(git_packbuilder *pb)
|
81
96
|
{
|
82
97
|
git_config *config;
|
83
|
-
int ret;
|
98
|
+
int ret = 0;
|
84
99
|
int64_t val;
|
85
100
|
|
86
|
-
if (
|
87
|
-
return
|
101
|
+
if ((ret = git_repository_config_snapshot(&config, pb->repo)) < 0)
|
102
|
+
return ret;
|
88
103
|
|
89
104
|
#define config_get(KEY,DST,DFLT) do { \
|
90
105
|
ret = git_config_get_int64(&val, config, KEY); \
|
91
|
-
if (!ret)
|
92
|
-
|
93
|
-
|
106
|
+
if (!ret) { \
|
107
|
+
if (!git__is_sizet(val)) { \
|
108
|
+
git_error_set(GIT_ERROR_CONFIG, \
|
109
|
+
"configuration value '%s' is too large", KEY); \
|
110
|
+
ret = -1; \
|
111
|
+
goto out; \
|
112
|
+
} \
|
113
|
+
(DST) = (size_t)val; \
|
114
|
+
} else if (ret == GIT_ENOTFOUND) { \
|
115
|
+
(DST) = (DFLT); \
|
116
|
+
ret = 0; \
|
117
|
+
} else if (ret < 0) goto out; } while (0)
|
94
118
|
|
95
119
|
config_get("pack.deltaCacheSize", pb->max_delta_cache_size,
|
96
120
|
GIT_PACK_DELTA_CACHE_SIZE);
|
@@ -102,7 +126,10 @@ static int packbuilder_config(git_packbuilder *pb)
|
|
102
126
|
|
103
127
|
#undef config_get
|
104
128
|
|
105
|
-
|
129
|
+
out:
|
130
|
+
git_config_free(config);
|
131
|
+
|
132
|
+
return ret;
|
106
133
|
}
|
107
134
|
|
108
135
|
int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
|
@@ -112,17 +139,23 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
|
|
112
139
|
*out = NULL;
|
113
140
|
|
114
141
|
pb = git__calloc(1, sizeof(*pb));
|
115
|
-
|
142
|
+
GIT_ERROR_CHECK_ALLOC(pb);
|
116
143
|
|
117
144
|
pb->object_ix = git_oidmap_alloc();
|
118
|
-
|
119
145
|
if (!pb->object_ix)
|
120
146
|
goto on_error;
|
121
147
|
|
148
|
+
pb->walk_objects = git_oidmap_alloc();
|
149
|
+
if (!pb->walk_objects)
|
150
|
+
goto on_error;
|
151
|
+
|
152
|
+
git_pool_init(&pb->object_pool, sizeof(struct walk_object));
|
153
|
+
|
122
154
|
pb->repo = repo;
|
123
155
|
pb->nr_threads = 1; /* do not spawn any thread by default */
|
124
156
|
|
125
157
|
if (git_hash_ctx_init(&pb->ctx) < 0 ||
|
158
|
+
git_zstream_init(&pb->zstream, GIT_ZSTREAM_DEFLATE) < 0 ||
|
126
159
|
git_repository_odb(&pb->odb, repo) < 0 ||
|
127
160
|
packbuilder_config(pb) < 0)
|
128
161
|
goto on_error;
|
@@ -133,7 +166,7 @@ int git_packbuilder_new(git_packbuilder **out, git_repository *repo)
|
|
133
166
|
git_mutex_init(&pb->progress_mutex) ||
|
134
167
|
git_cond_init(&pb->progress_cond))
|
135
168
|
{
|
136
|
-
|
169
|
+
git_error_set(GIT_ERROR_OS, "failed to initialize packbuilder mutex");
|
137
170
|
goto on_error;
|
138
171
|
}
|
139
172
|
|
@@ -164,14 +197,13 @@ unsigned int git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n)
|
|
164
197
|
static void rehash(git_packbuilder *pb)
|
165
198
|
{
|
166
199
|
git_pobject *po;
|
167
|
-
|
168
|
-
unsigned int i;
|
200
|
+
size_t pos, i;
|
169
201
|
int ret;
|
170
202
|
|
171
|
-
|
203
|
+
git_oidmap_clear(pb->object_ix);
|
172
204
|
for (i = 0, po = pb->object_list; i < pb->nr_objects; i++, po++) {
|
173
|
-
pos =
|
174
|
-
|
205
|
+
pos = git_oidmap_put(pb->object_ix, &po->id, &ret);
|
206
|
+
git_oidmap_set_value_at(pb->object_ix, pos, po);
|
175
207
|
}
|
176
208
|
}
|
177
209
|
|
@@ -179,82 +211,78 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
|
|
179
211
|
const char *name)
|
180
212
|
{
|
181
213
|
git_pobject *po;
|
182
|
-
|
214
|
+
size_t newsize, pos;
|
183
215
|
int ret;
|
184
216
|
|
185
217
|
assert(pb && oid);
|
186
218
|
|
187
219
|
/* If the object already exists in the hash table, then we don't
|
188
220
|
* have any work to do */
|
189
|
-
|
190
|
-
if (pos != kh_end(pb->object_ix))
|
221
|
+
if (git_oidmap_exists(pb->object_ix, oid))
|
191
222
|
return 0;
|
192
223
|
|
193
224
|
if (pb->nr_objects >= pb->nr_alloc) {
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
225
|
+
GIT_ERROR_CHECK_ALLOC_ADD(&newsize, pb->nr_alloc, 1024);
|
226
|
+
GIT_ERROR_CHECK_ALLOC_MULTIPLY(&newsize, newsize, 3 / 2);
|
227
|
+
|
228
|
+
if (!git__is_uint32(newsize)) {
|
229
|
+
git_error_set(GIT_ERROR_NOMEMORY, "packfile too large to fit in memory.");
|
230
|
+
return -1;
|
231
|
+
}
|
232
|
+
|
233
|
+
pb->nr_alloc = newsize;
|
234
|
+
|
235
|
+
pb->object_list = git__reallocarray(pb->object_list,
|
236
|
+
pb->nr_alloc, sizeof(*po));
|
237
|
+
GIT_ERROR_CHECK_ALLOC(pb->object_list);
|
198
238
|
rehash(pb);
|
199
239
|
}
|
200
240
|
|
201
241
|
po = pb->object_list + pb->nr_objects;
|
202
242
|
memset(po, 0x0, sizeof(*po));
|
203
243
|
|
204
|
-
if (git_odb_read_header(&po->size, &po->type, pb->odb, oid) < 0)
|
205
|
-
return
|
244
|
+
if ((ret = git_odb_read_header(&po->size, &po->type, pb->odb, oid)) < 0)
|
245
|
+
return ret;
|
206
246
|
|
207
247
|
pb->nr_objects++;
|
208
248
|
git_oid_cpy(&po->id, oid);
|
209
249
|
po->hash = name_hash(name);
|
210
250
|
|
211
|
-
pos =
|
251
|
+
pos = git_oidmap_put(pb->object_ix, &po->id, &ret);
|
252
|
+
if (ret < 0) {
|
253
|
+
git_error_set_oom();
|
254
|
+
return ret;
|
255
|
+
}
|
212
256
|
assert(ret != 0);
|
213
|
-
|
257
|
+
git_oidmap_set_value_at(pb->object_ix, pos, po);
|
214
258
|
|
215
259
|
pb->done = false;
|
216
|
-
return 0;
|
217
|
-
}
|
218
|
-
|
219
|
-
/*
|
220
|
-
* The per-object header is a pretty dense thing, which is
|
221
|
-
* - first byte: low four bits are "size",
|
222
|
-
* then three bits of "type",
|
223
|
-
* with the high bit being "size continues".
|
224
|
-
* - each byte afterwards: low seven bits are size continuation,
|
225
|
-
* with the high bit being "size continues"
|
226
|
-
*/
|
227
|
-
static int gen_pack_object_header(
|
228
|
-
unsigned char *hdr,
|
229
|
-
unsigned long size,
|
230
|
-
git_otype type)
|
231
|
-
{
|
232
|
-
unsigned char *hdr_base;
|
233
|
-
unsigned char c;
|
234
260
|
|
235
|
-
|
261
|
+
if (pb->progress_cb) {
|
262
|
+
double current_time = git__timer();
|
263
|
+
double elapsed = current_time - pb->last_progress_report_time;
|
236
264
|
|
237
|
-
|
265
|
+
if (elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
|
266
|
+
pb->last_progress_report_time = current_time;
|
238
267
|
|
239
|
-
|
240
|
-
|
241
|
-
|
268
|
+
ret = pb->progress_cb(
|
269
|
+
GIT_PACKBUILDER_ADDING_OBJECTS,
|
270
|
+
pb->nr_objects, 0, pb->progress_cb_payload);
|
242
271
|
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
size >>= 7;
|
272
|
+
if (ret)
|
273
|
+
return git_error_set_after_callback(ret);
|
274
|
+
}
|
247
275
|
}
|
248
|
-
*hdr++ = c;
|
249
276
|
|
250
|
-
return
|
277
|
+
return 0;
|
251
278
|
}
|
252
279
|
|
253
280
|
static int get_delta(void **out, git_odb *odb, git_pobject *po)
|
254
281
|
{
|
255
282
|
git_odb_object *src = NULL, *trg = NULL;
|
256
|
-
|
283
|
+
size_t delta_size;
|
257
284
|
void *delta_buf;
|
285
|
+
int error;
|
258
286
|
|
259
287
|
*out = NULL;
|
260
288
|
|
@@ -262,13 +290,16 @@ static int get_delta(void **out, git_odb *odb, git_pobject *po)
|
|
262
290
|
git_odb_read(&trg, odb, &po->id) < 0)
|
263
291
|
goto on_error;
|
264
292
|
|
265
|
-
|
266
|
-
git_odb_object_data(src),
|
267
|
-
git_odb_object_data(trg),
|
268
|
-
|
293
|
+
error = git_delta(&delta_buf, &delta_size,
|
294
|
+
git_odb_object_data(src), git_odb_object_size(src),
|
295
|
+
git_odb_object_data(trg), git_odb_object_size(trg),
|
296
|
+
0);
|
297
|
+
|
298
|
+
if (error < 0 && error != GIT_EBUFS)
|
299
|
+
goto on_error;
|
269
300
|
|
270
|
-
if (
|
271
|
-
|
301
|
+
if (error == GIT_EBUFS || delta_size != po->delta_size) {
|
302
|
+
git_error_set(GIT_ERROR_INVALID, "delta size changed");
|
272
303
|
goto on_error;
|
273
304
|
}
|
274
305
|
|
@@ -284,76 +315,96 @@ on_error:
|
|
284
315
|
return -1;
|
285
316
|
}
|
286
317
|
|
287
|
-
static int write_object(
|
318
|
+
static int write_object(
|
319
|
+
git_packbuilder *pb,
|
320
|
+
git_pobject *po,
|
321
|
+
int (*write_cb)(void *buf, size_t size, void *cb_data),
|
322
|
+
void *cb_data)
|
288
323
|
{
|
289
324
|
git_odb_object *obj = NULL;
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
void *data;
|
325
|
+
git_object_t type;
|
326
|
+
unsigned char hdr[10], *zbuf = NULL;
|
327
|
+
void *data = NULL;
|
328
|
+
size_t hdr_len, zbuf_len = COMPRESS_BUFLEN, data_len;
|
329
|
+
int error;
|
296
330
|
|
331
|
+
/*
|
332
|
+
* If we have a delta base, let's use the delta to save space.
|
333
|
+
* Otherwise load the whole object. 'data' ends up pointing to
|
334
|
+
* whatever data we want to put into the packfile.
|
335
|
+
*/
|
297
336
|
if (po->delta) {
|
298
337
|
if (po->delta_data)
|
299
338
|
data = po->delta_data;
|
300
|
-
else if (get_delta(&data, pb->odb, po) < 0)
|
301
|
-
goto
|
302
|
-
|
303
|
-
|
339
|
+
else if ((error = get_delta(&data, pb->odb, po)) < 0)
|
340
|
+
goto done;
|
341
|
+
|
342
|
+
data_len = po->delta_size;
|
343
|
+
type = GIT_OBJECT_REF_DELTA;
|
304
344
|
} else {
|
305
|
-
if (git_odb_read(&obj, pb->odb, &po->id))
|
306
|
-
goto
|
345
|
+
if ((error = git_odb_read(&obj, pb->odb, &po->id)) < 0)
|
346
|
+
goto done;
|
307
347
|
|
308
348
|
data = (void *)git_odb_object_data(obj);
|
309
|
-
|
349
|
+
data_len = git_odb_object_size(obj);
|
310
350
|
type = git_odb_object_type(obj);
|
311
351
|
}
|
312
352
|
|
313
353
|
/* Write header */
|
314
|
-
hdr_len =
|
354
|
+
hdr_len = git_packfile__object_header(hdr, data_len, type);
|
315
355
|
|
316
|
-
if (
|
317
|
-
|
318
|
-
|
319
|
-
if (git_hash_update(&pb->ctx, hdr, hdr_len) < 0)
|
320
|
-
goto on_error;
|
356
|
+
if ((error = write_cb(hdr, hdr_len, cb_data)) < 0 ||
|
357
|
+
(error = git_hash_update(&pb->ctx, hdr, hdr_len)) < 0)
|
358
|
+
goto done;
|
321
359
|
|
322
|
-
if (type ==
|
323
|
-
if (
|
324
|
-
git_hash_update(&pb->ctx, po->delta->id.id, GIT_OID_RAWSZ) < 0)
|
325
|
-
goto
|
360
|
+
if (type == GIT_OBJECT_REF_DELTA) {
|
361
|
+
if ((error = write_cb(po->delta->id.id, GIT_OID_RAWSZ, cb_data)) < 0 ||
|
362
|
+
(error = git_hash_update(&pb->ctx, po->delta->id.id, GIT_OID_RAWSZ)) < 0)
|
363
|
+
goto done;
|
326
364
|
}
|
327
365
|
|
328
366
|
/* Write data */
|
329
|
-
if (po->z_delta_size)
|
330
|
-
|
331
|
-
else if (git__compress(&zbuf, data, size) < 0)
|
332
|
-
goto on_error;
|
333
|
-
else {
|
334
|
-
if (po->delta)
|
335
|
-
git__free(data);
|
336
|
-
data = zbuf.ptr;
|
337
|
-
size = (unsigned long)zbuf.size;
|
338
|
-
}
|
367
|
+
if (po->z_delta_size) {
|
368
|
+
data_len = po->z_delta_size;
|
339
369
|
|
340
|
-
|
341
|
-
|
342
|
-
|
370
|
+
if ((error = write_cb(data, data_len, cb_data)) < 0 ||
|
371
|
+
(error = git_hash_update(&pb->ctx, data, data_len)) < 0)
|
372
|
+
goto done;
|
373
|
+
} else {
|
374
|
+
zbuf = git__malloc(zbuf_len);
|
375
|
+
GIT_ERROR_CHECK_ALLOC(zbuf);
|
343
376
|
|
344
|
-
|
345
|
-
|
377
|
+
git_zstream_reset(&pb->zstream);
|
378
|
+
git_zstream_set_input(&pb->zstream, data, data_len);
|
346
379
|
|
347
|
-
|
348
|
-
|
380
|
+
while (!git_zstream_done(&pb->zstream)) {
|
381
|
+
if ((error = git_zstream_get_output(zbuf, &zbuf_len, &pb->zstream)) < 0 ||
|
382
|
+
(error = write_cb(zbuf, zbuf_len, cb_data)) < 0 ||
|
383
|
+
(error = git_hash_update(&pb->ctx, zbuf, zbuf_len)) < 0)
|
384
|
+
goto done;
|
385
|
+
|
386
|
+
zbuf_len = COMPRESS_BUFLEN; /* reuse buffer */
|
387
|
+
}
|
388
|
+
}
|
389
|
+
|
390
|
+
/*
|
391
|
+
* If po->delta is true, data is a delta and it is our
|
392
|
+
* responsibility to free it (otherwise it's a git_object's
|
393
|
+
* data). We set po->delta_data to NULL in case we got the
|
394
|
+
* data from there instead of get_delta(). If we didn't,
|
395
|
+
* there's no harm.
|
396
|
+
*/
|
397
|
+
if (po->delta) {
|
398
|
+
git__free(data);
|
399
|
+
po->delta_data = NULL;
|
400
|
+
}
|
349
401
|
|
350
402
|
pb->nr_written++;
|
351
|
-
return 0;
|
352
403
|
|
353
|
-
|
404
|
+
done:
|
405
|
+
git__free(zbuf);
|
354
406
|
git_odb_object_free(obj);
|
355
|
-
|
356
|
-
return -1;
|
407
|
+
return error;
|
357
408
|
}
|
358
409
|
|
359
410
|
enum write_one_status {
|
@@ -363,9 +414,15 @@ enum write_one_status {
|
|
363
414
|
WRITE_ONE_RECURSIVE = 2 /* already scheduled to be written */
|
364
415
|
};
|
365
416
|
|
366
|
-
static int write_one(
|
367
|
-
|
417
|
+
static int write_one(
|
418
|
+
enum write_one_status *status,
|
419
|
+
git_packbuilder *pb,
|
420
|
+
git_pobject *po,
|
421
|
+
int (*write_cb)(void *buf, size_t size, void *cb_data),
|
422
|
+
void *cb_data)
|
368
423
|
{
|
424
|
+
int error;
|
425
|
+
|
369
426
|
if (po->recursing) {
|
370
427
|
*status = WRITE_ONE_RECURSIVE;
|
371
428
|
return 0;
|
@@ -376,25 +433,24 @@ static int write_one(git_buf *buf, git_packbuilder *pb, git_pobject *po,
|
|
376
433
|
|
377
434
|
if (po->delta) {
|
378
435
|
po->recursing = 1;
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
436
|
+
|
437
|
+
if ((error = write_one(status, pb, po->delta, write_cb, cb_data)) < 0)
|
438
|
+
return error;
|
439
|
+
|
440
|
+
/* we cannot depend on this one */
|
441
|
+
if (*status == WRITE_ONE_RECURSIVE)
|
384
442
|
po->delta = NULL;
|
385
|
-
break;
|
386
|
-
default:
|
387
|
-
break;
|
388
|
-
}
|
389
443
|
}
|
390
444
|
|
445
|
+
*status = WRITE_ONE_WRITTEN;
|
391
446
|
po->written = 1;
|
392
447
|
po->recursing = 0;
|
393
|
-
|
448
|
+
|
449
|
+
return write_object(pb, po, write_cb, cb_data);
|
394
450
|
}
|
395
451
|
|
396
|
-
GIT_INLINE(void) add_to_write_order(git_pobject **wo,
|
397
|
-
|
452
|
+
GIT_INLINE(void) add_to_write_order(git_pobject **wo, size_t *endp,
|
453
|
+
git_pobject *po)
|
398
454
|
{
|
399
455
|
if (po->filled)
|
400
456
|
return;
|
@@ -402,8 +458,8 @@ GIT_INLINE(void) add_to_write_order(git_pobject **wo, unsigned int *endp,
|
|
402
458
|
po->filled = 1;
|
403
459
|
}
|
404
460
|
|
405
|
-
static void add_descendants_to_write_order(git_pobject **wo,
|
406
|
-
|
461
|
+
static void add_descendants_to_write_order(git_pobject **wo, size_t *endp,
|
462
|
+
git_pobject *po)
|
407
463
|
{
|
408
464
|
int add_to_order = 1;
|
409
465
|
while (po) {
|
@@ -444,8 +500,8 @@ static void add_descendants_to_write_order(git_pobject **wo, unsigned int *endp,
|
|
444
500
|
};
|
445
501
|
}
|
446
502
|
|
447
|
-
static void add_family_to_write_order(git_pobject **wo,
|
448
|
-
|
503
|
+
static void add_family_to_write_order(git_pobject **wo, size_t *endp,
|
504
|
+
git_pobject *po)
|
449
505
|
{
|
450
506
|
git_pobject *root;
|
451
507
|
|
@@ -458,15 +514,15 @@ static int cb_tag_foreach(const char *name, git_oid *oid, void *data)
|
|
458
514
|
{
|
459
515
|
git_packbuilder *pb = data;
|
460
516
|
git_pobject *po;
|
461
|
-
|
517
|
+
size_t pos;
|
462
518
|
|
463
519
|
GIT_UNUSED(name);
|
464
520
|
|
465
|
-
pos =
|
466
|
-
if (
|
521
|
+
pos = git_oidmap_lookup_index(pb->object_ix, oid);
|
522
|
+
if (!git_oidmap_valid_index(pb->object_ix, pos))
|
467
523
|
return 0;
|
468
524
|
|
469
|
-
po =
|
525
|
+
po = git_oidmap_value_at(pb->object_ix, pos);
|
470
526
|
po->tagged = 1;
|
471
527
|
|
472
528
|
/* TODO: peel objects */
|
@@ -476,9 +532,11 @@ static int cb_tag_foreach(const char *name, git_oid *oid, void *data)
|
|
476
532
|
|
477
533
|
static git_pobject **compute_write_order(git_packbuilder *pb)
|
478
534
|
{
|
479
|
-
|
535
|
+
size_t i, wo_end, last_untagged;
|
536
|
+
git_pobject **wo;
|
480
537
|
|
481
|
-
|
538
|
+
if ((wo = git__mallocarray(pb->nr_objects, sizeof(*wo))) == NULL)
|
539
|
+
return NULL;
|
482
540
|
|
483
541
|
for (i = 0; i < pb->nr_objects; i++) {
|
484
542
|
git_pobject *po = pb->object_list + i;
|
@@ -505,8 +563,10 @@ static git_pobject **compute_write_order(git_packbuilder *pb)
|
|
505
563
|
/*
|
506
564
|
* Mark objects that are at the tip of tags.
|
507
565
|
*/
|
508
|
-
if (git_tag_foreach(pb->repo, &cb_tag_foreach, pb) < 0)
|
566
|
+
if (git_tag_foreach(pb->repo, &cb_tag_foreach, pb) < 0) {
|
567
|
+
git__free(wo);
|
509
568
|
return NULL;
|
569
|
+
}
|
510
570
|
|
511
571
|
/*
|
512
572
|
* Give the objects in the original recency order until
|
@@ -534,8 +594,8 @@ static git_pobject **compute_write_order(git_packbuilder *pb)
|
|
534
594
|
*/
|
535
595
|
for (i = last_untagged; i < pb->nr_objects; i++) {
|
536
596
|
git_pobject *po = pb->object_list + i;
|
537
|
-
if (po->type !=
|
538
|
-
po->type !=
|
597
|
+
if (po->type != GIT_OBJECT_COMMIT &&
|
598
|
+
po->type != GIT_OBJECT_TAG)
|
539
599
|
continue;
|
540
600
|
add_to_write_order(wo, &wo_end, po);
|
541
601
|
}
|
@@ -545,7 +605,7 @@ static git_pobject **compute_write_order(git_packbuilder *pb)
|
|
545
605
|
*/
|
546
606
|
for (i = last_untagged; i < pb->nr_objects; i++) {
|
547
607
|
git_pobject *po = pb->object_list + i;
|
548
|
-
if (po->type !=
|
608
|
+
if (po->type != GIT_OBJECT_TREE)
|
549
609
|
continue;
|
550
610
|
add_to_write_order(wo, &wo_end, po);
|
551
611
|
}
|
@@ -560,7 +620,8 @@ static git_pobject **compute_write_order(git_packbuilder *pb)
|
|
560
620
|
}
|
561
621
|
|
562
622
|
if (wo_end != pb->nr_objects) {
|
563
|
-
|
623
|
+
git__free(wo);
|
624
|
+
git_error_set(GIT_ERROR_INVALID, "invalid write order");
|
564
625
|
return NULL;
|
565
626
|
}
|
566
627
|
|
@@ -568,58 +629,65 @@ static git_pobject **compute_write_order(git_packbuilder *pb)
|
|
568
629
|
}
|
569
630
|
|
570
631
|
static int write_pack(git_packbuilder *pb,
|
571
|
-
|
572
|
-
|
632
|
+
int (*write_cb)(void *buf, size_t size, void *cb_data),
|
633
|
+
void *cb_data)
|
573
634
|
{
|
574
635
|
git_pobject **write_order;
|
575
636
|
git_pobject *po;
|
576
|
-
git_buf buf = GIT_BUF_INIT;
|
577
637
|
enum write_one_status status;
|
578
638
|
struct git_pack_header ph;
|
579
|
-
|
639
|
+
git_oid entry_oid;
|
640
|
+
size_t i = 0;
|
641
|
+
int error = 0;
|
580
642
|
|
581
643
|
write_order = compute_write_order(pb);
|
582
644
|
if (write_order == NULL)
|
583
|
-
|
645
|
+
return -1;
|
646
|
+
|
647
|
+
if (!git__is_uint32(pb->nr_objects)) {
|
648
|
+
git_error_set(GIT_ERROR_INVALID, "too many objects");
|
649
|
+
return -1;
|
650
|
+
}
|
584
651
|
|
585
652
|
/* Write pack header */
|
586
653
|
ph.hdr_signature = htonl(PACK_SIGNATURE);
|
587
654
|
ph.hdr_version = htonl(PACK_VERSION);
|
588
655
|
ph.hdr_entries = htonl(pb->nr_objects);
|
589
656
|
|
590
|
-
if (
|
591
|
-
|
592
|
-
|
593
|
-
if (git_hash_update(&pb->ctx, &ph, sizeof(ph)) < 0)
|
594
|
-
goto on_error;
|
657
|
+
if ((error = write_cb(&ph, sizeof(ph), cb_data)) < 0 ||
|
658
|
+
(error = git_hash_update(&pb->ctx, &ph, sizeof(ph))) < 0)
|
659
|
+
goto done;
|
595
660
|
|
596
661
|
pb->nr_remaining = pb->nr_objects;
|
597
662
|
do {
|
598
663
|
pb->nr_written = 0;
|
599
664
|
for ( ; i < pb->nr_objects; ++i) {
|
600
665
|
po = write_order[i];
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
goto on_error;
|
605
|
-
git_buf_clear(&buf);
|
666
|
+
|
667
|
+
if ((error = write_one(&status, pb, po, write_cb, cb_data)) < 0)
|
668
|
+
goto done;
|
606
669
|
}
|
607
670
|
|
608
671
|
pb->nr_remaining -= pb->nr_written;
|
609
672
|
} while (pb->nr_remaining && i < pb->nr_objects);
|
610
673
|
|
611
|
-
|
612
|
-
|
674
|
+
if ((error = git_hash_final(&entry_oid, &pb->ctx)) < 0)
|
675
|
+
goto done;
|
613
676
|
|
614
|
-
|
615
|
-
goto on_error;
|
677
|
+
error = write_cb(entry_oid.id, GIT_OID_RAWSZ, cb_data);
|
616
678
|
|
617
|
-
|
679
|
+
done:
|
680
|
+
/* if callback cancelled writing, we must still free delta_data */
|
681
|
+
for ( ; i < pb->nr_objects; ++i) {
|
682
|
+
po = write_order[i];
|
683
|
+
if (po->delta_data) {
|
684
|
+
git__free(po->delta_data);
|
685
|
+
po->delta_data = NULL;
|
686
|
+
}
|
687
|
+
}
|
618
688
|
|
619
|
-
on_error:
|
620
689
|
git__free(write_order);
|
621
|
-
|
622
|
-
return -1;
|
690
|
+
return error;
|
623
691
|
}
|
624
692
|
|
625
693
|
static int write_pack_buf(void *buf, size_t size, void *data)
|
@@ -656,11 +724,18 @@ static int type_size_sort(const void *_a, const void *_b)
|
|
656
724
|
return a < b ? -1 : (a > b); /* newest first */
|
657
725
|
}
|
658
726
|
|
659
|
-
static int delta_cacheable(
|
660
|
-
|
727
|
+
static int delta_cacheable(
|
728
|
+
git_packbuilder *pb,
|
729
|
+
size_t src_size,
|
730
|
+
size_t trg_size,
|
731
|
+
size_t delta_size)
|
661
732
|
{
|
662
|
-
|
663
|
-
|
733
|
+
size_t new_size;
|
734
|
+
|
735
|
+
if (git__add_sizet_overflow(&new_size, pb->delta_cache_size, delta_size))
|
736
|
+
return 0;
|
737
|
+
|
738
|
+
if (pb->max_delta_cache_size && new_size > pb->max_delta_cache_size)
|
664
739
|
return 0;
|
665
740
|
|
666
741
|
if (delta_size < pb->cache_max_small_delta_size)
|
@@ -674,15 +749,14 @@ static int delta_cacheable(git_packbuilder *pb, unsigned long src_size,
|
|
674
749
|
}
|
675
750
|
|
676
751
|
static int try_delta(git_packbuilder *pb, struct unpacked *trg,
|
677
|
-
struct unpacked *src,
|
678
|
-
|
752
|
+
struct unpacked *src, size_t max_depth,
|
753
|
+
size_t *mem_usage, int *ret)
|
679
754
|
{
|
680
755
|
git_pobject *trg_object = trg->object;
|
681
756
|
git_pobject *src_object = src->object;
|
682
757
|
git_odb_object *obj;
|
683
|
-
|
684
|
-
|
685
|
-
unsigned int ref_depth;
|
758
|
+
size_t trg_size, src_size, delta_size, sizediff, max_size, sz;
|
759
|
+
size_t ref_depth;
|
686
760
|
void *delta_buf;
|
687
761
|
|
688
762
|
/* Don't bother doing diffs between different types */
|
@@ -700,7 +774,7 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
|
|
700
774
|
return 0;
|
701
775
|
|
702
776
|
/* Now some size filtering heuristics. */
|
703
|
-
trg_size =
|
777
|
+
trg_size = trg_object->size;
|
704
778
|
if (!trg_object->delta) {
|
705
779
|
max_size = trg_size/2 - 20;
|
706
780
|
ref_depth = 1;
|
@@ -714,7 +788,7 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
|
|
714
788
|
if (max_size == 0)
|
715
789
|
return 0;
|
716
790
|
|
717
|
-
src_size =
|
791
|
+
src_size = src_object->size;
|
718
792
|
sizediff = src_size < trg_size ? trg_size - src_size : 0;
|
719
793
|
if (sizediff >= max_size)
|
720
794
|
return 0;
|
@@ -726,51 +800,52 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
|
|
726
800
|
if (git_odb_read(&obj, pb->odb, &trg_object->id) < 0)
|
727
801
|
return -1;
|
728
802
|
|
729
|
-
sz =
|
803
|
+
sz = git_odb_object_size(obj);
|
730
804
|
trg->data = git__malloc(sz);
|
731
|
-
|
805
|
+
GIT_ERROR_CHECK_ALLOC(trg->data);
|
732
806
|
memcpy(trg->data, git_odb_object_data(obj), sz);
|
733
807
|
|
734
808
|
git_odb_object_free(obj);
|
735
809
|
|
736
810
|
if (sz != trg_size) {
|
737
|
-
|
738
|
-
"
|
811
|
+
git_error_set(GIT_ERROR_INVALID,
|
812
|
+
"inconsistent target object length");
|
739
813
|
return -1;
|
740
814
|
}
|
741
815
|
|
742
816
|
*mem_usage += sz;
|
743
817
|
}
|
744
818
|
if (!src->data) {
|
745
|
-
|
819
|
+
size_t obj_sz;
|
820
|
+
|
821
|
+
if (git_odb_read(&obj, pb->odb, &src_object->id) < 0 ||
|
822
|
+
!git__is_ulong(obj_sz = git_odb_object_size(obj)))
|
746
823
|
return -1;
|
747
824
|
|
748
|
-
sz =
|
825
|
+
sz = obj_sz;
|
749
826
|
src->data = git__malloc(sz);
|
750
|
-
|
827
|
+
GIT_ERROR_CHECK_ALLOC(src->data);
|
751
828
|
memcpy(src->data, git_odb_object_data(obj), sz);
|
752
829
|
|
753
830
|
git_odb_object_free(obj);
|
754
831
|
|
755
832
|
if (sz != src_size) {
|
756
|
-
|
757
|
-
"
|
833
|
+
git_error_set(GIT_ERROR_INVALID,
|
834
|
+
"inconsistent source object length");
|
758
835
|
return -1;
|
759
836
|
}
|
760
837
|
|
761
838
|
*mem_usage += sz;
|
762
839
|
}
|
763
840
|
if (!src->index) {
|
764
|
-
src->index
|
765
|
-
if (!src->index)
|
841
|
+
if (git_delta_index_init(&src->index, src->data, src_size) < 0)
|
766
842
|
return 0; /* suboptimal pack - out of memory */
|
767
843
|
|
768
|
-
*mem_usage +=
|
844
|
+
*mem_usage += git_delta_index_size(src->index);
|
769
845
|
}
|
770
846
|
|
771
|
-
delta_buf
|
772
|
-
|
773
|
-
if (!delta_buf)
|
847
|
+
if (git_delta_create_from_index(&delta_buf, &delta_size, src->index, trg->data, trg_size,
|
848
|
+
max_size) < 0)
|
774
849
|
return 0;
|
775
850
|
|
776
851
|
if (trg_object->delta) {
|
@@ -785,15 +860,23 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
|
|
785
860
|
git_packbuilder__cache_lock(pb);
|
786
861
|
if (trg_object->delta_data) {
|
787
862
|
git__free(trg_object->delta_data);
|
863
|
+
assert(pb->delta_cache_size >= trg_object->delta_size);
|
788
864
|
pb->delta_cache_size -= trg_object->delta_size;
|
789
865
|
trg_object->delta_data = NULL;
|
790
866
|
}
|
791
867
|
if (delta_cacheable(pb, src_size, trg_size, delta_size)) {
|
792
|
-
|
868
|
+
bool overflow = git__add_sizet_overflow(
|
869
|
+
&pb->delta_cache_size, pb->delta_cache_size, delta_size);
|
870
|
+
|
793
871
|
git_packbuilder__cache_unlock(pb);
|
794
872
|
|
873
|
+
if (overflow) {
|
874
|
+
git__free(delta_buf);
|
875
|
+
return -1;
|
876
|
+
}
|
877
|
+
|
795
878
|
trg_object->delta_data = git__realloc(delta_buf, delta_size);
|
796
|
-
|
879
|
+
GIT_ERROR_CHECK_ALLOC(trg_object->delta_data);
|
797
880
|
} else {
|
798
881
|
/* create delta when writing the pack */
|
799
882
|
git_packbuilder__cache_unlock(pb);
|
@@ -808,13 +891,13 @@ static int try_delta(git_packbuilder *pb, struct unpacked *trg,
|
|
808
891
|
return 0;
|
809
892
|
}
|
810
893
|
|
811
|
-
static
|
894
|
+
static size_t check_delta_limit(git_pobject *me, size_t n)
|
812
895
|
{
|
813
896
|
git_pobject *child = me->delta_child;
|
814
|
-
|
897
|
+
size_t m = n;
|
815
898
|
|
816
899
|
while (child) {
|
817
|
-
|
900
|
+
size_t c = check_delta_limit(child, n + 1);
|
818
901
|
if (m < c)
|
819
902
|
m = c;
|
820
903
|
child = child->delta_sibling;
|
@@ -822,13 +905,18 @@ static unsigned int check_delta_limit(git_pobject *me, unsigned int n)
|
|
822
905
|
return m;
|
823
906
|
}
|
824
907
|
|
825
|
-
static
|
908
|
+
static size_t free_unpacked(struct unpacked *n)
|
826
909
|
{
|
827
|
-
|
828
|
-
|
910
|
+
size_t freed_mem = 0;
|
911
|
+
|
912
|
+
if (n->index) {
|
913
|
+
freed_mem += git_delta_index_size(n->index);
|
914
|
+
git_delta_index_free(n->index);
|
915
|
+
}
|
829
916
|
n->index = NULL;
|
917
|
+
|
830
918
|
if (n->data) {
|
831
|
-
freed_mem +=
|
919
|
+
freed_mem += n->object->size;
|
832
920
|
git__free(n->data);
|
833
921
|
n->data = NULL;
|
834
922
|
}
|
@@ -837,25 +925,47 @@ static unsigned long free_unpacked(struct unpacked *n)
|
|
837
925
|
return freed_mem;
|
838
926
|
}
|
839
927
|
|
928
|
+
static int report_delta_progress(
|
929
|
+
git_packbuilder *pb, uint32_t count, bool force)
|
930
|
+
{
|
931
|
+
int ret;
|
932
|
+
|
933
|
+
if (pb->progress_cb) {
|
934
|
+
double current_time = git__timer();
|
935
|
+
double elapsed = current_time - pb->last_progress_report_time;
|
936
|
+
|
937
|
+
if (force || elapsed >= MIN_PROGRESS_UPDATE_INTERVAL) {
|
938
|
+
pb->last_progress_report_time = current_time;
|
939
|
+
|
940
|
+
ret = pb->progress_cb(
|
941
|
+
GIT_PACKBUILDER_DELTAFICATION,
|
942
|
+
count, pb->nr_objects, pb->progress_cb_payload);
|
943
|
+
|
944
|
+
if (ret)
|
945
|
+
return git_error_set_after_callback(ret);
|
946
|
+
}
|
947
|
+
}
|
948
|
+
|
949
|
+
return 0;
|
950
|
+
}
|
951
|
+
|
840
952
|
static int find_deltas(git_packbuilder *pb, git_pobject **list,
|
841
|
-
|
842
|
-
unsigned int depth)
|
953
|
+
size_t *list_size, size_t window, size_t depth)
|
843
954
|
{
|
844
955
|
git_pobject *po;
|
845
956
|
git_buf zbuf = GIT_BUF_INIT;
|
846
957
|
struct unpacked *array;
|
847
|
-
|
848
|
-
|
849
|
-
|
958
|
+
size_t idx = 0, count = 0;
|
959
|
+
size_t mem_usage = 0;
|
960
|
+
size_t i;
|
850
961
|
int error = -1;
|
851
962
|
|
852
963
|
array = git__calloc(window, sizeof(struct unpacked));
|
853
|
-
|
964
|
+
GIT_ERROR_CHECK_ALLOC(array);
|
854
965
|
|
855
966
|
for (;;) {
|
856
967
|
struct unpacked *n = array + idx;
|
857
|
-
|
858
|
-
int j, best_base = -1;
|
968
|
+
size_t max_depth, j, best_base = SIZE_MAX;
|
859
969
|
|
860
970
|
git_packbuilder__progress_lock(pb);
|
861
971
|
if (!*list_size) {
|
@@ -863,6 +973,9 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
|
|
863
973
|
break;
|
864
974
|
}
|
865
975
|
|
976
|
+
pb->nr_deltified += 1;
|
977
|
+
report_delta_progress(pb, pb->nr_deltified, false);
|
978
|
+
|
866
979
|
po = *list++;
|
867
980
|
(*list_size)--;
|
868
981
|
git_packbuilder__progress_unlock(pb);
|
@@ -873,7 +986,7 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
|
|
873
986
|
while (pb->window_memory_limit &&
|
874
987
|
mem_usage > pb->window_memory_limit &&
|
875
988
|
count > 1) {
|
876
|
-
|
989
|
+
size_t tail = (idx + window - count) % window;
|
877
990
|
mem_usage -= free_unpacked(array + tail);
|
878
991
|
count--;
|
879
992
|
}
|
@@ -885,15 +998,18 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
|
|
885
998
|
*/
|
886
999
|
max_depth = depth;
|
887
1000
|
if (po->delta_child) {
|
888
|
-
|
889
|
-
|
1001
|
+
size_t delta_limit = check_delta_limit(po, 0);
|
1002
|
+
|
1003
|
+
if (delta_limit > max_depth)
|
890
1004
|
goto next;
|
1005
|
+
|
1006
|
+
max_depth -= delta_limit;
|
891
1007
|
}
|
892
1008
|
|
893
1009
|
j = window;
|
894
1010
|
while (--j > 0) {
|
895
1011
|
int ret;
|
896
|
-
|
1012
|
+
size_t other_idx = idx + j;
|
897
1013
|
struct unpacked *m;
|
898
1014
|
|
899
1015
|
if (other_idx >= window)
|
@@ -926,15 +1042,15 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
|
|
926
1042
|
* between writes at that moment.
|
927
1043
|
*/
|
928
1044
|
if (po->delta_data) {
|
929
|
-
if (
|
1045
|
+
if (git_zstream_deflatebuf(&zbuf, po->delta_data, po->delta_size) < 0)
|
930
1046
|
goto on_error;
|
931
1047
|
|
932
1048
|
git__free(po->delta_data);
|
933
1049
|
po->delta_data = git__malloc(zbuf.size);
|
934
|
-
|
1050
|
+
GIT_ERROR_CHECK_ALLOC(po->delta_data);
|
935
1051
|
|
936
1052
|
memcpy(po->delta_data, zbuf.ptr, zbuf.size);
|
937
|
-
po->z_delta_size =
|
1053
|
+
po->z_delta_size = zbuf.size;
|
938
1054
|
git_buf_clear(&zbuf);
|
939
1055
|
|
940
1056
|
git_packbuilder__cache_lock(pb);
|
@@ -958,10 +1074,10 @@ static int find_deltas(git_packbuilder *pb, git_pobject **list,
|
|
958
1074
|
*/
|
959
1075
|
if (po->delta) {
|
960
1076
|
struct unpacked swap = array[best_base];
|
961
|
-
|
962
|
-
|
1077
|
+
size_t dist = (window + idx - best_base) % window;
|
1078
|
+
size_t dst = best_base;
|
963
1079
|
while (dist--) {
|
964
|
-
|
1080
|
+
size_t src = (dst + 1) % window;
|
965
1081
|
array[dst] = array[src];
|
966
1082
|
dst = src;
|
967
1083
|
}
|
@@ -983,7 +1099,7 @@ on_error:
|
|
983
1099
|
git__free(array[i].data);
|
984
1100
|
}
|
985
1101
|
git__free(array);
|
986
|
-
|
1102
|
+
git_buf_dispose(&zbuf);
|
987
1103
|
|
988
1104
|
return error;
|
989
1105
|
}
|
@@ -999,13 +1115,13 @@ struct thread_params {
|
|
999
1115
|
git_cond cond;
|
1000
1116
|
git_mutex mutex;
|
1001
1117
|
|
1002
|
-
|
1003
|
-
|
1118
|
+
size_t list_size;
|
1119
|
+
size_t remaining;
|
1004
1120
|
|
1005
|
-
|
1006
|
-
|
1007
|
-
|
1008
|
-
|
1121
|
+
size_t window;
|
1122
|
+
size_t depth;
|
1123
|
+
size_t working;
|
1124
|
+
size_t data_ready;
|
1009
1125
|
};
|
1010
1126
|
|
1011
1127
|
static void *threaded_find_deltas(void *arg)
|
@@ -1024,7 +1140,7 @@ static void *threaded_find_deltas(void *arg)
|
|
1024
1140
|
git_packbuilder__progress_unlock(me->pb);
|
1025
1141
|
|
1026
1142
|
if (git_mutex_lock(&me->mutex)) {
|
1027
|
-
|
1143
|
+
git_error_set(GIT_ERROR_THREAD, "unable to lock packfile condition mutex");
|
1028
1144
|
return NULL;
|
1029
1145
|
}
|
1030
1146
|
|
@@ -1047,11 +1163,11 @@ static void *threaded_find_deltas(void *arg)
|
|
1047
1163
|
}
|
1048
1164
|
|
1049
1165
|
static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
|
1050
|
-
|
1051
|
-
unsigned int depth)
|
1166
|
+
size_t list_size, size_t window, size_t depth)
|
1052
1167
|
{
|
1053
1168
|
struct thread_params *p;
|
1054
|
-
|
1169
|
+
size_t i;
|
1170
|
+
int ret, active_threads = 0;
|
1055
1171
|
|
1056
1172
|
if (!pb->nr_threads)
|
1057
1173
|
pb->nr_threads = git_online_cpus();
|
@@ -1061,12 +1177,12 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
|
|
1061
1177
|
return 0;
|
1062
1178
|
}
|
1063
1179
|
|
1064
|
-
p =
|
1065
|
-
|
1180
|
+
p = git__mallocarray(pb->nr_threads, sizeof(*p));
|
1181
|
+
GIT_ERROR_CHECK_ALLOC(p);
|
1066
1182
|
|
1067
1183
|
/* Partition the work among the threads */
|
1068
1184
|
for (i = 0; i < pb->nr_threads; ++i) {
|
1069
|
-
|
1185
|
+
size_t sub_size = list_size / (pb->nr_threads - i);
|
1070
1186
|
|
1071
1187
|
/* don't use too small segments or no deltas will be found */
|
1072
1188
|
if (sub_size < 2*window && i+1 < pb->nr_threads)
|
@@ -1100,10 +1216,10 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
|
|
1100
1216
|
git_mutex_init(&p[i].mutex);
|
1101
1217
|
git_cond_init(&p[i].cond);
|
1102
1218
|
|
1103
|
-
ret = git_thread_create(&p[i].thread,
|
1219
|
+
ret = git_thread_create(&p[i].thread,
|
1104
1220
|
threaded_find_deltas, &p[i]);
|
1105
1221
|
if (ret) {
|
1106
|
-
|
1222
|
+
git_error_set(GIT_ERROR_THREAD, "unable to create thread");
|
1107
1223
|
return -1;
|
1108
1224
|
}
|
1109
1225
|
active_threads++;
|
@@ -1120,7 +1236,7 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
|
|
1120
1236
|
while (active_threads) {
|
1121
1237
|
struct thread_params *target = NULL;
|
1122
1238
|
struct thread_params *victim = NULL;
|
1123
|
-
|
1239
|
+
size_t sub_size = 0;
|
1124
1240
|
|
1125
1241
|
/* Start by locating a thread that has transitioned its
|
1126
1242
|
* 'working' flag from 1 -> 0. This indicates that it is
|
@@ -1172,7 +1288,7 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
|
|
1172
1288
|
git_packbuilder__progress_unlock(pb);
|
1173
1289
|
|
1174
1290
|
if (git_mutex_lock(&target->mutex)) {
|
1175
|
-
|
1291
|
+
git_error_set(GIT_ERROR_THREAD, "unable to lock packfile condition mutex");
|
1176
1292
|
git__free(p);
|
1177
1293
|
return -1;
|
1178
1294
|
}
|
@@ -1182,7 +1298,7 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
|
|
1182
1298
|
git_mutex_unlock(&target->mutex);
|
1183
1299
|
|
1184
1300
|
if (!sub_size) {
|
1185
|
-
git_thread_join(target->thread, NULL);
|
1301
|
+
git_thread_join(&target->thread, NULL);
|
1186
1302
|
git_cond_free(&target->cond);
|
1187
1303
|
git_mutex_free(&target->mutex);
|
1188
1304
|
active_threads--;
|
@@ -1200,13 +1316,20 @@ static int ll_find_deltas(git_packbuilder *pb, git_pobject **list,
|
|
1200
1316
|
static int prepare_pack(git_packbuilder *pb)
|
1201
1317
|
{
|
1202
1318
|
git_pobject **delta_list;
|
1203
|
-
|
1319
|
+
size_t i, n = 0;
|
1204
1320
|
|
1205
1321
|
if (pb->nr_objects == 0 || pb->done)
|
1206
1322
|
return 0; /* nothing to do */
|
1207
1323
|
|
1208
|
-
|
1209
|
-
|
1324
|
+
/*
|
1325
|
+
* Although we do not report progress during deltafication, we
|
1326
|
+
* at least report that we are in the deltafication stage
|
1327
|
+
*/
|
1328
|
+
if (pb->progress_cb)
|
1329
|
+
pb->progress_cb(GIT_PACKBUILDER_DELTAFICATION, 0, pb->nr_objects, pb->progress_cb_payload);
|
1330
|
+
|
1331
|
+
delta_list = git__mallocarray(pb->nr_objects, sizeof(*delta_list));
|
1332
|
+
GIT_ERROR_CHECK_ALLOC(delta_list);
|
1210
1333
|
|
1211
1334
|
for (i = 0; i < pb->nr_objects; ++i) {
|
1212
1335
|
git_pobject *po = pb->object_list + i;
|
@@ -1228,6 +1351,8 @@ static int prepare_pack(git_packbuilder *pb)
|
|
1228
1351
|
}
|
1229
1352
|
}
|
1230
1353
|
|
1354
|
+
report_delta_progress(pb, pb->nr_objects, true);
|
1355
|
+
|
1231
1356
|
pb->done = true;
|
1232
1357
|
git__free(delta_list);
|
1233
1358
|
return 0;
|
@@ -1244,61 +1369,80 @@ int git_packbuilder_foreach(git_packbuilder *pb, int (*cb)(void *buf, size_t siz
|
|
1244
1369
|
int git_packbuilder_write_buf(git_buf *buf, git_packbuilder *pb)
|
1245
1370
|
{
|
1246
1371
|
PREPARE_PACK;
|
1372
|
+
git_buf_sanitize(buf);
|
1247
1373
|
return write_pack(pb, &write_pack_buf, buf);
|
1248
1374
|
}
|
1249
1375
|
|
1250
1376
|
static int write_cb(void *buf, size_t len, void *payload)
|
1251
1377
|
{
|
1252
1378
|
struct pack_write_context *ctx = payload;
|
1253
|
-
return
|
1379
|
+
return git_indexer_append(ctx->indexer, buf, len, ctx->stats);
|
1254
1380
|
}
|
1255
1381
|
|
1256
1382
|
int git_packbuilder_write(
|
1257
1383
|
git_packbuilder *pb,
|
1258
1384
|
const char *path,
|
1259
|
-
|
1385
|
+
unsigned int mode,
|
1386
|
+
git_transfer_progress_cb progress_cb,
|
1260
1387
|
void *progress_cb_payload)
|
1261
1388
|
{
|
1262
|
-
|
1389
|
+
git_indexer_options opts = GIT_INDEXER_OPTIONS_INIT;
|
1390
|
+
git_indexer *indexer;
|
1263
1391
|
git_transfer_progress stats;
|
1264
1392
|
struct pack_write_context ctx;
|
1393
|
+
int t;
|
1265
1394
|
|
1266
1395
|
PREPARE_PACK;
|
1267
1396
|
|
1268
|
-
|
1269
|
-
|
1397
|
+
opts.progress_cb = progress_cb;
|
1398
|
+
opts.progress_cb_payload = progress_cb_payload;
|
1399
|
+
|
1400
|
+
if (git_indexer_new(
|
1401
|
+
&indexer, path, mode, pb->odb, &opts) < 0)
|
1270
1402
|
return -1;
|
1271
1403
|
|
1404
|
+
if (!git_repository__cvar(&t, pb->repo, GIT_CVAR_FSYNCOBJECTFILES) && t)
|
1405
|
+
git_indexer__set_fsync(indexer, 1);
|
1406
|
+
|
1272
1407
|
ctx.indexer = indexer;
|
1273
1408
|
ctx.stats = &stats;
|
1274
1409
|
|
1275
1410
|
if (git_packbuilder_foreach(pb, write_cb, &ctx) < 0 ||
|
1276
|
-
|
1277
|
-
|
1411
|
+
git_indexer_commit(indexer, &stats) < 0) {
|
1412
|
+
git_indexer_free(indexer);
|
1278
1413
|
return -1;
|
1279
1414
|
}
|
1280
1415
|
|
1281
|
-
|
1416
|
+
git_oid_cpy(&pb->pack_oid, git_indexer_hash(indexer));
|
1417
|
+
|
1418
|
+
git_indexer_free(indexer);
|
1282
1419
|
return 0;
|
1283
1420
|
}
|
1284
1421
|
|
1285
1422
|
#undef PREPARE_PACK
|
1286
1423
|
|
1287
|
-
|
1424
|
+
const git_oid *git_packbuilder_hash(git_packbuilder *pb)
|
1425
|
+
{
|
1426
|
+
return &pb->pack_oid;
|
1427
|
+
}
|
1428
|
+
|
1429
|
+
|
1430
|
+
static int cb_tree_walk(
|
1431
|
+
const char *root, const git_tree_entry *entry, void *payload)
|
1288
1432
|
{
|
1433
|
+
int error;
|
1289
1434
|
struct tree_walk_context *ctx = payload;
|
1290
1435
|
|
1291
1436
|
/* A commit inside a tree represents a submodule commit and should be skipped. */
|
1292
|
-
if (git_tree_entry_type(entry) ==
|
1437
|
+
if (git_tree_entry_type(entry) == GIT_OBJECT_COMMIT)
|
1293
1438
|
return 0;
|
1294
1439
|
|
1295
|
-
if (git_buf_sets(&ctx->buf, root)
|
1296
|
-
git_buf_puts(&ctx->buf, git_tree_entry_name(entry))
|
1297
|
-
|
1440
|
+
if (!(error = git_buf_sets(&ctx->buf, root)) &&
|
1441
|
+
!(error = git_buf_puts(&ctx->buf, git_tree_entry_name(entry))))
|
1442
|
+
error = git_packbuilder_insert(
|
1443
|
+
ctx->pb, git_tree_entry_id(entry), git_buf_cstr(&ctx->buf));
|
1298
1444
|
|
1299
|
-
return
|
1300
|
-
git_tree_entry_id(entry),
|
1301
|
-
git_buf_cstr(&ctx->buf));
|
1445
|
+
return error;
|
1302
1446
|
}
|
1303
1447
|
|
1304
1448
|
int git_packbuilder_insert_commit(git_packbuilder *pb, const git_oid *oid)
|
@@ -1318,32 +1462,307 @@ int git_packbuilder_insert_commit(git_packbuilder *pb, const git_oid *oid)
|
|
1318
1462
|
|
1319
1463
|
int git_packbuilder_insert_tree(git_packbuilder *pb, const git_oid *oid)
|
1320
1464
|
{
|
1321
|
-
|
1465
|
+
int error;
|
1466
|
+
git_tree *tree = NULL;
|
1322
1467
|
struct tree_walk_context context = { pb, GIT_BUF_INIT };
|
1323
1468
|
|
1324
|
-
if (git_tree_lookup(&tree, pb->repo, oid)
|
1325
|
-
git_packbuilder_insert(pb, oid, NULL)
|
1326
|
-
|
1469
|
+
if (!(error = git_tree_lookup(&tree, pb->repo, oid)) &&
|
1470
|
+
!(error = git_packbuilder_insert(pb, oid, NULL)))
|
1471
|
+
error = git_tree_walk(tree, GIT_TREEWALK_PRE, cb_tree_walk, &context);
|
1472
|
+
|
1473
|
+
git_tree_free(tree);
|
1474
|
+
git_buf_dispose(&context.buf);
|
1475
|
+
return error;
|
1476
|
+
}
|
1477
|
+
|
1478
|
+
int git_packbuilder_insert_recur(git_packbuilder *pb, const git_oid *id, const char *name)
|
1479
|
+
{
|
1480
|
+
git_object *obj;
|
1481
|
+
int error;
|
1482
|
+
|
1483
|
+
assert(pb && id);
|
1484
|
+
|
1485
|
+
if ((error = git_object_lookup(&obj, pb->repo, id, GIT_OBJECT_ANY)) < 0)
|
1486
|
+
return error;
|
1487
|
+
|
1488
|
+
switch (git_object_type(obj)) {
|
1489
|
+
case GIT_OBJECT_BLOB:
|
1490
|
+
error = git_packbuilder_insert(pb, id, name);
|
1491
|
+
break;
|
1492
|
+
case GIT_OBJECT_TREE:
|
1493
|
+
error = git_packbuilder_insert_tree(pb, id);
|
1494
|
+
break;
|
1495
|
+
case GIT_OBJECT_COMMIT:
|
1496
|
+
error = git_packbuilder_insert_commit(pb, id);
|
1497
|
+
break;
|
1498
|
+
case GIT_OBJECT_TAG:
|
1499
|
+
if ((error = git_packbuilder_insert(pb, id, name)) < 0)
|
1500
|
+
goto cleanup;
|
1501
|
+
error = git_packbuilder_insert_recur(pb, git_tag_target_id((git_tag *) obj), NULL);
|
1502
|
+
break;
|
1503
|
+
|
1504
|
+
default:
|
1505
|
+
git_error_set(GIT_ERROR_INVALID, "unknown object type");
|
1506
|
+
error = -1;
|
1507
|
+
}
|
1508
|
+
|
1509
|
+
cleanup:
|
1510
|
+
git_object_free(obj);
|
1511
|
+
return error;
|
1512
|
+
}
|
1513
|
+
|
1514
|
+
size_t git_packbuilder_object_count(git_packbuilder *pb)
|
1515
|
+
{
|
1516
|
+
return pb->nr_objects;
|
1517
|
+
}
|
1518
|
+
|
1519
|
+
size_t git_packbuilder_written(git_packbuilder *pb)
|
1520
|
+
{
|
1521
|
+
return pb->nr_written;
|
1522
|
+
}
|
1523
|
+
|
1524
|
+
static int lookup_walk_object(struct walk_object **out, git_packbuilder *pb, const git_oid *id)
|
1525
|
+
{
|
1526
|
+
struct walk_object *obj;
|
1327
1527
|
|
1328
|
-
|
1329
|
-
|
1330
|
-
|
1528
|
+
obj = git_pool_mallocz(&pb->object_pool, 1);
|
1529
|
+
if (!obj) {
|
1530
|
+
git_error_set_oom();
|
1331
1531
|
return -1;
|
1332
1532
|
}
|
1333
1533
|
|
1534
|
+
git_oid_cpy(&obj->id, id);
|
1535
|
+
|
1536
|
+
*out = obj;
|
1537
|
+
return 0;
|
1538
|
+
}
|
1539
|
+
|
1540
|
+
static int retrieve_object(struct walk_object **out, git_packbuilder *pb, const git_oid *id)
|
1541
|
+
{
|
1542
|
+
int error;
|
1543
|
+
size_t pos;
|
1544
|
+
struct walk_object *obj;
|
1545
|
+
|
1546
|
+
pos = git_oidmap_lookup_index(pb->walk_objects, id);
|
1547
|
+
if (git_oidmap_valid_index(pb->walk_objects, pos)) {
|
1548
|
+
obj = git_oidmap_value_at(pb->walk_objects, pos);
|
1549
|
+
} else {
|
1550
|
+
if ((error = lookup_walk_object(&obj, pb, id)) < 0)
|
1551
|
+
return error;
|
1552
|
+
|
1553
|
+
git_oidmap_insert(pb->walk_objects, &obj->id, obj, &error);
|
1554
|
+
}
|
1555
|
+
|
1556
|
+
*out = obj;
|
1557
|
+
return 0;
|
1558
|
+
}
|
1559
|
+
|
1560
|
+
static int mark_blob_uninteresting(git_packbuilder *pb, const git_oid *id)
|
1561
|
+
{
|
1562
|
+
int error;
|
1563
|
+
struct walk_object *obj;
|
1564
|
+
|
1565
|
+
if ((error = retrieve_object(&obj, pb, id)) < 0)
|
1566
|
+
return error;
|
1567
|
+
|
1568
|
+
obj->uninteresting = 1;
|
1569
|
+
|
1570
|
+
return 0;
|
1571
|
+
}
|
1572
|
+
|
1573
|
+
static int mark_tree_uninteresting(git_packbuilder *pb, const git_oid *id)
|
1574
|
+
{
|
1575
|
+
struct walk_object *obj;
|
1576
|
+
git_tree *tree;
|
1577
|
+
int error;
|
1578
|
+
size_t i;
|
1579
|
+
|
1580
|
+
if ((error = retrieve_object(&obj, pb, id)) < 0)
|
1581
|
+
return error;
|
1582
|
+
|
1583
|
+
if (obj->uninteresting)
|
1584
|
+
return 0;
|
1585
|
+
|
1586
|
+
obj->uninteresting = 1;
|
1587
|
+
|
1588
|
+
if ((error = git_tree_lookup(&tree, pb->repo, id)) < 0)
|
1589
|
+
return error;
|
1590
|
+
|
1591
|
+
for (i = 0; i < git_tree_entrycount(tree); i++) {
|
1592
|
+
const git_tree_entry *entry = git_tree_entry_byindex(tree, i);
|
1593
|
+
const git_oid *entry_id = git_tree_entry_id(entry);
|
1594
|
+
switch (git_tree_entry_type(entry)) {
|
1595
|
+
case GIT_OBJECT_TREE:
|
1596
|
+
if ((error = mark_tree_uninteresting(pb, entry_id)) < 0)
|
1597
|
+
goto cleanup;
|
1598
|
+
break;
|
1599
|
+
case GIT_OBJECT_BLOB:
|
1600
|
+
if ((error = mark_blob_uninteresting(pb, entry_id)) < 0)
|
1601
|
+
goto cleanup;
|
1602
|
+
break;
|
1603
|
+
default:
|
1604
|
+
/* it's a submodule or something unknown, we don't want it */
|
1605
|
+
;
|
1606
|
+
}
|
1607
|
+
}
|
1608
|
+
|
1609
|
+
cleanup:
|
1334
1610
|
git_tree_free(tree);
|
1335
|
-
|
1611
|
+
return error;
|
1612
|
+
}
|
1613
|
+
|
1614
|
+
/*
|
1615
|
+
* Mark the edges of the graph uninteresting. Since we start from a
|
1616
|
+
* git_revwalk, the commits are already uninteresting, but we need to
|
1617
|
+
* mark the trees and blobs.
|
1618
|
+
*/
|
1619
|
+
static int mark_edges_uninteresting(git_packbuilder *pb, git_commit_list *commits)
|
1620
|
+
{
|
1621
|
+
int error;
|
1622
|
+
git_commit_list *list;
|
1623
|
+
git_commit *commit;
|
1624
|
+
|
1625
|
+
for (list = commits; list; list = list->next) {
|
1626
|
+
if (!list->item->uninteresting)
|
1627
|
+
continue;
|
1628
|
+
|
1629
|
+
if ((error = git_commit_lookup(&commit, pb->repo, &list->item->oid)) < 0)
|
1630
|
+
return error;
|
1631
|
+
|
1632
|
+
error = mark_tree_uninteresting(pb, git_commit_tree_id(commit));
|
1633
|
+
git_commit_free(commit);
|
1634
|
+
|
1635
|
+
if (error < 0)
|
1636
|
+
return error;
|
1637
|
+
}
|
1638
|
+
|
1336
1639
|
return 0;
|
1337
1640
|
}
|
1338
1641
|
|
1339
|
-
|
1642
|
+
int insert_tree(git_packbuilder *pb, git_tree *tree)
|
1340
1643
|
{
|
1341
|
-
|
1644
|
+
size_t i;
|
1645
|
+
int error;
|
1646
|
+
git_tree *subtree;
|
1647
|
+
struct walk_object *obj;
|
1648
|
+
const char *name;
|
1649
|
+
|
1650
|
+
if ((error = retrieve_object(&obj, pb, git_tree_id(tree))) < 0)
|
1651
|
+
return error;
|
1652
|
+
|
1653
|
+
if (obj->seen || obj->uninteresting)
|
1654
|
+
return 0;
|
1655
|
+
|
1656
|
+
obj->seen = 1;
|
1657
|
+
|
1658
|
+
if ((error = git_packbuilder_insert(pb, &obj->id, NULL)))
|
1659
|
+
return error;
|
1660
|
+
|
1661
|
+
for (i = 0; i < git_tree_entrycount(tree); i++) {
|
1662
|
+
const git_tree_entry *entry = git_tree_entry_byindex(tree, i);
|
1663
|
+
const git_oid *entry_id = git_tree_entry_id(entry);
|
1664
|
+
switch (git_tree_entry_type(entry)) {
|
1665
|
+
case GIT_OBJECT_TREE:
|
1666
|
+
if ((error = git_tree_lookup(&subtree, pb->repo, entry_id)) < 0)
|
1667
|
+
return error;
|
1668
|
+
|
1669
|
+
error = insert_tree(pb, subtree);
|
1670
|
+
git_tree_free(subtree);
|
1671
|
+
|
1672
|
+
if (error < 0)
|
1673
|
+
return error;
|
1674
|
+
|
1675
|
+
break;
|
1676
|
+
case GIT_OBJECT_BLOB:
|
1677
|
+
if ((error = retrieve_object(&obj, pb, entry_id)) < 0)
|
1678
|
+
return error;
|
1679
|
+
if (obj->uninteresting)
|
1680
|
+
continue;
|
1681
|
+
name = git_tree_entry_name(entry);
|
1682
|
+
if ((error = git_packbuilder_insert(pb, entry_id, name)) < 0)
|
1683
|
+
return error;
|
1684
|
+
break;
|
1685
|
+
default:
|
1686
|
+
/* it's a submodule or something unknown, we don't want it */
|
1687
|
+
;
|
1688
|
+
}
|
1689
|
+
}
|
1690
|
+
|
1691
|
+
|
1692
|
+
return error;
|
1342
1693
|
}
|
1343
1694
|
|
1344
|
-
|
1695
|
+
int insert_commit(git_packbuilder *pb, struct walk_object *obj)
|
1345
1696
|
{
|
1346
|
-
|
1697
|
+
int error;
|
1698
|
+
git_commit *commit = NULL;
|
1699
|
+
git_tree *tree = NULL;
|
1700
|
+
|
1701
|
+
obj->seen = 1;
|
1702
|
+
|
1703
|
+
if ((error = git_packbuilder_insert(pb, &obj->id, NULL)) < 0)
|
1704
|
+
return error;
|
1705
|
+
|
1706
|
+
if ((error = git_commit_lookup(&commit, pb->repo, &obj->id)) < 0)
|
1707
|
+
return error;
|
1708
|
+
|
1709
|
+
if ((error = git_tree_lookup(&tree, pb->repo, git_commit_tree_id(commit))) < 0)
|
1710
|
+
goto cleanup;
|
1711
|
+
|
1712
|
+
if ((error = insert_tree(pb, tree)) < 0)
|
1713
|
+
goto cleanup;
|
1714
|
+
|
1715
|
+
cleanup:
|
1716
|
+
git_commit_free(commit);
|
1717
|
+
git_tree_free(tree);
|
1718
|
+
return error;
|
1719
|
+
}
|
1720
|
+
|
1721
|
+
int git_packbuilder_insert_walk(git_packbuilder *pb, git_revwalk *walk)
|
1722
|
+
{
|
1723
|
+
int error;
|
1724
|
+
git_oid id;
|
1725
|
+
struct walk_object *obj;
|
1726
|
+
|
1727
|
+
assert(pb && walk);
|
1728
|
+
|
1729
|
+
if ((error = mark_edges_uninteresting(pb, walk->user_input)) < 0)
|
1730
|
+
return error;
|
1731
|
+
|
1732
|
+
/*
|
1733
|
+
* TODO: git marks the parents of the edges
|
1734
|
+
* uninteresting. This may provide a speed advantage, but does
|
1735
|
+
* seem to assume the remote does not have a single-commit
|
1736
|
+
* history on the other end.
|
1737
|
+
*/
|
1738
|
+
|
1739
|
+
/* walk down each tree up to the blobs and insert them, stopping when uninteresting */
|
1740
|
+
while ((error = git_revwalk_next(&id, walk)) == 0) {
|
1741
|
+
if ((error = retrieve_object(&obj, pb, &id)) < 0)
|
1742
|
+
return error;
|
1743
|
+
|
1744
|
+
if (obj->seen || obj->uninteresting)
|
1745
|
+
continue;
|
1746
|
+
|
1747
|
+
if ((error = insert_commit(pb, obj)) < 0)
|
1748
|
+
return error;
|
1749
|
+
}
|
1750
|
+
|
1751
|
+
if (error == GIT_ITEROVER)
|
1752
|
+
error = 0;
|
1753
|
+
|
1754
|
+
return error;
|
1755
|
+
}
|
1756
|
+
|
1757
|
+
int git_packbuilder_set_callbacks(git_packbuilder *pb, git_packbuilder_progress progress_cb, void *progress_cb_payload)
|
1758
|
+
{
|
1759
|
+
if (!pb)
|
1760
|
+
return -1;
|
1761
|
+
|
1762
|
+
pb->progress_cb = progress_cb;
|
1763
|
+
pb->progress_cb_payload = progress_cb_payload;
|
1764
|
+
|
1765
|
+
return 0;
|
1347
1766
|
}
|
1348
1767
|
|
1349
1768
|
void git_packbuilder_free(git_packbuilder *pb)
|
@@ -1368,7 +1787,11 @@ void git_packbuilder_free(git_packbuilder *pb)
|
|
1368
1787
|
if (pb->object_list)
|
1369
1788
|
git__free(pb->object_list);
|
1370
1789
|
|
1790
|
+
git_oidmap_free(pb->walk_objects);
|
1791
|
+
git_pool_clear(&pb->object_pool);
|
1792
|
+
|
1371
1793
|
git_hash_ctx_cleanup(&pb->ctx);
|
1794
|
+
git_zstream_free(&pb->zstream);
|
1372
1795
|
|
1373
1796
|
git__free(pb);
|
1374
1797
|
}
|