rugged 1.3.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/rugged/extconf.rb +1 -1
- data/ext/rugged/rugged_config.c +7 -2
- data/ext/rugged/rugged_remote.c +17 -0
- data/lib/rugged/version.rb +1 -1
- data/vendor/libgit2/CMakeLists.txt +103 -276
- data/vendor/libgit2/COPYING +36 -19
- data/vendor/libgit2/cmake/AddCFlagIfSupported.cmake +21 -21
- data/vendor/libgit2/cmake/DefaultCFlags.cmake +154 -0
- data/vendor/libgit2/cmake/EnableWarnings.cmake +13 -13
- 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 +13 -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 +39 -49
- 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 +31 -31
- data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +1 -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/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 +2 -0
- 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 +4 -1
- data/vendor/libgit2/include/git2/config.h +19 -3
- 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 +1 -1
- data/vendor/libgit2/include/git2/describe.h +7 -2
- data/vendor/libgit2/include/git2/diff.h +17 -9
- data/vendor/libgit2/include/git2/email.h +1 -1
- data/vendor/libgit2/include/git2/errors.h +1 -1
- 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 +19 -0
- data/vendor/libgit2/include/git2/merge.h +23 -3
- data/vendor/libgit2/include/git2/message.h +2 -0
- data/vendor/libgit2/include/git2/object.h +23 -0
- data/vendor/libgit2/include/git2/odb.h +37 -7
- data/vendor/libgit2/include/git2/odb_backend.h +1 -1
- 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 +14 -9
- 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 +3 -3
- data/vendor/libgit2/include/git2/status.h +9 -3
- 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 +2 -5
- data/vendor/libgit2/include/git2/sys/remote.h +31 -0
- data/vendor/libgit2/include/git2/sys/stream.h +1 -1
- data/vendor/libgit2/include/git2/sys/transport.h +25 -34
- 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 +4 -4
- data/vendor/libgit2/include/git2/worktree.h +12 -2
- data/vendor/libgit2/src/CMakeLists.txt +189 -315
- data/vendor/libgit2/src/annotated_commit.h +1 -1
- data/vendor/libgit2/src/apply.c +18 -18
- data/vendor/libgit2/src/apply.h +2 -2
- data/vendor/libgit2/src/attr.c +18 -18
- data/vendor/libgit2/src/attr_file.c +17 -17
- data/vendor/libgit2/src/attr_file.h +4 -4
- data/vendor/libgit2/src/attrcache.c +17 -12
- data/vendor/libgit2/src/blame_git.c +1 -1
- data/vendor/libgit2/src/blob.c +33 -26
- data/vendor/libgit2/src/blob.h +1 -1
- data/vendor/libgit2/src/branch.c +150 -109
- data/vendor/libgit2/src/branch.h +15 -3
- data/vendor/libgit2/src/buf.c +126 -0
- data/vendor/libgit2/src/buf.h +50 -0
- data/vendor/libgit2/src/cc-compat.h +1 -1
- data/vendor/libgit2/src/checkout.c +74 -68
- data/vendor/libgit2/src/cherrypick.c +10 -10
- data/vendor/libgit2/src/clone.c +66 -66
- data/vendor/libgit2/src/commit.c +128 -58
- data/vendor/libgit2/src/commit.h +24 -1
- data/vendor/libgit2/src/commit_graph.c +68 -53
- data/vendor/libgit2/src/commit_graph.h +10 -3
- data/vendor/libgit2/src/commit_list.c +2 -3
- data/vendor/libgit2/src/common.h +10 -3
- data/vendor/libgit2/src/config.c +97 -68
- data/vendor/libgit2/src/config.h +15 -2
- data/vendor/libgit2/src/config_file.c +103 -91
- data/vendor/libgit2/src/config_mem.c +9 -9
- data/vendor/libgit2/src/config_parse.c +27 -23
- data/vendor/libgit2/src/crlf.c +24 -21
- data/vendor/libgit2/src/date.c +10 -17
- data/vendor/libgit2/src/date.h +33 -0
- data/vendor/libgit2/src/describe.c +27 -19
- data/vendor/libgit2/src/diff.c +25 -8
- data/vendor/libgit2/src/diff.h +2 -4
- data/vendor/libgit2/src/diff_driver.c +34 -36
- data/vendor/libgit2/src/diff_driver.h +3 -3
- data/vendor/libgit2/src/diff_file.c +29 -20
- data/vendor/libgit2/src/diff_generate.c +30 -6
- data/vendor/libgit2/src/diff_generate.h +5 -3
- data/vendor/libgit2/src/diff_print.c +102 -95
- data/vendor/libgit2/src/diff_stats.c +40 -29
- data/vendor/libgit2/src/{message.h → diff_stats.h} +7 -6
- data/vendor/libgit2/src/diff_tform.c +9 -8
- data/vendor/libgit2/src/diff_xdiff.c +3 -8
- data/vendor/libgit2/src/email.c +54 -38
- data/vendor/libgit2/src/email.h +1 -1
- data/vendor/libgit2/src/errors.c +18 -18
- data/vendor/libgit2/src/features.h.in +6 -1
- data/vendor/libgit2/src/fetch.c +69 -24
- data/vendor/libgit2/src/fetch.h +1 -1
- data/vendor/libgit2/src/fetchhead.c +19 -19
- data/vendor/libgit2/src/filebuf.c +28 -28
- data/vendor/libgit2/src/filebuf.h +1 -1
- data/vendor/libgit2/src/filter.c +96 -52
- data/vendor/libgit2/src/filter.h +26 -5
- data/vendor/libgit2/src/fs_path.c +1912 -0
- data/vendor/libgit2/src/fs_path.h +752 -0
- data/vendor/libgit2/src/futils.c +91 -85
- data/vendor/libgit2/src/futils.h +26 -14
- data/vendor/libgit2/src/hash/sha1/collisiondetect.c +2 -2
- data/vendor/libgit2/src/hash/sha1/common_crypto.c +2 -2
- data/vendor/libgit2/src/hash/sha1/generic.c +2 -2
- data/vendor/libgit2/src/hash/sha1/mbedtls.c +2 -2
- data/vendor/libgit2/src/hash/sha1/openssl.c +2 -2
- data/vendor/libgit2/src/hash/sha1/sha1dc/sha1.c +1 -1
- data/vendor/libgit2/src/hash/sha1/win32.c +6 -6
- data/vendor/libgit2/src/hash/sha1.h +3 -1
- data/vendor/libgit2/src/hash.c +67 -35
- data/vendor/libgit2/src/hash.h +12 -12
- data/vendor/libgit2/src/ident.c +18 -18
- data/vendor/libgit2/src/ignore.c +35 -34
- data/vendor/libgit2/src/ignore.h +2 -2
- data/vendor/libgit2/src/index.c +79 -80
- data/vendor/libgit2/src/index.h +6 -3
- data/vendor/libgit2/src/indexer.c +75 -57
- data/vendor/libgit2/src/iterator.c +64 -56
- data/vendor/libgit2/src/iterator.h +5 -5
- data/vendor/libgit2/src/khash.h +1 -1
- data/vendor/libgit2/src/libgit2.c +22 -11
- data/vendor/libgit2/src/mailmap.c +38 -36
- data/vendor/libgit2/src/merge.c +27 -27
- data/vendor/libgit2/src/merge.h +1 -14
- data/vendor/libgit2/src/merge_driver.c +2 -2
- data/vendor/libgit2/src/merge_file.c +13 -3
- data/vendor/libgit2/src/message.c +21 -10
- data/vendor/libgit2/src/midx.c +83 -66
- data/vendor/libgit2/src/midx.h +3 -3
- data/vendor/libgit2/src/mwindow.c +1 -1
- data/vendor/libgit2/src/net.c +278 -68
- data/vendor/libgit2/src/net.h +10 -3
- data/vendor/libgit2/src/netops.c +1 -1
- data/vendor/libgit2/src/netops.h +1 -1
- data/vendor/libgit2/src/notes.c +20 -29
- data/vendor/libgit2/src/object.c +49 -9
- data/vendor/libgit2/src/object.h +1 -1
- data/vendor/libgit2/src/odb.c +35 -32
- data/vendor/libgit2/src/odb.h +1 -1
- data/vendor/libgit2/src/odb_loose.c +68 -68
- data/vendor/libgit2/src/odb_mempack.c +18 -5
- data/vendor/libgit2/src/odb_pack.c +43 -43
- data/vendor/libgit2/src/oid.c +11 -4
- data/vendor/libgit2/src/oid.h +15 -0
- data/vendor/libgit2/src/pack-objects.c +41 -26
- data/vendor/libgit2/src/pack-objects.h +11 -6
- data/vendor/libgit2/src/pack.c +10 -10
- data/vendor/libgit2/src/patch.c +3 -3
- data/vendor/libgit2/src/patch.h +1 -0
- data/vendor/libgit2/src/patch_generate.c +27 -11
- data/vendor/libgit2/src/patch_generate.h +5 -5
- data/vendor/libgit2/src/patch_parse.c +24 -24
- data/vendor/libgit2/src/path.c +76 -1803
- data/vendor/libgit2/src/path.h +34 -703
- data/vendor/libgit2/src/pathspec.c +6 -6
- data/vendor/libgit2/src/pathspec.h +2 -2
- data/vendor/libgit2/src/posix.c +3 -3
- data/vendor/libgit2/src/posix.h +1 -0
- data/vendor/libgit2/src/pqueue.h +1 -1
- data/vendor/libgit2/src/proxy.c +4 -1
- data/vendor/libgit2/src/proxy.h +1 -1
- data/vendor/libgit2/src/push.c +30 -35
- data/vendor/libgit2/src/push.h +4 -16
- data/vendor/libgit2/src/rand.c +226 -0
- data/vendor/libgit2/src/rand.h +37 -0
- data/vendor/libgit2/src/reader.c +8 -8
- data/vendor/libgit2/src/reader.h +2 -2
- data/vendor/libgit2/src/rebase.c +89 -88
- data/vendor/libgit2/src/refdb_fs.c +447 -173
- data/vendor/libgit2/src/refs.c +32 -32
- data/vendor/libgit2/src/refs.h +2 -2
- data/vendor/libgit2/src/refspec.c +32 -37
- data/vendor/libgit2/src/refspec.h +5 -2
- data/vendor/libgit2/src/regexp.c +1 -1
- data/vendor/libgit2/src/remote.c +713 -419
- data/vendor/libgit2/src/remote.h +15 -10
- data/vendor/libgit2/src/repository.c +338 -323
- data/vendor/libgit2/src/repository.h +11 -9
- data/vendor/libgit2/src/reset.c +8 -5
- data/vendor/libgit2/src/revert.c +10 -10
- data/vendor/libgit2/src/revparse.c +48 -35
- data/vendor/libgit2/src/revwalk.c +7 -7
- data/vendor/libgit2/src/signature.c +12 -6
- data/vendor/libgit2/src/signature.h +1 -1
- data/vendor/libgit2/src/sortedcache.c +1 -1
- data/vendor/libgit2/src/sortedcache.h +1 -1
- data/vendor/libgit2/src/stash.c +36 -37
- data/vendor/libgit2/src/status.c +4 -1
- data/vendor/libgit2/src/{buffer.c → str.c} +157 -151
- data/vendor/libgit2/src/str.h +357 -0
- data/vendor/libgit2/src/streams/mbedtls.c +8 -6
- data/vendor/libgit2/src/streams/openssl_dynamic.h +3 -3
- data/vendor/libgit2/src/submodule.c +171 -159
- data/vendor/libgit2/src/submodule.h +1 -1
- data/vendor/libgit2/src/sysdir.c +68 -52
- data/vendor/libgit2/src/sysdir.h +15 -10
- data/vendor/libgit2/src/tag.c +29 -27
- data/vendor/libgit2/src/thread.h +3 -3
- data/vendor/libgit2/src/threadstate.c +3 -3
- data/vendor/libgit2/src/threadstate.h +1 -1
- data/vendor/libgit2/src/trace.c +1 -14
- data/vendor/libgit2/src/trace.h +5 -22
- data/vendor/libgit2/src/trailer.c +1 -1
- data/vendor/libgit2/src/transaction.c +1 -1
- data/vendor/libgit2/src/transport.c +10 -10
- data/vendor/libgit2/src/transports/auth.c +7 -9
- data/vendor/libgit2/src/transports/auth.h +2 -3
- data/vendor/libgit2/src/transports/auth_negotiate.c +12 -13
- data/vendor/libgit2/src/transports/auth_ntlm.c +10 -10
- data/vendor/libgit2/src/transports/auth_ntlm.h +0 -1
- data/vendor/libgit2/src/transports/git.c +9 -11
- data/vendor/libgit2/src/transports/http.c +37 -17
- data/vendor/libgit2/src/transports/http.h +2 -3
- data/vendor/libgit2/src/transports/httpclient.c +65 -65
- data/vendor/libgit2/src/transports/local.c +124 -116
- data/vendor/libgit2/src/transports/smart.c +51 -139
- data/vendor/libgit2/src/transports/smart.h +25 -31
- data/vendor/libgit2/src/transports/smart_pkt.c +33 -33
- data/vendor/libgit2/src/transports/smart_protocol.c +57 -39
- data/vendor/libgit2/src/transports/ssh.c +47 -112
- data/vendor/libgit2/src/transports/winhttp.c +50 -56
- data/vendor/libgit2/src/tree-cache.c +5 -5
- data/vendor/libgit2/src/tree-cache.h +2 -2
- data/vendor/libgit2/src/tree.c +59 -48
- data/vendor/libgit2/src/tree.h +1 -1
- data/vendor/libgit2/src/unix/map.c +0 -2
- data/vendor/libgit2/src/unix/posix.h +1 -4
- data/vendor/libgit2/src/unix/realpath.c +0 -2
- data/vendor/libgit2/src/util.c +14 -14
- data/vendor/libgit2/src/util.h +2 -28
- data/vendor/libgit2/src/vector.h +1 -1
- data/vendor/libgit2/src/win32/findfile.c +172 -116
- data/vendor/libgit2/src/win32/findfile.h +7 -4
- data/vendor/libgit2/src/win32/path_w32.c +140 -9
- data/vendor/libgit2/src/win32/path_w32.h +2 -0
- data/vendor/libgit2/src/win32/posix.h +0 -1
- data/vendor/libgit2/src/win32/posix_w32.c +11 -27
- data/vendor/libgit2/src/win32/w32_buffer.c +2 -3
- data/vendor/libgit2/src/win32/w32_buffer.h +2 -3
- data/vendor/libgit2/src/win32/w32_leakcheck.c +1 -1
- data/vendor/libgit2/src/worktree.c +116 -94
- data/vendor/libgit2/src/worktree.h +1 -1
- data/vendor/libgit2/src/xdiff/git-xdiff.h +53 -0
- data/vendor/libgit2/src/xdiff/xdiff.h +15 -15
- data/vendor/libgit2/src/xdiff/xdiffi.c +134 -108
- data/vendor/libgit2/src/xdiff/xemit.c +23 -7
- data/vendor/libgit2/src/xdiff/xhistogram.c +87 -78
- data/vendor/libgit2/src/xdiff/xinclude.h +1 -12
- data/vendor/libgit2/src/xdiff/xmerge.c +104 -117
- data/vendor/libgit2/src/xdiff/xpatience.c +6 -17
- data/vendor/libgit2/src/xdiff/xprepare.c +15 -20
- data/vendor/libgit2/src/xdiff/xutils.c +18 -7
- data/vendor/libgit2/src/zstream.c +5 -5
- data/vendor/libgit2/src/zstream.h +4 -4
- metadata +25 -10
- data/vendor/libgit2/src/buffer.h +0 -374
@@ -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
|
@@ -75,13 +76,13 @@ static int check_extensions(git_config *config, int version);
|
|
75
76
|
#define GIT_REPO_VERSION 0
|
76
77
|
#define GIT_REPO_MAX_VERSION 1
|
77
78
|
|
78
|
-
|
79
|
+
git_str git_repository__reserved_names_win32[] = {
|
79
80
|
{ DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
|
80
81
|
{ GIT_DIR_SHORTNAME, 0, CONST_STRLEN(GIT_DIR_SHORTNAME) }
|
81
82
|
};
|
82
83
|
size_t git_repository__reserved_names_win32_len = 2;
|
83
84
|
|
84
|
-
|
85
|
+
git_str git_repository__reserved_names_posix[] = {
|
85
86
|
{ DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
|
86
87
|
};
|
87
88
|
size_t git_repository__reserved_names_posix_len = 1;
|
@@ -171,7 +172,7 @@ void git_repository_free(git_repository *repo)
|
|
171
172
|
repo->diff_drivers = NULL;
|
172
173
|
|
173
174
|
for (i = 0; i < repo->reserved_names.size; i++)
|
174
|
-
|
175
|
+
git_str_dispose(git_array_get(repo->reserved_names, i));
|
175
176
|
git_array_clear(repo->reserved_names);
|
176
177
|
|
177
178
|
git__free(repo->gitlink);
|
@@ -187,18 +188,18 @@ void git_repository_free(git_repository *repo)
|
|
187
188
|
}
|
188
189
|
|
189
190
|
/* Check if we have a separate commondir (e.g. we have a worktree) */
|
190
|
-
static int lookup_commondir(bool *separate,
|
191
|
+
static int lookup_commondir(bool *separate, git_str *commondir, git_str *repository_path)
|
191
192
|
{
|
192
|
-
|
193
|
+
git_str common_link = GIT_STR_INIT;
|
193
194
|
int error;
|
194
195
|
|
195
196
|
/*
|
196
197
|
* If there's no commondir file, the repository path is the
|
197
198
|
* common path, but it needs a trailing slash.
|
198
199
|
*/
|
199
|
-
if (!
|
200
|
-
if ((error =
|
201
|
-
error =
|
200
|
+
if (!git_fs_path_contains_file(repository_path, GIT_COMMONDIR_FILE)) {
|
201
|
+
if ((error = git_str_set(commondir, repository_path->ptr, repository_path->size)) == 0)
|
202
|
+
error = git_fs_path_to_dir(commondir);
|
202
203
|
|
203
204
|
*separate = false;
|
204
205
|
goto done;
|
@@ -206,28 +207,28 @@ static int lookup_commondir(bool *separate, git_buf *commondir, git_buf *reposit
|
|
206
207
|
|
207
208
|
*separate = true;
|
208
209
|
|
209
|
-
if ((error =
|
210
|
+
if ((error = git_str_joinpath(&common_link, repository_path->ptr, GIT_COMMONDIR_FILE)) < 0 ||
|
210
211
|
(error = git_futils_readbuffer(&common_link, common_link.ptr)) < 0)
|
211
212
|
goto done;
|
212
213
|
|
213
|
-
|
214
|
-
if (
|
215
|
-
if ((error =
|
214
|
+
git_str_rtrim(&common_link);
|
215
|
+
if (git_fs_path_is_relative(common_link.ptr)) {
|
216
|
+
if ((error = git_str_joinpath(commondir, repository_path->ptr, common_link.ptr)) < 0)
|
216
217
|
goto done;
|
217
218
|
} else {
|
218
|
-
|
219
|
+
git_str_swap(commondir, &common_link);
|
219
220
|
}
|
220
221
|
|
221
|
-
|
222
|
+
git_str_dispose(&common_link);
|
222
223
|
|
223
224
|
/* Make sure the commondir path always has a trailing slash */
|
224
|
-
error =
|
225
|
+
error = git_fs_path_prettify_dir(commondir, commondir->ptr, NULL);
|
225
226
|
|
226
227
|
done:
|
227
228
|
return error;
|
228
229
|
}
|
229
230
|
|
230
|
-
GIT_INLINE(int) validate_repo_path(
|
231
|
+
GIT_INLINE(int) validate_repo_path(git_str *path)
|
231
232
|
{
|
232
233
|
/*
|
233
234
|
* The longest static path in a repository (or commondir) is the
|
@@ -239,8 +240,8 @@ GIT_INLINE(int) validate_repo_path(git_buf *path)
|
|
239
240
|
CONST_STRLEN("objects/pack/pack-.pack.lock") +
|
240
241
|
GIT_OID_HEXSZ;
|
241
242
|
|
242
|
-
return
|
243
|
-
path
|
243
|
+
return git_fs_path_validate_str_length_with_suffix(
|
244
|
+
path, suffix_len);
|
244
245
|
}
|
245
246
|
|
246
247
|
/*
|
@@ -248,7 +249,7 @@ GIT_INLINE(int) validate_repo_path(git_buf *path)
|
|
248
249
|
*
|
249
250
|
* Open a repository object from its path
|
250
251
|
*/
|
251
|
-
static int is_valid_repository_path(bool *out,
|
252
|
+
static int is_valid_repository_path(bool *out, git_str *repository_path, git_str *common_path)
|
252
253
|
{
|
253
254
|
bool separate_commondir = false;
|
254
255
|
int error;
|
@@ -259,13 +260,13 @@ static int is_valid_repository_path(bool *out, git_buf *repository_path, git_buf
|
|
259
260
|
return error;
|
260
261
|
|
261
262
|
/* Ensure HEAD file exists */
|
262
|
-
if (
|
263
|
+
if (git_fs_path_contains_file(repository_path, GIT_HEAD_FILE) == false)
|
263
264
|
return 0;
|
264
265
|
|
265
266
|
/* Check files in common dir */
|
266
|
-
if (
|
267
|
+
if (git_fs_path_contains_dir(common_path, GIT_OBJECTS_DIR) == false)
|
267
268
|
return 0;
|
268
|
-
if (
|
269
|
+
if (git_fs_path_contains_dir(common_path, GIT_REFS_DIR) == false)
|
269
270
|
return 0;
|
270
271
|
|
271
272
|
/* Ensure the repo (and commondir) are valid paths */
|
@@ -333,12 +334,12 @@ static int load_config_data(git_repository *repo, const git_config *config)
|
|
333
334
|
return 0;
|
334
335
|
}
|
335
336
|
|
336
|
-
static int load_workdir(git_repository *repo, git_config *config,
|
337
|
+
static int load_workdir(git_repository *repo, git_config *config, git_str *parent_path)
|
337
338
|
{
|
338
339
|
int error;
|
339
340
|
git_config_entry *ce;
|
340
|
-
|
341
|
-
|
341
|
+
git_str worktree = GIT_STR_INIT;
|
342
|
+
git_str path = GIT_STR_INIT;
|
342
343
|
|
343
344
|
if (repo->is_bare)
|
344
345
|
return 0;
|
@@ -354,38 +355,38 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
|
|
354
355
|
goto cleanup;
|
355
356
|
}
|
356
357
|
|
357
|
-
|
358
|
+
git_str_attach(&worktree, gitlink, 0);
|
358
359
|
|
359
|
-
if ((
|
360
|
-
|
360
|
+
if ((git_fs_path_dirname_r(&worktree, worktree.ptr)) < 0 ||
|
361
|
+
git_fs_path_to_dir(&worktree) < 0) {
|
361
362
|
error = -1;
|
362
363
|
goto cleanup;
|
363
364
|
}
|
364
365
|
|
365
|
-
repo->workdir =
|
366
|
+
repo->workdir = git_str_detach(&worktree);
|
366
367
|
}
|
367
368
|
else if (ce && ce->value) {
|
368
|
-
if ((error =
|
369
|
+
if ((error = git_fs_path_prettify_dir(
|
369
370
|
&worktree, ce->value, repo->gitdir)) < 0)
|
370
371
|
goto cleanup;
|
371
372
|
|
372
|
-
repo->workdir =
|
373
|
+
repo->workdir = git_str_detach(&worktree);
|
373
374
|
}
|
374
|
-
else if (parent_path &&
|
375
|
-
repo->workdir =
|
375
|
+
else if (parent_path && git_fs_path_isdir(parent_path->ptr))
|
376
|
+
repo->workdir = git_str_detach(parent_path);
|
376
377
|
else {
|
377
|
-
if (
|
378
|
-
|
378
|
+
if (git_fs_path_dirname_r(&worktree, repo->gitdir) < 0 ||
|
379
|
+
git_fs_path_to_dir(&worktree) < 0) {
|
379
380
|
error = -1;
|
380
381
|
goto cleanup;
|
381
382
|
}
|
382
383
|
|
383
|
-
repo->workdir =
|
384
|
+
repo->workdir = git_str_detach(&worktree);
|
384
385
|
}
|
385
386
|
|
386
387
|
GIT_ERROR_CHECK_ALLOC(repo->workdir);
|
387
388
|
cleanup:
|
388
|
-
|
389
|
+
git_str_dispose(&path);
|
389
390
|
git_config_entry_free(ce);
|
390
391
|
return error;
|
391
392
|
}
|
@@ -394,7 +395,7 @@ cleanup:
|
|
394
395
|
* This function returns furthest offset into path where a ceiling dir
|
395
396
|
* is found, so we can stop processing the path at that point.
|
396
397
|
*
|
397
|
-
* Note: converting this to use
|
398
|
+
* Note: converting this to use git_strs instead of GIT_PATH_MAX buffers on
|
398
399
|
* the stack could remove directories name limits, but at the cost of doing
|
399
400
|
* repeated malloc/frees inside the loop below, so let's not do it now.
|
400
401
|
*/
|
@@ -409,7 +410,7 @@ static size_t find_ceiling_dir_offset(
|
|
409
410
|
|
410
411
|
GIT_ASSERT_ARG(path);
|
411
412
|
|
412
|
-
min_len = (size_t)(
|
413
|
+
min_len = (size_t)(git_fs_path_root(path) + 1);
|
413
414
|
|
414
415
|
if (ceiling_directories == NULL || min_len == 0)
|
415
416
|
return min_len;
|
@@ -418,7 +419,7 @@ static size_t find_ceiling_dir_offset(
|
|
418
419
|
for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++);
|
419
420
|
len = sep - ceil;
|
420
421
|
|
421
|
-
if (len == 0 || len >= sizeof(buf) ||
|
422
|
+
if (len == 0 || len >= sizeof(buf) || git_fs_path_root(ceil) == -1)
|
422
423
|
continue;
|
423
424
|
|
424
425
|
strncpy(buf, ceil, len);
|
@@ -447,10 +448,10 @@ static size_t find_ceiling_dir_offset(
|
|
447
448
|
* it points to. Before calling, set `path_out` to the base directory that
|
448
449
|
* should be used if the contents of `file_path` are a relative path.
|
449
450
|
*/
|
450
|
-
static int read_gitfile(
|
451
|
+
static int read_gitfile(git_str *path_out, const char *file_path)
|
451
452
|
{
|
452
453
|
int error = 0;
|
453
|
-
|
454
|
+
git_str file = GIT_STR_INIT;
|
454
455
|
size_t prefix_len = strlen(GIT_FILE_CONTENT_PREFIX);
|
455
456
|
|
456
457
|
GIT_ASSERT_ARG(path_out);
|
@@ -459,41 +460,41 @@ static int read_gitfile(git_buf *path_out, const char *file_path)
|
|
459
460
|
if (git_futils_readbuffer(&file, file_path) < 0)
|
460
461
|
return -1;
|
461
462
|
|
462
|
-
|
463
|
+
git_str_rtrim(&file);
|
463
464
|
/* apparently on Windows, some people use backslashes in paths */
|
464
|
-
|
465
|
+
git_fs_path_mkposix(file.ptr);
|
465
466
|
|
466
|
-
if (
|
467
|
-
memcmp(
|
467
|
+
if (git_str_len(&file) <= prefix_len ||
|
468
|
+
memcmp(git_str_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0)
|
468
469
|
{
|
469
470
|
git_error_set(GIT_ERROR_REPOSITORY,
|
470
471
|
"the `.git` file at '%s' is malformed", file_path);
|
471
472
|
error = -1;
|
472
473
|
}
|
473
|
-
else if ((error =
|
474
|
-
const char *gitlink =
|
474
|
+
else if ((error = git_fs_path_dirname_r(path_out, file_path)) >= 0) {
|
475
|
+
const char *gitlink = git_str_cstr(&file) + prefix_len;
|
475
476
|
while (*gitlink && git__isspace(*gitlink)) gitlink++;
|
476
477
|
|
477
|
-
error =
|
478
|
-
path_out, gitlink,
|
478
|
+
error = git_fs_path_prettify_dir(
|
479
|
+
path_out, gitlink, git_str_cstr(path_out));
|
479
480
|
}
|
480
481
|
|
481
|
-
|
482
|
+
git_str_dispose(&file);
|
482
483
|
return error;
|
483
484
|
}
|
484
485
|
|
485
486
|
static int find_repo(
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
487
|
+
git_str *gitdir_path,
|
488
|
+
git_str *workdir_path,
|
489
|
+
git_str *gitlink_path,
|
490
|
+
git_str *commondir_path,
|
490
491
|
const char *start_path,
|
491
492
|
uint32_t flags,
|
492
493
|
const char *ceiling_dirs)
|
493
494
|
{
|
494
|
-
|
495
|
-
|
496
|
-
|
495
|
+
git_str path = GIT_STR_INIT;
|
496
|
+
git_str repo_link = GIT_STR_INIT;
|
497
|
+
git_str common_link = GIT_STR_INIT;
|
497
498
|
struct stat st;
|
498
499
|
dev_t initial_device = 0;
|
499
500
|
int min_iterations;
|
@@ -501,9 +502,9 @@ static int find_repo(
|
|
501
502
|
size_t ceiling_offset = 0;
|
502
503
|
int error;
|
503
504
|
|
504
|
-
|
505
|
+
git_str_clear(gitdir_path);
|
505
506
|
|
506
|
-
error =
|
507
|
+
error = git_fs_path_prettify(&path, start_path, NULL);
|
507
508
|
if (error < 0)
|
508
509
|
return error;
|
509
510
|
|
@@ -525,7 +526,7 @@ static int find_repo(
|
|
525
526
|
for (;;) {
|
526
527
|
if (!(flags & GIT_REPOSITORY_OPEN_NO_DOTGIT)) {
|
527
528
|
if (!in_dot_git) {
|
528
|
-
if ((error =
|
529
|
+
if ((error = git_str_joinpath(&path, path.ptr, DOT_GIT)) < 0)
|
529
530
|
goto out;
|
530
531
|
}
|
531
532
|
in_dot_git = !in_dot_git;
|
@@ -544,15 +545,15 @@ static int find_repo(
|
|
544
545
|
goto out;
|
545
546
|
|
546
547
|
if (is_valid) {
|
547
|
-
if ((error =
|
548
|
-
(error =
|
548
|
+
if ((error = git_fs_path_to_dir(&path)) < 0 ||
|
549
|
+
(error = git_str_set(gitdir_path, path.ptr, path.size)) < 0)
|
549
550
|
goto out;
|
550
551
|
|
551
552
|
if (gitlink_path)
|
552
|
-
if ((error =
|
553
|
+
if ((error = git_str_attach(gitlink_path, git_worktree__read_link(path.ptr, GIT_GITDIR_FILE), 0)) < 0)
|
553
554
|
goto out;
|
554
555
|
if (commondir_path)
|
555
|
-
|
556
|
+
git_str_swap(&common_link, commondir_path);
|
556
557
|
|
557
558
|
break;
|
558
559
|
}
|
@@ -562,13 +563,13 @@ static int find_repo(
|
|
562
563
|
goto out;
|
563
564
|
|
564
565
|
if (is_valid) {
|
565
|
-
|
566
|
+
git_str_swap(gitdir_path, &repo_link);
|
566
567
|
|
567
568
|
if (gitlink_path)
|
568
|
-
if ((error =
|
569
|
+
if ((error = git_str_put(gitlink_path, path.ptr, path.size)) < 0)
|
569
570
|
goto out;
|
570
571
|
if (commondir_path)
|
571
|
-
|
572
|
+
git_str_swap(&common_link, commondir_path);
|
572
573
|
}
|
573
574
|
break;
|
574
575
|
}
|
@@ -577,7 +578,7 @@ static int find_repo(
|
|
577
578
|
/* Move up one directory. If we're in_dot_git, we'll search the
|
578
579
|
* parent itself next. If we're !in_dot_git, we'll search .git
|
579
580
|
* in the parent directory next (added at the top of the loop). */
|
580
|
-
if ((error =
|
581
|
+
if ((error = git_fs_path_dirname_r(&path, path.ptr)) < 0)
|
581
582
|
goto out;
|
582
583
|
|
583
584
|
/* Once we've checked the directory (and .git if applicable),
|
@@ -592,25 +593,25 @@ static int find_repo(
|
|
592
593
|
}
|
593
594
|
|
594
595
|
if (workdir_path && !(flags & GIT_REPOSITORY_OPEN_BARE)) {
|
595
|
-
if (!
|
596
|
-
|
597
|
-
else if ((error =
|
598
|
-
(error =
|
596
|
+
if (!git_str_len(gitdir_path))
|
597
|
+
git_str_clear(workdir_path);
|
598
|
+
else if ((error = git_fs_path_dirname_r(workdir_path, path.ptr)) < 0 ||
|
599
|
+
(error = git_fs_path_to_dir(workdir_path)) < 0)
|
599
600
|
goto out;
|
600
601
|
}
|
601
602
|
|
602
603
|
/* If we didn't find the repository, and we don't have any other error
|
603
604
|
* to report, report that. */
|
604
|
-
if (!
|
605
|
+
if (!git_str_len(gitdir_path)) {
|
605
606
|
git_error_set(GIT_ERROR_REPOSITORY, "could not find repository from '%s'", start_path);
|
606
607
|
error = GIT_ENOTFOUND;
|
607
608
|
goto out;
|
608
609
|
}
|
609
610
|
|
610
611
|
out:
|
611
|
-
|
612
|
-
|
613
|
-
|
612
|
+
git_str_dispose(&path);
|
613
|
+
git_str_dispose(&repo_link);
|
614
|
+
git_str_dispose(&common_link);
|
614
615
|
return error;
|
615
616
|
}
|
616
617
|
|
@@ -618,18 +619,18 @@ int git_repository_open_bare(
|
|
618
619
|
git_repository **repo_ptr,
|
619
620
|
const char *bare_path)
|
620
621
|
{
|
621
|
-
|
622
|
+
git_str path = GIT_STR_INIT, common_path = GIT_STR_INIT;
|
622
623
|
git_repository *repo = NULL;
|
623
624
|
bool is_valid;
|
624
625
|
int error;
|
625
626
|
|
626
|
-
if ((error =
|
627
|
+
if ((error = git_fs_path_prettify_dir(&path, bare_path, NULL)) < 0 ||
|
627
628
|
(error = is_valid_repository_path(&is_valid, &path, &common_path)) < 0)
|
628
629
|
return error;
|
629
630
|
|
630
631
|
if (!is_valid) {
|
631
|
-
|
632
|
-
|
632
|
+
git_str_dispose(&path);
|
633
|
+
git_str_dispose(&common_path);
|
633
634
|
git_error_set(GIT_ERROR_REPOSITORY, "path is not a repository: %s", bare_path);
|
634
635
|
return GIT_ENOTFOUND;
|
635
636
|
}
|
@@ -637,9 +638,9 @@ int git_repository_open_bare(
|
|
637
638
|
repo = repository_alloc();
|
638
639
|
GIT_ERROR_CHECK_ALLOC(repo);
|
639
640
|
|
640
|
-
repo->gitdir =
|
641
|
+
repo->gitdir = git_str_detach(&path);
|
641
642
|
GIT_ERROR_CHECK_ALLOC(repo->gitdir);
|
642
|
-
repo->commondir =
|
643
|
+
repo->commondir = git_str_detach(&common_path);
|
643
644
|
GIT_ERROR_CHECK_ALLOC(repo->commondir);
|
644
645
|
|
645
646
|
/* of course we're bare! */
|
@@ -658,15 +659,15 @@ static int _git_repository_open_ext_from_env(
|
|
658
659
|
git_repository *repo = NULL;
|
659
660
|
git_index *index = NULL;
|
660
661
|
git_odb *odb = NULL;
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
662
|
+
git_str dir_buf = GIT_STR_INIT;
|
663
|
+
git_str ceiling_dirs_buf = GIT_STR_INIT;
|
664
|
+
git_str across_fs_buf = GIT_STR_INIT;
|
665
|
+
git_str index_file_buf = GIT_STR_INIT;
|
666
|
+
git_str namespace_buf = GIT_STR_INIT;
|
667
|
+
git_str object_dir_buf = GIT_STR_INIT;
|
668
|
+
git_str alts_buf = GIT_STR_INIT;
|
669
|
+
git_str work_tree_buf = GIT_STR_INIT;
|
670
|
+
git_str common_dir_buf = GIT_STR_INIT;
|
670
671
|
const char *ceiling_dirs = NULL;
|
671
672
|
unsigned flags = 0;
|
672
673
|
int error;
|
@@ -679,7 +680,7 @@ static int _git_repository_open_ext_from_env(
|
|
679
680
|
} else if (error < 0)
|
680
681
|
goto error;
|
681
682
|
else {
|
682
|
-
start_path =
|
683
|
+
start_path = git_str_cstr(&dir_buf);
|
683
684
|
flags |= GIT_REPOSITORY_OPEN_NO_SEARCH;
|
684
685
|
flags |= GIT_REPOSITORY_OPEN_NO_DOTGIT;
|
685
686
|
}
|
@@ -691,7 +692,7 @@ static int _git_repository_open_ext_from_env(
|
|
691
692
|
else if (error < 0)
|
692
693
|
goto error;
|
693
694
|
else
|
694
|
-
ceiling_dirs =
|
695
|
+
ceiling_dirs = git_str_cstr(&ceiling_dirs_buf);
|
695
696
|
|
696
697
|
error = git__getenv(&across_fs_buf, "GIT_DISCOVERY_ACROSS_FILESYSTEM");
|
697
698
|
if (error == GIT_ENOTFOUND)
|
@@ -700,7 +701,7 @@ static int _git_repository_open_ext_from_env(
|
|
700
701
|
goto error;
|
701
702
|
else {
|
702
703
|
int across_fs = 0;
|
703
|
-
error = git_config_parse_bool(&across_fs,
|
704
|
+
error = git_config_parse_bool(&across_fs, git_str_cstr(&across_fs_buf));
|
704
705
|
if (error < 0)
|
705
706
|
goto error;
|
706
707
|
if (across_fs)
|
@@ -713,7 +714,7 @@ static int _git_repository_open_ext_from_env(
|
|
713
714
|
else if (error < 0)
|
714
715
|
goto error;
|
715
716
|
else {
|
716
|
-
error = git_index_open(&index,
|
717
|
+
error = git_index_open(&index, git_str_cstr(&index_file_buf));
|
717
718
|
if (error < 0)
|
718
719
|
goto error;
|
719
720
|
}
|
@@ -730,7 +731,7 @@ static int _git_repository_open_ext_from_env(
|
|
730
731
|
else if (error < 0)
|
731
732
|
goto error;
|
732
733
|
else {
|
733
|
-
error = git_odb_open(&odb,
|
734
|
+
error = git_odb_open(&odb, git_str_cstr(&object_dir_buf));
|
734
735
|
if (error < 0)
|
735
736
|
goto error;
|
736
737
|
}
|
@@ -779,7 +780,7 @@ static int _git_repository_open_ext_from_env(
|
|
779
780
|
goto error;
|
780
781
|
}
|
781
782
|
|
782
|
-
end =
|
783
|
+
end = git_str_cstr(&alts_buf) + git_str_len(&alts_buf);
|
783
784
|
for (sep = alt = alts_buf.ptr; sep != end; alt = sep+1) {
|
784
785
|
for (sep = alt; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++)
|
785
786
|
;
|
@@ -791,8 +792,8 @@ static int _git_repository_open_ext_from_env(
|
|
791
792
|
}
|
792
793
|
}
|
793
794
|
|
794
|
-
if (
|
795
|
-
error = git_repository_set_namespace(repo,
|
795
|
+
if (git_str_len(&namespace_buf)) {
|
796
|
+
error = git_repository_set_namespace(repo, git_str_cstr(&namespace_buf));
|
796
797
|
if (error < 0)
|
797
798
|
goto error;
|
798
799
|
}
|
@@ -808,21 +809,21 @@ error:
|
|
808
809
|
success:
|
809
810
|
git_odb_free(odb);
|
810
811
|
git_index_free(index);
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
812
|
+
git_str_dispose(&common_dir_buf);
|
813
|
+
git_str_dispose(&work_tree_buf);
|
814
|
+
git_str_dispose(&alts_buf);
|
815
|
+
git_str_dispose(&object_dir_buf);
|
816
|
+
git_str_dispose(&namespace_buf);
|
817
|
+
git_str_dispose(&index_file_buf);
|
818
|
+
git_str_dispose(&across_fs_buf);
|
819
|
+
git_str_dispose(&ceiling_dirs_buf);
|
820
|
+
git_str_dispose(&dir_buf);
|
820
821
|
return error;
|
821
822
|
}
|
822
823
|
|
823
824
|
static int repo_is_worktree(unsigned *out, const git_repository *repo)
|
824
825
|
{
|
825
|
-
|
826
|
+
git_str gitdir_link = GIT_STR_INIT;
|
826
827
|
int error;
|
827
828
|
|
828
829
|
/* Worktrees cannot have the same commondir and gitdir */
|
@@ -832,14 +833,14 @@ static int repo_is_worktree(unsigned *out, const git_repository *repo)
|
|
832
833
|
return 0;
|
833
834
|
}
|
834
835
|
|
835
|
-
if ((error =
|
836
|
+
if ((error = git_str_joinpath(&gitdir_link, repo->gitdir, "gitdir")) < 0)
|
836
837
|
return -1;
|
837
838
|
|
838
839
|
/* A 'gitdir' file inside a git directory is currently
|
839
840
|
* only used when the repository is a working tree. */
|
840
|
-
*out = !!
|
841
|
+
*out = !!git_fs_path_exists(gitdir_link.ptr);
|
841
842
|
|
842
|
-
|
843
|
+
git_str_dispose(&gitdir_link);
|
843
844
|
return error;
|
844
845
|
}
|
845
846
|
|
@@ -851,8 +852,8 @@ int git_repository_open_ext(
|
|
851
852
|
{
|
852
853
|
int error;
|
853
854
|
unsigned is_worktree;
|
854
|
-
|
855
|
-
gitlink =
|
855
|
+
git_str gitdir = GIT_STR_INIT, workdir = GIT_STR_INIT,
|
856
|
+
gitlink = GIT_STR_INIT, commondir = GIT_STR_INIT;
|
856
857
|
git_repository *repo = NULL;
|
857
858
|
git_config *config = NULL;
|
858
859
|
int version = 0;
|
@@ -872,15 +873,15 @@ int git_repository_open_ext(
|
|
872
873
|
repo = repository_alloc();
|
873
874
|
GIT_ERROR_CHECK_ALLOC(repo);
|
874
875
|
|
875
|
-
repo->gitdir =
|
876
|
+
repo->gitdir = git_str_detach(&gitdir);
|
876
877
|
GIT_ERROR_CHECK_ALLOC(repo->gitdir);
|
877
878
|
|
878
879
|
if (gitlink.size) {
|
879
|
-
repo->gitlink =
|
880
|
+
repo->gitlink = git_str_detach(&gitlink);
|
880
881
|
GIT_ERROR_CHECK_ALLOC(repo->gitlink);
|
881
882
|
}
|
882
883
|
if (commondir.size) {
|
883
|
-
repo->commondir =
|
884
|
+
repo->commondir = git_str_detach(&commondir);
|
884
885
|
GIT_ERROR_CHECK_ALLOC(repo->commondir);
|
885
886
|
}
|
886
887
|
|
@@ -914,10 +915,10 @@ int git_repository_open_ext(
|
|
914
915
|
}
|
915
916
|
|
916
917
|
cleanup:
|
917
|
-
|
918
|
-
|
919
|
-
|
920
|
-
|
918
|
+
git_str_dispose(&gitdir);
|
919
|
+
git_str_dispose(&workdir);
|
920
|
+
git_str_dispose(&gitlink);
|
921
|
+
git_str_dispose(&commondir);
|
921
922
|
git_config_free(config);
|
922
923
|
|
923
924
|
if (error < 0)
|
@@ -936,7 +937,7 @@ int git_repository_open(git_repository **repo_out, const char *path)
|
|
936
937
|
|
937
938
|
int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *wt)
|
938
939
|
{
|
939
|
-
|
940
|
+
git_str path = GIT_STR_INIT;
|
940
941
|
git_repository *repo = NULL;
|
941
942
|
size_t len;
|
942
943
|
int err;
|
@@ -952,7 +953,7 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
|
|
952
953
|
goto out;
|
953
954
|
}
|
954
955
|
|
955
|
-
if ((err =
|
956
|
+
if ((err = git_str_set(&path, wt->gitlink_path, len - 4)) < 0)
|
956
957
|
goto out;
|
957
958
|
|
958
959
|
if ((err = git_repository_open(&repo, path.ptr)) < 0)
|
@@ -961,7 +962,7 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
|
|
961
962
|
*repo_out = repo;
|
962
963
|
|
963
964
|
out:
|
964
|
-
|
965
|
+
git_str_dispose(&path);
|
965
966
|
|
966
967
|
return err;
|
967
968
|
}
|
@@ -986,14 +987,10 @@ int git_repository_discover(
|
|
986
987
|
const char *ceiling_dirs)
|
987
988
|
{
|
988
989
|
uint32_t flags = across_fs ? GIT_REPOSITORY_OPEN_CROSS_FS : 0;
|
989
|
-
int error;
|
990
990
|
|
991
991
|
GIT_ASSERT_ARG(start_path);
|
992
992
|
|
993
|
-
|
994
|
-
return error;
|
995
|
-
|
996
|
-
return find_repo(out, NULL, NULL, NULL, start_path, flags, ceiling_dirs);
|
993
|
+
GIT_BUF_WRAP_PRIVATE(out, find_repo, NULL, NULL, NULL, start_path, flags, ceiling_dirs);
|
997
994
|
}
|
998
995
|
|
999
996
|
static int load_config(
|
@@ -1005,7 +1002,7 @@ static int load_config(
|
|
1005
1002
|
const char *programdata_path)
|
1006
1003
|
{
|
1007
1004
|
int error;
|
1008
|
-
|
1005
|
+
git_str config_path = GIT_STR_INIT;
|
1009
1006
|
git_config *cfg = NULL;
|
1010
1007
|
|
1011
1008
|
GIT_ASSERT_ARG(out);
|
@@ -1014,13 +1011,13 @@ static int load_config(
|
|
1014
1011
|
return error;
|
1015
1012
|
|
1016
1013
|
if (repo) {
|
1017
|
-
if ((error =
|
1014
|
+
if ((error = git_repository__item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG)) == 0)
|
1018
1015
|
error = git_config_add_file_ondisk(cfg, config_path.ptr, GIT_CONFIG_LEVEL_LOCAL, repo, 0);
|
1019
1016
|
|
1020
1017
|
if (error && error != GIT_ENOTFOUND)
|
1021
1018
|
goto on_error;
|
1022
1019
|
|
1023
|
-
|
1020
|
+
git_str_dispose(&config_path);
|
1024
1021
|
}
|
1025
1022
|
|
1026
1023
|
if (global_config_path != NULL &&
|
@@ -1053,15 +1050,15 @@ static int load_config(
|
|
1053
1050
|
return 0;
|
1054
1051
|
|
1055
1052
|
on_error:
|
1056
|
-
|
1053
|
+
git_str_dispose(&config_path);
|
1057
1054
|
git_config_free(cfg);
|
1058
1055
|
*out = NULL;
|
1059
1056
|
return error;
|
1060
1057
|
}
|
1061
1058
|
|
1062
|
-
static const char *path_unless_empty(
|
1059
|
+
static const char *path_unless_empty(git_str *buf)
|
1063
1060
|
{
|
1064
|
-
return
|
1061
|
+
return git_str_len(buf) > 0 ? git_str_cstr(buf) : NULL;
|
1065
1062
|
}
|
1066
1063
|
|
1067
1064
|
int git_repository_config__weakptr(git_config **out, git_repository *repo)
|
@@ -1069,19 +1066,19 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
|
|
1069
1066
|
int error = 0;
|
1070
1067
|
|
1071
1068
|
if (repo->_config == NULL) {
|
1072
|
-
|
1073
|
-
|
1074
|
-
|
1075
|
-
|
1069
|
+
git_str global_buf = GIT_STR_INIT;
|
1070
|
+
git_str xdg_buf = GIT_STR_INIT;
|
1071
|
+
git_str system_buf = GIT_STR_INIT;
|
1072
|
+
git_str programdata_buf = GIT_STR_INIT;
|
1076
1073
|
git_config *config;
|
1077
1074
|
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1075
|
+
git_config__find_global(&global_buf);
|
1076
|
+
git_config__find_xdg(&xdg_buf);
|
1077
|
+
git_config__find_system(&system_buf);
|
1078
|
+
git_config__find_programdata(&programdata_buf);
|
1082
1079
|
|
1083
1080
|
/* If there is no global file, open a backend for it anyway */
|
1084
|
-
if (
|
1081
|
+
if (git_str_len(&global_buf) == 0)
|
1085
1082
|
git_config__global_location(&global_buf);
|
1086
1083
|
|
1087
1084
|
error = load_config(
|
@@ -1099,10 +1096,10 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
|
|
1099
1096
|
}
|
1100
1097
|
}
|
1101
1098
|
|
1102
|
-
|
1103
|
-
|
1104
|
-
|
1105
|
-
|
1099
|
+
git_str_dispose(&global_buf);
|
1100
|
+
git_str_dispose(&xdg_buf);
|
1101
|
+
git_str_dispose(&system_buf);
|
1102
|
+
git_str_dispose(&programdata_buf);
|
1106
1103
|
}
|
1107
1104
|
|
1108
1105
|
*out = repo->_config;
|
@@ -1147,10 +1144,10 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
|
|
1147
1144
|
|
1148
1145
|
*out = git_atomic_load(repo->_odb);
|
1149
1146
|
if (*out == NULL) {
|
1150
|
-
|
1147
|
+
git_str odb_path = GIT_STR_INIT;
|
1151
1148
|
git_odb *odb;
|
1152
1149
|
|
1153
|
-
if ((error =
|
1150
|
+
if ((error = git_repository__item_path(&odb_path, repo,
|
1154
1151
|
GIT_REPOSITORY_ITEM_OBJECTS)) < 0 ||
|
1155
1152
|
(error = git_odb_new(&odb)) < 0)
|
1156
1153
|
return error;
|
@@ -1168,7 +1165,7 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
|
|
1168
1165
|
git_odb_free(odb);
|
1169
1166
|
}
|
1170
1167
|
|
1171
|
-
|
1168
|
+
git_str_dispose(&odb_path);
|
1172
1169
|
*out = git_atomic_load(repo->_odb);
|
1173
1170
|
}
|
1174
1171
|
|
@@ -1244,10 +1241,10 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
|
|
1244
1241
|
GIT_ASSERT_ARG(repo);
|
1245
1242
|
|
1246
1243
|
if (repo->_index == NULL) {
|
1247
|
-
|
1244
|
+
git_str index_path = GIT_STR_INIT;
|
1248
1245
|
git_index *index;
|
1249
1246
|
|
1250
|
-
if ((error =
|
1247
|
+
if ((error = git_str_joinpath(&index_path, repo->gitdir, GIT_INDEX_FILE)) < 0)
|
1251
1248
|
return error;
|
1252
1249
|
|
1253
1250
|
error = git_index_open(&index, index_path.ptr);
|
@@ -1263,7 +1260,7 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
|
|
1263
1260
|
GIT_INDEX_CAPABILITY_FROM_OWNER);
|
1264
1261
|
}
|
1265
1262
|
|
1266
|
-
|
1263
|
+
git_str_dispose(&index_path);
|
1267
1264
|
}
|
1268
1265
|
|
1269
1266
|
*out = repo->_index;
|
@@ -1311,7 +1308,7 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
|
|
1311
1308
|
const char *def_dot_git = DOT_GIT;
|
1312
1309
|
size_t name_len, def_len = CONST_STRLEN(GIT_DIR_SHORTNAME);
|
1313
1310
|
size_t def_dot_git_len = CONST_STRLEN(DOT_GIT);
|
1314
|
-
|
1311
|
+
git_str *buf;
|
1315
1312
|
|
1316
1313
|
if (!name)
|
1317
1314
|
return 0;
|
@@ -1327,17 +1324,17 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
|
|
1327
1324
|
if ((buf = git_array_alloc(repo->reserved_names)) == NULL)
|
1328
1325
|
return -1;
|
1329
1326
|
|
1330
|
-
|
1327
|
+
git_str_attach(buf, name, name_len);
|
1331
1328
|
return true;
|
1332
1329
|
}
|
1333
1330
|
|
1334
1331
|
bool git_repository__reserved_names(
|
1335
|
-
|
1332
|
+
git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs)
|
1336
1333
|
{
|
1337
1334
|
GIT_UNUSED(include_ntfs);
|
1338
1335
|
|
1339
1336
|
if (repo->reserved_names.size == 0) {
|
1340
|
-
|
1337
|
+
git_str *buf;
|
1341
1338
|
size_t i;
|
1342
1339
|
|
1343
1340
|
/* Add the static defaults */
|
@@ -1389,7 +1386,7 @@ on_error:
|
|
1389
1386
|
}
|
1390
1387
|
#else
|
1391
1388
|
bool git_repository__reserved_names(
|
1392
|
-
|
1389
|
+
git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs)
|
1393
1390
|
{
|
1394
1391
|
GIT_UNUSED(repo);
|
1395
1392
|
|
@@ -1435,7 +1432,7 @@ static git_vector user_extensions = GIT_VECTOR_INIT;
|
|
1435
1432
|
|
1436
1433
|
static int check_valid_extension(const git_config_entry *entry, void *payload)
|
1437
1434
|
{
|
1438
|
-
|
1435
|
+
git_str cfg = GIT_STR_INIT;
|
1439
1436
|
bool reject;
|
1440
1437
|
const char *extension;
|
1441
1438
|
size_t i;
|
@@ -1444,7 +1441,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
|
|
1444
1441
|
GIT_UNUSED(payload);
|
1445
1442
|
|
1446
1443
|
git_vector_foreach (&user_extensions, i, extension) {
|
1447
|
-
|
1444
|
+
git_str_clear(&cfg);
|
1448
1445
|
|
1449
1446
|
/*
|
1450
1447
|
* Users can specify that they don't want to support an
|
@@ -1453,7 +1450,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
|
|
1453
1450
|
if ((reject = (extension[0] == '!')) == true)
|
1454
1451
|
extension = &extension[1];
|
1455
1452
|
|
1456
|
-
if ((error =
|
1453
|
+
if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0)
|
1457
1454
|
goto done;
|
1458
1455
|
|
1459
1456
|
if (strcmp(entry->name, cfg.ptr) == 0) {
|
@@ -1467,7 +1464,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
|
|
1467
1464
|
for (i = 0; i < ARRAY_SIZE(builtin_extensions); i++) {
|
1468
1465
|
extension = builtin_extensions[i];
|
1469
1466
|
|
1470
|
-
if ((error =
|
1467
|
+
if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0)
|
1471
1468
|
goto done;
|
1472
1469
|
|
1473
1470
|
if (strcmp(entry->name, cfg.ptr) == 0)
|
@@ -1479,7 +1476,7 @@ fail:
|
|
1479
1476
|
error = -1;
|
1480
1477
|
|
1481
1478
|
done:
|
1482
|
-
|
1479
|
+
git_str_dispose(&cfg);
|
1483
1480
|
return error;
|
1484
1481
|
}
|
1485
1482
|
|
@@ -1557,12 +1554,12 @@ void git_repository__free_extensions(void)
|
|
1557
1554
|
|
1558
1555
|
int git_repository_create_head(const char *git_dir, const char *ref_name)
|
1559
1556
|
{
|
1560
|
-
|
1557
|
+
git_str ref_path = GIT_STR_INIT;
|
1561
1558
|
git_filebuf ref = GIT_FILEBUF_INIT;
|
1562
1559
|
const char *fmt;
|
1563
1560
|
int error;
|
1564
1561
|
|
1565
|
-
if ((error =
|
1562
|
+
if ((error = git_str_joinpath(&ref_path, git_dir, GIT_HEAD_FILE)) < 0 ||
|
1566
1563
|
(error = git_filebuf_open(&ref, ref_path.ptr, 0, GIT_REFS_FILE_MODE)) < 0)
|
1567
1564
|
goto out;
|
1568
1565
|
|
@@ -1576,7 +1573,7 @@ int git_repository_create_head(const char *git_dir, const char *ref_name)
|
|
1576
1573
|
goto out;
|
1577
1574
|
|
1578
1575
|
out:
|
1579
|
-
|
1576
|
+
git_str_dispose(&ref_path);
|
1580
1577
|
git_filebuf_cleanup(&ref);
|
1581
1578
|
return error;
|
1582
1579
|
}
|
@@ -1599,23 +1596,23 @@ static bool is_chmod_supported(const char *file_path)
|
|
1599
1596
|
|
1600
1597
|
static bool is_filesystem_case_insensitive(const char *gitdir_path)
|
1601
1598
|
{
|
1602
|
-
|
1599
|
+
git_str path = GIT_STR_INIT;
|
1603
1600
|
int is_insensitive = -1;
|
1604
1601
|
|
1605
|
-
if (!
|
1606
|
-
is_insensitive =
|
1602
|
+
if (!git_str_joinpath(&path, gitdir_path, "CoNfIg"))
|
1603
|
+
is_insensitive = git_fs_path_exists(git_str_cstr(&path));
|
1607
1604
|
|
1608
|
-
|
1605
|
+
git_str_dispose(&path);
|
1609
1606
|
return is_insensitive;
|
1610
1607
|
}
|
1611
1608
|
|
1612
1609
|
static bool are_symlinks_supported(const char *wd_path)
|
1613
1610
|
{
|
1614
1611
|
git_config *config = NULL;
|
1615
|
-
|
1616
|
-
|
1617
|
-
|
1618
|
-
|
1612
|
+
git_str global_buf = GIT_STR_INIT;
|
1613
|
+
git_str xdg_buf = GIT_STR_INIT;
|
1614
|
+
git_str system_buf = GIT_STR_INIT;
|
1615
|
+
git_str programdata_buf = GIT_STR_INIT;
|
1619
1616
|
int symlinks = 0;
|
1620
1617
|
|
1621
1618
|
/*
|
@@ -1626,10 +1623,10 @@ static bool are_symlinks_supported(const char *wd_path)
|
|
1626
1623
|
* _not_ set, then we do not test or enable symlink support.
|
1627
1624
|
*/
|
1628
1625
|
#ifdef GIT_WIN32
|
1629
|
-
|
1630
|
-
|
1631
|
-
|
1632
|
-
|
1626
|
+
git_config__find_global(&global_buf);
|
1627
|
+
git_config__find_xdg(&xdg_buf);
|
1628
|
+
git_config__find_system(&system_buf);
|
1629
|
+
git_config__find_programdata(&programdata_buf);
|
1633
1630
|
|
1634
1631
|
if (load_config(&config, NULL,
|
1635
1632
|
path_unless_empty(&global_buf),
|
@@ -1642,14 +1639,14 @@ static bool are_symlinks_supported(const char *wd_path)
|
|
1642
1639
|
goto done;
|
1643
1640
|
#endif
|
1644
1641
|
|
1645
|
-
if (!(symlinks =
|
1642
|
+
if (!(symlinks = git_fs_path_supports_symlinks(wd_path)))
|
1646
1643
|
goto done;
|
1647
1644
|
|
1648
1645
|
done:
|
1649
|
-
|
1650
|
-
|
1651
|
-
|
1652
|
-
|
1646
|
+
git_str_dispose(&global_buf);
|
1647
|
+
git_str_dispose(&xdg_buf);
|
1648
|
+
git_str_dispose(&system_buf);
|
1649
|
+
git_str_dispose(&programdata_buf);
|
1653
1650
|
git_config_free(config);
|
1654
1651
|
return symlinks != 0;
|
1655
1652
|
}
|
@@ -1673,7 +1670,7 @@ static int create_empty_file(const char *path, mode_t mode)
|
|
1673
1670
|
|
1674
1671
|
static int repo_local_config(
|
1675
1672
|
git_config **out,
|
1676
|
-
|
1673
|
+
git_str *config_dir,
|
1677
1674
|
git_repository *repo,
|
1678
1675
|
const char *repo_dir)
|
1679
1676
|
{
|
@@ -1681,12 +1678,12 @@ static int repo_local_config(
|
|
1681
1678
|
git_config *parent;
|
1682
1679
|
const char *cfg_path;
|
1683
1680
|
|
1684
|
-
if (
|
1681
|
+
if (git_str_joinpath(config_dir, repo_dir, GIT_CONFIG_FILENAME_INREPO) < 0)
|
1685
1682
|
return -1;
|
1686
|
-
cfg_path =
|
1683
|
+
cfg_path = git_str_cstr(config_dir);
|
1687
1684
|
|
1688
1685
|
/* make LOCAL config if missing */
|
1689
|
-
if (!
|
1686
|
+
if (!git_fs_path_isfile(cfg_path) &&
|
1690
1687
|
(error = create_empty_file(cfg_path, GIT_CONFIG_FILE_MODE)) < 0)
|
1691
1688
|
return error;
|
1692
1689
|
|
@@ -1744,7 +1741,7 @@ static int repo_init_fs_configs(
|
|
1744
1741
|
#ifdef GIT_USE_ICONV
|
1745
1742
|
if ((error = git_config_set_bool(
|
1746
1743
|
cfg, "core.precomposeunicode",
|
1747
|
-
|
1744
|
+
git_fs_path_does_decompose_unicode(work_dir))) < 0)
|
1748
1745
|
return error;
|
1749
1746
|
/* on non-iconv platforms, don't even set core.precomposeunicode */
|
1750
1747
|
#endif
|
@@ -1759,7 +1756,7 @@ static int repo_init_config(
|
|
1759
1756
|
uint32_t mode)
|
1760
1757
|
{
|
1761
1758
|
int error = 0;
|
1762
|
-
|
1759
|
+
git_str cfg_path = GIT_STR_INIT, worktree_path = GIT_STR_INIT;
|
1763
1760
|
git_config *config = NULL;
|
1764
1761
|
bool is_bare = ((flags & GIT_REPOSITORY_INIT_BARE) != 0);
|
1765
1762
|
bool is_reinit = ((flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0);
|
@@ -1789,11 +1786,11 @@ static int repo_init_config(
|
|
1789
1786
|
SET_REPO_CONFIG(bool, "core.logallrefupdates", true);
|
1790
1787
|
|
1791
1788
|
if (!(flags & GIT_REPOSITORY_INIT__NATURAL_WD)) {
|
1792
|
-
if ((error =
|
1789
|
+
if ((error = git_str_sets(&worktree_path, work_dir)) < 0)
|
1793
1790
|
goto cleanup;
|
1794
1791
|
|
1795
1792
|
if ((flags & GIT_REPOSITORY_INIT_RELATIVE_GITLINK))
|
1796
|
-
if ((error =
|
1793
|
+
if ((error = git_fs_path_make_relative(&worktree_path, repo_dir)) < 0)
|
1797
1794
|
goto cleanup;
|
1798
1795
|
|
1799
1796
|
SET_REPO_CONFIG(string, "core.worktree", worktree_path.ptr);
|
@@ -1813,8 +1810,8 @@ static int repo_init_config(
|
|
1813
1810
|
}
|
1814
1811
|
|
1815
1812
|
cleanup:
|
1816
|
-
|
1817
|
-
|
1813
|
+
git_str_dispose(&cfg_path);
|
1814
|
+
git_str_dispose(&worktree_path);
|
1818
1815
|
git_config_free(config);
|
1819
1816
|
|
1820
1817
|
return error;
|
@@ -1836,7 +1833,7 @@ static int repo_reinit_submodule_fs(git_submodule *sm, const char *n, void *p)
|
|
1836
1833
|
int git_repository_reinit_filesystem(git_repository *repo, int recurse)
|
1837
1834
|
{
|
1838
1835
|
int error = 0;
|
1839
|
-
|
1836
|
+
git_str path = GIT_STR_INIT;
|
1840
1837
|
git_config *config = NULL;
|
1841
1838
|
const char *repo_dir = git_repository_path(repo);
|
1842
1839
|
|
@@ -1845,7 +1842,7 @@ int git_repository_reinit_filesystem(git_repository *repo, int recurse)
|
|
1845
1842
|
config, path.ptr, repo_dir, git_repository_workdir(repo), true);
|
1846
1843
|
|
1847
1844
|
git_config_free(config);
|
1848
|
-
|
1845
|
+
git_str_dispose(&path);
|
1849
1846
|
|
1850
1847
|
git_repository__configmap_lookup_cache_clear(repo);
|
1851
1848
|
|
@@ -1863,10 +1860,10 @@ static int repo_write_template(
|
|
1863
1860
|
bool hidden,
|
1864
1861
|
const char *content)
|
1865
1862
|
{
|
1866
|
-
|
1863
|
+
git_str path = GIT_STR_INIT;
|
1867
1864
|
int fd, error = 0, flags;
|
1868
1865
|
|
1869
|
-
if (
|
1866
|
+
if (git_str_joinpath(&path, git_dir, file) < 0)
|
1870
1867
|
return -1;
|
1871
1868
|
|
1872
1869
|
if (allow_overwrite)
|
@@ -1874,7 +1871,7 @@ static int repo_write_template(
|
|
1874
1871
|
else
|
1875
1872
|
flags = O_WRONLY | O_CREAT | O_EXCL;
|
1876
1873
|
|
1877
|
-
fd = p_open(
|
1874
|
+
fd = p_open(git_str_cstr(&path), flags, mode);
|
1878
1875
|
|
1879
1876
|
if (fd >= 0) {
|
1880
1877
|
error = p_write(fd, content, strlen(content));
|
@@ -1893,7 +1890,7 @@ static int repo_write_template(
|
|
1893
1890
|
GIT_UNUSED(hidden);
|
1894
1891
|
#endif
|
1895
1892
|
|
1896
|
-
|
1893
|
+
git_str_dispose(&path);
|
1897
1894
|
|
1898
1895
|
if (error)
|
1899
1896
|
git_error_set(GIT_ERROR_OS,
|
@@ -1906,13 +1903,13 @@ static int repo_write_gitlink(
|
|
1906
1903
|
const char *in_dir, const char *to_repo, bool use_relative_path)
|
1907
1904
|
{
|
1908
1905
|
int error;
|
1909
|
-
|
1910
|
-
|
1906
|
+
git_str buf = GIT_STR_INIT;
|
1907
|
+
git_str path_to_repo = GIT_STR_INIT;
|
1911
1908
|
struct stat st;
|
1912
1909
|
|
1913
|
-
|
1914
|
-
|
1915
|
-
if (
|
1910
|
+
git_fs_path_dirname_r(&buf, to_repo);
|
1911
|
+
git_fs_path_to_dir(&buf);
|
1912
|
+
if (git_str_oom(&buf))
|
1916
1913
|
return -1;
|
1917
1914
|
|
1918
1915
|
/* don't write gitlink to natural workdir */
|
@@ -1923,7 +1920,7 @@ static int repo_write_gitlink(
|
|
1923
1920
|
goto cleanup;
|
1924
1921
|
}
|
1925
1922
|
|
1926
|
-
if ((error =
|
1923
|
+
if ((error = git_str_joinpath(&buf, in_dir, DOT_GIT)) < 0)
|
1927
1924
|
goto cleanup;
|
1928
1925
|
|
1929
1926
|
if (!p_stat(buf.ptr, &st) && !S_ISREG(st.st_mode)) {
|
@@ -1933,22 +1930,22 @@ static int repo_write_gitlink(
|
|
1933
1930
|
goto cleanup;
|
1934
1931
|
}
|
1935
1932
|
|
1936
|
-
|
1933
|
+
git_str_clear(&buf);
|
1937
1934
|
|
1938
|
-
error =
|
1935
|
+
error = git_str_sets(&path_to_repo, to_repo);
|
1939
1936
|
|
1940
1937
|
if (!error && use_relative_path)
|
1941
|
-
error =
|
1938
|
+
error = git_fs_path_make_relative(&path_to_repo, in_dir);
|
1942
1939
|
|
1943
1940
|
if (!error)
|
1944
|
-
error =
|
1941
|
+
error = git_str_join(&buf, ' ', GIT_FILE_CONTENT_PREFIX, path_to_repo.ptr);
|
1945
1942
|
|
1946
1943
|
if (!error)
|
1947
1944
|
error = repo_write_template(in_dir, true, DOT_GIT, 0666, true, buf.ptr);
|
1948
1945
|
|
1949
1946
|
cleanup:
|
1950
|
-
|
1951
|
-
|
1947
|
+
git_str_dispose(&buf);
|
1948
|
+
git_str_dispose(&path_to_repo);
|
1952
1949
|
return error;
|
1953
1950
|
}
|
1954
1951
|
|
@@ -2001,12 +1998,12 @@ static int repo_init_structure(
|
|
2001
1998
|
git_config *cfg = NULL;
|
2002
1999
|
const char *tdir = NULL;
|
2003
2000
|
bool default_template = false;
|
2004
|
-
|
2001
|
+
git_str template_buf = GIT_STR_INIT;
|
2005
2002
|
|
2006
2003
|
if (opts->template_path)
|
2007
2004
|
tdir = opts->template_path;
|
2008
2005
|
else if ((error = git_config_open_default(&cfg)) >= 0) {
|
2009
|
-
if (!
|
2006
|
+
if (!git_config__get_path(&template_buf, cfg, "init.templatedir"))
|
2010
2007
|
tdir = template_buf.ptr;
|
2011
2008
|
git_error_clear();
|
2012
2009
|
}
|
@@ -2032,11 +2029,16 @@ static int repo_init_structure(
|
|
2032
2029
|
error = git_futils_cp_r(tdir, repo_dir, cpflags, dmode);
|
2033
2030
|
}
|
2034
2031
|
|
2035
|
-
|
2032
|
+
git_str_dispose(&template_buf);
|
2036
2033
|
git_config_free(cfg);
|
2037
2034
|
|
2035
|
+
/* If tdir does not exist, then do not error out. This matches the
|
2036
|
+
* behaviour of git(1), which just prints a warning and continues.
|
2037
|
+
* TODO: issue warning when warning API is available.
|
2038
|
+
* `git` prints to stderr: 'warning: templates not found in /path/to/tdir'
|
2039
|
+
*/
|
2038
2040
|
if (error < 0) {
|
2039
|
-
if (!default_template)
|
2041
|
+
if (!default_template && error != GIT_ENOTFOUND)
|
2040
2042
|
return error;
|
2041
2043
|
|
2042
2044
|
/* if template was default, ignore error and use internal */
|
@@ -2073,7 +2075,7 @@ static int repo_init_structure(
|
|
2073
2075
|
return error;
|
2074
2076
|
}
|
2075
2077
|
|
2076
|
-
static int mkdir_parent(
|
2078
|
+
static int mkdir_parent(git_str *buf, uint32_t mode, bool skip2)
|
2077
2079
|
{
|
2078
2080
|
/* When making parent directories during repository initialization
|
2079
2081
|
* don't try to set gid or grant world write access
|
@@ -2085,8 +2087,8 @@ static int mkdir_parent(git_buf *buf, uint32_t mode, bool skip2)
|
|
2085
2087
|
}
|
2086
2088
|
|
2087
2089
|
static int repo_init_directories(
|
2088
|
-
|
2089
|
-
|
2090
|
+
git_str *repo_path,
|
2091
|
+
git_str *wd_path,
|
2090
2092
|
const char *given_repo,
|
2091
2093
|
git_repository_init_options *opts)
|
2092
2094
|
{
|
@@ -2124,7 +2126,7 @@ static int repo_init_directories(
|
|
2124
2126
|
git__suffixcmp(given_repo, "/" DOT_GIT) != 0 &&
|
2125
2127
|
git__suffixcmp(given_repo, "/" GIT_DIR) != 0;
|
2126
2128
|
|
2127
|
-
if (
|
2129
|
+
if (git_str_joinpath(repo_path, given_repo, add_dotgit ? GIT_DIR : "") < 0)
|
2128
2130
|
return -1;
|
2129
2131
|
|
2130
2132
|
has_dotgit = (git__suffixcmp(repo_path->ptr, "/" GIT_DIR) == 0);
|
@@ -2135,11 +2137,11 @@ static int repo_init_directories(
|
|
2135
2137
|
|
2136
2138
|
if (!is_bare) {
|
2137
2139
|
if (opts->workdir_path) {
|
2138
|
-
if (
|
2140
|
+
if (git_fs_path_join_unrooted(
|
2139
2141
|
wd_path, opts->workdir_path, repo_path->ptr, NULL) < 0)
|
2140
2142
|
return -1;
|
2141
2143
|
} else if (has_dotgit) {
|
2142
|
-
if (
|
2144
|
+
if (git_fs_path_dirname_r(wd_path, repo_path->ptr) < 0)
|
2143
2145
|
return -1;
|
2144
2146
|
} else {
|
2145
2147
|
git_error_set(GIT_ERROR_REPOSITORY, "cannot pick working directory"
|
@@ -2147,10 +2149,10 @@ static int repo_init_directories(
|
|
2147
2149
|
return -1;
|
2148
2150
|
}
|
2149
2151
|
|
2150
|
-
if (
|
2152
|
+
if (git_fs_path_to_dir(wd_path) < 0)
|
2151
2153
|
return -1;
|
2152
2154
|
} else {
|
2153
|
-
|
2155
|
+
git_str_clear(wd_path);
|
2154
2156
|
}
|
2155
2157
|
|
2156
2158
|
natural_wd =
|
@@ -2207,10 +2209,10 @@ static int repo_init_directories(
|
|
2207
2209
|
/* prettify both directories now that they are created */
|
2208
2210
|
|
2209
2211
|
if (!error) {
|
2210
|
-
error =
|
2212
|
+
error = git_fs_path_prettify_dir(repo_path, repo_path->ptr, NULL);
|
2211
2213
|
|
2212
2214
|
if (!error && wd_path->size > 0)
|
2213
|
-
error =
|
2215
|
+
error = git_fs_path_prettify_dir(wd_path, wd_path->ptr, NULL);
|
2214
2216
|
}
|
2215
2217
|
|
2216
2218
|
return error;
|
@@ -2219,24 +2221,24 @@ static int repo_init_directories(
|
|
2219
2221
|
static int repo_init_head(const char *repo_dir, const char *given)
|
2220
2222
|
{
|
2221
2223
|
git_config *cfg = NULL;
|
2222
|
-
|
2224
|
+
git_str head_path = GIT_STR_INIT, cfg_branch = GIT_STR_INIT;
|
2223
2225
|
const char *initial_head = NULL;
|
2224
2226
|
int error;
|
2225
2227
|
|
2226
|
-
if ((error =
|
2228
|
+
if ((error = git_str_joinpath(&head_path, repo_dir, GIT_HEAD_FILE)) < 0)
|
2227
2229
|
goto out;
|
2228
2230
|
|
2229
2231
|
/*
|
2230
2232
|
* A template may have set a HEAD; use that unless it's been
|
2231
2233
|
* overridden by the caller's given initial head setting.
|
2232
2234
|
*/
|
2233
|
-
if (
|
2235
|
+
if (git_fs_path_exists(head_path.ptr) && !given)
|
2234
2236
|
goto out;
|
2235
2237
|
|
2236
2238
|
if (given) {
|
2237
2239
|
initial_head = given;
|
2238
2240
|
} else if ((error = git_config_open_default(&cfg)) >= 0 &&
|
2239
|
-
(error =
|
2241
|
+
(error = git_config__get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0 &&
|
2240
2242
|
*cfg_branch.ptr) {
|
2241
2243
|
initial_head = cfg_branch.ptr;
|
2242
2244
|
}
|
@@ -2248,8 +2250,8 @@ static int repo_init_head(const char *repo_dir, const char *given)
|
|
2248
2250
|
|
2249
2251
|
out:
|
2250
2252
|
git_config_free(cfg);
|
2251
|
-
|
2252
|
-
|
2253
|
+
git_str_dispose(&head_path);
|
2254
|
+
git_str_dispose(&cfg_branch);
|
2253
2255
|
|
2254
2256
|
return error;
|
2255
2257
|
}
|
@@ -2283,8 +2285,8 @@ int git_repository_init_ext(
|
|
2283
2285
|
const char *given_repo,
|
2284
2286
|
git_repository_init_options *opts)
|
2285
2287
|
{
|
2286
|
-
|
2287
|
-
common_path =
|
2288
|
+
git_str repo_path = GIT_STR_INIT, wd_path = GIT_STR_INIT,
|
2289
|
+
common_path = GIT_STR_INIT;
|
2288
2290
|
const char *wd;
|
2289
2291
|
bool is_valid;
|
2290
2292
|
int error;
|
@@ -2298,7 +2300,7 @@ int git_repository_init_ext(
|
|
2298
2300
|
if ((error = repo_init_directories(&repo_path, &wd_path, given_repo, opts)) < 0)
|
2299
2301
|
goto out;
|
2300
2302
|
|
2301
|
-
wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL :
|
2303
|
+
wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL : git_str_cstr(&wd_path);
|
2302
2304
|
|
2303
2305
|
if ((error = is_valid_repository_path(&is_valid, &repo_path, &common_path)) < 0)
|
2304
2306
|
goto out;
|
@@ -2332,9 +2334,9 @@ int git_repository_init_ext(
|
|
2332
2334
|
goto out;
|
2333
2335
|
|
2334
2336
|
out:
|
2335
|
-
|
2336
|
-
|
2337
|
-
|
2337
|
+
git_str_dispose(&common_path);
|
2338
|
+
git_str_dispose(&repo_path);
|
2339
|
+
git_str_dispose(&wd_path);
|
2338
2340
|
|
2339
2341
|
return error;
|
2340
2342
|
}
|
@@ -2522,7 +2524,7 @@ static int repo_contains_no_reference(git_repository *repo)
|
|
2522
2524
|
return error;
|
2523
2525
|
}
|
2524
2526
|
|
2525
|
-
int git_repository_initialbranch(
|
2527
|
+
int git_repository_initialbranch(git_str *out, git_repository *repo)
|
2526
2528
|
{
|
2527
2529
|
git_config *config;
|
2528
2530
|
git_config_entry *entry = NULL;
|
@@ -2543,8 +2545,8 @@ int git_repository_initialbranch(git_buf *out, git_repository *repo)
|
|
2543
2545
|
goto done;
|
2544
2546
|
}
|
2545
2547
|
|
2546
|
-
if ((error =
|
2547
|
-
(error =
|
2548
|
+
if ((error = git_str_puts(out, GIT_REFS_HEADS_DIR)) < 0 ||
|
2549
|
+
(error = git_str_puts(out, branch)) < 0 ||
|
2548
2550
|
(error = git_reference_name_is_valid(&valid, out->ptr)) < 0)
|
2549
2551
|
goto done;
|
2550
2552
|
|
@@ -2561,7 +2563,7 @@ done:
|
|
2561
2563
|
int git_repository_is_empty(git_repository *repo)
|
2562
2564
|
{
|
2563
2565
|
git_reference *head = NULL;
|
2564
|
-
|
2566
|
+
git_str initialbranch = GIT_STR_INIT;
|
2565
2567
|
int result = 0;
|
2566
2568
|
|
2567
2569
|
if ((result = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0 ||
|
@@ -2574,7 +2576,7 @@ int git_repository_is_empty(git_repository *repo)
|
|
2574
2576
|
|
2575
2577
|
done:
|
2576
2578
|
git_reference_free(head);
|
2577
|
-
|
2579
|
+
git_str_dispose(&initialbranch);
|
2578
2580
|
|
2579
2581
|
return result;
|
2580
2582
|
}
|
@@ -2603,7 +2605,18 @@ static const char *resolved_parent_path(const git_repository *repo, git_reposito
|
|
2603
2605
|
return parent;
|
2604
2606
|
}
|
2605
2607
|
|
2606
|
-
int git_repository_item_path(
|
2608
|
+
int git_repository_item_path(
|
2609
|
+
git_buf *out,
|
2610
|
+
const git_repository *repo,
|
2611
|
+
git_repository_item_t item)
|
2612
|
+
{
|
2613
|
+
GIT_BUF_WRAP_PRIVATE(out, git_repository__item_path, repo, item);
|
2614
|
+
}
|
2615
|
+
|
2616
|
+
int git_repository__item_path(
|
2617
|
+
git_str *out,
|
2618
|
+
const git_repository *repo,
|
2619
|
+
git_repository_item_t item)
|
2607
2620
|
{
|
2608
2621
|
const char *parent = resolved_parent_path(repo, items[item].parent, items[item].fallback);
|
2609
2622
|
if (parent == NULL) {
|
@@ -2611,16 +2624,16 @@ int git_repository_item_path(git_buf *out, const git_repository *repo, git_repos
|
|
2611
2624
|
return GIT_ENOTFOUND;
|
2612
2625
|
}
|
2613
2626
|
|
2614
|
-
if (
|
2627
|
+
if (git_str_sets(out, parent) < 0)
|
2615
2628
|
return -1;
|
2616
2629
|
|
2617
2630
|
if (items[item].name) {
|
2618
|
-
if (
|
2631
|
+
if (git_str_joinpath(out, parent, items[item].name) < 0)
|
2619
2632
|
return -1;
|
2620
2633
|
}
|
2621
2634
|
|
2622
2635
|
if (items[item].directory) {
|
2623
|
-
if (
|
2636
|
+
if (git_fs_path_to_dir(out) < 0)
|
2624
2637
|
return -1;
|
2625
2638
|
}
|
2626
2639
|
|
@@ -2644,7 +2657,7 @@ const char *git_repository_workdir(const git_repository *repo)
|
|
2644
2657
|
}
|
2645
2658
|
|
2646
2659
|
int git_repository_workdir_path(
|
2647
|
-
|
2660
|
+
git_str *out, git_repository *repo, const char *path)
|
2648
2661
|
{
|
2649
2662
|
int error;
|
2650
2663
|
|
@@ -2653,8 +2666,8 @@ int git_repository_workdir_path(
|
|
2653
2666
|
return GIT_EBAREREPO;
|
2654
2667
|
}
|
2655
2668
|
|
2656
|
-
if (!(error =
|
2657
|
-
error =
|
2669
|
+
if (!(error = git_str_joinpath(out, repo->workdir, path)))
|
2670
|
+
error = git_path_validate_str_length(repo, out);
|
2658
2671
|
|
2659
2672
|
return error;
|
2660
2673
|
}
|
@@ -2669,12 +2682,12 @@ int git_repository_set_workdir(
|
|
2669
2682
|
git_repository *repo, const char *workdir, int update_gitlink)
|
2670
2683
|
{
|
2671
2684
|
int error = 0;
|
2672
|
-
|
2685
|
+
git_str path = GIT_STR_INIT;
|
2673
2686
|
|
2674
2687
|
GIT_ASSERT_ARG(repo);
|
2675
2688
|
GIT_ASSERT_ARG(workdir);
|
2676
2689
|
|
2677
|
-
if (
|
2690
|
+
if (git_fs_path_prettify_dir(&path, workdir, NULL) < 0)
|
2678
2691
|
return -1;
|
2679
2692
|
|
2680
2693
|
if (repo->workdir && strcmp(repo->workdir, path.ptr) == 0)
|
@@ -2701,7 +2714,7 @@ int git_repository_set_workdir(
|
|
2701
2714
|
if (!error) {
|
2702
2715
|
char *old_workdir = repo->workdir;
|
2703
2716
|
|
2704
|
-
repo->workdir =
|
2717
|
+
repo->workdir = git_str_detach(&path);
|
2705
2718
|
repo->is_bare = 0;
|
2706
2719
|
|
2707
2720
|
git__free(old_workdir);
|
@@ -2770,13 +2783,13 @@ cleanup:
|
|
2770
2783
|
int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head)
|
2771
2784
|
{
|
2772
2785
|
git_filebuf file = GIT_FILEBUF_INIT;
|
2773
|
-
|
2786
|
+
git_str file_path = GIT_STR_INIT;
|
2774
2787
|
char orig_head_str[GIT_OID_HEXSZ];
|
2775
2788
|
int error = 0;
|
2776
2789
|
|
2777
2790
|
git_oid_fmt(orig_head_str, orig_head);
|
2778
2791
|
|
2779
|
-
if ((error =
|
2792
|
+
if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_ORIG_HEAD_FILE)) == 0 &&
|
2780
2793
|
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) == 0 &&
|
2781
2794
|
(error = git_filebuf_printf(&file, "%.*s\n", GIT_OID_HEXSZ, orig_head_str)) == 0)
|
2782
2795
|
error = git_filebuf_commit(&file);
|
@@ -2784,46 +2797,48 @@ int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head
|
|
2784
2797
|
if (error < 0)
|
2785
2798
|
git_filebuf_cleanup(&file);
|
2786
2799
|
|
2787
|
-
|
2800
|
+
git_str_dispose(&file_path);
|
2788
2801
|
|
2789
2802
|
return error;
|
2790
2803
|
}
|
2791
2804
|
|
2792
|
-
int
|
2805
|
+
static int git_repository__message(git_str *out, git_repository *repo)
|
2793
2806
|
{
|
2794
|
-
|
2807
|
+
git_str path = GIT_STR_INIT;
|
2795
2808
|
struct stat st;
|
2796
2809
|
int error;
|
2797
2810
|
|
2798
|
-
if ((
|
2799
|
-
return error;
|
2800
|
-
|
2801
|
-
if (git_buf_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
|
2811
|
+
if (git_str_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
|
2802
2812
|
return -1;
|
2803
2813
|
|
2804
|
-
if ((error = p_stat(
|
2814
|
+
if ((error = p_stat(git_str_cstr(&path), &st)) < 0) {
|
2805
2815
|
if (errno == ENOENT)
|
2806
2816
|
error = GIT_ENOTFOUND;
|
2807
2817
|
git_error_set(GIT_ERROR_OS, "could not access message file");
|
2808
2818
|
} else {
|
2809
|
-
error = git_futils_readbuffer(out,
|
2819
|
+
error = git_futils_readbuffer(out, git_str_cstr(&path));
|
2810
2820
|
}
|
2811
2821
|
|
2812
|
-
|
2822
|
+
git_str_dispose(&path);
|
2813
2823
|
|
2814
2824
|
return error;
|
2815
2825
|
}
|
2816
2826
|
|
2827
|
+
int git_repository_message(git_buf *out, git_repository *repo)
|
2828
|
+
{
|
2829
|
+
GIT_BUF_WRAP_PRIVATE(out, git_repository__message, repo);
|
2830
|
+
}
|
2831
|
+
|
2817
2832
|
int git_repository_message_remove(git_repository *repo)
|
2818
2833
|
{
|
2819
|
-
|
2834
|
+
git_str path = GIT_STR_INIT;
|
2820
2835
|
int error;
|
2821
2836
|
|
2822
|
-
if (
|
2837
|
+
if (git_str_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
|
2823
2838
|
return -1;
|
2824
2839
|
|
2825
|
-
error = p_unlink(
|
2826
|
-
|
2840
|
+
error = p_unlink(git_str_cstr(&path));
|
2841
|
+
git_str_dispose(&path);
|
2827
2842
|
|
2828
2843
|
return error;
|
2829
2844
|
}
|
@@ -2839,7 +2854,7 @@ int git_repository_hashfile(
|
|
2839
2854
|
git_filter_list *fl = NULL;
|
2840
2855
|
git_file fd = -1;
|
2841
2856
|
uint64_t len;
|
2842
|
-
|
2857
|
+
git_str full_path = GIT_STR_INIT;
|
2843
2858
|
const char *workdir = git_repository_workdir(repo);
|
2844
2859
|
|
2845
2860
|
/* as_path can be NULL */
|
@@ -2847,8 +2862,8 @@ int git_repository_hashfile(
|
|
2847
2862
|
GIT_ASSERT_ARG(path);
|
2848
2863
|
GIT_ASSERT_ARG(repo);
|
2849
2864
|
|
2850
|
-
if ((error =
|
2851
|
-
(error =
|
2865
|
+
if ((error = git_fs_path_join_unrooted(&full_path, path, workdir, NULL)) < 0 ||
|
2866
|
+
(error = git_path_validate_str_length(repo, &full_path)) < 0)
|
2852
2867
|
return error;
|
2853
2868
|
|
2854
2869
|
/*
|
@@ -2895,30 +2910,30 @@ cleanup:
|
|
2895
2910
|
if (fd >= 0)
|
2896
2911
|
p_close(fd);
|
2897
2912
|
git_filter_list_free(fl);
|
2898
|
-
|
2913
|
+
git_str_dispose(&full_path);
|
2899
2914
|
|
2900
2915
|
return error;
|
2901
2916
|
}
|
2902
2917
|
|
2903
|
-
static int checkout_message(
|
2918
|
+
static int checkout_message(git_str *out, git_reference *old, const char *new)
|
2904
2919
|
{
|
2905
|
-
|
2920
|
+
git_str_puts(out, "checkout: moving from ");
|
2906
2921
|
|
2907
2922
|
if (git_reference_type(old) == GIT_REFERENCE_SYMBOLIC)
|
2908
|
-
|
2923
|
+
git_str_puts(out, git_reference__shorthand(git_reference_symbolic_target(old)));
|
2909
2924
|
else
|
2910
|
-
|
2925
|
+
git_str_puts(out, git_oid_tostr_s(git_reference_target(old)));
|
2911
2926
|
|
2912
|
-
|
2927
|
+
git_str_puts(out, " to ");
|
2913
2928
|
|
2914
2929
|
if (git_reference__is_branch(new) ||
|
2915
2930
|
git_reference__is_tag(new) ||
|
2916
2931
|
git_reference__is_remote(new))
|
2917
|
-
|
2932
|
+
git_str_puts(out, git_reference__shorthand(new));
|
2918
2933
|
else
|
2919
|
-
|
2934
|
+
git_str_puts(out, new);
|
2920
2935
|
|
2921
|
-
if (
|
2936
|
+
if (git_str_oom(out))
|
2922
2937
|
return -1;
|
2923
2938
|
|
2924
2939
|
return 0;
|
@@ -2927,7 +2942,7 @@ static int checkout_message(git_buf *out, git_reference *old, const char *new)
|
|
2927
2942
|
static int detach(git_repository *repo, const git_oid *id, const char *new)
|
2928
2943
|
{
|
2929
2944
|
int error;
|
2930
|
-
|
2945
|
+
git_str log_message = GIT_STR_INIT;
|
2931
2946
|
git_object *object = NULL, *peeled = NULL;
|
2932
2947
|
git_reference *new_head = NULL, *current = NULL;
|
2933
2948
|
|
@@ -2949,10 +2964,10 @@ static int detach(git_repository *repo, const git_oid *id, const char *new)
|
|
2949
2964
|
if ((error = checkout_message(&log_message, current, new)) < 0)
|
2950
2965
|
goto cleanup;
|
2951
2966
|
|
2952
|
-
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true,
|
2967
|
+
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_object_id(peeled), true, git_str_cstr(&log_message));
|
2953
2968
|
|
2954
2969
|
cleanup:
|
2955
|
-
|
2970
|
+
git_str_dispose(&log_message);
|
2956
2971
|
git_object_free(object);
|
2957
2972
|
git_object_free(peeled);
|
2958
2973
|
git_reference_free(current);
|
@@ -2965,7 +2980,7 @@ int git_repository_set_head(
|
|
2965
2980
|
const char *refname)
|
2966
2981
|
{
|
2967
2982
|
git_reference *ref = NULL, *current = NULL, *new_head = NULL;
|
2968
|
-
|
2983
|
+
git_str log_message = GIT_STR_INIT;
|
2969
2984
|
int error;
|
2970
2985
|
|
2971
2986
|
GIT_ASSERT_ARG(repo);
|
@@ -2992,18 +3007,18 @@ int git_repository_set_head(
|
|
2992
3007
|
if (!error) {
|
2993
3008
|
if (git_reference_is_branch(ref)) {
|
2994
3009
|
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE,
|
2995
|
-
git_reference_name(ref), true,
|
3010
|
+
git_reference_name(ref), true, git_str_cstr(&log_message));
|
2996
3011
|
} else {
|
2997
3012
|
error = detach(repo, git_reference_target(ref),
|
2998
3013
|
git_reference_is_tag(ref) || git_reference_is_remote(ref) ? refname : NULL);
|
2999
3014
|
}
|
3000
3015
|
} else if (git_reference__is_branch(refname)) {
|
3001
3016
|
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname,
|
3002
|
-
true,
|
3017
|
+
true, git_str_cstr(&log_message));
|
3003
3018
|
}
|
3004
3019
|
|
3005
3020
|
cleanup:
|
3006
|
-
|
3021
|
+
git_str_dispose(&log_message);
|
3007
3022
|
git_reference_free(current);
|
3008
3023
|
git_reference_free(ref);
|
3009
3024
|
git_reference_free(new_head);
|
@@ -3012,26 +3027,26 @@ cleanup:
|
|
3012
3027
|
|
3013
3028
|
int git_repository_set_head_detached(
|
3014
3029
|
git_repository *repo,
|
3015
|
-
const git_oid *
|
3030
|
+
const git_oid *committish)
|
3016
3031
|
{
|
3017
|
-
return detach(repo,
|
3032
|
+
return detach(repo, committish, NULL);
|
3018
3033
|
}
|
3019
3034
|
|
3020
3035
|
int git_repository_set_head_detached_from_annotated(
|
3021
3036
|
git_repository *repo,
|
3022
|
-
const git_annotated_commit *
|
3037
|
+
const git_annotated_commit *committish)
|
3023
3038
|
{
|
3024
3039
|
GIT_ASSERT_ARG(repo);
|
3025
|
-
GIT_ASSERT_ARG(
|
3040
|
+
GIT_ASSERT_ARG(committish);
|
3026
3041
|
|
3027
|
-
return detach(repo, git_annotated_commit_id(
|
3042
|
+
return detach(repo, git_annotated_commit_id(committish), committish->description);
|
3028
3043
|
}
|
3029
3044
|
|
3030
3045
|
int git_repository_detach_head(git_repository *repo)
|
3031
3046
|
{
|
3032
3047
|
git_reference *old_head = NULL, *new_head = NULL, *current = NULL;
|
3033
3048
|
git_object *object = NULL;
|
3034
|
-
|
3049
|
+
git_str log_message = GIT_STR_INIT;
|
3035
3050
|
int error;
|
3036
3051
|
|
3037
3052
|
GIT_ASSERT_ARG(repo);
|
@@ -3049,10 +3064,10 @@ int git_repository_detach_head(git_repository *repo)
|
|
3049
3064
|
goto cleanup;
|
3050
3065
|
|
3051
3066
|
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head),
|
3052
|
-
1,
|
3067
|
+
1, git_str_cstr(&log_message));
|
3053
3068
|
|
3054
3069
|
cleanup:
|
3055
|
-
|
3070
|
+
git_str_dispose(&log_message);
|
3056
3071
|
git_object_free(object);
|
3057
3072
|
git_reference_free(old_head);
|
3058
3073
|
git_reference_free(new_head);
|
@@ -3066,69 +3081,69 @@ cleanup:
|
|
3066
3081
|
*/
|
3067
3082
|
int git_repository_state(git_repository *repo)
|
3068
3083
|
{
|
3069
|
-
|
3084
|
+
git_str repo_path = GIT_STR_INIT;
|
3070
3085
|
int state = GIT_REPOSITORY_STATE_NONE;
|
3071
3086
|
|
3072
3087
|
GIT_ASSERT_ARG(repo);
|
3073
3088
|
|
3074
|
-
if (
|
3089
|
+
if (git_str_puts(&repo_path, repo->gitdir) < 0)
|
3075
3090
|
return -1;
|
3076
3091
|
|
3077
|
-
if (
|
3092
|
+
if (git_fs_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE))
|
3078
3093
|
state = GIT_REPOSITORY_STATE_REBASE_INTERACTIVE;
|
3079
|
-
else if (
|
3094
|
+
else if (git_fs_path_contains_dir(&repo_path, GIT_REBASE_MERGE_DIR))
|
3080
3095
|
state = GIT_REPOSITORY_STATE_REBASE_MERGE;
|
3081
|
-
else if (
|
3096
|
+
else if (git_fs_path_contains_file(&repo_path, GIT_REBASE_APPLY_REBASING_FILE))
|
3082
3097
|
state = GIT_REPOSITORY_STATE_REBASE;
|
3083
|
-
else if (
|
3098
|
+
else if (git_fs_path_contains_file(&repo_path, GIT_REBASE_APPLY_APPLYING_FILE))
|
3084
3099
|
state = GIT_REPOSITORY_STATE_APPLY_MAILBOX;
|
3085
|
-
else if (
|
3100
|
+
else if (git_fs_path_contains_dir(&repo_path, GIT_REBASE_APPLY_DIR))
|
3086
3101
|
state = GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE;
|
3087
|
-
else if (
|
3102
|
+
else if (git_fs_path_contains_file(&repo_path, GIT_MERGE_HEAD_FILE))
|
3088
3103
|
state = GIT_REPOSITORY_STATE_MERGE;
|
3089
|
-
else if (
|
3104
|
+
else if (git_fs_path_contains_file(&repo_path, GIT_REVERT_HEAD_FILE)) {
|
3090
3105
|
state = GIT_REPOSITORY_STATE_REVERT;
|
3091
|
-
if (
|
3106
|
+
if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
|
3092
3107
|
state = GIT_REPOSITORY_STATE_REVERT_SEQUENCE;
|
3093
3108
|
}
|
3094
|
-
} else if (
|
3109
|
+
} else if (git_fs_path_contains_file(&repo_path, GIT_CHERRYPICK_HEAD_FILE)) {
|
3095
3110
|
state = GIT_REPOSITORY_STATE_CHERRYPICK;
|
3096
|
-
if (
|
3111
|
+
if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
|
3097
3112
|
state = GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE;
|
3098
3113
|
}
|
3099
|
-
} else if (
|
3114
|
+
} else if (git_fs_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE))
|
3100
3115
|
state = GIT_REPOSITORY_STATE_BISECT;
|
3101
3116
|
|
3102
|
-
|
3117
|
+
git_str_dispose(&repo_path);
|
3103
3118
|
return state;
|
3104
3119
|
}
|
3105
3120
|
|
3106
3121
|
int git_repository__cleanup_files(
|
3107
3122
|
git_repository *repo, const char *files[], size_t files_len)
|
3108
3123
|
{
|
3109
|
-
|
3124
|
+
git_str buf = GIT_STR_INIT;
|
3110
3125
|
size_t i;
|
3111
3126
|
int error;
|
3112
3127
|
|
3113
3128
|
for (error = 0, i = 0; !error && i < files_len; ++i) {
|
3114
3129
|
const char *path;
|
3115
3130
|
|
3116
|
-
if (
|
3131
|
+
if (git_str_joinpath(&buf, repo->gitdir, files[i]) < 0)
|
3117
3132
|
return -1;
|
3118
3133
|
|
3119
|
-
path =
|
3134
|
+
path = git_str_cstr(&buf);
|
3120
3135
|
|
3121
|
-
if (
|
3136
|
+
if (git_fs_path_isfile(path)) {
|
3122
3137
|
error = p_unlink(path);
|
3123
|
-
} else if (
|
3138
|
+
} else if (git_fs_path_isdir(path)) {
|
3124
3139
|
error = git_futils_rmdir_r(path, NULL,
|
3125
3140
|
GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS);
|
3126
3141
|
}
|
3127
3142
|
|
3128
|
-
|
3143
|
+
git_str_clear(&buf);
|
3129
3144
|
}
|
3130
3145
|
|
3131
|
-
|
3146
|
+
git_str_dispose(&buf);
|
3132
3147
|
return error;
|
3133
3148
|
}
|
3134
3149
|
|
@@ -3153,15 +3168,15 @@ int git_repository_state_cleanup(git_repository *repo)
|
|
3153
3168
|
|
3154
3169
|
int git_repository_is_shallow(git_repository *repo)
|
3155
3170
|
{
|
3156
|
-
|
3171
|
+
git_str path = GIT_STR_INIT;
|
3157
3172
|
struct stat st;
|
3158
3173
|
int error;
|
3159
3174
|
|
3160
|
-
if ((error =
|
3175
|
+
if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0)
|
3161
3176
|
return error;
|
3162
3177
|
|
3163
|
-
error =
|
3164
|
-
|
3178
|
+
error = git_fs_path_lstat(path.ptr, &st);
|
3179
|
+
git_str_dispose(&path);
|
3165
3180
|
|
3166
3181
|
if (error == GIT_ENOTFOUND) {
|
3167
3182
|
git_error_clear();
|