rugged 1.3.2 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +34 -2
- data/ext/rugged/extconf.rb +7 -4
- data/ext/rugged/rugged.c +16 -0
- data/ext/rugged/rugged.h +4 -0
- data/ext/rugged/rugged_blame.c +2 -0
- data/ext/rugged/rugged_blob.c +3 -0
- data/ext/rugged/rugged_commit.c +1 -0
- data/ext/rugged/rugged_config.c +9 -2
- data/ext/rugged/rugged_diff.c +1 -0
- data/ext/rugged/rugged_index.c +2 -0
- data/ext/rugged/rugged_patch.c +1 -0
- data/ext/rugged/rugged_rebase.c +1 -0
- data/ext/rugged/rugged_reference.c +1 -0
- data/ext/rugged/rugged_remote.c +28 -10
- data/ext/rugged/rugged_repo.c +7 -9
- data/ext/rugged/rugged_revwalk.c +5 -1
- data/ext/rugged/rugged_settings.c +5 -0
- data/ext/rugged/rugged_submodule.c +1 -0
- data/ext/rugged/rugged_tag.c +1 -0
- data/ext/rugged/rugged_tree.c +4 -0
- data/lib/rugged/index.rb +1 -1
- data/lib/rugged/tree.rb +5 -1
- data/lib/rugged/version.rb +1 -1
- data/vendor/libgit2/CMakeLists.txt +132 -288
- data/vendor/libgit2/COPYING +106 -19
- data/vendor/libgit2/cmake/AddCFlagIfSupported.cmake +21 -21
- data/vendor/libgit2/cmake/AddClarTest.cmake +7 -0
- data/vendor/libgit2/cmake/DefaultCFlags.cmake +154 -0
- data/vendor/libgit2/cmake/EnableWarnings.cmake +13 -13
- data/vendor/libgit2/cmake/ExperimentalFeatures.cmake +23 -0
- data/vendor/libgit2/cmake/FindCoreFoundation.cmake +13 -13
- data/vendor/libgit2/cmake/FindGSSAPI.cmake +171 -287
- data/vendor/libgit2/cmake/FindGSSFramework.cmake +13 -13
- data/vendor/libgit2/cmake/{FindHTTP_Parser.cmake → FindHTTPParser.cmake} +17 -17
- data/vendor/libgit2/cmake/FindIconv.cmake +27 -27
- data/vendor/libgit2/cmake/FindLibSSH2.cmake +5 -5
- data/vendor/libgit2/cmake/FindPCRE.cmake +12 -13
- data/vendor/libgit2/cmake/FindPCRE2.cmake +12 -12
- data/vendor/libgit2/cmake/FindPkgLibraries.cmake +19 -19
- data/vendor/libgit2/cmake/FindSecurity.cmake +14 -14
- data/vendor/libgit2/cmake/FindStatNsec.cmake +12 -18
- data/vendor/libgit2/cmake/Findfutimens.cmake +8 -8
- data/vendor/libgit2/cmake/FindmbedTLS.cmake +63 -70
- data/vendor/libgit2/cmake/IdeSplitSources.cmake +18 -18
- data/vendor/libgit2/cmake/PkgBuildConfig.cmake +60 -60
- data/vendor/libgit2/cmake/SanitizeBool.cmake +20 -20
- data/vendor/libgit2/cmake/SelectGSSAPI.cmake +37 -37
- data/vendor/libgit2/cmake/SelectHTTPParser.cmake +19 -0
- data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +100 -100
- data/vendor/libgit2/cmake/SelectHashes.cmake +91 -53
- data/vendor/libgit2/cmake/SelectRegex.cmake +51 -0
- data/vendor/libgit2/cmake/SelectSSH.cmake +41 -0
- data/vendor/libgit2/cmake/SelectWinHTTP.cmake +17 -0
- data/vendor/libgit2/cmake/SelectZlib.cmake +34 -0
- data/vendor/libgit2/deps/chromium-zlib/CMakeLists.txt +6 -6
- data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +33 -31
- data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +3 -1
- data/vendor/libgit2/deps/ntlmclient/ntlm.c +4 -4
- data/vendor/libgit2/deps/ntlmclient/ntlm.h +4 -4
- data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +2 -2
- data/vendor/libgit2/deps/pcre/CMakeLists.txt +88 -88
- data/vendor/libgit2/deps/winhttp/CMakeLists.txt +14 -16
- data/vendor/libgit2/deps/zlib/adler32.c +7 -0
- data/vendor/libgit2/deps/zlib/crc32.c +975 -288
- data/vendor/libgit2/deps/zlib/crc32.h +9441 -436
- data/vendor/libgit2/deps/zlib/deflate.c +83 -31
- data/vendor/libgit2/deps/zlib/deflate.h +12 -15
- data/vendor/libgit2/deps/zlib/gzguts.h +3 -2
- data/vendor/libgit2/deps/zlib/infback.c +2 -1
- data/vendor/libgit2/deps/zlib/inffast.c +14 -14
- data/vendor/libgit2/deps/zlib/inflate.c +39 -8
- data/vendor/libgit2/deps/zlib/inflate.h +3 -2
- data/vendor/libgit2/deps/zlib/inftrees.c +3 -3
- data/vendor/libgit2/deps/zlib/trees.c +27 -48
- data/vendor/libgit2/deps/zlib/zlib.h +126 -100
- data/vendor/libgit2/deps/zlib/zutil.c +2 -2
- data/vendor/libgit2/deps/zlib/zutil.h +12 -9
- data/vendor/libgit2/include/git2/apply.h +16 -2
- data/vendor/libgit2/include/git2/attr.h +11 -2
- data/vendor/libgit2/include/git2/blame.h +4 -1
- data/vendor/libgit2/include/git2/blob.h +14 -1
- data/vendor/libgit2/include/git2/branch.h +4 -2
- data/vendor/libgit2/include/git2/buffer.h +18 -78
- data/vendor/libgit2/include/git2/cert.h +2 -2
- data/vendor/libgit2/include/git2/checkout.h +5 -2
- data/vendor/libgit2/include/git2/clone.h +3 -3
- data/vendor/libgit2/include/git2/commit.h +2 -0
- data/vendor/libgit2/include/git2/common.h +28 -7
- data/vendor/libgit2/include/git2/config.h +25 -9
- data/vendor/libgit2/include/git2/credential.h +2 -1
- data/vendor/libgit2/include/git2/credential_helpers.h +1 -0
- data/vendor/libgit2/include/git2/deprecated.h +9 -1
- data/vendor/libgit2/include/git2/describe.h +7 -2
- data/vendor/libgit2/include/git2/diff.h +18 -10
- data/vendor/libgit2/include/git2/email.h +1 -1
- data/vendor/libgit2/include/git2/errors.h +17 -3
- data/vendor/libgit2/include/git2/experimental.h +20 -0
- data/vendor/libgit2/include/git2/filter.h +7 -2
- data/vendor/libgit2/include/git2/graph.h +1 -0
- data/vendor/libgit2/include/git2/ignore.h +1 -1
- data/vendor/libgit2/include/git2/index.h +11 -5
- data/vendor/libgit2/include/git2/indexer.h +48 -0
- data/vendor/libgit2/include/git2/merge.h +24 -4
- data/vendor/libgit2/include/git2/message.h +2 -0
- data/vendor/libgit2/include/git2/object.h +49 -0
- data/vendor/libgit2/include/git2/odb.h +94 -13
- data/vendor/libgit2/include/git2/odb_backend.h +107 -19
- data/vendor/libgit2/include/git2/oid.h +115 -15
- data/vendor/libgit2/include/git2/pack.h +24 -8
- data/vendor/libgit2/include/git2/patch.h +8 -0
- data/vendor/libgit2/include/git2/pathspec.h +1 -1
- data/vendor/libgit2/include/git2/proxy.h +1 -1
- data/vendor/libgit2/include/git2/rebase.h +9 -1
- data/vendor/libgit2/include/git2/refdb.h +3 -0
- data/vendor/libgit2/include/git2/reflog.h +1 -1
- data/vendor/libgit2/include/git2/refs.h +2 -2
- data/vendor/libgit2/include/git2/remote.h +184 -37
- data/vendor/libgit2/include/git2/repository.h +34 -10
- data/vendor/libgit2/include/git2/reset.h +2 -2
- data/vendor/libgit2/include/git2/revparse.h +1 -1
- data/vendor/libgit2/include/git2/revwalk.h +4 -1
- data/vendor/libgit2/include/git2/signature.h +1 -1
- data/vendor/libgit2/include/git2/stash.h +61 -7
- data/vendor/libgit2/include/git2/status.h +14 -5
- data/vendor/libgit2/include/git2/strarray.h +0 -13
- data/vendor/libgit2/include/git2/submodule.h +7 -2
- data/vendor/libgit2/include/git2/sys/commit_graph.h +1 -1
- data/vendor/libgit2/include/git2/sys/odb_backend.h +3 -6
- data/vendor/libgit2/include/git2/sys/remote.h +46 -0
- data/vendor/libgit2/include/git2/sys/stream.h +1 -1
- data/vendor/libgit2/include/git2/sys/transport.h +46 -39
- data/vendor/libgit2/include/git2/tag.h +1 -0
- data/vendor/libgit2/include/git2/tree.h +4 -3
- data/vendor/libgit2/include/git2/types.h +7 -7
- data/vendor/libgit2/include/git2/version.h +27 -6
- data/vendor/libgit2/include/git2/worktree.h +12 -2
- data/vendor/libgit2/include/git2.h +1 -0
- data/vendor/libgit2/src/CMakeLists.txt +177 -419
- data/vendor/libgit2/src/README.md +12 -0
- data/vendor/libgit2/src/cli/CMakeLists.txt +57 -0
- data/vendor/libgit2/src/cli/README.md +26 -0
- data/vendor/libgit2/src/cli/cli.h +20 -0
- data/vendor/libgit2/src/cli/cmd.c +21 -0
- data/vendor/libgit2/src/cli/cmd.h +33 -0
- data/vendor/libgit2/src/cli/cmd_cat_file.c +204 -0
- data/vendor/libgit2/src/cli/cmd_clone.c +176 -0
- data/vendor/libgit2/src/cli/cmd_hash_object.c +154 -0
- data/vendor/libgit2/src/cli/cmd_help.c +86 -0
- data/vendor/libgit2/src/cli/error.h +51 -0
- data/vendor/libgit2/src/cli/main.c +106 -0
- data/vendor/libgit2/src/cli/opt.c +669 -0
- data/vendor/libgit2/src/cli/opt.h +349 -0
- data/vendor/libgit2/src/cli/opt_usage.c +194 -0
- data/vendor/libgit2/src/cli/opt_usage.h +35 -0
- data/vendor/libgit2/src/cli/progress.c +345 -0
- data/vendor/libgit2/src/cli/progress.h +117 -0
- data/vendor/libgit2/src/cli/sighandler.h +20 -0
- data/vendor/libgit2/src/cli/unix/sighandler.c +36 -0
- data/vendor/libgit2/src/cli/win32/precompiled.h +3 -0
- data/vendor/libgit2/src/cli/win32/sighandler.c +37 -0
- data/vendor/libgit2/src/libgit2/CMakeLists.txt +141 -0
- data/vendor/libgit2/src/{annotated_commit.c → libgit2/annotated_commit.c} +1 -1
- data/vendor/libgit2/src/{annotated_commit.h → libgit2/annotated_commit.h} +2 -2
- data/vendor/libgit2/src/{apply.c → libgit2/apply.c} +18 -18
- data/vendor/libgit2/src/{apply.h → libgit2/apply.h} +2 -2
- data/vendor/libgit2/src/{attr.c → libgit2/attr.c} +18 -18
- data/vendor/libgit2/src/{attr_file.c → libgit2/attr_file.c} +18 -18
- data/vendor/libgit2/src/{attr_file.h → libgit2/attr_file.h} +4 -4
- data/vendor/libgit2/src/{attrcache.c → libgit2/attrcache.c} +18 -13
- data/vendor/libgit2/src/{blame.c → libgit2/blame.c} +2 -0
- data/vendor/libgit2/src/{blame_git.c → libgit2/blame_git.c} +1 -1
- data/vendor/libgit2/src/{blob.c → libgit2/blob.c} +38 -29
- data/vendor/libgit2/src/{blob.h → libgit2/blob.h} +3 -3
- data/vendor/libgit2/src/{branch.c → libgit2/branch.c} +164 -118
- data/vendor/libgit2/src/{branch.h → libgit2/branch.h} +15 -3
- data/vendor/libgit2/src/libgit2/buf.c +126 -0
- data/vendor/libgit2/src/libgit2/buf.h +50 -0
- data/vendor/libgit2/src/{checkout.c → libgit2/checkout.c} +74 -68
- data/vendor/libgit2/src/{cherrypick.c → libgit2/cherrypick.c} +13 -13
- data/vendor/libgit2/src/{clone.c → libgit2/clone.c} +96 -67
- data/vendor/libgit2/src/{commit.c → libgit2/commit.c} +178 -73
- data/vendor/libgit2/src/libgit2/commit.h +87 -0
- data/vendor/libgit2/src/{commit_graph.c → libgit2/commit_graph.c} +122 -89
- data/vendor/libgit2/src/{commit_graph.h → libgit2/commit_graph.h} +14 -4
- data/vendor/libgit2/src/{commit_list.c → libgit2/commit_list.c} +7 -4
- data/vendor/libgit2/src/libgit2/common.h +55 -0
- data/vendor/libgit2/src/{config.c → libgit2/config.c} +101 -69
- data/vendor/libgit2/src/{config.h → libgit2/config.h} +15 -2
- data/vendor/libgit2/src/{config_file.c → libgit2/config_file.c} +105 -93
- data/vendor/libgit2/src/{config_mem.c → libgit2/config_mem.c} +9 -9
- data/vendor/libgit2/src/{config_parse.c → libgit2/config_parse.c} +27 -23
- data/vendor/libgit2/src/{crlf.c → libgit2/crlf.c} +24 -21
- data/vendor/libgit2/src/{describe.c → libgit2/describe.c} +35 -27
- data/vendor/libgit2/src/{diff.c → libgit2/diff.c} +30 -9
- data/vendor/libgit2/src/{diff.h → libgit2/diff.h} +2 -4
- data/vendor/libgit2/src/{diff_driver.c → libgit2/diff_driver.c} +34 -36
- data/vendor/libgit2/src/{diff_driver.h → libgit2/diff_driver.h} +3 -3
- data/vendor/libgit2/src/{diff_file.c → libgit2/diff_file.c} +44 -26
- data/vendor/libgit2/src/{diff_generate.c → libgit2/diff_generate.c} +47 -18
- data/vendor/libgit2/src/{diff_generate.h → libgit2/diff_generate.h} +5 -3
- data/vendor/libgit2/src/{diff_print.c → libgit2/diff_print.c} +112 -100
- data/vendor/libgit2/src/{diff_stats.c → libgit2/diff_stats.c} +40 -29
- data/vendor/libgit2/src/libgit2/diff_stats.h +18 -0
- data/vendor/libgit2/src/{diff_tform.c → libgit2/diff_tform.c} +13 -8
- data/vendor/libgit2/src/{diff_xdiff.c → libgit2/diff_xdiff.c} +4 -8
- data/vendor/libgit2/src/{email.c → libgit2/email.c} +55 -39
- data/vendor/libgit2/src/{email.h → libgit2/email.h} +1 -1
- data/vendor/libgit2/src/{errors.c → libgit2/errors.c} +18 -18
- data/vendor/libgit2/src/{errors.h → libgit2/errors.h} +1 -2
- data/vendor/libgit2/src/libgit2/experimental.h.in +13 -0
- data/vendor/libgit2/src/{fetch.c → libgit2/fetch.c} +72 -27
- data/vendor/libgit2/src/{fetch.h → libgit2/fetch.h} +1 -1
- data/vendor/libgit2/src/{fetchhead.c → libgit2/fetchhead.c} +23 -23
- data/vendor/libgit2/src/{filter.c → libgit2/filter.c} +127 -53
- data/vendor/libgit2/src/{filter.h → libgit2/filter.h} +26 -5
- data/vendor/libgit2/src/{ident.c → libgit2/ident.c} +20 -20
- data/vendor/libgit2/src/{ignore.c → libgit2/ignore.c} +35 -34
- data/vendor/libgit2/src/{ignore.h → libgit2/ignore.h} +2 -2
- data/vendor/libgit2/src/{index.c → libgit2/index.c} +91 -90
- data/vendor/libgit2/src/{index.h → libgit2/index.h} +6 -3
- data/vendor/libgit2/src/{indexer.c → libgit2/indexer.c} +173 -92
- data/vendor/libgit2/src/{iterator.c → libgit2/iterator.c} +71 -61
- data/vendor/libgit2/src/{iterator.h → libgit2/iterator.h} +5 -5
- data/vendor/libgit2/src/{libgit2.c → libgit2/libgit2.c} +46 -11
- data/vendor/libgit2/src/{mailmap.c → libgit2/mailmap.c} +38 -36
- data/vendor/libgit2/src/{merge.c → libgit2/merge.c} +30 -30
- data/vendor/libgit2/src/{merge.h → libgit2/merge.h} +1 -14
- data/vendor/libgit2/src/{merge_driver.c → libgit2/merge_driver.c} +2 -2
- data/vendor/libgit2/src/{merge_file.c → libgit2/merge_file.c} +13 -3
- data/vendor/libgit2/src/{message.c → libgit2/message.c} +21 -10
- data/vendor/libgit2/src/{midx.c → libgit2/midx.c} +112 -92
- data/vendor/libgit2/src/{midx.h → libgit2/midx.h} +5 -4
- data/vendor/libgit2/src/{mwindow.c → libgit2/mwindow.c} +15 -12
- data/vendor/libgit2/src/{mwindow.h → libgit2/mwindow.h} +5 -2
- data/vendor/libgit2/src/{netops.c → libgit2/netops.c} +1 -2
- data/vendor/libgit2/src/{netops.h → libgit2/netops.h} +1 -1
- data/vendor/libgit2/src/{notes.c → libgit2/notes.c} +25 -34
- data/vendor/libgit2/src/{object.c → libgit2/object.c} +135 -30
- data/vendor/libgit2/src/{object.h → libgit2/object.h} +12 -3
- data/vendor/libgit2/src/{odb.c → libgit2/odb.c} +228 -81
- data/vendor/libgit2/src/{odb.h → libgit2/odb.h} +44 -5
- data/vendor/libgit2/src/{odb_loose.c → libgit2/odb_loose.c} +192 -134
- data/vendor/libgit2/src/{odb_mempack.c → libgit2/odb_mempack.c} +18 -5
- data/vendor/libgit2/src/{odb_pack.c → libgit2/odb_pack.c} +137 -85
- data/vendor/libgit2/src/{oid.c → libgit2/oid.c} +136 -90
- data/vendor/libgit2/src/libgit2/oid.h +273 -0
- data/vendor/libgit2/src/{oidmap.c → libgit2/oidmap.c} +1 -1
- data/vendor/libgit2/src/{pack-objects.c → libgit2/pack-objects.c} +56 -30
- data/vendor/libgit2/src/{pack-objects.h → libgit2/pack-objects.h} +11 -6
- data/vendor/libgit2/src/{pack.c → libgit2/pack.c} +114 -84
- data/vendor/libgit2/src/{pack.h → libgit2/pack.h} +31 -16
- data/vendor/libgit2/src/{parse.c → libgit2/parse.c} +4 -3
- data/vendor/libgit2/src/{patch.c → libgit2/patch.c} +3 -3
- data/vendor/libgit2/src/{patch.h → libgit2/patch.h} +1 -0
- data/vendor/libgit2/src/{patch_generate.c → libgit2/patch_generate.c} +27 -11
- data/vendor/libgit2/src/{patch_generate.h → libgit2/patch_generate.h} +5 -5
- data/vendor/libgit2/src/{patch_parse.c → libgit2/patch_parse.c} +29 -29
- data/vendor/libgit2/src/libgit2/path.c +375 -0
- data/vendor/libgit2/src/libgit2/path.h +68 -0
- data/vendor/libgit2/src/{pathspec.c → libgit2/pathspec.c} +6 -6
- data/vendor/libgit2/src/{pathspec.h → libgit2/pathspec.h} +2 -2
- data/vendor/libgit2/src/{proxy.c → libgit2/proxy.c} +4 -1
- data/vendor/libgit2/src/{proxy.h → libgit2/proxy.h} +1 -1
- data/vendor/libgit2/src/{push.c → libgit2/push.c} +43 -38
- data/vendor/libgit2/src/{push.h → libgit2/push.h} +4 -16
- data/vendor/libgit2/src/{reader.c → libgit2/reader.c} +9 -9
- data/vendor/libgit2/src/{reader.h → libgit2/reader.h} +2 -2
- data/vendor/libgit2/src/{rebase.c → libgit2/rebase.c} +119 -107
- data/vendor/libgit2/src/{refdb_fs.c → libgit2/refdb_fs.c} +506 -197
- data/vendor/libgit2/src/{reflog.c → libgit2/reflog.c} +7 -5
- data/vendor/libgit2/src/{reflog.h → libgit2/reflog.h} +1 -2
- data/vendor/libgit2/src/{refs.c → libgit2/refs.c} +34 -32
- data/vendor/libgit2/src/{refs.h → libgit2/refs.h} +2 -2
- data/vendor/libgit2/src/{refspec.c → libgit2/refspec.c} +32 -37
- data/vendor/libgit2/src/{refspec.h → libgit2/refspec.h} +5 -2
- data/vendor/libgit2/src/{remote.c → libgit2/remote.c} +718 -420
- data/vendor/libgit2/src/libgit2/remote.h +100 -0
- data/vendor/libgit2/src/{repository.c → libgit2/repository.c} +629 -386
- data/vendor/libgit2/src/{repository.h → libgit2/repository.h} +20 -9
- data/vendor/libgit2/src/{reset.c → libgit2/reset.c} +8 -5
- data/vendor/libgit2/src/{revert.c → libgit2/revert.c} +14 -14
- data/vendor/libgit2/src/{revparse.c → libgit2/revparse.c} +71 -42
- data/vendor/libgit2/src/{revwalk.c → libgit2/revwalk.c} +12 -8
- data/vendor/libgit2/src/{signature.c → libgit2/signature.c} +12 -6
- data/vendor/libgit2/src/{signature.h → libgit2/signature.h} +1 -1
- data/vendor/libgit2/src/{stash.c → libgit2/stash.c} +235 -61
- data/vendor/libgit2/src/{status.c → libgit2/status.c} +4 -1
- data/vendor/libgit2/src/{strarray.c → libgit2/strarray.c} +1 -0
- data/vendor/libgit2/src/libgit2/strarray.h +25 -0
- data/vendor/libgit2/src/{streams → libgit2/streams}/mbedtls.c +8 -6
- data/vendor/libgit2/src/{streams → libgit2/streams}/openssl.c +1 -1
- data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_dynamic.c +7 -3
- data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_dynamic.h +3 -3
- data/vendor/libgit2/src/{streams → libgit2/streams}/socket.c +4 -1
- data/vendor/libgit2/src/{submodule.c → libgit2/submodule.c} +177 -161
- data/vendor/libgit2/src/{submodule.h → libgit2/submodule.h} +1 -1
- data/vendor/libgit2/src/libgit2/sysdir.c +650 -0
- data/vendor/libgit2/src/{sysdir.h → libgit2/sysdir.h} +53 -18
- data/vendor/libgit2/src/{tag.c → libgit2/tag.c} +73 -42
- data/vendor/libgit2/src/{tag.h → libgit2/tag.h} +2 -2
- data/vendor/libgit2/src/{threadstate.c → libgit2/threadstate.c} +3 -3
- data/vendor/libgit2/src/{threadstate.h → libgit2/threadstate.h} +2 -2
- data/vendor/libgit2/src/{trace.c → libgit2/trace.c} +1 -14
- data/vendor/libgit2/src/{trace.h → libgit2/trace.h} +5 -22
- data/vendor/libgit2/src/{trailer.c → libgit2/trailer.c} +1 -1
- data/vendor/libgit2/src/{transaction.c → libgit2/transaction.c} +1 -1
- data/vendor/libgit2/src/{transport.c → libgit2/transport.c} +10 -10
- data/vendor/libgit2/src/{transports → libgit2/transports}/auth.c +7 -9
- data/vendor/libgit2/src/{transports → libgit2/transports}/auth.h +2 -3
- data/vendor/libgit2/src/{transports → libgit2/transports}/auth_negotiate.c +12 -13
- data/vendor/libgit2/src/{transports → libgit2/transports}/auth_ntlm.c +10 -10
- data/vendor/libgit2/src/{transports → libgit2/transports}/auth_ntlm.h +0 -1
- data/vendor/libgit2/src/{transports → libgit2/transports}/git.c +9 -11
- data/vendor/libgit2/src/{transports → libgit2/transports}/http.c +41 -20
- data/vendor/libgit2/src/{transports → libgit2/transports}/http.h +2 -3
- data/vendor/libgit2/src/{transports → libgit2/transports}/httpclient.c +75 -66
- data/vendor/libgit2/src/{transports → libgit2/transports}/httpclient.h +10 -0
- data/vendor/libgit2/src/{transports → libgit2/transports}/local.c +138 -116
- data/vendor/libgit2/src/{transports → libgit2/transports}/smart.c +92 -133
- data/vendor/libgit2/src/{transports → libgit2/transports}/smart.h +35 -32
- data/vendor/libgit2/src/{transports → libgit2/transports}/smart_pkt.c +177 -65
- data/vendor/libgit2/src/{transports → libgit2/transports}/smart_protocol.c +97 -49
- data/vendor/libgit2/src/{transports → libgit2/transports}/ssh.c +365 -198
- data/vendor/libgit2/src/{transports → libgit2/transports}/winhttp.c +58 -59
- data/vendor/libgit2/src/{tree-cache.c → libgit2/tree-cache.c} +8 -8
- data/vendor/libgit2/src/{tree-cache.h → libgit2/tree-cache.h} +2 -2
- data/vendor/libgit2/src/{tree.c → libgit2/tree.c} +93 -83
- data/vendor/libgit2/src/{tree.h → libgit2/tree.h} +4 -4
- data/vendor/libgit2/src/{worktree.c → libgit2/worktree.c} +121 -94
- data/vendor/libgit2/src/{worktree.h → libgit2/worktree.h} +1 -1
- data/vendor/libgit2/src/libgit2/xdiff/git-xdiff.h +53 -0
- data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xdiff.h +15 -15
- data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xdiffi.c +134 -108
- data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xemit.c +23 -7
- data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xhistogram.c +87 -78
- data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xinclude.h +1 -12
- data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xmerge.c +104 -117
- data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xpatience.c +6 -17
- data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xprepare.c +15 -20
- data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xutils.c +18 -7
- data/vendor/libgit2/src/util/CMakeLists.txt +80 -0
- data/vendor/libgit2/src/{allocators → util/allocators}/failalloc.h +1 -1
- data/vendor/libgit2/src/{allocators → util/allocators}/stdalloc.h +1 -1
- data/vendor/libgit2/src/{allocators → util/allocators}/win32_leakcheck.h +1 -1
- data/vendor/libgit2/src/{array.h → util/array.h} +1 -1
- data/vendor/libgit2/src/{assert_safe.h → util/assert_safe.h} +16 -0
- data/vendor/libgit2/src/{cc-compat.h → util/cc-compat.h} +1 -1
- data/vendor/libgit2/src/{date.c → util/date.c} +14 -20
- data/vendor/libgit2/src/util/date.h +33 -0
- data/vendor/libgit2/src/{filebuf.c → util/filebuf.c} +29 -29
- data/vendor/libgit2/src/{filebuf.h → util/filebuf.h} +2 -2
- data/vendor/libgit2/src/{path.c → util/fs_path.c} +453 -647
- data/vendor/libgit2/src/{path.h → util/fs_path.h} +221 -188
- data/vendor/libgit2/src/{futils.c → util/futils.c} +135 -90
- data/vendor/libgit2/src/{futils.h → util/futils.h} +28 -15
- data/vendor/libgit2/src/{features.h.in → util/git2_features.h.in} +15 -1
- data/vendor/libgit2/src/{common.h → util/git2_util.h} +20 -59
- data/vendor/libgit2/src/util/hash/builtin.c +53 -0
- data/vendor/libgit2/src/{hash/sha1/openssl.h → util/hash/builtin.h} +6 -6
- data/vendor/libgit2/src/{hash/sha1 → util/hash}/collisiondetect.c +3 -3
- data/vendor/libgit2/src/{hash/sha1 → util/hash}/collisiondetect.h +3 -3
- data/vendor/libgit2/src/util/hash/common_crypto.c +112 -0
- data/vendor/libgit2/src/{hash/sha1 → util/hash}/common_crypto.h +11 -3
- data/vendor/libgit2/src/util/hash/mbedtls.c +92 -0
- data/vendor/libgit2/src/{hash/sha1 → util/hash}/mbedtls.h +14 -4
- data/vendor/libgit2/src/util/hash/openssl.c +195 -0
- data/vendor/libgit2/src/util/hash/openssl.h +45 -0
- data/vendor/libgit2/src/util/hash/rfc6234/sha.h +243 -0
- data/vendor/libgit2/src/util/hash/rfc6234/sha224-256.c +601 -0
- data/vendor/libgit2/src/util/hash/sha.h +70 -0
- data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/sha1.c +1 -1
- data/vendor/libgit2/src/util/hash/win32.c +549 -0
- data/vendor/libgit2/src/util/hash/win32.h +60 -0
- data/vendor/libgit2/src/util/hash.c +158 -0
- data/vendor/libgit2/src/util/hash.h +61 -0
- data/vendor/libgit2/src/{khash.h → util/khash.h} +1 -1
- data/vendor/libgit2/src/{map.h → util/map.h} +1 -1
- data/vendor/libgit2/src/util/net.c +1003 -0
- data/vendor/libgit2/src/{net.h → util/net.h} +18 -4
- data/vendor/libgit2/src/{pool.h → util/pool.h} +1 -1
- data/vendor/libgit2/src/{posix.c → util/posix.c} +3 -3
- data/vendor/libgit2/src/{posix.h → util/posix.h} +4 -1
- data/vendor/libgit2/src/{pqueue.h → util/pqueue.h} +2 -2
- data/vendor/libgit2/src/util/rand.c +234 -0
- data/vendor/libgit2/src/util/rand.h +37 -0
- data/vendor/libgit2/src/{regexp.c → util/regexp.c} +4 -4
- data/vendor/libgit2/src/{regexp.h → util/regexp.h} +1 -1
- data/vendor/libgit2/src/{runtime.c → util/runtime.c} +1 -1
- data/vendor/libgit2/src/{runtime.h → util/runtime.h} +1 -1
- data/vendor/libgit2/src/{sortedcache.c → util/sortedcache.c} +1 -1
- data/vendor/libgit2/src/{sortedcache.h → util/sortedcache.h} +2 -2
- data/vendor/libgit2/src/{buffer.c → util/str.c} +157 -151
- data/vendor/libgit2/src/util/str.h +357 -0
- data/vendor/libgit2/src/{strmap.h → util/strmap.h} +1 -1
- data/vendor/libgit2/src/{thread.c → util/thread.c} +1 -1
- data/vendor/libgit2/src/{thread.h → util/thread.h} +23 -22
- data/vendor/libgit2/src/{tsort.c → util/tsort.c} +1 -1
- data/vendor/libgit2/src/{unix → util/unix}/map.c +1 -3
- data/vendor/libgit2/src/{unix → util/unix}/posix.h +1 -4
- data/vendor/libgit2/src/{unix → util/unix}/realpath.c +1 -3
- data/vendor/libgit2/src/{utf8.c → util/utf8.c} +1 -1
- data/vendor/libgit2/src/{utf8.h → util/utf8.h} +1 -1
- data/vendor/libgit2/src/{util.c → util/util.c} +15 -15
- data/vendor/libgit2/src/{util.h → util/util.h} +4 -29
- data/vendor/libgit2/src/{varint.h → util/varint.h} +1 -1
- data/vendor/libgit2/src/{vector.h → util/vector.h} +2 -2
- data/vendor/libgit2/src/{wildmatch.h → util/wildmatch.h} +1 -1
- data/vendor/libgit2/src/{win32 → util/win32}/dir.h +1 -1
- data/vendor/libgit2/src/{win32 → util/win32}/error.h +1 -1
- data/vendor/libgit2/src/{win32 → util/win32}/map.c +1 -1
- data/vendor/libgit2/src/{win32 → util/win32}/path_w32.c +140 -9
- data/vendor/libgit2/src/{win32 → util/win32}/path_w32.h +3 -1
- data/vendor/libgit2/src/{win32 → util/win32}/posix.h +1 -2
- data/vendor/libgit2/src/{win32 → util/win32}/posix_w32.c +12 -28
- data/vendor/libgit2/src/util/win32/precompiled.c +1 -0
- data/vendor/libgit2/src/{win32 → util/win32}/precompiled.h +1 -1
- data/vendor/libgit2/src/{win32 → util/win32}/thread.h +1 -1
- data/vendor/libgit2/src/{win32 → util/win32}/utf-conv.h +1 -1
- data/vendor/libgit2/src/{win32 → util/win32}/w32_buffer.c +2 -3
- data/vendor/libgit2/src/{win32 → util/win32}/w32_buffer.h +3 -4
- data/vendor/libgit2/src/{win32 → util/win32}/w32_leakcheck.c +1 -1
- data/vendor/libgit2/src/{win32 → util/win32}/w32_leakcheck.h +1 -1
- data/vendor/libgit2/src/{win32 → util/win32}/w32_util.h +1 -1
- data/vendor/libgit2/src/{zstream.c → util/zstream.c} +5 -5
- data/vendor/libgit2/src/{zstream.h → util/zstream.h} +5 -5
- metadata +402 -356
- data/vendor/libgit2/src/buffer.h +0 -374
- data/vendor/libgit2/src/commit.h +0 -46
- data/vendor/libgit2/src/hash/sha1/common_crypto.c +0 -57
- data/vendor/libgit2/src/hash/sha1/generic.c +0 -300
- data/vendor/libgit2/src/hash/sha1/generic.h +0 -19
- data/vendor/libgit2/src/hash/sha1/mbedtls.c +0 -46
- data/vendor/libgit2/src/hash/sha1/openssl.c +0 -59
- data/vendor/libgit2/src/hash/sha1/win32.c +0 -333
- data/vendor/libgit2/src/hash/sha1/win32.h +0 -128
- data/vendor/libgit2/src/hash/sha1.h +0 -38
- data/vendor/libgit2/src/hash.c +0 -110
- data/vendor/libgit2/src/hash.h +0 -46
- data/vendor/libgit2/src/message.h +0 -17
- data/vendor/libgit2/src/net.c +0 -540
- data/vendor/libgit2/src/oid.h +0 -51
- data/vendor/libgit2/src/remote.h +0 -55
- data/vendor/libgit2/src/sysdir.c +0 -347
- data/vendor/libgit2/src/win32/findfile.c +0 -230
- data/vendor/libgit2/src/win32/findfile.h +0 -19
- /data/vendor/libgit2/src/{win32 → cli/win32}/precompiled.c +0 -0
- /data/vendor/libgit2/src/{attr.h → libgit2/attr.h} +0 -0
- /data/vendor/libgit2/src/{attrcache.h → libgit2/attrcache.h} +0 -0
- /data/vendor/libgit2/src/{blame.h → libgit2/blame.h} +0 -0
- /data/vendor/libgit2/src/{blame_git.h → libgit2/blame_git.h} +0 -0
- /data/vendor/libgit2/src/{cache.c → libgit2/cache.c} +0 -0
- /data/vendor/libgit2/src/{cache.h → libgit2/cache.h} +0 -0
- /data/vendor/libgit2/src/{checkout.h → libgit2/checkout.h} +0 -0
- /data/vendor/libgit2/src/{clone.h → libgit2/clone.h} +0 -0
- /data/vendor/libgit2/src/{commit_list.h → libgit2/commit_list.h} +0 -0
- /data/vendor/libgit2/src/{config_backend.h → libgit2/config_backend.h} +0 -0
- /data/vendor/libgit2/src/{config_cache.c → libgit2/config_cache.c} +0 -0
- /data/vendor/libgit2/src/{config_entries.c → libgit2/config_entries.c} +0 -0
- /data/vendor/libgit2/src/{config_entries.h → libgit2/config_entries.h} +0 -0
- /data/vendor/libgit2/src/{config_parse.h → libgit2/config_parse.h} +0 -0
- /data/vendor/libgit2/src/{config_snapshot.c → libgit2/config_snapshot.c} +0 -0
- /data/vendor/libgit2/src/{delta.c → libgit2/delta.c} +0 -0
- /data/vendor/libgit2/src/{delta.h → libgit2/delta.h} +0 -0
- /data/vendor/libgit2/src/{diff_file.h → libgit2/diff_file.h} +0 -0
- /data/vendor/libgit2/src/{diff_parse.c → libgit2/diff_parse.c} +0 -0
- /data/vendor/libgit2/src/{diff_parse.h → libgit2/diff_parse.h} +0 -0
- /data/vendor/libgit2/src/{diff_tform.h → libgit2/diff_tform.h} +0 -0
- /data/vendor/libgit2/src/{diff_xdiff.h → libgit2/diff_xdiff.h} +0 -0
- /data/vendor/libgit2/src/{fetchhead.h → libgit2/fetchhead.h} +0 -0
- /data/vendor/libgit2/src/{win32 → libgit2}/git2.rc +0 -0
- /data/vendor/libgit2/src/{graph.c → libgit2/graph.c} +0 -0
- /data/vendor/libgit2/src/{hashsig.c → libgit2/hashsig.c} +0 -0
- /data/vendor/libgit2/src/{idxmap.c → libgit2/idxmap.c} +0 -0
- /data/vendor/libgit2/src/{idxmap.h → libgit2/idxmap.h} +0 -0
- /data/vendor/libgit2/src/{indexer.h → libgit2/indexer.h} +0 -0
- /data/vendor/libgit2/src/{libgit2.h → libgit2/libgit2.h} +0 -0
- /data/vendor/libgit2/src/{mailmap.h → libgit2/mailmap.h} +0 -0
- /data/vendor/libgit2/src/{merge_driver.h → libgit2/merge_driver.h} +0 -0
- /data/vendor/libgit2/src/{notes.h → libgit2/notes.h} +0 -0
- /data/vendor/libgit2/src/{object_api.c → libgit2/object_api.c} +0 -0
- /data/vendor/libgit2/src/{offmap.c → libgit2/offmap.c} +0 -0
- /data/vendor/libgit2/src/{offmap.h → libgit2/offmap.h} +0 -0
- /data/vendor/libgit2/src/{oidarray.c → libgit2/oidarray.c} +0 -0
- /data/vendor/libgit2/src/{oidarray.h → libgit2/oidarray.h} +0 -0
- /data/vendor/libgit2/src/{oidmap.h → libgit2/oidmap.h} +0 -0
- /data/vendor/libgit2/src/{parse.h → libgit2/parse.h} +0 -0
- /data/vendor/libgit2/src/{patch_parse.h → libgit2/patch_parse.h} +0 -0
- /data/vendor/libgit2/src/{refdb.c → libgit2/refdb.c} +0 -0
- /data/vendor/libgit2/src/{refdb.h → libgit2/refdb.h} +0 -0
- /data/vendor/libgit2/src/{repo_template.h → libgit2/repo_template.h} +0 -0
- /data/vendor/libgit2/src/{revwalk.h → libgit2/revwalk.h} +0 -0
- /data/vendor/libgit2/src/{settings.h → libgit2/settings.h} +0 -0
- /data/vendor/libgit2/src/{status.h → libgit2/status.h} +0 -0
- /data/vendor/libgit2/src/{stream.h → libgit2/stream.h} +0 -0
- /data/vendor/libgit2/src/{streams → libgit2/streams}/mbedtls.h +0 -0
- /data/vendor/libgit2/src/{streams → libgit2/streams}/openssl.h +0 -0
- /data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_legacy.c +0 -0
- /data/vendor/libgit2/src/{streams → libgit2/streams}/openssl_legacy.h +0 -0
- /data/vendor/libgit2/src/{streams → libgit2/streams}/registry.c +0 -0
- /data/vendor/libgit2/src/{streams → libgit2/streams}/registry.h +0 -0
- /data/vendor/libgit2/src/{streams → libgit2/streams}/socket.h +0 -0
- /data/vendor/libgit2/src/{streams → libgit2/streams}/stransport.c +0 -0
- /data/vendor/libgit2/src/{streams → libgit2/streams}/stransport.h +0 -0
- /data/vendor/libgit2/src/{streams → libgit2/streams}/tls.c +0 -0
- /data/vendor/libgit2/src/{streams → libgit2/streams}/tls.h +0 -0
- /data/vendor/libgit2/src/{transaction.h → libgit2/transaction.h} +0 -0
- /data/vendor/libgit2/src/{transports → libgit2/transports}/auth_negotiate.h +0 -0
- /data/vendor/libgit2/src/{transports → libgit2/transports}/credential.c +0 -0
- /data/vendor/libgit2/src/{transports → libgit2/transports}/credential_helpers.c +0 -0
- /data/vendor/libgit2/src/{transports → libgit2/transports}/ssh.h +0 -0
- /data/vendor/libgit2/src/{userdiff.h → libgit2/userdiff.h} +0 -0
- /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xdiffi.h +0 -0
- /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xemit.h +0 -0
- /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xmacros.h +0 -0
- /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xprepare.h +0 -0
- /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xtypes.h +0 -0
- /data/vendor/libgit2/src/{xdiff → libgit2/xdiff}/xutils.h +0 -0
- /data/vendor/libgit2/src/{alloc.c → util/alloc.c} +0 -0
- /data/vendor/libgit2/src/{alloc.h → util/alloc.h} +0 -0
- /data/vendor/libgit2/src/{allocators → util/allocators}/failalloc.c +0 -0
- /data/vendor/libgit2/src/{allocators → util/allocators}/stdalloc.c +0 -0
- /data/vendor/libgit2/src/{allocators → util/allocators}/win32_leakcheck.c +0 -0
- /data/vendor/libgit2/src/{bitvec.h → util/bitvec.h} +0 -0
- /data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/sha1.h +0 -0
- /data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/ubc_check.c +0 -0
- /data/vendor/libgit2/src/{hash/sha1 → util/hash}/sha1dc/ubc_check.h +0 -0
- /data/vendor/libgit2/src/{integer.h → util/integer.h} +0 -0
- /data/vendor/libgit2/src/{pool.c → util/pool.c} +0 -0
- /data/vendor/libgit2/src/{pqueue.c → util/pqueue.c} +0 -0
- /data/vendor/libgit2/src/{strmap.c → util/strmap.c} +0 -0
- /data/vendor/libgit2/src/{strnlen.h → util/strnlen.h} +0 -0
- /data/vendor/libgit2/src/{unix → util/unix}/pthread.h +0 -0
- /data/vendor/libgit2/src/{varint.c → util/varint.c} +0 -0
- /data/vendor/libgit2/src/{vector.c → util/vector.c} +0 -0
- /data/vendor/libgit2/src/{wildmatch.c → util/wildmatch.c} +0 -0
- /data/vendor/libgit2/src/{win32 → util/win32}/dir.c +0 -0
- /data/vendor/libgit2/src/{win32 → util/win32}/error.c +0 -0
- /data/vendor/libgit2/src/{win32 → util/win32}/mingw-compat.h +0 -0
- /data/vendor/libgit2/src/{win32 → util/win32}/msvc-compat.h +0 -0
- /data/vendor/libgit2/src/{win32 → util/win32}/reparse.h +0 -0
- /data/vendor/libgit2/src/{win32 → util/win32}/thread.c +0 -0
- /data/vendor/libgit2/src/{win32 → util/win32}/utf-conv.c +0 -0
- /data/vendor/libgit2/src/{win32 → util/win32}/version.h +0 -0
- /data/vendor/libgit2/src/{win32 → util/win32}/w32_common.h +0 -0
- /data/vendor/libgit2/src/{win32 → util/win32}/w32_util.c +0 -0
- /data/vendor/libgit2/src/{win32 → util/win32}/win32-compat.h +0 -0
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
#include "git2/object.h"
|
|
13
13
|
#include "git2/sys/repository.h"
|
|
14
14
|
|
|
15
|
+
#include "buf.h"
|
|
15
16
|
#include "common.h"
|
|
16
17
|
#include "commit.h"
|
|
17
18
|
#include "tag.h"
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
#include "annotated_commit.h"
|
|
32
33
|
#include "submodule.h"
|
|
33
34
|
#include "worktree.h"
|
|
34
|
-
|
|
35
|
+
#include "path.h"
|
|
35
36
|
#include "strmap.h"
|
|
36
37
|
|
|
37
38
|
#ifdef GIT_WIN32
|
|
@@ -66,6 +67,7 @@ static const struct {
|
|
|
66
67
|
static int check_repositoryformatversion(int *version, git_config *config);
|
|
67
68
|
static int check_extensions(git_config *config, int version);
|
|
68
69
|
static int load_global_config(git_config **config);
|
|
70
|
+
static int load_objectformat(git_repository *repo, git_config *config);
|
|
69
71
|
|
|
70
72
|
#define GIT_COMMONDIR_FILE "commondir"
|
|
71
73
|
#define GIT_GITDIR_FILE "gitdir"
|
|
@@ -74,16 +76,16 @@ static int load_global_config(git_config **config);
|
|
|
74
76
|
|
|
75
77
|
#define GIT_BRANCH_DEFAULT "master"
|
|
76
78
|
|
|
77
|
-
#define
|
|
78
|
-
#define
|
|
79
|
+
#define GIT_REPO_VERSION_DEFAULT 0
|
|
80
|
+
#define GIT_REPO_VERSION_MAX 1
|
|
79
81
|
|
|
80
|
-
|
|
82
|
+
git_str git_repository__reserved_names_win32[] = {
|
|
81
83
|
{ DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
|
|
82
84
|
{ GIT_DIR_SHORTNAME, 0, CONST_STRLEN(GIT_DIR_SHORTNAME) }
|
|
83
85
|
};
|
|
84
86
|
size_t git_repository__reserved_names_win32_len = 2;
|
|
85
87
|
|
|
86
|
-
|
|
88
|
+
git_str git_repository__reserved_names_posix[] = {
|
|
87
89
|
{ DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
|
|
88
90
|
};
|
|
89
91
|
size_t git_repository__reserved_names_posix_len = 1;
|
|
@@ -173,7 +175,7 @@ void git_repository_free(git_repository *repo)
|
|
|
173
175
|
repo->diff_drivers = NULL;
|
|
174
176
|
|
|
175
177
|
for (i = 0; i < repo->reserved_names.size; i++)
|
|
176
|
-
|
|
178
|
+
git_str_dispose(git_array_get(repo->reserved_names, i));
|
|
177
179
|
git_array_clear(repo->reserved_names);
|
|
178
180
|
|
|
179
181
|
git__free(repo->gitlink);
|
|
@@ -189,18 +191,18 @@ void git_repository_free(git_repository *repo)
|
|
|
189
191
|
}
|
|
190
192
|
|
|
191
193
|
/* Check if we have a separate commondir (e.g. we have a worktree) */
|
|
192
|
-
static int lookup_commondir(bool *separate,
|
|
194
|
+
static int lookup_commondir(bool *separate, git_str *commondir, git_str *repository_path)
|
|
193
195
|
{
|
|
194
|
-
|
|
196
|
+
git_str common_link = GIT_STR_INIT;
|
|
195
197
|
int error;
|
|
196
198
|
|
|
197
199
|
/*
|
|
198
200
|
* If there's no commondir file, the repository path is the
|
|
199
201
|
* common path, but it needs a trailing slash.
|
|
200
202
|
*/
|
|
201
|
-
if (!
|
|
202
|
-
if ((error =
|
|
203
|
-
error =
|
|
203
|
+
if (!git_fs_path_contains_file(repository_path, GIT_COMMONDIR_FILE)) {
|
|
204
|
+
if ((error = git_str_set(commondir, repository_path->ptr, repository_path->size)) == 0)
|
|
205
|
+
error = git_fs_path_to_dir(commondir);
|
|
204
206
|
|
|
205
207
|
*separate = false;
|
|
206
208
|
goto done;
|
|
@@ -208,28 +210,28 @@ static int lookup_commondir(bool *separate, git_buf *commondir, git_buf *reposit
|
|
|
208
210
|
|
|
209
211
|
*separate = true;
|
|
210
212
|
|
|
211
|
-
if ((error =
|
|
213
|
+
if ((error = git_str_joinpath(&common_link, repository_path->ptr, GIT_COMMONDIR_FILE)) < 0 ||
|
|
212
214
|
(error = git_futils_readbuffer(&common_link, common_link.ptr)) < 0)
|
|
213
215
|
goto done;
|
|
214
216
|
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
if ((error =
|
|
217
|
+
git_str_rtrim(&common_link);
|
|
218
|
+
if (git_fs_path_is_relative(common_link.ptr)) {
|
|
219
|
+
if ((error = git_str_joinpath(commondir, repository_path->ptr, common_link.ptr)) < 0)
|
|
218
220
|
goto done;
|
|
219
221
|
} else {
|
|
220
|
-
|
|
222
|
+
git_str_swap(commondir, &common_link);
|
|
221
223
|
}
|
|
222
224
|
|
|
223
|
-
|
|
225
|
+
git_str_dispose(&common_link);
|
|
224
226
|
|
|
225
227
|
/* Make sure the commondir path always has a trailing slash */
|
|
226
|
-
error =
|
|
228
|
+
error = git_fs_path_prettify_dir(commondir, commondir->ptr, NULL);
|
|
227
229
|
|
|
228
230
|
done:
|
|
229
231
|
return error;
|
|
230
232
|
}
|
|
231
233
|
|
|
232
|
-
GIT_INLINE(int) validate_repo_path(
|
|
234
|
+
GIT_INLINE(int) validate_repo_path(git_str *path)
|
|
233
235
|
{
|
|
234
236
|
/*
|
|
235
237
|
* The longest static path in a repository (or commondir) is the
|
|
@@ -239,10 +241,10 @@ GIT_INLINE(int) validate_repo_path(git_buf *path)
|
|
|
239
241
|
*/
|
|
240
242
|
static size_t suffix_len =
|
|
241
243
|
CONST_STRLEN("objects/pack/pack-.pack.lock") +
|
|
242
|
-
|
|
244
|
+
GIT_OID_MAX_HEXSIZE;
|
|
243
245
|
|
|
244
|
-
return
|
|
245
|
-
path
|
|
246
|
+
return git_fs_path_validate_str_length_with_suffix(
|
|
247
|
+
path, suffix_len);
|
|
246
248
|
}
|
|
247
249
|
|
|
248
250
|
/*
|
|
@@ -250,7 +252,7 @@ GIT_INLINE(int) validate_repo_path(git_buf *path)
|
|
|
250
252
|
*
|
|
251
253
|
* Open a repository object from its path
|
|
252
254
|
*/
|
|
253
|
-
static int is_valid_repository_path(bool *out,
|
|
255
|
+
static int is_valid_repository_path(bool *out, git_str *repository_path, git_str *common_path)
|
|
254
256
|
{
|
|
255
257
|
bool separate_commondir = false;
|
|
256
258
|
int error;
|
|
@@ -261,13 +263,13 @@ static int is_valid_repository_path(bool *out, git_buf *repository_path, git_buf
|
|
|
261
263
|
return error;
|
|
262
264
|
|
|
263
265
|
/* Ensure HEAD file exists */
|
|
264
|
-
if (
|
|
266
|
+
if (git_fs_path_contains_file(repository_path, GIT_HEAD_FILE) == false)
|
|
265
267
|
return 0;
|
|
266
268
|
|
|
267
269
|
/* Check files in common dir */
|
|
268
|
-
if (
|
|
270
|
+
if (git_fs_path_contains_dir(common_path, GIT_OBJECTS_DIR) == false)
|
|
269
271
|
return 0;
|
|
270
|
-
if (
|
|
272
|
+
if (git_fs_path_contains_dir(common_path, GIT_REFS_DIR) == false)
|
|
271
273
|
return 0;
|
|
272
274
|
|
|
273
275
|
/* Ensure the repo (and commondir) are valid paths */
|
|
@@ -335,12 +337,12 @@ static int load_config_data(git_repository *repo, const git_config *config)
|
|
|
335
337
|
return 0;
|
|
336
338
|
}
|
|
337
339
|
|
|
338
|
-
static int load_workdir(git_repository *repo, git_config *config,
|
|
340
|
+
static int load_workdir(git_repository *repo, git_config *config, git_str *parent_path)
|
|
339
341
|
{
|
|
340
342
|
int error;
|
|
341
343
|
git_config_entry *ce;
|
|
342
|
-
|
|
343
|
-
|
|
344
|
+
git_str worktree = GIT_STR_INIT;
|
|
345
|
+
git_str path = GIT_STR_INIT;
|
|
344
346
|
|
|
345
347
|
if (repo->is_bare)
|
|
346
348
|
return 0;
|
|
@@ -356,38 +358,38 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
|
|
|
356
358
|
goto cleanup;
|
|
357
359
|
}
|
|
358
360
|
|
|
359
|
-
|
|
361
|
+
git_str_attach(&worktree, gitlink, 0);
|
|
360
362
|
|
|
361
|
-
if ((
|
|
362
|
-
|
|
363
|
+
if ((git_fs_path_dirname_r(&worktree, worktree.ptr)) < 0 ||
|
|
364
|
+
git_fs_path_to_dir(&worktree) < 0) {
|
|
363
365
|
error = -1;
|
|
364
366
|
goto cleanup;
|
|
365
367
|
}
|
|
366
368
|
|
|
367
|
-
repo->workdir =
|
|
369
|
+
repo->workdir = git_str_detach(&worktree);
|
|
368
370
|
}
|
|
369
371
|
else if (ce && ce->value) {
|
|
370
|
-
if ((error =
|
|
372
|
+
if ((error = git_fs_path_prettify_dir(
|
|
371
373
|
&worktree, ce->value, repo->gitdir)) < 0)
|
|
372
374
|
goto cleanup;
|
|
373
375
|
|
|
374
|
-
repo->workdir =
|
|
376
|
+
repo->workdir = git_str_detach(&worktree);
|
|
375
377
|
}
|
|
376
|
-
else if (parent_path &&
|
|
377
|
-
repo->workdir =
|
|
378
|
+
else if (parent_path && git_fs_path_isdir(parent_path->ptr))
|
|
379
|
+
repo->workdir = git_str_detach(parent_path);
|
|
378
380
|
else {
|
|
379
|
-
if (
|
|
380
|
-
|
|
381
|
+
if (git_fs_path_dirname_r(&worktree, repo->gitdir) < 0 ||
|
|
382
|
+
git_fs_path_to_dir(&worktree) < 0) {
|
|
381
383
|
error = -1;
|
|
382
384
|
goto cleanup;
|
|
383
385
|
}
|
|
384
386
|
|
|
385
|
-
repo->workdir =
|
|
387
|
+
repo->workdir = git_str_detach(&worktree);
|
|
386
388
|
}
|
|
387
389
|
|
|
388
390
|
GIT_ERROR_CHECK_ALLOC(repo->workdir);
|
|
389
391
|
cleanup:
|
|
390
|
-
|
|
392
|
+
git_str_dispose(&path);
|
|
391
393
|
git_config_entry_free(ce);
|
|
392
394
|
return error;
|
|
393
395
|
}
|
|
@@ -396,7 +398,7 @@ cleanup:
|
|
|
396
398
|
* This function returns furthest offset into path where a ceiling dir
|
|
397
399
|
* is found, so we can stop processing the path at that point.
|
|
398
400
|
*
|
|
399
|
-
* Note: converting this to use
|
|
401
|
+
* Note: converting this to use git_strs instead of GIT_PATH_MAX buffers on
|
|
400
402
|
* the stack could remove directories name limits, but at the cost of doing
|
|
401
403
|
* repeated malloc/frees inside the loop below, so let's not do it now.
|
|
402
404
|
*/
|
|
@@ -411,7 +413,7 @@ static size_t find_ceiling_dir_offset(
|
|
|
411
413
|
|
|
412
414
|
GIT_ASSERT_ARG(path);
|
|
413
415
|
|
|
414
|
-
min_len = (size_t)(
|
|
416
|
+
min_len = (size_t)(git_fs_path_root(path) + 1);
|
|
415
417
|
|
|
416
418
|
if (ceiling_directories == NULL || min_len == 0)
|
|
417
419
|
return min_len;
|
|
@@ -420,7 +422,7 @@ static size_t find_ceiling_dir_offset(
|
|
|
420
422
|
for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++);
|
|
421
423
|
len = sep - ceil;
|
|
422
424
|
|
|
423
|
-
if (len == 0 || len >= sizeof(buf) ||
|
|
425
|
+
if (len == 0 || len >= sizeof(buf) || git_fs_path_root(ceil) == -1)
|
|
424
426
|
continue;
|
|
425
427
|
|
|
426
428
|
strncpy(buf, ceil, len);
|
|
@@ -449,10 +451,10 @@ static size_t find_ceiling_dir_offset(
|
|
|
449
451
|
* it points to. Before calling, set `path_out` to the base directory that
|
|
450
452
|
* should be used if the contents of `file_path` are a relative path.
|
|
451
453
|
*/
|
|
452
|
-
static int read_gitfile(
|
|
454
|
+
static int read_gitfile(git_str *path_out, const char *file_path)
|
|
453
455
|
{
|
|
454
456
|
int error = 0;
|
|
455
|
-
|
|
457
|
+
git_str file = GIT_STR_INIT;
|
|
456
458
|
size_t prefix_len = strlen(GIT_FILE_CONTENT_PREFIX);
|
|
457
459
|
|
|
458
460
|
GIT_ASSERT_ARG(path_out);
|
|
@@ -461,98 +463,192 @@ static int read_gitfile(git_buf *path_out, const char *file_path)
|
|
|
461
463
|
if (git_futils_readbuffer(&file, file_path) < 0)
|
|
462
464
|
return -1;
|
|
463
465
|
|
|
464
|
-
|
|
466
|
+
git_str_rtrim(&file);
|
|
465
467
|
/* apparently on Windows, some people use backslashes in paths */
|
|
466
|
-
|
|
468
|
+
git_fs_path_mkposix(file.ptr);
|
|
467
469
|
|
|
468
|
-
if (
|
|
469
|
-
memcmp(
|
|
470
|
+
if (git_str_len(&file) <= prefix_len ||
|
|
471
|
+
memcmp(git_str_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0)
|
|
470
472
|
{
|
|
471
473
|
git_error_set(GIT_ERROR_REPOSITORY,
|
|
472
474
|
"the `.git` file at '%s' is malformed", file_path);
|
|
473
475
|
error = -1;
|
|
474
476
|
}
|
|
475
|
-
else if ((error =
|
|
476
|
-
const char *gitlink =
|
|
477
|
+
else if ((error = git_fs_path_dirname_r(path_out, file_path)) >= 0) {
|
|
478
|
+
const char *gitlink = git_str_cstr(&file) + prefix_len;
|
|
477
479
|
while (*gitlink && git__isspace(*gitlink)) gitlink++;
|
|
478
480
|
|
|
479
|
-
error =
|
|
480
|
-
path_out, gitlink,
|
|
481
|
+
error = git_fs_path_prettify_dir(
|
|
482
|
+
path_out, gitlink, git_str_cstr(path_out));
|
|
481
483
|
}
|
|
482
484
|
|
|
483
|
-
|
|
485
|
+
git_str_dispose(&file);
|
|
484
486
|
return error;
|
|
485
487
|
}
|
|
486
488
|
|
|
487
489
|
typedef struct {
|
|
488
490
|
const char *repo_path;
|
|
489
|
-
|
|
490
|
-
bool is_safe;
|
|
491
|
+
git_str tmp;
|
|
492
|
+
bool *is_safe;
|
|
491
493
|
} validate_ownership_data;
|
|
492
494
|
|
|
493
495
|
static int validate_ownership_cb(const git_config_entry *entry, void *payload)
|
|
494
496
|
{
|
|
495
497
|
validate_ownership_data *data = payload;
|
|
496
498
|
|
|
497
|
-
if (strcmp(entry->value, "") == 0)
|
|
498
|
-
data->is_safe = false;
|
|
499
|
+
if (strcmp(entry->value, "") == 0) {
|
|
500
|
+
*data->is_safe = false;
|
|
501
|
+
} else if (strcmp(entry->value, "*") == 0) {
|
|
502
|
+
*data->is_safe = true;
|
|
503
|
+
} else {
|
|
504
|
+
const char *test_path = entry->value;
|
|
499
505
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
506
|
+
#ifdef GIT_WIN32
|
|
507
|
+
/*
|
|
508
|
+
* Git for Windows does some truly bizarre things with
|
|
509
|
+
* paths that start with a forward slash; and expects you
|
|
510
|
+
* to escape that with `%(prefix)`. This syntax generally
|
|
511
|
+
* means to add the prefix that Git was installed to -- eg
|
|
512
|
+
* `/usr/local` -- unless it's an absolute path, in which
|
|
513
|
+
* case the leading `%(prefix)/` is just removed. And Git
|
|
514
|
+
* for Windows expects you to use this syntax for absolute
|
|
515
|
+
* Unix-style paths (in "Git Bash" or Windows Subsystem for
|
|
516
|
+
* Linux).
|
|
517
|
+
*
|
|
518
|
+
* Worse, the behavior used to be that a leading `/` was
|
|
519
|
+
* not absolute. It would indicate that Git for Windows
|
|
520
|
+
* should add the prefix. So `//` is required for absolute
|
|
521
|
+
* Unix-style paths. Yes, this is truly horrifying.
|
|
522
|
+
*
|
|
523
|
+
* Emulate that behavior, I guess, but only for absolute
|
|
524
|
+
* paths. We won't deal with the Git install prefix. Also,
|
|
525
|
+
* give WSL users an escape hatch where they don't have to
|
|
526
|
+
* think about this and can use the literal path that the
|
|
527
|
+
* filesystem APIs provide (`//wsl.localhost/...`).
|
|
528
|
+
*/
|
|
529
|
+
if (strncmp(test_path, "%(prefix)//", strlen("%(prefix)//")) == 0)
|
|
530
|
+
test_path += strlen("%(prefix)/");
|
|
531
|
+
else if (strncmp(test_path, "//", 2) == 0 &&
|
|
532
|
+
strncmp(test_path, "//wsl.localhost/", strlen("//wsl.localhost/")) != 0)
|
|
533
|
+
test_path++;
|
|
534
|
+
#endif
|
|
535
|
+
|
|
536
|
+
if (git_fs_path_prettify_dir(&data->tmp, test_path, NULL) == 0 &&
|
|
537
|
+
strcmp(data->tmp.ptr, data->repo_path) == 0)
|
|
538
|
+
*data->is_safe = true;
|
|
539
|
+
}
|
|
503
540
|
|
|
504
541
|
return 0;
|
|
505
542
|
}
|
|
506
543
|
|
|
507
|
-
static int
|
|
544
|
+
static int validate_ownership_config(bool *is_safe, const char *path)
|
|
508
545
|
{
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
546
|
+
validate_ownership_data ownership_data = {
|
|
547
|
+
path, GIT_STR_INIT, is_safe
|
|
548
|
+
};
|
|
549
|
+
git_config *config;
|
|
512
550
|
int error;
|
|
513
551
|
|
|
514
|
-
if ((
|
|
515
|
-
|
|
516
|
-
error = 0;
|
|
552
|
+
if (load_global_config(&config) != 0)
|
|
553
|
+
return 0;
|
|
517
554
|
|
|
518
|
-
|
|
519
|
-
|
|
555
|
+
error = git_config_get_multivar_foreach(config,
|
|
556
|
+
"safe.directory", NULL,
|
|
557
|
+
validate_ownership_cb,
|
|
558
|
+
&ownership_data);
|
|
520
559
|
|
|
521
|
-
if (
|
|
560
|
+
if (error == GIT_ENOTFOUND)
|
|
561
|
+
error = 0;
|
|
562
|
+
|
|
563
|
+
git_config_free(config);
|
|
564
|
+
git_str_dispose(&ownership_data.tmp);
|
|
565
|
+
|
|
566
|
+
return error;
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
static int validate_ownership_path(bool *is_safe, const char *path)
|
|
570
|
+
{
|
|
571
|
+
git_fs_path_owner_t owner_level =
|
|
572
|
+
GIT_FS_PATH_OWNER_CURRENT_USER |
|
|
573
|
+
GIT_FS_PATH_USER_IS_ADMINISTRATOR |
|
|
574
|
+
GIT_FS_PATH_OWNER_RUNNING_SUDO;
|
|
575
|
+
int error = 0;
|
|
576
|
+
|
|
577
|
+
if (path)
|
|
578
|
+
error = git_fs_path_owner_is(is_safe, path, owner_level);
|
|
579
|
+
|
|
580
|
+
if (error == GIT_ENOTFOUND) {
|
|
581
|
+
*is_safe = true;
|
|
582
|
+
error = 0;
|
|
583
|
+
} else if (error == GIT_EINVALID) {
|
|
584
|
+
*is_safe = false;
|
|
522
585
|
error = 0;
|
|
523
|
-
goto done;
|
|
524
586
|
}
|
|
525
587
|
|
|
526
|
-
|
|
527
|
-
|
|
588
|
+
return error;
|
|
589
|
+
}
|
|
528
590
|
|
|
529
|
-
|
|
591
|
+
static int validate_ownership(git_repository *repo)
|
|
592
|
+
{
|
|
593
|
+
const char *validation_paths[3] = { NULL }, *path;
|
|
594
|
+
size_t validation_len = 0, i;
|
|
595
|
+
bool is_safe = false;
|
|
596
|
+
int error = 0;
|
|
597
|
+
|
|
598
|
+
/*
|
|
599
|
+
* If there's a worktree, validate the permissions to it *and*
|
|
600
|
+
* the git directory, and use the worktree as the configuration
|
|
601
|
+
* key for allowlisting the directory. In a bare setup, only
|
|
602
|
+
* look at the gitdir and use that as the allowlist. So we
|
|
603
|
+
* examine all `validation_paths` but use only the first as
|
|
604
|
+
* the configuration lookup.
|
|
605
|
+
*/
|
|
606
|
+
|
|
607
|
+
if (repo->workdir)
|
|
608
|
+
validation_paths[validation_len++] = repo->workdir;
|
|
609
|
+
|
|
610
|
+
if (repo->gitlink)
|
|
611
|
+
validation_paths[validation_len++] = repo->gitlink;
|
|
612
|
+
|
|
613
|
+
validation_paths[validation_len++] = repo->gitdir;
|
|
614
|
+
|
|
615
|
+
for (i = 0; i < validation_len; i++) {
|
|
616
|
+
path = validation_paths[i];
|
|
617
|
+
|
|
618
|
+
if ((error = validate_ownership_path(&is_safe, path)) < 0)
|
|
530
619
|
goto done;
|
|
620
|
+
|
|
621
|
+
if (!is_safe)
|
|
622
|
+
break;
|
|
531
623
|
}
|
|
532
624
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
625
|
+
if (is_safe ||
|
|
626
|
+
(error = validate_ownership_config(&is_safe, validation_paths[0])) < 0)
|
|
627
|
+
goto done;
|
|
628
|
+
|
|
629
|
+
if (!is_safe) {
|
|
630
|
+
git_error_set(GIT_ERROR_CONFIG,
|
|
631
|
+
"repository path '%s' is not owned by current user",
|
|
632
|
+
path);
|
|
633
|
+
error = GIT_EOWNER;
|
|
634
|
+
}
|
|
537
635
|
|
|
538
636
|
done:
|
|
539
|
-
git_config_free(config);
|
|
540
|
-
git_buf_dispose(&data.tmp);
|
|
541
637
|
return error;
|
|
542
638
|
}
|
|
543
639
|
|
|
544
640
|
static int find_repo(
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
641
|
+
git_str *gitdir_path,
|
|
642
|
+
git_str *workdir_path,
|
|
643
|
+
git_str *gitlink_path,
|
|
644
|
+
git_str *commondir_path,
|
|
549
645
|
const char *start_path,
|
|
550
646
|
uint32_t flags,
|
|
551
647
|
const char *ceiling_dirs)
|
|
552
648
|
{
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
649
|
+
git_str path = GIT_STR_INIT;
|
|
650
|
+
git_str repo_link = GIT_STR_INIT;
|
|
651
|
+
git_str common_link = GIT_STR_INIT;
|
|
556
652
|
struct stat st;
|
|
557
653
|
dev_t initial_device = 0;
|
|
558
654
|
int min_iterations;
|
|
@@ -560,9 +656,9 @@ static int find_repo(
|
|
|
560
656
|
size_t ceiling_offset = 0;
|
|
561
657
|
int error;
|
|
562
658
|
|
|
563
|
-
|
|
659
|
+
git_str_clear(gitdir_path);
|
|
564
660
|
|
|
565
|
-
error =
|
|
661
|
+
error = git_fs_path_prettify(&path, start_path, NULL);
|
|
566
662
|
if (error < 0)
|
|
567
663
|
return error;
|
|
568
664
|
|
|
@@ -584,7 +680,7 @@ static int find_repo(
|
|
|
584
680
|
for (;;) {
|
|
585
681
|
if (!(flags & GIT_REPOSITORY_OPEN_NO_DOTGIT)) {
|
|
586
682
|
if (!in_dot_git) {
|
|
587
|
-
if ((error =
|
|
683
|
+
if ((error = git_str_joinpath(&path, path.ptr, DOT_GIT)) < 0)
|
|
588
684
|
goto out;
|
|
589
685
|
}
|
|
590
686
|
in_dot_git = !in_dot_git;
|
|
@@ -603,15 +699,15 @@ static int find_repo(
|
|
|
603
699
|
goto out;
|
|
604
700
|
|
|
605
701
|
if (is_valid) {
|
|
606
|
-
if ((error =
|
|
607
|
-
(error =
|
|
702
|
+
if ((error = git_fs_path_to_dir(&path)) < 0 ||
|
|
703
|
+
(error = git_str_set(gitdir_path, path.ptr, path.size)) < 0)
|
|
608
704
|
goto out;
|
|
609
705
|
|
|
610
706
|
if (gitlink_path)
|
|
611
|
-
if ((error =
|
|
707
|
+
if ((error = git_str_attach(gitlink_path, git_worktree__read_link(path.ptr, GIT_GITDIR_FILE), 0)) < 0)
|
|
612
708
|
goto out;
|
|
613
709
|
if (commondir_path)
|
|
614
|
-
|
|
710
|
+
git_str_swap(&common_link, commondir_path);
|
|
615
711
|
|
|
616
712
|
break;
|
|
617
713
|
}
|
|
@@ -621,13 +717,13 @@ static int find_repo(
|
|
|
621
717
|
goto out;
|
|
622
718
|
|
|
623
719
|
if (is_valid) {
|
|
624
|
-
|
|
720
|
+
git_str_swap(gitdir_path, &repo_link);
|
|
625
721
|
|
|
626
722
|
if (gitlink_path)
|
|
627
|
-
if ((error =
|
|
723
|
+
if ((error = git_str_put(gitlink_path, path.ptr, path.size)) < 0)
|
|
628
724
|
goto out;
|
|
629
725
|
if (commondir_path)
|
|
630
|
-
|
|
726
|
+
git_str_swap(&common_link, commondir_path);
|
|
631
727
|
}
|
|
632
728
|
break;
|
|
633
729
|
}
|
|
@@ -636,7 +732,7 @@ static int find_repo(
|
|
|
636
732
|
/* Move up one directory. If we're in_dot_git, we'll search the
|
|
637
733
|
* parent itself next. If we're !in_dot_git, we'll search .git
|
|
638
734
|
* in the parent directory next (added at the top of the loop). */
|
|
639
|
-
if ((error =
|
|
735
|
+
if ((error = git_fs_path_dirname_r(&path, path.ptr)) < 0)
|
|
640
736
|
goto out;
|
|
641
737
|
|
|
642
738
|
/* Once we've checked the directory (and .git if applicable),
|
|
@@ -651,25 +747,62 @@ static int find_repo(
|
|
|
651
747
|
}
|
|
652
748
|
|
|
653
749
|
if (workdir_path && !(flags & GIT_REPOSITORY_OPEN_BARE)) {
|
|
654
|
-
if (!
|
|
655
|
-
|
|
656
|
-
else if ((error =
|
|
657
|
-
(error =
|
|
750
|
+
if (!git_str_len(gitdir_path))
|
|
751
|
+
git_str_clear(workdir_path);
|
|
752
|
+
else if ((error = git_fs_path_dirname_r(workdir_path, path.ptr)) < 0 ||
|
|
753
|
+
(error = git_fs_path_to_dir(workdir_path)) < 0)
|
|
658
754
|
goto out;
|
|
659
755
|
}
|
|
660
756
|
|
|
661
757
|
/* If we didn't find the repository, and we don't have any other error
|
|
662
758
|
* to report, report that. */
|
|
663
|
-
if (!
|
|
759
|
+
if (!git_str_len(gitdir_path)) {
|
|
664
760
|
git_error_set(GIT_ERROR_REPOSITORY, "could not find repository from '%s'", start_path);
|
|
665
761
|
error = GIT_ENOTFOUND;
|
|
666
762
|
goto out;
|
|
667
763
|
}
|
|
668
764
|
|
|
669
765
|
out:
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
766
|
+
git_str_dispose(&path);
|
|
767
|
+
git_str_dispose(&repo_link);
|
|
768
|
+
git_str_dispose(&common_link);
|
|
769
|
+
return error;
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
static int obtain_config_and_set_oid_type(
|
|
773
|
+
git_config **config_ptr,
|
|
774
|
+
git_repository *repo)
|
|
775
|
+
{
|
|
776
|
+
int error;
|
|
777
|
+
git_config *config = NULL;
|
|
778
|
+
int version = 0;
|
|
779
|
+
|
|
780
|
+
/*
|
|
781
|
+
* We'd like to have the config, but git doesn't particularly
|
|
782
|
+
* care if it's not there, so we need to deal with that.
|
|
783
|
+
*/
|
|
784
|
+
|
|
785
|
+
error = git_repository_config_snapshot(&config, repo);
|
|
786
|
+
if (error < 0 && error != GIT_ENOTFOUND)
|
|
787
|
+
goto out;
|
|
788
|
+
|
|
789
|
+
if (config &&
|
|
790
|
+
(error = check_repositoryformatversion(&version, config)) < 0)
|
|
791
|
+
goto out;
|
|
792
|
+
|
|
793
|
+
if ((error = check_extensions(config, version)) < 0)
|
|
794
|
+
goto out;
|
|
795
|
+
|
|
796
|
+
if (version > 0) {
|
|
797
|
+
if ((error = load_objectformat(repo, config)) < 0)
|
|
798
|
+
goto out;
|
|
799
|
+
} else {
|
|
800
|
+
repo->oid_type = GIT_OID_SHA1;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
out:
|
|
804
|
+
*config_ptr = config;
|
|
805
|
+
|
|
673
806
|
return error;
|
|
674
807
|
}
|
|
675
808
|
|
|
@@ -677,18 +810,19 @@ int git_repository_open_bare(
|
|
|
677
810
|
git_repository **repo_ptr,
|
|
678
811
|
const char *bare_path)
|
|
679
812
|
{
|
|
680
|
-
|
|
813
|
+
git_str path = GIT_STR_INIT, common_path = GIT_STR_INIT;
|
|
681
814
|
git_repository *repo = NULL;
|
|
682
815
|
bool is_valid;
|
|
683
816
|
int error;
|
|
817
|
+
git_config *config;
|
|
684
818
|
|
|
685
|
-
if ((error =
|
|
819
|
+
if ((error = git_fs_path_prettify_dir(&path, bare_path, NULL)) < 0 ||
|
|
686
820
|
(error = is_valid_repository_path(&is_valid, &path, &common_path)) < 0)
|
|
687
821
|
return error;
|
|
688
822
|
|
|
689
823
|
if (!is_valid) {
|
|
690
|
-
|
|
691
|
-
|
|
824
|
+
git_str_dispose(&path);
|
|
825
|
+
git_str_dispose(&common_path);
|
|
692
826
|
git_error_set(GIT_ERROR_REPOSITORY, "path is not a repository: %s", bare_path);
|
|
693
827
|
return GIT_ENOTFOUND;
|
|
694
828
|
}
|
|
@@ -696,9 +830,9 @@ int git_repository_open_bare(
|
|
|
696
830
|
repo = repository_alloc();
|
|
697
831
|
GIT_ERROR_CHECK_ALLOC(repo);
|
|
698
832
|
|
|
699
|
-
repo->gitdir =
|
|
833
|
+
repo->gitdir = git_str_detach(&path);
|
|
700
834
|
GIT_ERROR_CHECK_ALLOC(repo->gitdir);
|
|
701
|
-
repo->commondir =
|
|
835
|
+
repo->commondir = git_str_detach(&common_path);
|
|
702
836
|
GIT_ERROR_CHECK_ALLOC(repo->commondir);
|
|
703
837
|
|
|
704
838
|
/* of course we're bare! */
|
|
@@ -706,8 +840,15 @@ int git_repository_open_bare(
|
|
|
706
840
|
repo->is_worktree = 0;
|
|
707
841
|
repo->workdir = NULL;
|
|
708
842
|
|
|
843
|
+
if ((error = obtain_config_and_set_oid_type(&config, repo)) < 0)
|
|
844
|
+
goto cleanup;
|
|
845
|
+
|
|
709
846
|
*repo_ptr = repo;
|
|
710
|
-
|
|
847
|
+
|
|
848
|
+
cleanup:
|
|
849
|
+
git_config_free(config);
|
|
850
|
+
|
|
851
|
+
return error;
|
|
711
852
|
}
|
|
712
853
|
|
|
713
854
|
static int _git_repository_open_ext_from_env(
|
|
@@ -717,15 +858,15 @@ static int _git_repository_open_ext_from_env(
|
|
|
717
858
|
git_repository *repo = NULL;
|
|
718
859
|
git_index *index = NULL;
|
|
719
860
|
git_odb *odb = NULL;
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
861
|
+
git_str dir_buf = GIT_STR_INIT;
|
|
862
|
+
git_str ceiling_dirs_buf = GIT_STR_INIT;
|
|
863
|
+
git_str across_fs_buf = GIT_STR_INIT;
|
|
864
|
+
git_str index_file_buf = GIT_STR_INIT;
|
|
865
|
+
git_str namespace_buf = GIT_STR_INIT;
|
|
866
|
+
git_str object_dir_buf = GIT_STR_INIT;
|
|
867
|
+
git_str alts_buf = GIT_STR_INIT;
|
|
868
|
+
git_str work_tree_buf = GIT_STR_INIT;
|
|
869
|
+
git_str common_dir_buf = GIT_STR_INIT;
|
|
729
870
|
const char *ceiling_dirs = NULL;
|
|
730
871
|
unsigned flags = 0;
|
|
731
872
|
int error;
|
|
@@ -738,7 +879,7 @@ static int _git_repository_open_ext_from_env(
|
|
|
738
879
|
} else if (error < 0)
|
|
739
880
|
goto error;
|
|
740
881
|
else {
|
|
741
|
-
start_path =
|
|
882
|
+
start_path = git_str_cstr(&dir_buf);
|
|
742
883
|
flags |= GIT_REPOSITORY_OPEN_NO_SEARCH;
|
|
743
884
|
flags |= GIT_REPOSITORY_OPEN_NO_DOTGIT;
|
|
744
885
|
}
|
|
@@ -750,7 +891,7 @@ static int _git_repository_open_ext_from_env(
|
|
|
750
891
|
else if (error < 0)
|
|
751
892
|
goto error;
|
|
752
893
|
else
|
|
753
|
-
ceiling_dirs =
|
|
894
|
+
ceiling_dirs = git_str_cstr(&ceiling_dirs_buf);
|
|
754
895
|
|
|
755
896
|
error = git__getenv(&across_fs_buf, "GIT_DISCOVERY_ACROSS_FILESYSTEM");
|
|
756
897
|
if (error == GIT_ENOTFOUND)
|
|
@@ -759,7 +900,7 @@ static int _git_repository_open_ext_from_env(
|
|
|
759
900
|
goto error;
|
|
760
901
|
else {
|
|
761
902
|
int across_fs = 0;
|
|
762
|
-
error = git_config_parse_bool(&across_fs,
|
|
903
|
+
error = git_config_parse_bool(&across_fs, git_str_cstr(&across_fs_buf));
|
|
763
904
|
if (error < 0)
|
|
764
905
|
goto error;
|
|
765
906
|
if (across_fs)
|
|
@@ -772,7 +913,7 @@ static int _git_repository_open_ext_from_env(
|
|
|
772
913
|
else if (error < 0)
|
|
773
914
|
goto error;
|
|
774
915
|
else {
|
|
775
|
-
error = git_index_open(&index,
|
|
916
|
+
error = git_index_open(&index, git_str_cstr(&index_file_buf));
|
|
776
917
|
if (error < 0)
|
|
777
918
|
goto error;
|
|
778
919
|
}
|
|
@@ -789,7 +930,7 @@ static int _git_repository_open_ext_from_env(
|
|
|
789
930
|
else if (error < 0)
|
|
790
931
|
goto error;
|
|
791
932
|
else {
|
|
792
|
-
error =
|
|
933
|
+
error = git_odb__open(&odb, git_str_cstr(&object_dir_buf), NULL);
|
|
793
934
|
if (error < 0)
|
|
794
935
|
goto error;
|
|
795
936
|
}
|
|
@@ -838,7 +979,7 @@ static int _git_repository_open_ext_from_env(
|
|
|
838
979
|
goto error;
|
|
839
980
|
}
|
|
840
981
|
|
|
841
|
-
end =
|
|
982
|
+
end = git_str_cstr(&alts_buf) + git_str_len(&alts_buf);
|
|
842
983
|
for (sep = alt = alts_buf.ptr; sep != end; alt = sep+1) {
|
|
843
984
|
for (sep = alt; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++)
|
|
844
985
|
;
|
|
@@ -850,8 +991,8 @@ static int _git_repository_open_ext_from_env(
|
|
|
850
991
|
}
|
|
851
992
|
}
|
|
852
993
|
|
|
853
|
-
if (
|
|
854
|
-
error = git_repository_set_namespace(repo,
|
|
994
|
+
if (git_str_len(&namespace_buf)) {
|
|
995
|
+
error = git_repository_set_namespace(repo, git_str_cstr(&namespace_buf));
|
|
855
996
|
if (error < 0)
|
|
856
997
|
goto error;
|
|
857
998
|
}
|
|
@@ -867,21 +1008,21 @@ error:
|
|
|
867
1008
|
success:
|
|
868
1009
|
git_odb_free(odb);
|
|
869
1010
|
git_index_free(index);
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
1011
|
+
git_str_dispose(&common_dir_buf);
|
|
1012
|
+
git_str_dispose(&work_tree_buf);
|
|
1013
|
+
git_str_dispose(&alts_buf);
|
|
1014
|
+
git_str_dispose(&object_dir_buf);
|
|
1015
|
+
git_str_dispose(&namespace_buf);
|
|
1016
|
+
git_str_dispose(&index_file_buf);
|
|
1017
|
+
git_str_dispose(&across_fs_buf);
|
|
1018
|
+
git_str_dispose(&ceiling_dirs_buf);
|
|
1019
|
+
git_str_dispose(&dir_buf);
|
|
879
1020
|
return error;
|
|
880
1021
|
}
|
|
881
1022
|
|
|
882
1023
|
static int repo_is_worktree(unsigned *out, const git_repository *repo)
|
|
883
1024
|
{
|
|
884
|
-
|
|
1025
|
+
git_str gitdir_link = GIT_STR_INIT;
|
|
885
1026
|
int error;
|
|
886
1027
|
|
|
887
1028
|
/* Worktrees cannot have the same commondir and gitdir */
|
|
@@ -891,14 +1032,14 @@ static int repo_is_worktree(unsigned *out, const git_repository *repo)
|
|
|
891
1032
|
return 0;
|
|
892
1033
|
}
|
|
893
1034
|
|
|
894
|
-
if ((error =
|
|
1035
|
+
if ((error = git_str_joinpath(&gitdir_link, repo->gitdir, "gitdir")) < 0)
|
|
895
1036
|
return -1;
|
|
896
1037
|
|
|
897
1038
|
/* A 'gitdir' file inside a git directory is currently
|
|
898
1039
|
* only used when the repository is a working tree. */
|
|
899
|
-
*out = !!
|
|
1040
|
+
*out = !!git_fs_path_exists(gitdir_link.ptr);
|
|
900
1041
|
|
|
901
|
-
|
|
1042
|
+
git_str_dispose(&gitdir_link);
|
|
902
1043
|
return error;
|
|
903
1044
|
}
|
|
904
1045
|
|
|
@@ -910,12 +1051,10 @@ int git_repository_open_ext(
|
|
|
910
1051
|
{
|
|
911
1052
|
int error;
|
|
912
1053
|
unsigned is_worktree;
|
|
913
|
-
|
|
914
|
-
gitlink =
|
|
1054
|
+
git_str gitdir = GIT_STR_INIT, workdir = GIT_STR_INIT,
|
|
1055
|
+
gitlink = GIT_STR_INIT, commondir = GIT_STR_INIT;
|
|
915
1056
|
git_repository *repo = NULL;
|
|
916
1057
|
git_config *config = NULL;
|
|
917
|
-
const char *validation_path;
|
|
918
|
-
int version = 0;
|
|
919
1058
|
|
|
920
1059
|
if (flags & GIT_REPOSITORY_OPEN_FROM_ENV)
|
|
921
1060
|
return _git_repository_open_ext_from_env(repo_ptr, start_path);
|
|
@@ -932,15 +1071,15 @@ int git_repository_open_ext(
|
|
|
932
1071
|
repo = repository_alloc();
|
|
933
1072
|
GIT_ERROR_CHECK_ALLOC(repo);
|
|
934
1073
|
|
|
935
|
-
repo->gitdir =
|
|
1074
|
+
repo->gitdir = git_str_detach(&gitdir);
|
|
936
1075
|
GIT_ERROR_CHECK_ALLOC(repo->gitdir);
|
|
937
1076
|
|
|
938
1077
|
if (gitlink.size) {
|
|
939
|
-
repo->gitlink =
|
|
1078
|
+
repo->gitlink = git_str_detach(&gitlink);
|
|
940
1079
|
GIT_ERROR_CHECK_ALLOC(repo->gitlink);
|
|
941
1080
|
}
|
|
942
1081
|
if (commondir.size) {
|
|
943
|
-
repo->commondir =
|
|
1082
|
+
repo->commondir = git_str_detach(&commondir);
|
|
944
1083
|
GIT_ERROR_CHECK_ALLOC(repo->commondir);
|
|
945
1084
|
}
|
|
946
1085
|
|
|
@@ -948,19 +1087,8 @@ int git_repository_open_ext(
|
|
|
948
1087
|
goto cleanup;
|
|
949
1088
|
repo->is_worktree = is_worktree;
|
|
950
1089
|
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
* care if it's not there, so we need to deal with that.
|
|
954
|
-
*/
|
|
955
|
-
|
|
956
|
-
error = git_repository_config_snapshot(&config, repo);
|
|
957
|
-
if (error < 0 && error != GIT_ENOTFOUND)
|
|
958
|
-
goto cleanup;
|
|
959
|
-
|
|
960
|
-
if (config && (error = check_repositoryformatversion(&version, config)) < 0)
|
|
961
|
-
goto cleanup;
|
|
962
|
-
|
|
963
|
-
if ((error = check_extensions(config, version)) < 0)
|
|
1090
|
+
error = obtain_config_and_set_oid_type(&config, repo);
|
|
1091
|
+
if (error < 0)
|
|
964
1092
|
goto cleanup;
|
|
965
1093
|
|
|
966
1094
|
if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0) {
|
|
@@ -973,19 +1101,18 @@ int git_repository_open_ext(
|
|
|
973
1101
|
}
|
|
974
1102
|
|
|
975
1103
|
/*
|
|
976
|
-
* Ensure that the git directory
|
|
1104
|
+
* Ensure that the git directory and worktree are
|
|
1105
|
+
* owned by the current user.
|
|
977
1106
|
*/
|
|
978
|
-
validation_path = repo->is_bare ? repo->gitdir : repo->workdir;
|
|
979
|
-
|
|
980
1107
|
if (git_repository__validate_ownership &&
|
|
981
|
-
(error = validate_ownership(
|
|
1108
|
+
(error = validate_ownership(repo)) < 0)
|
|
982
1109
|
goto cleanup;
|
|
983
1110
|
|
|
984
1111
|
cleanup:
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
1112
|
+
git_str_dispose(&gitdir);
|
|
1113
|
+
git_str_dispose(&workdir);
|
|
1114
|
+
git_str_dispose(&gitlink);
|
|
1115
|
+
git_str_dispose(&commondir);
|
|
989
1116
|
git_config_free(config);
|
|
990
1117
|
|
|
991
1118
|
if (error < 0)
|
|
@@ -1004,7 +1131,7 @@ int git_repository_open(git_repository **repo_out, const char *path)
|
|
|
1004
1131
|
|
|
1005
1132
|
int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *wt)
|
|
1006
1133
|
{
|
|
1007
|
-
|
|
1134
|
+
git_str path = GIT_STR_INIT;
|
|
1008
1135
|
git_repository *repo = NULL;
|
|
1009
1136
|
size_t len;
|
|
1010
1137
|
int err;
|
|
@@ -1020,7 +1147,7 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
|
|
|
1020
1147
|
goto out;
|
|
1021
1148
|
}
|
|
1022
1149
|
|
|
1023
|
-
if ((err =
|
|
1150
|
+
if ((err = git_str_set(&path, wt->gitlink_path, len - 4)) < 0)
|
|
1024
1151
|
goto out;
|
|
1025
1152
|
|
|
1026
1153
|
if ((err = git_repository_open(&repo, path.ptr)) < 0)
|
|
@@ -1029,7 +1156,7 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
|
|
|
1029
1156
|
*repo_out = repo;
|
|
1030
1157
|
|
|
1031
1158
|
out:
|
|
1032
|
-
|
|
1159
|
+
git_str_dispose(&path);
|
|
1033
1160
|
|
|
1034
1161
|
return err;
|
|
1035
1162
|
}
|
|
@@ -1054,14 +1181,10 @@ int git_repository_discover(
|
|
|
1054
1181
|
const char *ceiling_dirs)
|
|
1055
1182
|
{
|
|
1056
1183
|
uint32_t flags = across_fs ? GIT_REPOSITORY_OPEN_CROSS_FS : 0;
|
|
1057
|
-
int error;
|
|
1058
1184
|
|
|
1059
1185
|
GIT_ASSERT_ARG(start_path);
|
|
1060
1186
|
|
|
1061
|
-
|
|
1062
|
-
return error;
|
|
1063
|
-
|
|
1064
|
-
return find_repo(out, NULL, NULL, NULL, start_path, flags, ceiling_dirs);
|
|
1187
|
+
GIT_BUF_WRAP_PRIVATE(out, find_repo, NULL, NULL, NULL, start_path, flags, ceiling_dirs);
|
|
1065
1188
|
}
|
|
1066
1189
|
|
|
1067
1190
|
static int load_config(
|
|
@@ -1073,7 +1196,7 @@ static int load_config(
|
|
|
1073
1196
|
const char *programdata_path)
|
|
1074
1197
|
{
|
|
1075
1198
|
int error;
|
|
1076
|
-
|
|
1199
|
+
git_str config_path = GIT_STR_INIT;
|
|
1077
1200
|
git_config *cfg = NULL;
|
|
1078
1201
|
|
|
1079
1202
|
GIT_ASSERT_ARG(out);
|
|
@@ -1082,13 +1205,13 @@ static int load_config(
|
|
|
1082
1205
|
return error;
|
|
1083
1206
|
|
|
1084
1207
|
if (repo) {
|
|
1085
|
-
if ((error =
|
|
1208
|
+
if ((error = git_repository__item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG)) == 0)
|
|
1086
1209
|
error = git_config_add_file_ondisk(cfg, config_path.ptr, GIT_CONFIG_LEVEL_LOCAL, repo, 0);
|
|
1087
1210
|
|
|
1088
1211
|
if (error && error != GIT_ENOTFOUND)
|
|
1089
1212
|
goto on_error;
|
|
1090
1213
|
|
|
1091
|
-
|
|
1214
|
+
git_str_dispose(&config_path);
|
|
1092
1215
|
}
|
|
1093
1216
|
|
|
1094
1217
|
if (global_config_path != NULL &&
|
|
@@ -1121,15 +1244,15 @@ static int load_config(
|
|
|
1121
1244
|
return 0;
|
|
1122
1245
|
|
|
1123
1246
|
on_error:
|
|
1124
|
-
|
|
1247
|
+
git_str_dispose(&config_path);
|
|
1125
1248
|
git_config_free(cfg);
|
|
1126
1249
|
*out = NULL;
|
|
1127
1250
|
return error;
|
|
1128
1251
|
}
|
|
1129
1252
|
|
|
1130
|
-
static const char *path_unless_empty(
|
|
1253
|
+
static const char *path_unless_empty(git_str *buf)
|
|
1131
1254
|
{
|
|
1132
|
-
return
|
|
1255
|
+
return git_str_len(buf) > 0 ? git_str_cstr(buf) : NULL;
|
|
1133
1256
|
}
|
|
1134
1257
|
|
|
1135
1258
|
int git_repository_config__weakptr(git_config **out, git_repository *repo)
|
|
@@ -1137,19 +1260,19 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
|
|
|
1137
1260
|
int error = 0;
|
|
1138
1261
|
|
|
1139
1262
|
if (repo->_config == NULL) {
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1263
|
+
git_str global_buf = GIT_STR_INIT;
|
|
1264
|
+
git_str xdg_buf = GIT_STR_INIT;
|
|
1265
|
+
git_str system_buf = GIT_STR_INIT;
|
|
1266
|
+
git_str programdata_buf = GIT_STR_INIT;
|
|
1144
1267
|
git_config *config;
|
|
1145
1268
|
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1269
|
+
git_config__find_global(&global_buf);
|
|
1270
|
+
git_config__find_xdg(&xdg_buf);
|
|
1271
|
+
git_config__find_system(&system_buf);
|
|
1272
|
+
git_config__find_programdata(&programdata_buf);
|
|
1150
1273
|
|
|
1151
1274
|
/* If there is no global file, open a backend for it anyway */
|
|
1152
|
-
if (
|
|
1275
|
+
if (git_str_len(&global_buf) == 0)
|
|
1153
1276
|
git_config__global_location(&global_buf);
|
|
1154
1277
|
|
|
1155
1278
|
error = load_config(
|
|
@@ -1167,10 +1290,10 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
|
|
|
1167
1290
|
}
|
|
1168
1291
|
}
|
|
1169
1292
|
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1293
|
+
git_str_dispose(&global_buf);
|
|
1294
|
+
git_str_dispose(&xdg_buf);
|
|
1295
|
+
git_str_dispose(&system_buf);
|
|
1296
|
+
git_str_dispose(&programdata_buf);
|
|
1174
1297
|
}
|
|
1175
1298
|
|
|
1176
1299
|
*out = repo->_config;
|
|
@@ -1215,12 +1338,15 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
|
|
|
1215
1338
|
|
|
1216
1339
|
*out = git_atomic_load(repo->_odb);
|
|
1217
1340
|
if (*out == NULL) {
|
|
1218
|
-
|
|
1341
|
+
git_str odb_path = GIT_STR_INIT;
|
|
1342
|
+
git_odb_options odb_opts = GIT_ODB_OPTIONS_INIT;
|
|
1219
1343
|
git_odb *odb;
|
|
1220
1344
|
|
|
1221
|
-
|
|
1345
|
+
odb_opts.oid_type = repo->oid_type;
|
|
1346
|
+
|
|
1347
|
+
if ((error = git_repository__item_path(&odb_path, repo,
|
|
1222
1348
|
GIT_REPOSITORY_ITEM_OBJECTS)) < 0 ||
|
|
1223
|
-
(error =
|
|
1349
|
+
(error = git_odb__new(&odb, &odb_opts)) < 0)
|
|
1224
1350
|
return error;
|
|
1225
1351
|
|
|
1226
1352
|
GIT_REFCOUNT_OWN(odb, repo);
|
|
@@ -1236,7 +1362,7 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
|
|
|
1236
1362
|
git_odb_free(odb);
|
|
1237
1363
|
}
|
|
1238
1364
|
|
|
1239
|
-
|
|
1365
|
+
git_str_dispose(&odb_path);
|
|
1240
1366
|
*out = git_atomic_load(repo->_odb);
|
|
1241
1367
|
}
|
|
1242
1368
|
|
|
@@ -1312,10 +1438,10 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
|
|
|
1312
1438
|
GIT_ASSERT_ARG(repo);
|
|
1313
1439
|
|
|
1314
1440
|
if (repo->_index == NULL) {
|
|
1315
|
-
|
|
1441
|
+
git_str index_path = GIT_STR_INIT;
|
|
1316
1442
|
git_index *index;
|
|
1317
1443
|
|
|
1318
|
-
if ((error =
|
|
1444
|
+
if ((error = git_str_joinpath(&index_path, repo->gitdir, GIT_INDEX_FILE)) < 0)
|
|
1319
1445
|
return error;
|
|
1320
1446
|
|
|
1321
1447
|
error = git_index_open(&index, index_path.ptr);
|
|
@@ -1331,7 +1457,7 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
|
|
|
1331
1457
|
GIT_INDEX_CAPABILITY_FROM_OWNER);
|
|
1332
1458
|
}
|
|
1333
1459
|
|
|
1334
|
-
|
|
1460
|
+
git_str_dispose(&index_path);
|
|
1335
1461
|
}
|
|
1336
1462
|
|
|
1337
1463
|
*out = repo->_index;
|
|
@@ -1379,7 +1505,7 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
|
|
|
1379
1505
|
const char *def_dot_git = DOT_GIT;
|
|
1380
1506
|
size_t name_len, def_len = CONST_STRLEN(GIT_DIR_SHORTNAME);
|
|
1381
1507
|
size_t def_dot_git_len = CONST_STRLEN(DOT_GIT);
|
|
1382
|
-
|
|
1508
|
+
git_str *buf;
|
|
1383
1509
|
|
|
1384
1510
|
if (!name)
|
|
1385
1511
|
return 0;
|
|
@@ -1395,17 +1521,17 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
|
|
|
1395
1521
|
if ((buf = git_array_alloc(repo->reserved_names)) == NULL)
|
|
1396
1522
|
return -1;
|
|
1397
1523
|
|
|
1398
|
-
|
|
1524
|
+
git_str_attach(buf, name, name_len);
|
|
1399
1525
|
return true;
|
|
1400
1526
|
}
|
|
1401
1527
|
|
|
1402
1528
|
bool git_repository__reserved_names(
|
|
1403
|
-
|
|
1529
|
+
git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs)
|
|
1404
1530
|
{
|
|
1405
1531
|
GIT_UNUSED(include_ntfs);
|
|
1406
1532
|
|
|
1407
1533
|
if (repo->reserved_names.size == 0) {
|
|
1408
|
-
|
|
1534
|
+
git_str *buf;
|
|
1409
1535
|
size_t i;
|
|
1410
1536
|
|
|
1411
1537
|
/* Add the static defaults */
|
|
@@ -1457,7 +1583,7 @@ on_error:
|
|
|
1457
1583
|
}
|
|
1458
1584
|
#else
|
|
1459
1585
|
bool git_repository__reserved_names(
|
|
1460
|
-
|
|
1586
|
+
git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs)
|
|
1461
1587
|
{
|
|
1462
1588
|
GIT_UNUSED(repo);
|
|
1463
1589
|
|
|
@@ -1478,6 +1604,7 @@ static int check_repositoryformatversion(int *version, git_config *config)
|
|
|
1478
1604
|
int error;
|
|
1479
1605
|
|
|
1480
1606
|
error = git_config_get_int32(version, config, "core.repositoryformatversion");
|
|
1607
|
+
|
|
1481
1608
|
/* git ignores this if the config variable isn't there */
|
|
1482
1609
|
if (error == GIT_ENOTFOUND)
|
|
1483
1610
|
return 0;
|
|
@@ -1485,10 +1612,15 @@ static int check_repositoryformatversion(int *version, git_config *config)
|
|
|
1485
1612
|
if (error < 0)
|
|
1486
1613
|
return -1;
|
|
1487
1614
|
|
|
1488
|
-
if (
|
|
1615
|
+
if (*version < 0) {
|
|
1616
|
+
git_error_set(GIT_ERROR_REPOSITORY,
|
|
1617
|
+
"invalid repository version %d", *version);
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
if (GIT_REPO_VERSION_MAX < *version) {
|
|
1489
1621
|
git_error_set(GIT_ERROR_REPOSITORY,
|
|
1490
1622
|
"unsupported repository version %d; only versions up to %d are supported",
|
|
1491
|
-
*version,
|
|
1623
|
+
*version, GIT_REPO_VERSION_MAX);
|
|
1492
1624
|
return -1;
|
|
1493
1625
|
}
|
|
1494
1626
|
|
|
@@ -1496,14 +1628,15 @@ static int check_repositoryformatversion(int *version, git_config *config)
|
|
|
1496
1628
|
}
|
|
1497
1629
|
|
|
1498
1630
|
static const char *builtin_extensions[] = {
|
|
1499
|
-
"noop"
|
|
1631
|
+
"noop",
|
|
1632
|
+
"objectformat"
|
|
1500
1633
|
};
|
|
1501
1634
|
|
|
1502
1635
|
static git_vector user_extensions = GIT_VECTOR_INIT;
|
|
1503
1636
|
|
|
1504
1637
|
static int check_valid_extension(const git_config_entry *entry, void *payload)
|
|
1505
1638
|
{
|
|
1506
|
-
|
|
1639
|
+
git_str cfg = GIT_STR_INIT;
|
|
1507
1640
|
bool reject;
|
|
1508
1641
|
const char *extension;
|
|
1509
1642
|
size_t i;
|
|
@@ -1512,7 +1645,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
|
|
|
1512
1645
|
GIT_UNUSED(payload);
|
|
1513
1646
|
|
|
1514
1647
|
git_vector_foreach (&user_extensions, i, extension) {
|
|
1515
|
-
|
|
1648
|
+
git_str_clear(&cfg);
|
|
1516
1649
|
|
|
1517
1650
|
/*
|
|
1518
1651
|
* Users can specify that they don't want to support an
|
|
@@ -1521,7 +1654,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
|
|
|
1521
1654
|
if ((reject = (extension[0] == '!')) == true)
|
|
1522
1655
|
extension = &extension[1];
|
|
1523
1656
|
|
|
1524
|
-
if ((error =
|
|
1657
|
+
if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0)
|
|
1525
1658
|
goto done;
|
|
1526
1659
|
|
|
1527
1660
|
if (strcmp(entry->name, cfg.ptr) == 0) {
|
|
@@ -1533,9 +1666,10 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
|
|
|
1533
1666
|
}
|
|
1534
1667
|
|
|
1535
1668
|
for (i = 0; i < ARRAY_SIZE(builtin_extensions); i++) {
|
|
1669
|
+
git_str_clear(&cfg);
|
|
1536
1670
|
extension = builtin_extensions[i];
|
|
1537
1671
|
|
|
1538
|
-
if ((error =
|
|
1672
|
+
if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0)
|
|
1539
1673
|
goto done;
|
|
1540
1674
|
|
|
1541
1675
|
if (strcmp(entry->name, cfg.ptr) == 0)
|
|
@@ -1547,7 +1681,7 @@ fail:
|
|
|
1547
1681
|
error = -1;
|
|
1548
1682
|
|
|
1549
1683
|
done:
|
|
1550
|
-
|
|
1684
|
+
git_str_dispose(&cfg);
|
|
1551
1685
|
return error;
|
|
1552
1686
|
}
|
|
1553
1687
|
|
|
@@ -1559,6 +1693,79 @@ static int check_extensions(git_config *config, int version)
|
|
|
1559
1693
|
return git_config_foreach_match(config, "^extensions\\.", check_valid_extension, NULL);
|
|
1560
1694
|
}
|
|
1561
1695
|
|
|
1696
|
+
static int load_objectformat(git_repository *repo, git_config *config)
|
|
1697
|
+
{
|
|
1698
|
+
git_config_entry *entry = NULL;
|
|
1699
|
+
int error;
|
|
1700
|
+
|
|
1701
|
+
if ((error = git_config_get_entry(&entry, config, "extensions.objectformat")) < 0) {
|
|
1702
|
+
if (error == GIT_ENOTFOUND) {
|
|
1703
|
+
repo->oid_type = GIT_OID_SHA1;
|
|
1704
|
+
git_error_clear();
|
|
1705
|
+
error = 0;
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
goto done;
|
|
1709
|
+
}
|
|
1710
|
+
|
|
1711
|
+
if ((repo->oid_type = git_oid_type_fromstr(entry->value)) == 0) {
|
|
1712
|
+
git_error_set(GIT_ERROR_REPOSITORY,
|
|
1713
|
+
"unknown object format '%s'", entry->value);
|
|
1714
|
+
error = GIT_EINVALID;
|
|
1715
|
+
}
|
|
1716
|
+
|
|
1717
|
+
done:
|
|
1718
|
+
git_config_entry_free(entry);
|
|
1719
|
+
return error;
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
int git_repository__set_objectformat(
|
|
1723
|
+
git_repository *repo,
|
|
1724
|
+
git_oid_t oid_type)
|
|
1725
|
+
{
|
|
1726
|
+
git_config *cfg;
|
|
1727
|
+
|
|
1728
|
+
/*
|
|
1729
|
+
* Older clients do not necessarily understand the
|
|
1730
|
+
* `objectformat` extension, even when it's set to an
|
|
1731
|
+
* object format that they understand (SHA1). Do not set
|
|
1732
|
+
* the objectformat extension unless we're not using the
|
|
1733
|
+
* default object format.
|
|
1734
|
+
*/
|
|
1735
|
+
if (oid_type == GIT_OID_DEFAULT)
|
|
1736
|
+
return 0;
|
|
1737
|
+
|
|
1738
|
+
if (!git_repository_is_empty(repo) && repo->oid_type != oid_type) {
|
|
1739
|
+
git_error_set(GIT_ERROR_REPOSITORY,
|
|
1740
|
+
"cannot change object id type of existing repository");
|
|
1741
|
+
return -1;
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
if (git_repository_config__weakptr(&cfg, repo) < 0)
|
|
1745
|
+
return -1;
|
|
1746
|
+
|
|
1747
|
+
if (git_config_set_int32(cfg,
|
|
1748
|
+
"core.repositoryformatversion", 1) < 0 ||
|
|
1749
|
+
git_config_set_string(cfg, "extensions.objectformat",
|
|
1750
|
+
git_oid_type_name(oid_type)) < 0)
|
|
1751
|
+
return -1;
|
|
1752
|
+
|
|
1753
|
+
/*
|
|
1754
|
+
* During repo init, we may create some backends with the
|
|
1755
|
+
* default oid type. Clear them so that we create them with
|
|
1756
|
+
* the proper oid type.
|
|
1757
|
+
*/
|
|
1758
|
+
if (repo->oid_type != oid_type) {
|
|
1759
|
+
set_index(repo, NULL);
|
|
1760
|
+
set_odb(repo, NULL);
|
|
1761
|
+
set_refdb(repo, NULL);
|
|
1762
|
+
|
|
1763
|
+
repo->oid_type = oid_type;
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
return 0;
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1562
1769
|
int git_repository__extensions(char ***out, size_t *out_len)
|
|
1563
1770
|
{
|
|
1564
1771
|
git_vector extensions;
|
|
@@ -1625,12 +1832,12 @@ void git_repository__free_extensions(void)
|
|
|
1625
1832
|
|
|
1626
1833
|
int git_repository_create_head(const char *git_dir, const char *ref_name)
|
|
1627
1834
|
{
|
|
1628
|
-
|
|
1835
|
+
git_str ref_path = GIT_STR_INIT;
|
|
1629
1836
|
git_filebuf ref = GIT_FILEBUF_INIT;
|
|
1630
1837
|
const char *fmt;
|
|
1631
1838
|
int error;
|
|
1632
1839
|
|
|
1633
|
-
if ((error =
|
|
1840
|
+
if ((error = git_str_joinpath(&ref_path, git_dir, GIT_HEAD_FILE)) < 0 ||
|
|
1634
1841
|
(error = git_filebuf_open(&ref, ref_path.ptr, 0, GIT_REFS_FILE_MODE)) < 0)
|
|
1635
1842
|
goto out;
|
|
1636
1843
|
|
|
@@ -1644,7 +1851,7 @@ int git_repository_create_head(const char *git_dir, const char *ref_name)
|
|
|
1644
1851
|
goto out;
|
|
1645
1852
|
|
|
1646
1853
|
out:
|
|
1647
|
-
|
|
1854
|
+
git_str_dispose(&ref_path);
|
|
1648
1855
|
git_filebuf_cleanup(&ref);
|
|
1649
1856
|
return error;
|
|
1650
1857
|
}
|
|
@@ -1667,13 +1874,13 @@ static bool is_chmod_supported(const char *file_path)
|
|
|
1667
1874
|
|
|
1668
1875
|
static bool is_filesystem_case_insensitive(const char *gitdir_path)
|
|
1669
1876
|
{
|
|
1670
|
-
|
|
1877
|
+
git_str path = GIT_STR_INIT;
|
|
1671
1878
|
int is_insensitive = -1;
|
|
1672
1879
|
|
|
1673
|
-
if (!
|
|
1674
|
-
is_insensitive =
|
|
1880
|
+
if (!git_str_joinpath(&path, gitdir_path, "CoNfIg"))
|
|
1881
|
+
is_insensitive = git_fs_path_exists(git_str_cstr(&path));
|
|
1675
1882
|
|
|
1676
|
-
|
|
1883
|
+
git_str_dispose(&path);
|
|
1677
1884
|
return is_insensitive;
|
|
1678
1885
|
}
|
|
1679
1886
|
|
|
@@ -1683,16 +1890,16 @@ static bool is_filesystem_case_insensitive(const char *gitdir_path)
|
|
|
1683
1890
|
*/
|
|
1684
1891
|
static int load_global_config(git_config **config)
|
|
1685
1892
|
{
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1893
|
+
git_str global_buf = GIT_STR_INIT;
|
|
1894
|
+
git_str xdg_buf = GIT_STR_INIT;
|
|
1895
|
+
git_str system_buf = GIT_STR_INIT;
|
|
1896
|
+
git_str programdata_buf = GIT_STR_INIT;
|
|
1690
1897
|
int error;
|
|
1691
1898
|
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1899
|
+
git_config__find_global(&global_buf);
|
|
1900
|
+
git_config__find_xdg(&xdg_buf);
|
|
1901
|
+
git_config__find_system(&system_buf);
|
|
1902
|
+
git_config__find_programdata(&programdata_buf);
|
|
1696
1903
|
|
|
1697
1904
|
error = load_config(config, NULL,
|
|
1698
1905
|
path_unless_empty(&global_buf),
|
|
@@ -1700,10 +1907,10 @@ static int load_global_config(git_config **config)
|
|
|
1700
1907
|
path_unless_empty(&system_buf),
|
|
1701
1908
|
path_unless_empty(&programdata_buf));
|
|
1702
1909
|
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1910
|
+
git_str_dispose(&global_buf);
|
|
1911
|
+
git_str_dispose(&xdg_buf);
|
|
1912
|
+
git_str_dispose(&system_buf);
|
|
1913
|
+
git_str_dispose(&programdata_buf);
|
|
1707
1914
|
|
|
1708
1915
|
return error;
|
|
1709
1916
|
}
|
|
@@ -1727,7 +1934,7 @@ static bool are_symlinks_supported(const char *wd_path)
|
|
|
1727
1934
|
goto done;
|
|
1728
1935
|
#endif
|
|
1729
1936
|
|
|
1730
|
-
if (!(symlinks =
|
|
1937
|
+
if (!(symlinks = git_fs_path_supports_symlinks(wd_path)))
|
|
1731
1938
|
goto done;
|
|
1732
1939
|
|
|
1733
1940
|
done:
|
|
@@ -1754,7 +1961,7 @@ static int create_empty_file(const char *path, mode_t mode)
|
|
|
1754
1961
|
|
|
1755
1962
|
static int repo_local_config(
|
|
1756
1963
|
git_config **out,
|
|
1757
|
-
|
|
1964
|
+
git_str *config_dir,
|
|
1758
1965
|
git_repository *repo,
|
|
1759
1966
|
const char *repo_dir)
|
|
1760
1967
|
{
|
|
@@ -1762,12 +1969,12 @@ static int repo_local_config(
|
|
|
1762
1969
|
git_config *parent;
|
|
1763
1970
|
const char *cfg_path;
|
|
1764
1971
|
|
|
1765
|
-
if (
|
|
1972
|
+
if (git_str_joinpath(config_dir, repo_dir, GIT_CONFIG_FILENAME_INREPO) < 0)
|
|
1766
1973
|
return -1;
|
|
1767
|
-
cfg_path =
|
|
1974
|
+
cfg_path = git_str_cstr(config_dir);
|
|
1768
1975
|
|
|
1769
1976
|
/* make LOCAL config if missing */
|
|
1770
|
-
if (!
|
|
1977
|
+
if (!git_fs_path_isfile(cfg_path) &&
|
|
1771
1978
|
(error = create_empty_file(cfg_path, GIT_CONFIG_FILE_MODE)) < 0)
|
|
1772
1979
|
return error;
|
|
1773
1980
|
|
|
@@ -1825,7 +2032,7 @@ static int repo_init_fs_configs(
|
|
|
1825
2032
|
#ifdef GIT_USE_ICONV
|
|
1826
2033
|
if ((error = git_config_set_bool(
|
|
1827
2034
|
cfg, "core.precomposeunicode",
|
|
1828
|
-
|
|
2035
|
+
git_fs_path_does_decompose_unicode(work_dir))) < 0)
|
|
1829
2036
|
return error;
|
|
1830
2037
|
/* on non-iconv platforms, don't even set core.precomposeunicode */
|
|
1831
2038
|
#endif
|
|
@@ -1837,19 +2044,21 @@ static int repo_init_config(
|
|
|
1837
2044
|
const char *repo_dir,
|
|
1838
2045
|
const char *work_dir,
|
|
1839
2046
|
uint32_t flags,
|
|
1840
|
-
uint32_t mode
|
|
2047
|
+
uint32_t mode,
|
|
2048
|
+
git_oid_t oid_type)
|
|
1841
2049
|
{
|
|
1842
2050
|
int error = 0;
|
|
1843
|
-
|
|
2051
|
+
git_str cfg_path = GIT_STR_INIT, worktree_path = GIT_STR_INIT;
|
|
1844
2052
|
git_config *config = NULL;
|
|
1845
2053
|
bool is_bare = ((flags & GIT_REPOSITORY_INIT_BARE) != 0);
|
|
1846
2054
|
bool is_reinit = ((flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0);
|
|
1847
|
-
int version =
|
|
2055
|
+
int version = GIT_REPO_VERSION_DEFAULT;
|
|
1848
2056
|
|
|
1849
2057
|
if ((error = repo_local_config(&config, &cfg_path, NULL, repo_dir)) < 0)
|
|
1850
2058
|
goto cleanup;
|
|
1851
2059
|
|
|
1852
|
-
if (is_reinit &&
|
|
2060
|
+
if (is_reinit &&
|
|
2061
|
+
(error = check_repositoryformatversion(&version, config)) < 0)
|
|
1853
2062
|
goto cleanup;
|
|
1854
2063
|
|
|
1855
2064
|
if ((error = check_extensions(config, version)) < 0)
|
|
@@ -1860,7 +2069,7 @@ static int repo_init_config(
|
|
|
1860
2069
|
goto cleanup; } while (0)
|
|
1861
2070
|
|
|
1862
2071
|
SET_REPO_CONFIG(bool, "core.bare", is_bare);
|
|
1863
|
-
SET_REPO_CONFIG(int32, "core.repositoryformatversion",
|
|
2072
|
+
SET_REPO_CONFIG(int32, "core.repositoryformatversion", version);
|
|
1864
2073
|
|
|
1865
2074
|
if ((error = repo_init_fs_configs(
|
|
1866
2075
|
config, cfg_path.ptr, repo_dir, work_dir, !is_reinit)) < 0)
|
|
@@ -1870,11 +2079,11 @@ static int repo_init_config(
|
|
|
1870
2079
|
SET_REPO_CONFIG(bool, "core.logallrefupdates", true);
|
|
1871
2080
|
|
|
1872
2081
|
if (!(flags & GIT_REPOSITORY_INIT__NATURAL_WD)) {
|
|
1873
|
-
if ((error =
|
|
2082
|
+
if ((error = git_str_sets(&worktree_path, work_dir)) < 0)
|
|
1874
2083
|
goto cleanup;
|
|
1875
2084
|
|
|
1876
2085
|
if ((flags & GIT_REPOSITORY_INIT_RELATIVE_GITLINK))
|
|
1877
|
-
if ((error =
|
|
2086
|
+
if ((error = git_fs_path_make_relative(&worktree_path, repo_dir)) < 0)
|
|
1878
2087
|
goto cleanup;
|
|
1879
2088
|
|
|
1880
2089
|
SET_REPO_CONFIG(string, "core.worktree", worktree_path.ptr);
|
|
@@ -1893,9 +2102,14 @@ static int repo_init_config(
|
|
|
1893
2102
|
SET_REPO_CONFIG(bool, "receive.denyNonFastforwards", true);
|
|
1894
2103
|
}
|
|
1895
2104
|
|
|
2105
|
+
if (oid_type != GIT_OID_SHA1) {
|
|
2106
|
+
SET_REPO_CONFIG(int32, "core.repositoryformatversion", 1);
|
|
2107
|
+
SET_REPO_CONFIG(string, "extensions.objectformat", git_oid_type_name(oid_type));
|
|
2108
|
+
}
|
|
2109
|
+
|
|
1896
2110
|
cleanup:
|
|
1897
|
-
|
|
1898
|
-
|
|
2111
|
+
git_str_dispose(&cfg_path);
|
|
2112
|
+
git_str_dispose(&worktree_path);
|
|
1899
2113
|
git_config_free(config);
|
|
1900
2114
|
|
|
1901
2115
|
return error;
|
|
@@ -1917,7 +2131,7 @@ static int repo_reinit_submodule_fs(git_submodule *sm, const char *n, void *p)
|
|
|
1917
2131
|
int git_repository_reinit_filesystem(git_repository *repo, int recurse)
|
|
1918
2132
|
{
|
|
1919
2133
|
int error = 0;
|
|
1920
|
-
|
|
2134
|
+
git_str path = GIT_STR_INIT;
|
|
1921
2135
|
git_config *config = NULL;
|
|
1922
2136
|
const char *repo_dir = git_repository_path(repo);
|
|
1923
2137
|
|
|
@@ -1926,7 +2140,7 @@ int git_repository_reinit_filesystem(git_repository *repo, int recurse)
|
|
|
1926
2140
|
config, path.ptr, repo_dir, git_repository_workdir(repo), true);
|
|
1927
2141
|
|
|
1928
2142
|
git_config_free(config);
|
|
1929
|
-
|
|
2143
|
+
git_str_dispose(&path);
|
|
1930
2144
|
|
|
1931
2145
|
git_repository__configmap_lookup_cache_clear(repo);
|
|
1932
2146
|
|
|
@@ -1944,10 +2158,10 @@ static int repo_write_template(
|
|
|
1944
2158
|
bool hidden,
|
|
1945
2159
|
const char *content)
|
|
1946
2160
|
{
|
|
1947
|
-
|
|
2161
|
+
git_str path = GIT_STR_INIT;
|
|
1948
2162
|
int fd, error = 0, flags;
|
|
1949
2163
|
|
|
1950
|
-
if (
|
|
2164
|
+
if (git_str_joinpath(&path, git_dir, file) < 0)
|
|
1951
2165
|
return -1;
|
|
1952
2166
|
|
|
1953
2167
|
if (allow_overwrite)
|
|
@@ -1955,7 +2169,7 @@ static int repo_write_template(
|
|
|
1955
2169
|
else
|
|
1956
2170
|
flags = O_WRONLY | O_CREAT | O_EXCL;
|
|
1957
2171
|
|
|
1958
|
-
fd = p_open(
|
|
2172
|
+
fd = p_open(git_str_cstr(&path), flags, mode);
|
|
1959
2173
|
|
|
1960
2174
|
if (fd >= 0) {
|
|
1961
2175
|
error = p_write(fd, content, strlen(content));
|
|
@@ -1974,7 +2188,7 @@ static int repo_write_template(
|
|
|
1974
2188
|
GIT_UNUSED(hidden);
|
|
1975
2189
|
#endif
|
|
1976
2190
|
|
|
1977
|
-
|
|
2191
|
+
git_str_dispose(&path);
|
|
1978
2192
|
|
|
1979
2193
|
if (error)
|
|
1980
2194
|
git_error_set(GIT_ERROR_OS,
|
|
@@ -1987,13 +2201,13 @@ static int repo_write_gitlink(
|
|
|
1987
2201
|
const char *in_dir, const char *to_repo, bool use_relative_path)
|
|
1988
2202
|
{
|
|
1989
2203
|
int error;
|
|
1990
|
-
|
|
1991
|
-
|
|
2204
|
+
git_str buf = GIT_STR_INIT;
|
|
2205
|
+
git_str path_to_repo = GIT_STR_INIT;
|
|
1992
2206
|
struct stat st;
|
|
1993
2207
|
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
if (
|
|
2208
|
+
git_fs_path_dirname_r(&buf, to_repo);
|
|
2209
|
+
git_fs_path_to_dir(&buf);
|
|
2210
|
+
if (git_str_oom(&buf))
|
|
1997
2211
|
return -1;
|
|
1998
2212
|
|
|
1999
2213
|
/* don't write gitlink to natural workdir */
|
|
@@ -2004,7 +2218,7 @@ static int repo_write_gitlink(
|
|
|
2004
2218
|
goto cleanup;
|
|
2005
2219
|
}
|
|
2006
2220
|
|
|
2007
|
-
if ((error =
|
|
2221
|
+
if ((error = git_str_joinpath(&buf, in_dir, DOT_GIT)) < 0)
|
|
2008
2222
|
goto cleanup;
|
|
2009
2223
|
|
|
2010
2224
|
if (!p_stat(buf.ptr, &st) && !S_ISREG(st.st_mode)) {
|
|
@@ -2014,22 +2228,22 @@ static int repo_write_gitlink(
|
|
|
2014
2228
|
goto cleanup;
|
|
2015
2229
|
}
|
|
2016
2230
|
|
|
2017
|
-
|
|
2231
|
+
git_str_clear(&buf);
|
|
2018
2232
|
|
|
2019
|
-
error =
|
|
2233
|
+
error = git_str_sets(&path_to_repo, to_repo);
|
|
2020
2234
|
|
|
2021
2235
|
if (!error && use_relative_path)
|
|
2022
|
-
error =
|
|
2236
|
+
error = git_fs_path_make_relative(&path_to_repo, in_dir);
|
|
2023
2237
|
|
|
2024
2238
|
if (!error)
|
|
2025
|
-
error =
|
|
2239
|
+
error = git_str_join(&buf, ' ', GIT_FILE_CONTENT_PREFIX, path_to_repo.ptr);
|
|
2026
2240
|
|
|
2027
2241
|
if (!error)
|
|
2028
2242
|
error = repo_write_template(in_dir, true, DOT_GIT, 0666, true, buf.ptr);
|
|
2029
2243
|
|
|
2030
2244
|
cleanup:
|
|
2031
|
-
|
|
2032
|
-
|
|
2245
|
+
git_str_dispose(&buf);
|
|
2246
|
+
git_str_dispose(&path_to_repo);
|
|
2033
2247
|
return error;
|
|
2034
2248
|
}
|
|
2035
2249
|
|
|
@@ -2082,12 +2296,12 @@ static int repo_init_structure(
|
|
|
2082
2296
|
git_config *cfg = NULL;
|
|
2083
2297
|
const char *tdir = NULL;
|
|
2084
2298
|
bool default_template = false;
|
|
2085
|
-
|
|
2299
|
+
git_str template_buf = GIT_STR_INIT;
|
|
2086
2300
|
|
|
2087
2301
|
if (opts->template_path)
|
|
2088
2302
|
tdir = opts->template_path;
|
|
2089
2303
|
else if ((error = git_config_open_default(&cfg)) >= 0) {
|
|
2090
|
-
if (!
|
|
2304
|
+
if (!git_config__get_path(&template_buf, cfg, "init.templatedir"))
|
|
2091
2305
|
tdir = template_buf.ptr;
|
|
2092
2306
|
git_error_clear();
|
|
2093
2307
|
}
|
|
@@ -2113,11 +2327,16 @@ static int repo_init_structure(
|
|
|
2113
2327
|
error = git_futils_cp_r(tdir, repo_dir, cpflags, dmode);
|
|
2114
2328
|
}
|
|
2115
2329
|
|
|
2116
|
-
|
|
2330
|
+
git_str_dispose(&template_buf);
|
|
2117
2331
|
git_config_free(cfg);
|
|
2118
2332
|
|
|
2333
|
+
/* If tdir does not exist, then do not error out. This matches the
|
|
2334
|
+
* behaviour of git(1), which just prints a warning and continues.
|
|
2335
|
+
* TODO: issue warning when warning API is available.
|
|
2336
|
+
* `git` prints to stderr: 'warning: templates not found in /path/to/tdir'
|
|
2337
|
+
*/
|
|
2119
2338
|
if (error < 0) {
|
|
2120
|
-
if (!default_template)
|
|
2339
|
+
if (!default_template && error != GIT_ENOTFOUND)
|
|
2121
2340
|
return error;
|
|
2122
2341
|
|
|
2123
2342
|
/* if template was default, ignore error and use internal */
|
|
@@ -2154,7 +2373,7 @@ static int repo_init_structure(
|
|
|
2154
2373
|
return error;
|
|
2155
2374
|
}
|
|
2156
2375
|
|
|
2157
|
-
static int mkdir_parent(
|
|
2376
|
+
static int mkdir_parent(git_str *buf, uint32_t mode, bool skip2)
|
|
2158
2377
|
{
|
|
2159
2378
|
/* When making parent directories during repository initialization
|
|
2160
2379
|
* don't try to set gid or grant world write access
|
|
@@ -2166,8 +2385,8 @@ static int mkdir_parent(git_buf *buf, uint32_t mode, bool skip2)
|
|
|
2166
2385
|
}
|
|
2167
2386
|
|
|
2168
2387
|
static int repo_init_directories(
|
|
2169
|
-
|
|
2170
|
-
|
|
2388
|
+
git_str *repo_path,
|
|
2389
|
+
git_str *wd_path,
|
|
2171
2390
|
const char *given_repo,
|
|
2172
2391
|
git_repository_init_options *opts)
|
|
2173
2392
|
{
|
|
@@ -2205,7 +2424,7 @@ static int repo_init_directories(
|
|
|
2205
2424
|
git__suffixcmp(given_repo, "/" DOT_GIT) != 0 &&
|
|
2206
2425
|
git__suffixcmp(given_repo, "/" GIT_DIR) != 0;
|
|
2207
2426
|
|
|
2208
|
-
if (
|
|
2427
|
+
if (git_str_joinpath(repo_path, given_repo, add_dotgit ? GIT_DIR : "") < 0)
|
|
2209
2428
|
return -1;
|
|
2210
2429
|
|
|
2211
2430
|
has_dotgit = (git__suffixcmp(repo_path->ptr, "/" GIT_DIR) == 0);
|
|
@@ -2216,11 +2435,11 @@ static int repo_init_directories(
|
|
|
2216
2435
|
|
|
2217
2436
|
if (!is_bare) {
|
|
2218
2437
|
if (opts->workdir_path) {
|
|
2219
|
-
if (
|
|
2438
|
+
if (git_fs_path_join_unrooted(
|
|
2220
2439
|
wd_path, opts->workdir_path, repo_path->ptr, NULL) < 0)
|
|
2221
2440
|
return -1;
|
|
2222
2441
|
} else if (has_dotgit) {
|
|
2223
|
-
if (
|
|
2442
|
+
if (git_fs_path_dirname_r(wd_path, repo_path->ptr) < 0)
|
|
2224
2443
|
return -1;
|
|
2225
2444
|
} else {
|
|
2226
2445
|
git_error_set(GIT_ERROR_REPOSITORY, "cannot pick working directory"
|
|
@@ -2228,10 +2447,10 @@ static int repo_init_directories(
|
|
|
2228
2447
|
return -1;
|
|
2229
2448
|
}
|
|
2230
2449
|
|
|
2231
|
-
if (
|
|
2450
|
+
if (git_fs_path_to_dir(wd_path) < 0)
|
|
2232
2451
|
return -1;
|
|
2233
2452
|
} else {
|
|
2234
|
-
|
|
2453
|
+
git_str_clear(wd_path);
|
|
2235
2454
|
}
|
|
2236
2455
|
|
|
2237
2456
|
natural_wd =
|
|
@@ -2288,10 +2507,10 @@ static int repo_init_directories(
|
|
|
2288
2507
|
/* prettify both directories now that they are created */
|
|
2289
2508
|
|
|
2290
2509
|
if (!error) {
|
|
2291
|
-
error =
|
|
2510
|
+
error = git_fs_path_prettify_dir(repo_path, repo_path->ptr, NULL);
|
|
2292
2511
|
|
|
2293
2512
|
if (!error && wd_path->size > 0)
|
|
2294
|
-
error =
|
|
2513
|
+
error = git_fs_path_prettify_dir(wd_path, wd_path->ptr, NULL);
|
|
2295
2514
|
}
|
|
2296
2515
|
|
|
2297
2516
|
return error;
|
|
@@ -2300,24 +2519,24 @@ static int repo_init_directories(
|
|
|
2300
2519
|
static int repo_init_head(const char *repo_dir, const char *given)
|
|
2301
2520
|
{
|
|
2302
2521
|
git_config *cfg = NULL;
|
|
2303
|
-
|
|
2522
|
+
git_str head_path = GIT_STR_INIT, cfg_branch = GIT_STR_INIT;
|
|
2304
2523
|
const char *initial_head = NULL;
|
|
2305
2524
|
int error;
|
|
2306
2525
|
|
|
2307
|
-
if ((error =
|
|
2526
|
+
if ((error = git_str_joinpath(&head_path, repo_dir, GIT_HEAD_FILE)) < 0)
|
|
2308
2527
|
goto out;
|
|
2309
2528
|
|
|
2310
2529
|
/*
|
|
2311
2530
|
* A template may have set a HEAD; use that unless it's been
|
|
2312
2531
|
* overridden by the caller's given initial head setting.
|
|
2313
2532
|
*/
|
|
2314
|
-
if (
|
|
2533
|
+
if (git_fs_path_exists(head_path.ptr) && !given)
|
|
2315
2534
|
goto out;
|
|
2316
2535
|
|
|
2317
2536
|
if (given) {
|
|
2318
2537
|
initial_head = given;
|
|
2319
2538
|
} else if ((error = git_config_open_default(&cfg)) >= 0 &&
|
|
2320
|
-
(error =
|
|
2539
|
+
(error = git_config__get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0 &&
|
|
2321
2540
|
*cfg_branch.ptr) {
|
|
2322
2541
|
initial_head = cfg_branch.ptr;
|
|
2323
2542
|
}
|
|
@@ -2329,8 +2548,8 @@ static int repo_init_head(const char *repo_dir, const char *given)
|
|
|
2329
2548
|
|
|
2330
2549
|
out:
|
|
2331
2550
|
git_config_free(cfg);
|
|
2332
|
-
|
|
2333
|
-
|
|
2551
|
+
git_str_dispose(&head_path);
|
|
2552
|
+
git_str_dispose(&cfg_branch);
|
|
2334
2553
|
|
|
2335
2554
|
return error;
|
|
2336
2555
|
}
|
|
@@ -2364,10 +2583,11 @@ int git_repository_init_ext(
|
|
|
2364
2583
|
const char *given_repo,
|
|
2365
2584
|
git_repository_init_options *opts)
|
|
2366
2585
|
{
|
|
2367
|
-
|
|
2368
|
-
common_path =
|
|
2586
|
+
git_str repo_path = GIT_STR_INIT, wd_path = GIT_STR_INIT,
|
|
2587
|
+
common_path = GIT_STR_INIT;
|
|
2369
2588
|
const char *wd;
|
|
2370
2589
|
bool is_valid;
|
|
2590
|
+
git_oid_t oid_type = GIT_OID_DEFAULT;
|
|
2371
2591
|
int error;
|
|
2372
2592
|
|
|
2373
2593
|
GIT_ASSERT_ARG(out);
|
|
@@ -2376,10 +2596,15 @@ int git_repository_init_ext(
|
|
|
2376
2596
|
|
|
2377
2597
|
GIT_ERROR_CHECK_VERSION(opts, GIT_REPOSITORY_INIT_OPTIONS_VERSION, "git_repository_init_options");
|
|
2378
2598
|
|
|
2599
|
+
#ifdef GIT_EXPERIMENTAL_SHA256
|
|
2600
|
+
if (opts->oid_type)
|
|
2601
|
+
oid_type = opts->oid_type;
|
|
2602
|
+
#endif
|
|
2603
|
+
|
|
2379
2604
|
if ((error = repo_init_directories(&repo_path, &wd_path, given_repo, opts)) < 0)
|
|
2380
2605
|
goto out;
|
|
2381
2606
|
|
|
2382
|
-
wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL :
|
|
2607
|
+
wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL : git_str_cstr(&wd_path);
|
|
2383
2608
|
|
|
2384
2609
|
if ((error = is_valid_repository_path(&is_valid, &repo_path, &common_path)) < 0)
|
|
2385
2610
|
goto out;
|
|
@@ -2394,13 +2619,13 @@ int git_repository_init_ext(
|
|
|
2394
2619
|
|
|
2395
2620
|
opts->flags |= GIT_REPOSITORY_INIT__IS_REINIT;
|
|
2396
2621
|
|
|
2397
|
-
if ((error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode)) < 0)
|
|
2622
|
+
if ((error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode, oid_type)) < 0)
|
|
2398
2623
|
goto out;
|
|
2399
2624
|
|
|
2400
2625
|
/* TODO: reinitialize the templates */
|
|
2401
2626
|
} else {
|
|
2402
2627
|
if ((error = repo_init_structure(repo_path.ptr, wd, opts)) < 0 ||
|
|
2403
|
-
(error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode)) < 0 ||
|
|
2628
|
+
(error = repo_init_config(repo_path.ptr, wd, opts->flags, opts->mode, oid_type)) < 0 ||
|
|
2404
2629
|
(error = repo_init_head(repo_path.ptr, opts->initial_head)) < 0)
|
|
2405
2630
|
goto out;
|
|
2406
2631
|
}
|
|
@@ -2413,9 +2638,9 @@ int git_repository_init_ext(
|
|
|
2413
2638
|
goto out;
|
|
2414
2639
|
|
|
2415
2640
|
out:
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2641
|
+
git_str_dispose(&common_path);
|
|
2642
|
+
git_str_dispose(&repo_path);
|
|
2643
|
+
git_str_dispose(&wd_path);
|
|
2419
2644
|
|
|
2420
2645
|
return error;
|
|
2421
2646
|
}
|
|
@@ -2603,7 +2828,7 @@ static int repo_contains_no_reference(git_repository *repo)
|
|
|
2603
2828
|
return error;
|
|
2604
2829
|
}
|
|
2605
2830
|
|
|
2606
|
-
int git_repository_initialbranch(
|
|
2831
|
+
int git_repository_initialbranch(git_str *out, git_repository *repo)
|
|
2607
2832
|
{
|
|
2608
2833
|
git_config *config;
|
|
2609
2834
|
git_config_entry *entry = NULL;
|
|
@@ -2624,8 +2849,8 @@ int git_repository_initialbranch(git_buf *out, git_repository *repo)
|
|
|
2624
2849
|
goto done;
|
|
2625
2850
|
}
|
|
2626
2851
|
|
|
2627
|
-
if ((error =
|
|
2628
|
-
(error =
|
|
2852
|
+
if ((error = git_str_puts(out, GIT_REFS_HEADS_DIR)) < 0 ||
|
|
2853
|
+
(error = git_str_puts(out, branch)) < 0 ||
|
|
2629
2854
|
(error = git_reference_name_is_valid(&valid, out->ptr)) < 0)
|
|
2630
2855
|
goto done;
|
|
2631
2856
|
|
|
@@ -2642,7 +2867,7 @@ done:
|
|
|
2642
2867
|
int git_repository_is_empty(git_repository *repo)
|
|
2643
2868
|
{
|
|
2644
2869
|
git_reference *head = NULL;
|
|
2645
|
-
|
|
2870
|
+
git_str initialbranch = GIT_STR_INIT;
|
|
2646
2871
|
int result = 0;
|
|
2647
2872
|
|
|
2648
2873
|
if ((result = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0 ||
|
|
@@ -2655,7 +2880,7 @@ int git_repository_is_empty(git_repository *repo)
|
|
|
2655
2880
|
|
|
2656
2881
|
done:
|
|
2657
2882
|
git_reference_free(head);
|
|
2658
|
-
|
|
2883
|
+
git_str_dispose(&initialbranch);
|
|
2659
2884
|
|
|
2660
2885
|
return result;
|
|
2661
2886
|
}
|
|
@@ -2684,7 +2909,18 @@ static const char *resolved_parent_path(const git_repository *repo, git_reposito
|
|
|
2684
2909
|
return parent;
|
|
2685
2910
|
}
|
|
2686
2911
|
|
|
2687
|
-
int git_repository_item_path(
|
|
2912
|
+
int git_repository_item_path(
|
|
2913
|
+
git_buf *out,
|
|
2914
|
+
const git_repository *repo,
|
|
2915
|
+
git_repository_item_t item)
|
|
2916
|
+
{
|
|
2917
|
+
GIT_BUF_WRAP_PRIVATE(out, git_repository__item_path, repo, item);
|
|
2918
|
+
}
|
|
2919
|
+
|
|
2920
|
+
int git_repository__item_path(
|
|
2921
|
+
git_str *out,
|
|
2922
|
+
const git_repository *repo,
|
|
2923
|
+
git_repository_item_t item)
|
|
2688
2924
|
{
|
|
2689
2925
|
const char *parent = resolved_parent_path(repo, items[item].parent, items[item].fallback);
|
|
2690
2926
|
if (parent == NULL) {
|
|
@@ -2692,16 +2928,16 @@ int git_repository_item_path(git_buf *out, const git_repository *repo, git_repos
|
|
|
2692
2928
|
return GIT_ENOTFOUND;
|
|
2693
2929
|
}
|
|
2694
2930
|
|
|
2695
|
-
if (
|
|
2931
|
+
if (git_str_sets(out, parent) < 0)
|
|
2696
2932
|
return -1;
|
|
2697
2933
|
|
|
2698
2934
|
if (items[item].name) {
|
|
2699
|
-
if (
|
|
2935
|
+
if (git_str_joinpath(out, parent, items[item].name) < 0)
|
|
2700
2936
|
return -1;
|
|
2701
2937
|
}
|
|
2702
2938
|
|
|
2703
2939
|
if (items[item].directory) {
|
|
2704
|
-
if (
|
|
2940
|
+
if (git_fs_path_to_dir(out) < 0)
|
|
2705
2941
|
return -1;
|
|
2706
2942
|
}
|
|
2707
2943
|
|
|
@@ -2725,7 +2961,7 @@ const char *git_repository_workdir(const git_repository *repo)
|
|
|
2725
2961
|
}
|
|
2726
2962
|
|
|
2727
2963
|
int git_repository_workdir_path(
|
|
2728
|
-
|
|
2964
|
+
git_str *out, git_repository *repo, const char *path)
|
|
2729
2965
|
{
|
|
2730
2966
|
int error;
|
|
2731
2967
|
|
|
@@ -2734,8 +2970,8 @@ int git_repository_workdir_path(
|
|
|
2734
2970
|
return GIT_EBAREREPO;
|
|
2735
2971
|
}
|
|
2736
2972
|
|
|
2737
|
-
if (!(error =
|
|
2738
|
-
error =
|
|
2973
|
+
if (!(error = git_str_joinpath(out, repo->workdir, path)))
|
|
2974
|
+
error = git_path_validate_str_length(repo, out);
|
|
2739
2975
|
|
|
2740
2976
|
return error;
|
|
2741
2977
|
}
|
|
@@ -2750,12 +2986,12 @@ int git_repository_set_workdir(
|
|
|
2750
2986
|
git_repository *repo, const char *workdir, int update_gitlink)
|
|
2751
2987
|
{
|
|
2752
2988
|
int error = 0;
|
|
2753
|
-
|
|
2989
|
+
git_str path = GIT_STR_INIT;
|
|
2754
2990
|
|
|
2755
2991
|
GIT_ASSERT_ARG(repo);
|
|
2756
2992
|
GIT_ASSERT_ARG(workdir);
|
|
2757
2993
|
|
|
2758
|
-
if (
|
|
2994
|
+
if (git_fs_path_prettify_dir(&path, workdir, NULL) < 0)
|
|
2759
2995
|
return -1;
|
|
2760
2996
|
|
|
2761
2997
|
if (repo->workdir && strcmp(repo->workdir, path.ptr) == 0)
|
|
@@ -2782,7 +3018,7 @@ int git_repository_set_workdir(
|
|
|
2782
3018
|
if (!error) {
|
|
2783
3019
|
char *old_workdir = repo->workdir;
|
|
2784
3020
|
|
|
2785
|
-
repo->workdir =
|
|
3021
|
+
repo->workdir = git_str_detach(&path);
|
|
2786
3022
|
repo->is_bare = 0;
|
|
2787
3023
|
|
|
2788
3024
|
git__free(old_workdir);
|
|
@@ -2851,60 +3087,62 @@ cleanup:
|
|
|
2851
3087
|
int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head)
|
|
2852
3088
|
{
|
|
2853
3089
|
git_filebuf file = GIT_FILEBUF_INIT;
|
|
2854
|
-
|
|
2855
|
-
char orig_head_str[
|
|
3090
|
+
git_str file_path = GIT_STR_INIT;
|
|
3091
|
+
char orig_head_str[GIT_OID_MAX_HEXSIZE];
|
|
2856
3092
|
int error = 0;
|
|
2857
3093
|
|
|
2858
3094
|
git_oid_fmt(orig_head_str, orig_head);
|
|
2859
3095
|
|
|
2860
|
-
if ((error =
|
|
3096
|
+
if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_ORIG_HEAD_FILE)) == 0 &&
|
|
2861
3097
|
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) == 0 &&
|
|
2862
|
-
(error = git_filebuf_printf(&file, "%.*s\n",
|
|
3098
|
+
(error = git_filebuf_printf(&file, "%.*s\n", (int)git_oid_hexsize(repo->oid_type), orig_head_str)) == 0)
|
|
2863
3099
|
error = git_filebuf_commit(&file);
|
|
2864
3100
|
|
|
2865
3101
|
if (error < 0)
|
|
2866
3102
|
git_filebuf_cleanup(&file);
|
|
2867
3103
|
|
|
2868
|
-
|
|
3104
|
+
git_str_dispose(&file_path);
|
|
2869
3105
|
|
|
2870
3106
|
return error;
|
|
2871
3107
|
}
|
|
2872
3108
|
|
|
2873
|
-
int
|
|
3109
|
+
static int git_repository__message(git_str *out, git_repository *repo)
|
|
2874
3110
|
{
|
|
2875
|
-
|
|
3111
|
+
git_str path = GIT_STR_INIT;
|
|
2876
3112
|
struct stat st;
|
|
2877
3113
|
int error;
|
|
2878
3114
|
|
|
2879
|
-
if ((
|
|
2880
|
-
return error;
|
|
2881
|
-
|
|
2882
|
-
if (git_buf_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
|
|
3115
|
+
if (git_str_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
|
|
2883
3116
|
return -1;
|
|
2884
3117
|
|
|
2885
|
-
if ((error = p_stat(
|
|
3118
|
+
if ((error = p_stat(git_str_cstr(&path), &st)) < 0) {
|
|
2886
3119
|
if (errno == ENOENT)
|
|
2887
3120
|
error = GIT_ENOTFOUND;
|
|
2888
3121
|
git_error_set(GIT_ERROR_OS, "could not access message file");
|
|
2889
3122
|
} else {
|
|
2890
|
-
error = git_futils_readbuffer(out,
|
|
3123
|
+
error = git_futils_readbuffer(out, git_str_cstr(&path));
|
|
2891
3124
|
}
|
|
2892
3125
|
|
|
2893
|
-
|
|
3126
|
+
git_str_dispose(&path);
|
|
2894
3127
|
|
|
2895
3128
|
return error;
|
|
2896
3129
|
}
|
|
2897
3130
|
|
|
3131
|
+
int git_repository_message(git_buf *out, git_repository *repo)
|
|
3132
|
+
{
|
|
3133
|
+
GIT_BUF_WRAP_PRIVATE(out, git_repository__message, repo);
|
|
3134
|
+
}
|
|
3135
|
+
|
|
2898
3136
|
int git_repository_message_remove(git_repository *repo)
|
|
2899
3137
|
{
|
|
2900
|
-
|
|
3138
|
+
git_str path = GIT_STR_INIT;
|
|
2901
3139
|
int error;
|
|
2902
3140
|
|
|
2903
|
-
if (
|
|
3141
|
+
if (git_str_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
|
|
2904
3142
|
return -1;
|
|
2905
3143
|
|
|
2906
|
-
error = p_unlink(
|
|
2907
|
-
|
|
3144
|
+
error = p_unlink(git_str_cstr(&path));
|
|
3145
|
+
git_str_dispose(&path);
|
|
2908
3146
|
|
|
2909
3147
|
return error;
|
|
2910
3148
|
}
|
|
@@ -2920,7 +3158,7 @@ int git_repository_hashfile(
|
|
|
2920
3158
|
git_filter_list *fl = NULL;
|
|
2921
3159
|
git_file fd = -1;
|
|
2922
3160
|
uint64_t len;
|
|
2923
|
-
|
|
3161
|
+
git_str full_path = GIT_STR_INIT;
|
|
2924
3162
|
const char *workdir = git_repository_workdir(repo);
|
|
2925
3163
|
|
|
2926
3164
|
/* as_path can be NULL */
|
|
@@ -2928,8 +3166,8 @@ int git_repository_hashfile(
|
|
|
2928
3166
|
GIT_ASSERT_ARG(path);
|
|
2929
3167
|
GIT_ASSERT_ARG(repo);
|
|
2930
3168
|
|
|
2931
|
-
if ((error =
|
|
2932
|
-
(error =
|
|
3169
|
+
if ((error = git_fs_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 ||
|
|
3170
|
+
(error = git_path_validate_str_length(repo, &full_path)) < 0)
|
|
2933
3171
|
return error;
|
|
2934
3172
|
|
|
2935
3173
|
/*
|
|
@@ -2970,36 +3208,36 @@ int git_repository_hashfile(
|
|
|
2970
3208
|
goto cleanup;
|
|
2971
3209
|
}
|
|
2972
3210
|
|
|
2973
|
-
error = git_odb__hashfd_filtered(out, fd, (size_t)len, type, fl);
|
|
3211
|
+
error = git_odb__hashfd_filtered(out, fd, (size_t)len, type, repo->oid_type, fl);
|
|
2974
3212
|
|
|
2975
3213
|
cleanup:
|
|
2976
3214
|
if (fd >= 0)
|
|
2977
3215
|
p_close(fd);
|
|
2978
3216
|
git_filter_list_free(fl);
|
|
2979
|
-
|
|
3217
|
+
git_str_dispose(&full_path);
|
|
2980
3218
|
|
|
2981
3219
|
return error;
|
|
2982
3220
|
}
|
|
2983
3221
|
|
|
2984
|
-
static int checkout_message(
|
|
3222
|
+
static int checkout_message(git_str *out, git_reference *old, const char *new)
|
|
2985
3223
|
{
|
|
2986
|
-
|
|
3224
|
+
git_str_puts(out, "checkout: moving from ");
|
|
2987
3225
|
|
|
2988
3226
|
if (git_reference_type(old) == GIT_REFERENCE_SYMBOLIC)
|
|
2989
|
-
|
|
3227
|
+
git_str_puts(out, git_reference__shorthand(git_reference_symbolic_target(old)));
|
|
2990
3228
|
else
|
|
2991
|
-
|
|
3229
|
+
git_str_puts(out, git_oid_tostr_s(git_reference_target(old)));
|
|
2992
3230
|
|
|
2993
|
-
|
|
3231
|
+
git_str_puts(out, " to ");
|
|
2994
3232
|
|
|
2995
3233
|
if (git_reference__is_branch(new) ||
|
|
2996
3234
|
git_reference__is_tag(new) ||
|
|
2997
3235
|
git_reference__is_remote(new))
|
|
2998
|
-
|
|
3236
|
+
git_str_puts(out, git_reference__shorthand(new));
|
|
2999
3237
|
else
|
|
3000
|
-
|
|
3238
|
+
git_str_puts(out, new);
|
|
3001
3239
|
|
|
3002
|
-
if (
|
|
3240
|
+
if (git_str_oom(out))
|
|
3003
3241
|
return -1;
|
|
3004
3242
|
|
|
3005
3243
|
return 0;
|
|
@@ -3008,7 +3246,7 @@ static int checkout_message(git_buf *out, git_reference *old, const char *new)
|
|
|
3008
3246
|
static int detach(git_repository *repo, const git_oid *id, const char *new)
|
|
3009
3247
|
{
|
|
3010
3248
|
int error;
|
|
3011
|
-
|
|
3249
|
+
git_str log_message = GIT_STR_INIT;
|
|
3012
3250
|
git_object *object = NULL, *peeled = NULL;
|
|
3013
3251
|
git_reference *new_head = NULL, *current = NULL;
|
|
3014
3252
|
|
|
@@ -3030,10 +3268,10 @@ static int detach(git_repository *repo, const git_oid *id, const char *new)
|
|
|
3030
3268
|
if ((error = checkout_message(&log_message, current, new)) < 0)
|
|
3031
3269
|
goto cleanup;
|
|
3032
3270
|
|
|
3033
|
-
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true,
|
|
3271
|
+
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, git_str_cstr(&log_message));
|
|
3034
3272
|
|
|
3035
3273
|
cleanup:
|
|
3036
|
-
|
|
3274
|
+
git_str_dispose(&log_message);
|
|
3037
3275
|
git_object_free(object);
|
|
3038
3276
|
git_object_free(peeled);
|
|
3039
3277
|
git_reference_free(current);
|
|
@@ -3046,7 +3284,7 @@ int git_repository_set_head(
|
|
|
3046
3284
|
const char *refname)
|
|
3047
3285
|
{
|
|
3048
3286
|
git_reference *ref = NULL, *current = NULL, *new_head = NULL;
|
|
3049
|
-
|
|
3287
|
+
git_str log_message = GIT_STR_INIT;
|
|
3050
3288
|
int error;
|
|
3051
3289
|
|
|
3052
3290
|
GIT_ASSERT_ARG(repo);
|
|
@@ -3073,18 +3311,18 @@ int git_repository_set_head(
|
|
|
3073
3311
|
if (!error) {
|
|
3074
3312
|
if (git_reference_is_branch(ref)) {
|
|
3075
3313
|
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE,
|
|
3076
|
-
git_reference_name(ref), true,
|
|
3314
|
+
git_reference_name(ref), true, git_str_cstr(&log_message));
|
|
3077
3315
|
} else {
|
|
3078
3316
|
error = detach(repo, git_reference_target(ref),
|
|
3079
3317
|
git_reference_is_tag(ref) || git_reference_is_remote(ref) ? refname : NULL);
|
|
3080
3318
|
}
|
|
3081
3319
|
} else if (git_reference__is_branch(refname)) {
|
|
3082
3320
|
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname,
|
|
3083
|
-
true,
|
|
3321
|
+
true, git_str_cstr(&log_message));
|
|
3084
3322
|
}
|
|
3085
3323
|
|
|
3086
3324
|
cleanup:
|
|
3087
|
-
|
|
3325
|
+
git_str_dispose(&log_message);
|
|
3088
3326
|
git_reference_free(current);
|
|
3089
3327
|
git_reference_free(ref);
|
|
3090
3328
|
git_reference_free(new_head);
|
|
@@ -3093,26 +3331,26 @@ cleanup:
|
|
|
3093
3331
|
|
|
3094
3332
|
int git_repository_set_head_detached(
|
|
3095
3333
|
git_repository *repo,
|
|
3096
|
-
const git_oid *
|
|
3334
|
+
const git_oid *committish)
|
|
3097
3335
|
{
|
|
3098
|
-
return detach(repo,
|
|
3336
|
+
return detach(repo, committish, NULL);
|
|
3099
3337
|
}
|
|
3100
3338
|
|
|
3101
3339
|
int git_repository_set_head_detached_from_annotated(
|
|
3102
3340
|
git_repository *repo,
|
|
3103
|
-
const git_annotated_commit *
|
|
3341
|
+
const git_annotated_commit *committish)
|
|
3104
3342
|
{
|
|
3105
3343
|
GIT_ASSERT_ARG(repo);
|
|
3106
|
-
GIT_ASSERT_ARG(
|
|
3344
|
+
GIT_ASSERT_ARG(committish);
|
|
3107
3345
|
|
|
3108
|
-
return detach(repo, git_annotated_commit_id(
|
|
3346
|
+
return detach(repo, git_annotated_commit_id(committish), committish->description);
|
|
3109
3347
|
}
|
|
3110
3348
|
|
|
3111
3349
|
int git_repository_detach_head(git_repository *repo)
|
|
3112
3350
|
{
|
|
3113
3351
|
git_reference *old_head = NULL, *new_head = NULL, *current = NULL;
|
|
3114
3352
|
git_object *object = NULL;
|
|
3115
|
-
|
|
3353
|
+
git_str log_message = GIT_STR_INIT;
|
|
3116
3354
|
int error;
|
|
3117
3355
|
|
|
3118
3356
|
GIT_ASSERT_ARG(repo);
|
|
@@ -3130,10 +3368,10 @@ int git_repository_detach_head(git_repository *repo)
|
|
|
3130
3368
|
goto cleanup;
|
|
3131
3369
|
|
|
3132
3370
|
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head),
|
|
3133
|
-
1,
|
|
3371
|
+
1, git_str_cstr(&log_message));
|
|
3134
3372
|
|
|
3135
3373
|
cleanup:
|
|
3136
|
-
|
|
3374
|
+
git_str_dispose(&log_message);
|
|
3137
3375
|
git_object_free(object);
|
|
3138
3376
|
git_reference_free(old_head);
|
|
3139
3377
|
git_reference_free(new_head);
|
|
@@ -3147,69 +3385,69 @@ cleanup:
|
|
|
3147
3385
|
*/
|
|
3148
3386
|
int git_repository_state(git_repository *repo)
|
|
3149
3387
|
{
|
|
3150
|
-
|
|
3388
|
+
git_str repo_path = GIT_STR_INIT;
|
|
3151
3389
|
int state = GIT_REPOSITORY_STATE_NONE;
|
|
3152
3390
|
|
|
3153
3391
|
GIT_ASSERT_ARG(repo);
|
|
3154
3392
|
|
|
3155
|
-
if (
|
|
3393
|
+
if (git_str_puts(&repo_path, repo->gitdir) < 0)
|
|
3156
3394
|
return -1;
|
|
3157
3395
|
|
|
3158
|
-
if (
|
|
3396
|
+
if (git_fs_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE))
|
|
3159
3397
|
state = GIT_REPOSITORY_STATE_REBASE_INTERACTIVE;
|
|
3160
|
-
else if (
|
|
3398
|
+
else if (git_fs_path_contains_dir(&repo_path, GIT_REBASE_MERGE_DIR))
|
|
3161
3399
|
state = GIT_REPOSITORY_STATE_REBASE_MERGE;
|
|
3162
|
-
else if (
|
|
3400
|
+
else if (git_fs_path_contains_file(&repo_path, GIT_REBASE_APPLY_REBASING_FILE))
|
|
3163
3401
|
state = GIT_REPOSITORY_STATE_REBASE;
|
|
3164
|
-
else if (
|
|
3402
|
+
else if (git_fs_path_contains_file(&repo_path, GIT_REBASE_APPLY_APPLYING_FILE))
|
|
3165
3403
|
state = GIT_REPOSITORY_STATE_APPLY_MAILBOX;
|
|
3166
|
-
else if (
|
|
3404
|
+
else if (git_fs_path_contains_dir(&repo_path, GIT_REBASE_APPLY_DIR))
|
|
3167
3405
|
state = GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE;
|
|
3168
|
-
else if (
|
|
3406
|
+
else if (git_fs_path_contains_file(&repo_path, GIT_MERGE_HEAD_FILE))
|
|
3169
3407
|
state = GIT_REPOSITORY_STATE_MERGE;
|
|
3170
|
-
else if (
|
|
3408
|
+
else if (git_fs_path_contains_file(&repo_path, GIT_REVERT_HEAD_FILE)) {
|
|
3171
3409
|
state = GIT_REPOSITORY_STATE_REVERT;
|
|
3172
|
-
if (
|
|
3410
|
+
if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
|
|
3173
3411
|
state = GIT_REPOSITORY_STATE_REVERT_SEQUENCE;
|
|
3174
3412
|
}
|
|
3175
|
-
} else if (
|
|
3413
|
+
} else if (git_fs_path_contains_file(&repo_path, GIT_CHERRYPICK_HEAD_FILE)) {
|
|
3176
3414
|
state = GIT_REPOSITORY_STATE_CHERRYPICK;
|
|
3177
|
-
if (
|
|
3415
|
+
if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
|
|
3178
3416
|
state = GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE;
|
|
3179
3417
|
}
|
|
3180
|
-
} else if (
|
|
3418
|
+
} else if (git_fs_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE))
|
|
3181
3419
|
state = GIT_REPOSITORY_STATE_BISECT;
|
|
3182
3420
|
|
|
3183
|
-
|
|
3421
|
+
git_str_dispose(&repo_path);
|
|
3184
3422
|
return state;
|
|
3185
3423
|
}
|
|
3186
3424
|
|
|
3187
3425
|
int git_repository__cleanup_files(
|
|
3188
3426
|
git_repository *repo, const char *files[], size_t files_len)
|
|
3189
3427
|
{
|
|
3190
|
-
|
|
3428
|
+
git_str buf = GIT_STR_INIT;
|
|
3191
3429
|
size_t i;
|
|
3192
3430
|
int error;
|
|
3193
3431
|
|
|
3194
3432
|
for (error = 0, i = 0; !error && i < files_len; ++i) {
|
|
3195
3433
|
const char *path;
|
|
3196
3434
|
|
|
3197
|
-
if (
|
|
3435
|
+
if (git_str_joinpath(&buf, repo->gitdir, files[i]) < 0)
|
|
3198
3436
|
return -1;
|
|
3199
3437
|
|
|
3200
|
-
path =
|
|
3438
|
+
path = git_str_cstr(&buf);
|
|
3201
3439
|
|
|
3202
|
-
if (
|
|
3440
|
+
if (git_fs_path_isfile(path)) {
|
|
3203
3441
|
error = p_unlink(path);
|
|
3204
|
-
} else if (
|
|
3442
|
+
} else if (git_fs_path_isdir(path)) {
|
|
3205
3443
|
error = git_futils_rmdir_r(path, NULL,
|
|
3206
3444
|
GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS);
|
|
3207
3445
|
}
|
|
3208
3446
|
|
|
3209
|
-
|
|
3447
|
+
git_str_clear(&buf);
|
|
3210
3448
|
}
|
|
3211
3449
|
|
|
3212
|
-
|
|
3450
|
+
git_str_dispose(&buf);
|
|
3213
3451
|
return error;
|
|
3214
3452
|
}
|
|
3215
3453
|
|
|
@@ -3234,15 +3472,15 @@ int git_repository_state_cleanup(git_repository *repo)
|
|
|
3234
3472
|
|
|
3235
3473
|
int git_repository_is_shallow(git_repository *repo)
|
|
3236
3474
|
{
|
|
3237
|
-
|
|
3475
|
+
git_str path = GIT_STR_INIT;
|
|
3238
3476
|
struct stat st;
|
|
3239
3477
|
int error;
|
|
3240
3478
|
|
|
3241
|
-
if ((error =
|
|
3479
|
+
if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0)
|
|
3242
3480
|
return error;
|
|
3243
3481
|
|
|
3244
|
-
error =
|
|
3245
|
-
|
|
3482
|
+
error = git_fs_path_lstat(path.ptr, &st);
|
|
3483
|
+
git_str_dispose(&path);
|
|
3246
3484
|
|
|
3247
3485
|
if (error == GIT_ENOTFOUND) {
|
|
3248
3486
|
git_error_clear();
|
|
@@ -3317,3 +3555,8 @@ int git_repository_submodule_cache_clear(git_repository *repo)
|
|
|
3317
3555
|
repo->submodule_cache = NULL;
|
|
3318
3556
|
return error;
|
|
3319
3557
|
}
|
|
3558
|
+
|
|
3559
|
+
git_oid_t git_repository_oid_type(git_repository *repo)
|
|
3560
|
+
{
|
|
3561
|
+
return repo ? repo->oid_type : 0;
|
|
3562
|
+
}
|