rugged 1.3.2 → 1.4.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/ext/rugged/extconf.rb +2 -2
- 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 +5 -12
- 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 -2
- 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 +99 -74
- 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 -19
- 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 -1962
- data/vendor/libgit2/src/path.h +34 -723
- 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 +350 -416
- data/vendor/libgit2/src/repository.h +11 -10
- 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,14 +32,13 @@
|
|
|
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
|
|
38
39
|
# include "win32/w32_util.h"
|
|
39
40
|
#endif
|
|
40
41
|
|
|
41
|
-
bool git_repository__validate_ownership = true;
|
|
42
42
|
bool git_repository__fsync_gitdir = false;
|
|
43
43
|
|
|
44
44
|
static const struct {
|
|
@@ -65,7 +65,6 @@ static const struct {
|
|
|
65
65
|
|
|
66
66
|
static int check_repositoryformatversion(int *version, git_config *config);
|
|
67
67
|
static int check_extensions(git_config *config, int version);
|
|
68
|
-
static int load_global_config(git_config **config);
|
|
69
68
|
|
|
70
69
|
#define GIT_COMMONDIR_FILE "commondir"
|
|
71
70
|
#define GIT_GITDIR_FILE "gitdir"
|
|
@@ -77,13 +76,13 @@ static int load_global_config(git_config **config);
|
|
|
77
76
|
#define GIT_REPO_VERSION 0
|
|
78
77
|
#define GIT_REPO_MAX_VERSION 1
|
|
79
78
|
|
|
80
|
-
|
|
79
|
+
git_str git_repository__reserved_names_win32[] = {
|
|
81
80
|
{ DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
|
|
82
81
|
{ GIT_DIR_SHORTNAME, 0, CONST_STRLEN(GIT_DIR_SHORTNAME) }
|
|
83
82
|
};
|
|
84
83
|
size_t git_repository__reserved_names_win32_len = 2;
|
|
85
84
|
|
|
86
|
-
|
|
85
|
+
git_str git_repository__reserved_names_posix[] = {
|
|
87
86
|
{ DOT_GIT, 0, CONST_STRLEN(DOT_GIT) },
|
|
88
87
|
};
|
|
89
88
|
size_t git_repository__reserved_names_posix_len = 1;
|
|
@@ -173,7 +172,7 @@ void git_repository_free(git_repository *repo)
|
|
|
173
172
|
repo->diff_drivers = NULL;
|
|
174
173
|
|
|
175
174
|
for (i = 0; i < repo->reserved_names.size; i++)
|
|
176
|
-
|
|
175
|
+
git_str_dispose(git_array_get(repo->reserved_names, i));
|
|
177
176
|
git_array_clear(repo->reserved_names);
|
|
178
177
|
|
|
179
178
|
git__free(repo->gitlink);
|
|
@@ -189,18 +188,18 @@ void git_repository_free(git_repository *repo)
|
|
|
189
188
|
}
|
|
190
189
|
|
|
191
190
|
/* Check if we have a separate commondir (e.g. we have a worktree) */
|
|
192
|
-
static int lookup_commondir(bool *separate,
|
|
191
|
+
static int lookup_commondir(bool *separate, git_str *commondir, git_str *repository_path)
|
|
193
192
|
{
|
|
194
|
-
|
|
193
|
+
git_str common_link = GIT_STR_INIT;
|
|
195
194
|
int error;
|
|
196
195
|
|
|
197
196
|
/*
|
|
198
197
|
* If there's no commondir file, the repository path is the
|
|
199
198
|
* common path, but it needs a trailing slash.
|
|
200
199
|
*/
|
|
201
|
-
if (!
|
|
202
|
-
if ((error =
|
|
203
|
-
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);
|
|
204
203
|
|
|
205
204
|
*separate = false;
|
|
206
205
|
goto done;
|
|
@@ -208,28 +207,28 @@ static int lookup_commondir(bool *separate, git_buf *commondir, git_buf *reposit
|
|
|
208
207
|
|
|
209
208
|
*separate = true;
|
|
210
209
|
|
|
211
|
-
if ((error =
|
|
210
|
+
if ((error = git_str_joinpath(&common_link, repository_path->ptr, GIT_COMMONDIR_FILE)) < 0 ||
|
|
212
211
|
(error = git_futils_readbuffer(&common_link, common_link.ptr)) < 0)
|
|
213
212
|
goto done;
|
|
214
213
|
|
|
215
|
-
|
|
216
|
-
if (
|
|
217
|
-
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)
|
|
218
217
|
goto done;
|
|
219
218
|
} else {
|
|
220
|
-
|
|
219
|
+
git_str_swap(commondir, &common_link);
|
|
221
220
|
}
|
|
222
221
|
|
|
223
|
-
|
|
222
|
+
git_str_dispose(&common_link);
|
|
224
223
|
|
|
225
224
|
/* Make sure the commondir path always has a trailing slash */
|
|
226
|
-
error =
|
|
225
|
+
error = git_fs_path_prettify_dir(commondir, commondir->ptr, NULL);
|
|
227
226
|
|
|
228
227
|
done:
|
|
229
228
|
return error;
|
|
230
229
|
}
|
|
231
230
|
|
|
232
|
-
GIT_INLINE(int) validate_repo_path(
|
|
231
|
+
GIT_INLINE(int) validate_repo_path(git_str *path)
|
|
233
232
|
{
|
|
234
233
|
/*
|
|
235
234
|
* The longest static path in a repository (or commondir) is the
|
|
@@ -241,8 +240,8 @@ GIT_INLINE(int) validate_repo_path(git_buf *path)
|
|
|
241
240
|
CONST_STRLEN("objects/pack/pack-.pack.lock") +
|
|
242
241
|
GIT_OID_HEXSZ;
|
|
243
242
|
|
|
244
|
-
return
|
|
245
|
-
path
|
|
243
|
+
return git_fs_path_validate_str_length_with_suffix(
|
|
244
|
+
path, suffix_len);
|
|
246
245
|
}
|
|
247
246
|
|
|
248
247
|
/*
|
|
@@ -250,7 +249,7 @@ GIT_INLINE(int) validate_repo_path(git_buf *path)
|
|
|
250
249
|
*
|
|
251
250
|
* Open a repository object from its path
|
|
252
251
|
*/
|
|
253
|
-
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)
|
|
254
253
|
{
|
|
255
254
|
bool separate_commondir = false;
|
|
256
255
|
int error;
|
|
@@ -261,13 +260,13 @@ static int is_valid_repository_path(bool *out, git_buf *repository_path, git_buf
|
|
|
261
260
|
return error;
|
|
262
261
|
|
|
263
262
|
/* Ensure HEAD file exists */
|
|
264
|
-
if (
|
|
263
|
+
if (git_fs_path_contains_file(repository_path, GIT_HEAD_FILE) == false)
|
|
265
264
|
return 0;
|
|
266
265
|
|
|
267
266
|
/* Check files in common dir */
|
|
268
|
-
if (
|
|
267
|
+
if (git_fs_path_contains_dir(common_path, GIT_OBJECTS_DIR) == false)
|
|
269
268
|
return 0;
|
|
270
|
-
if (
|
|
269
|
+
if (git_fs_path_contains_dir(common_path, GIT_REFS_DIR) == false)
|
|
271
270
|
return 0;
|
|
272
271
|
|
|
273
272
|
/* Ensure the repo (and commondir) are valid paths */
|
|
@@ -335,12 +334,12 @@ static int load_config_data(git_repository *repo, const git_config *config)
|
|
|
335
334
|
return 0;
|
|
336
335
|
}
|
|
337
336
|
|
|
338
|
-
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)
|
|
339
338
|
{
|
|
340
339
|
int error;
|
|
341
340
|
git_config_entry *ce;
|
|
342
|
-
|
|
343
|
-
|
|
341
|
+
git_str worktree = GIT_STR_INIT;
|
|
342
|
+
git_str path = GIT_STR_INIT;
|
|
344
343
|
|
|
345
344
|
if (repo->is_bare)
|
|
346
345
|
return 0;
|
|
@@ -356,38 +355,38 @@ static int load_workdir(git_repository *repo, git_config *config, git_buf *paren
|
|
|
356
355
|
goto cleanup;
|
|
357
356
|
}
|
|
358
357
|
|
|
359
|
-
|
|
358
|
+
git_str_attach(&worktree, gitlink, 0);
|
|
360
359
|
|
|
361
|
-
if ((
|
|
362
|
-
|
|
360
|
+
if ((git_fs_path_dirname_r(&worktree, worktree.ptr)) < 0 ||
|
|
361
|
+
git_fs_path_to_dir(&worktree) < 0) {
|
|
363
362
|
error = -1;
|
|
364
363
|
goto cleanup;
|
|
365
364
|
}
|
|
366
365
|
|
|
367
|
-
repo->workdir =
|
|
366
|
+
repo->workdir = git_str_detach(&worktree);
|
|
368
367
|
}
|
|
369
368
|
else if (ce && ce->value) {
|
|
370
|
-
if ((error =
|
|
369
|
+
if ((error = git_fs_path_prettify_dir(
|
|
371
370
|
&worktree, ce->value, repo->gitdir)) < 0)
|
|
372
371
|
goto cleanup;
|
|
373
372
|
|
|
374
|
-
repo->workdir =
|
|
373
|
+
repo->workdir = git_str_detach(&worktree);
|
|
375
374
|
}
|
|
376
|
-
else if (parent_path &&
|
|
377
|
-
repo->workdir =
|
|
375
|
+
else if (parent_path && git_fs_path_isdir(parent_path->ptr))
|
|
376
|
+
repo->workdir = git_str_detach(parent_path);
|
|
378
377
|
else {
|
|
379
|
-
if (
|
|
380
|
-
|
|
378
|
+
if (git_fs_path_dirname_r(&worktree, repo->gitdir) < 0 ||
|
|
379
|
+
git_fs_path_to_dir(&worktree) < 0) {
|
|
381
380
|
error = -1;
|
|
382
381
|
goto cleanup;
|
|
383
382
|
}
|
|
384
383
|
|
|
385
|
-
repo->workdir =
|
|
384
|
+
repo->workdir = git_str_detach(&worktree);
|
|
386
385
|
}
|
|
387
386
|
|
|
388
387
|
GIT_ERROR_CHECK_ALLOC(repo->workdir);
|
|
389
388
|
cleanup:
|
|
390
|
-
|
|
389
|
+
git_str_dispose(&path);
|
|
391
390
|
git_config_entry_free(ce);
|
|
392
391
|
return error;
|
|
393
392
|
}
|
|
@@ -396,7 +395,7 @@ cleanup:
|
|
|
396
395
|
* This function returns furthest offset into path where a ceiling dir
|
|
397
396
|
* is found, so we can stop processing the path at that point.
|
|
398
397
|
*
|
|
399
|
-
* Note: converting this to use
|
|
398
|
+
* Note: converting this to use git_strs instead of GIT_PATH_MAX buffers on
|
|
400
399
|
* the stack could remove directories name limits, but at the cost of doing
|
|
401
400
|
* repeated malloc/frees inside the loop below, so let's not do it now.
|
|
402
401
|
*/
|
|
@@ -411,7 +410,7 @@ static size_t find_ceiling_dir_offset(
|
|
|
411
410
|
|
|
412
411
|
GIT_ASSERT_ARG(path);
|
|
413
412
|
|
|
414
|
-
min_len = (size_t)(
|
|
413
|
+
min_len = (size_t)(git_fs_path_root(path) + 1);
|
|
415
414
|
|
|
416
415
|
if (ceiling_directories == NULL || min_len == 0)
|
|
417
416
|
return min_len;
|
|
@@ -420,7 +419,7 @@ static size_t find_ceiling_dir_offset(
|
|
|
420
419
|
for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++);
|
|
421
420
|
len = sep - ceil;
|
|
422
421
|
|
|
423
|
-
if (len == 0 || len >= sizeof(buf) ||
|
|
422
|
+
if (len == 0 || len >= sizeof(buf) || git_fs_path_root(ceil) == -1)
|
|
424
423
|
continue;
|
|
425
424
|
|
|
426
425
|
strncpy(buf, ceil, len);
|
|
@@ -449,10 +448,10 @@ static size_t find_ceiling_dir_offset(
|
|
|
449
448
|
* it points to. Before calling, set `path_out` to the base directory that
|
|
450
449
|
* should be used if the contents of `file_path` are a relative path.
|
|
451
450
|
*/
|
|
452
|
-
static int read_gitfile(
|
|
451
|
+
static int read_gitfile(git_str *path_out, const char *file_path)
|
|
453
452
|
{
|
|
454
453
|
int error = 0;
|
|
455
|
-
|
|
454
|
+
git_str file = GIT_STR_INIT;
|
|
456
455
|
size_t prefix_len = strlen(GIT_FILE_CONTENT_PREFIX);
|
|
457
456
|
|
|
458
457
|
GIT_ASSERT_ARG(path_out);
|
|
@@ -461,98 +460,41 @@ static int read_gitfile(git_buf *path_out, const char *file_path)
|
|
|
461
460
|
if (git_futils_readbuffer(&file, file_path) < 0)
|
|
462
461
|
return -1;
|
|
463
462
|
|
|
464
|
-
|
|
463
|
+
git_str_rtrim(&file);
|
|
465
464
|
/* apparently on Windows, some people use backslashes in paths */
|
|
466
|
-
|
|
465
|
+
git_fs_path_mkposix(file.ptr);
|
|
467
466
|
|
|
468
|
-
if (
|
|
469
|
-
memcmp(
|
|
467
|
+
if (git_str_len(&file) <= prefix_len ||
|
|
468
|
+
memcmp(git_str_cstr(&file), GIT_FILE_CONTENT_PREFIX, prefix_len) != 0)
|
|
470
469
|
{
|
|
471
470
|
git_error_set(GIT_ERROR_REPOSITORY,
|
|
472
471
|
"the `.git` file at '%s' is malformed", file_path);
|
|
473
472
|
error = -1;
|
|
474
473
|
}
|
|
475
|
-
else if ((error =
|
|
476
|
-
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;
|
|
477
476
|
while (*gitlink && git__isspace(*gitlink)) gitlink++;
|
|
478
477
|
|
|
479
|
-
error =
|
|
480
|
-
path_out, gitlink,
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
git_buf_dispose(&file);
|
|
484
|
-
return error;
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
typedef struct {
|
|
488
|
-
const char *repo_path;
|
|
489
|
-
git_buf tmp;
|
|
490
|
-
bool is_safe;
|
|
491
|
-
} validate_ownership_data;
|
|
492
|
-
|
|
493
|
-
static int validate_ownership_cb(const git_config_entry *entry, void *payload)
|
|
494
|
-
{
|
|
495
|
-
validate_ownership_data *data = payload;
|
|
496
|
-
|
|
497
|
-
if (strcmp(entry->value, "") == 0)
|
|
498
|
-
data->is_safe = false;
|
|
499
|
-
|
|
500
|
-
if (git_path_prettify_dir(&data->tmp, entry->value, NULL) == 0 &&
|
|
501
|
-
strcmp(data->tmp.ptr, data->repo_path) == 0)
|
|
502
|
-
data->is_safe = true;
|
|
503
|
-
|
|
504
|
-
return 0;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
static int validate_ownership(const char *repo_path)
|
|
508
|
-
{
|
|
509
|
-
git_config *config = NULL;
|
|
510
|
-
validate_ownership_data data = { repo_path, GIT_BUF_INIT, false };
|
|
511
|
-
bool is_safe;
|
|
512
|
-
int error;
|
|
513
|
-
|
|
514
|
-
if ((error = git_path_owner_is_current_user(&is_safe, repo_path)) < 0) {
|
|
515
|
-
if (error == GIT_ENOTFOUND)
|
|
516
|
-
error = 0;
|
|
517
|
-
|
|
518
|
-
goto done;
|
|
478
|
+
error = git_fs_path_prettify_dir(
|
|
479
|
+
path_out, gitlink, git_str_cstr(path_out));
|
|
519
480
|
}
|
|
520
481
|
|
|
521
|
-
|
|
522
|
-
error = 0;
|
|
523
|
-
goto done;
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
if (load_global_config(&config) == 0) {
|
|
527
|
-
error = git_config_get_multivar_foreach(config, "safe.directory", NULL, validate_ownership_cb, &data);
|
|
528
|
-
|
|
529
|
-
if (!error && data.is_safe)
|
|
530
|
-
goto done;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
git_error_set(GIT_ERROR_CONFIG,
|
|
534
|
-
"repository path '%s' is not owned by current user",
|
|
535
|
-
repo_path);
|
|
536
|
-
error = GIT_EOWNER;
|
|
537
|
-
|
|
538
|
-
done:
|
|
539
|
-
git_config_free(config);
|
|
540
|
-
git_buf_dispose(&data.tmp);
|
|
482
|
+
git_str_dispose(&file);
|
|
541
483
|
return error;
|
|
542
484
|
}
|
|
543
485
|
|
|
544
486
|
static int find_repo(
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
487
|
+
git_str *gitdir_path,
|
|
488
|
+
git_str *workdir_path,
|
|
489
|
+
git_str *gitlink_path,
|
|
490
|
+
git_str *commondir_path,
|
|
549
491
|
const char *start_path,
|
|
550
492
|
uint32_t flags,
|
|
551
493
|
const char *ceiling_dirs)
|
|
552
494
|
{
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
495
|
+
git_str path = GIT_STR_INIT;
|
|
496
|
+
git_str repo_link = GIT_STR_INIT;
|
|
497
|
+
git_str common_link = GIT_STR_INIT;
|
|
556
498
|
struct stat st;
|
|
557
499
|
dev_t initial_device = 0;
|
|
558
500
|
int min_iterations;
|
|
@@ -560,9 +502,9 @@ static int find_repo(
|
|
|
560
502
|
size_t ceiling_offset = 0;
|
|
561
503
|
int error;
|
|
562
504
|
|
|
563
|
-
|
|
505
|
+
git_str_clear(gitdir_path);
|
|
564
506
|
|
|
565
|
-
error =
|
|
507
|
+
error = git_fs_path_prettify(&path, start_path, NULL);
|
|
566
508
|
if (error < 0)
|
|
567
509
|
return error;
|
|
568
510
|
|
|
@@ -584,7 +526,7 @@ static int find_repo(
|
|
|
584
526
|
for (;;) {
|
|
585
527
|
if (!(flags & GIT_REPOSITORY_OPEN_NO_DOTGIT)) {
|
|
586
528
|
if (!in_dot_git) {
|
|
587
|
-
if ((error =
|
|
529
|
+
if ((error = git_str_joinpath(&path, path.ptr, DOT_GIT)) < 0)
|
|
588
530
|
goto out;
|
|
589
531
|
}
|
|
590
532
|
in_dot_git = !in_dot_git;
|
|
@@ -603,15 +545,15 @@ static int find_repo(
|
|
|
603
545
|
goto out;
|
|
604
546
|
|
|
605
547
|
if (is_valid) {
|
|
606
|
-
if ((error =
|
|
607
|
-
(error =
|
|
548
|
+
if ((error = git_fs_path_to_dir(&path)) < 0 ||
|
|
549
|
+
(error = git_str_set(gitdir_path, path.ptr, path.size)) < 0)
|
|
608
550
|
goto out;
|
|
609
551
|
|
|
610
552
|
if (gitlink_path)
|
|
611
|
-
if ((error =
|
|
553
|
+
if ((error = git_str_attach(gitlink_path, git_worktree__read_link(path.ptr, GIT_GITDIR_FILE), 0)) < 0)
|
|
612
554
|
goto out;
|
|
613
555
|
if (commondir_path)
|
|
614
|
-
|
|
556
|
+
git_str_swap(&common_link, commondir_path);
|
|
615
557
|
|
|
616
558
|
break;
|
|
617
559
|
}
|
|
@@ -621,13 +563,13 @@ static int find_repo(
|
|
|
621
563
|
goto out;
|
|
622
564
|
|
|
623
565
|
if (is_valid) {
|
|
624
|
-
|
|
566
|
+
git_str_swap(gitdir_path, &repo_link);
|
|
625
567
|
|
|
626
568
|
if (gitlink_path)
|
|
627
|
-
if ((error =
|
|
569
|
+
if ((error = git_str_put(gitlink_path, path.ptr, path.size)) < 0)
|
|
628
570
|
goto out;
|
|
629
571
|
if (commondir_path)
|
|
630
|
-
|
|
572
|
+
git_str_swap(&common_link, commondir_path);
|
|
631
573
|
}
|
|
632
574
|
break;
|
|
633
575
|
}
|
|
@@ -636,7 +578,7 @@ static int find_repo(
|
|
|
636
578
|
/* Move up one directory. If we're in_dot_git, we'll search the
|
|
637
579
|
* parent itself next. If we're !in_dot_git, we'll search .git
|
|
638
580
|
* in the parent directory next (added at the top of the loop). */
|
|
639
|
-
if ((error =
|
|
581
|
+
if ((error = git_fs_path_dirname_r(&path, path.ptr)) < 0)
|
|
640
582
|
goto out;
|
|
641
583
|
|
|
642
584
|
/* Once we've checked the directory (and .git if applicable),
|
|
@@ -651,25 +593,25 @@ static int find_repo(
|
|
|
651
593
|
}
|
|
652
594
|
|
|
653
595
|
if (workdir_path && !(flags & GIT_REPOSITORY_OPEN_BARE)) {
|
|
654
|
-
if (!
|
|
655
|
-
|
|
656
|
-
else if ((error =
|
|
657
|
-
(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)
|
|
658
600
|
goto out;
|
|
659
601
|
}
|
|
660
602
|
|
|
661
603
|
/* If we didn't find the repository, and we don't have any other error
|
|
662
604
|
* to report, report that. */
|
|
663
|
-
if (!
|
|
605
|
+
if (!git_str_len(gitdir_path)) {
|
|
664
606
|
git_error_set(GIT_ERROR_REPOSITORY, "could not find repository from '%s'", start_path);
|
|
665
607
|
error = GIT_ENOTFOUND;
|
|
666
608
|
goto out;
|
|
667
609
|
}
|
|
668
610
|
|
|
669
611
|
out:
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
612
|
+
git_str_dispose(&path);
|
|
613
|
+
git_str_dispose(&repo_link);
|
|
614
|
+
git_str_dispose(&common_link);
|
|
673
615
|
return error;
|
|
674
616
|
}
|
|
675
617
|
|
|
@@ -677,18 +619,18 @@ int git_repository_open_bare(
|
|
|
677
619
|
git_repository **repo_ptr,
|
|
678
620
|
const char *bare_path)
|
|
679
621
|
{
|
|
680
|
-
|
|
622
|
+
git_str path = GIT_STR_INIT, common_path = GIT_STR_INIT;
|
|
681
623
|
git_repository *repo = NULL;
|
|
682
624
|
bool is_valid;
|
|
683
625
|
int error;
|
|
684
626
|
|
|
685
|
-
if ((error =
|
|
627
|
+
if ((error = git_fs_path_prettify_dir(&path, bare_path, NULL)) < 0 ||
|
|
686
628
|
(error = is_valid_repository_path(&is_valid, &path, &common_path)) < 0)
|
|
687
629
|
return error;
|
|
688
630
|
|
|
689
631
|
if (!is_valid) {
|
|
690
|
-
|
|
691
|
-
|
|
632
|
+
git_str_dispose(&path);
|
|
633
|
+
git_str_dispose(&common_path);
|
|
692
634
|
git_error_set(GIT_ERROR_REPOSITORY, "path is not a repository: %s", bare_path);
|
|
693
635
|
return GIT_ENOTFOUND;
|
|
694
636
|
}
|
|
@@ -696,9 +638,9 @@ int git_repository_open_bare(
|
|
|
696
638
|
repo = repository_alloc();
|
|
697
639
|
GIT_ERROR_CHECK_ALLOC(repo);
|
|
698
640
|
|
|
699
|
-
repo->gitdir =
|
|
641
|
+
repo->gitdir = git_str_detach(&path);
|
|
700
642
|
GIT_ERROR_CHECK_ALLOC(repo->gitdir);
|
|
701
|
-
repo->commondir =
|
|
643
|
+
repo->commondir = git_str_detach(&common_path);
|
|
702
644
|
GIT_ERROR_CHECK_ALLOC(repo->commondir);
|
|
703
645
|
|
|
704
646
|
/* of course we're bare! */
|
|
@@ -717,15 +659,15 @@ static int _git_repository_open_ext_from_env(
|
|
|
717
659
|
git_repository *repo = NULL;
|
|
718
660
|
git_index *index = NULL;
|
|
719
661
|
git_odb *odb = NULL;
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
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;
|
|
729
671
|
const char *ceiling_dirs = NULL;
|
|
730
672
|
unsigned flags = 0;
|
|
731
673
|
int error;
|
|
@@ -738,7 +680,7 @@ static int _git_repository_open_ext_from_env(
|
|
|
738
680
|
} else if (error < 0)
|
|
739
681
|
goto error;
|
|
740
682
|
else {
|
|
741
|
-
start_path =
|
|
683
|
+
start_path = git_str_cstr(&dir_buf);
|
|
742
684
|
flags |= GIT_REPOSITORY_OPEN_NO_SEARCH;
|
|
743
685
|
flags |= GIT_REPOSITORY_OPEN_NO_DOTGIT;
|
|
744
686
|
}
|
|
@@ -750,7 +692,7 @@ static int _git_repository_open_ext_from_env(
|
|
|
750
692
|
else if (error < 0)
|
|
751
693
|
goto error;
|
|
752
694
|
else
|
|
753
|
-
ceiling_dirs =
|
|
695
|
+
ceiling_dirs = git_str_cstr(&ceiling_dirs_buf);
|
|
754
696
|
|
|
755
697
|
error = git__getenv(&across_fs_buf, "GIT_DISCOVERY_ACROSS_FILESYSTEM");
|
|
756
698
|
if (error == GIT_ENOTFOUND)
|
|
@@ -759,7 +701,7 @@ static int _git_repository_open_ext_from_env(
|
|
|
759
701
|
goto error;
|
|
760
702
|
else {
|
|
761
703
|
int across_fs = 0;
|
|
762
|
-
error = git_config_parse_bool(&across_fs,
|
|
704
|
+
error = git_config_parse_bool(&across_fs, git_str_cstr(&across_fs_buf));
|
|
763
705
|
if (error < 0)
|
|
764
706
|
goto error;
|
|
765
707
|
if (across_fs)
|
|
@@ -772,7 +714,7 @@ static int _git_repository_open_ext_from_env(
|
|
|
772
714
|
else if (error < 0)
|
|
773
715
|
goto error;
|
|
774
716
|
else {
|
|
775
|
-
error = git_index_open(&index,
|
|
717
|
+
error = git_index_open(&index, git_str_cstr(&index_file_buf));
|
|
776
718
|
if (error < 0)
|
|
777
719
|
goto error;
|
|
778
720
|
}
|
|
@@ -789,7 +731,7 @@ static int _git_repository_open_ext_from_env(
|
|
|
789
731
|
else if (error < 0)
|
|
790
732
|
goto error;
|
|
791
733
|
else {
|
|
792
|
-
error = git_odb_open(&odb,
|
|
734
|
+
error = git_odb_open(&odb, git_str_cstr(&object_dir_buf));
|
|
793
735
|
if (error < 0)
|
|
794
736
|
goto error;
|
|
795
737
|
}
|
|
@@ -838,7 +780,7 @@ static int _git_repository_open_ext_from_env(
|
|
|
838
780
|
goto error;
|
|
839
781
|
}
|
|
840
782
|
|
|
841
|
-
end =
|
|
783
|
+
end = git_str_cstr(&alts_buf) + git_str_len(&alts_buf);
|
|
842
784
|
for (sep = alt = alts_buf.ptr; sep != end; alt = sep+1) {
|
|
843
785
|
for (sep = alt; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++)
|
|
844
786
|
;
|
|
@@ -850,8 +792,8 @@ static int _git_repository_open_ext_from_env(
|
|
|
850
792
|
}
|
|
851
793
|
}
|
|
852
794
|
|
|
853
|
-
if (
|
|
854
|
-
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));
|
|
855
797
|
if (error < 0)
|
|
856
798
|
goto error;
|
|
857
799
|
}
|
|
@@ -867,21 +809,21 @@ error:
|
|
|
867
809
|
success:
|
|
868
810
|
git_odb_free(odb);
|
|
869
811
|
git_index_free(index);
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
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);
|
|
879
821
|
return error;
|
|
880
822
|
}
|
|
881
823
|
|
|
882
824
|
static int repo_is_worktree(unsigned *out, const git_repository *repo)
|
|
883
825
|
{
|
|
884
|
-
|
|
826
|
+
git_str gitdir_link = GIT_STR_INIT;
|
|
885
827
|
int error;
|
|
886
828
|
|
|
887
829
|
/* Worktrees cannot have the same commondir and gitdir */
|
|
@@ -891,14 +833,14 @@ static int repo_is_worktree(unsigned *out, const git_repository *repo)
|
|
|
891
833
|
return 0;
|
|
892
834
|
}
|
|
893
835
|
|
|
894
|
-
if ((error =
|
|
836
|
+
if ((error = git_str_joinpath(&gitdir_link, repo->gitdir, "gitdir")) < 0)
|
|
895
837
|
return -1;
|
|
896
838
|
|
|
897
839
|
/* A 'gitdir' file inside a git directory is currently
|
|
898
840
|
* only used when the repository is a working tree. */
|
|
899
|
-
*out = !!
|
|
841
|
+
*out = !!git_fs_path_exists(gitdir_link.ptr);
|
|
900
842
|
|
|
901
|
-
|
|
843
|
+
git_str_dispose(&gitdir_link);
|
|
902
844
|
return error;
|
|
903
845
|
}
|
|
904
846
|
|
|
@@ -910,11 +852,10 @@ int git_repository_open_ext(
|
|
|
910
852
|
{
|
|
911
853
|
int error;
|
|
912
854
|
unsigned is_worktree;
|
|
913
|
-
|
|
914
|
-
gitlink =
|
|
855
|
+
git_str gitdir = GIT_STR_INIT, workdir = GIT_STR_INIT,
|
|
856
|
+
gitlink = GIT_STR_INIT, commondir = GIT_STR_INIT;
|
|
915
857
|
git_repository *repo = NULL;
|
|
916
858
|
git_config *config = NULL;
|
|
917
|
-
const char *validation_path;
|
|
918
859
|
int version = 0;
|
|
919
860
|
|
|
920
861
|
if (flags & GIT_REPOSITORY_OPEN_FROM_ENV)
|
|
@@ -932,15 +873,15 @@ int git_repository_open_ext(
|
|
|
932
873
|
repo = repository_alloc();
|
|
933
874
|
GIT_ERROR_CHECK_ALLOC(repo);
|
|
934
875
|
|
|
935
|
-
repo->gitdir =
|
|
876
|
+
repo->gitdir = git_str_detach(&gitdir);
|
|
936
877
|
GIT_ERROR_CHECK_ALLOC(repo->gitdir);
|
|
937
878
|
|
|
938
879
|
if (gitlink.size) {
|
|
939
|
-
repo->gitlink =
|
|
880
|
+
repo->gitlink = git_str_detach(&gitlink);
|
|
940
881
|
GIT_ERROR_CHECK_ALLOC(repo->gitlink);
|
|
941
882
|
}
|
|
942
883
|
if (commondir.size) {
|
|
943
|
-
repo->commondir =
|
|
884
|
+
repo->commondir = git_str_detach(&commondir);
|
|
944
885
|
GIT_ERROR_CHECK_ALLOC(repo->commondir);
|
|
945
886
|
}
|
|
946
887
|
|
|
@@ -963,29 +904,21 @@ int git_repository_open_ext(
|
|
|
963
904
|
if ((error = check_extensions(config, version)) < 0)
|
|
964
905
|
goto cleanup;
|
|
965
906
|
|
|
966
|
-
if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0)
|
|
907
|
+
if ((flags & GIT_REPOSITORY_OPEN_BARE) != 0)
|
|
967
908
|
repo->is_bare = 1;
|
|
968
|
-
|
|
909
|
+
else {
|
|
910
|
+
|
|
969
911
|
if (config &&
|
|
970
912
|
((error = load_config_data(repo, config)) < 0 ||
|
|
971
913
|
(error = load_workdir(repo, config, &workdir)) < 0))
|
|
972
914
|
goto cleanup;
|
|
973
915
|
}
|
|
974
916
|
|
|
975
|
-
/*
|
|
976
|
-
* Ensure that the git directory is owned by the current user.
|
|
977
|
-
*/
|
|
978
|
-
validation_path = repo->is_bare ? repo->gitdir : repo->workdir;
|
|
979
|
-
|
|
980
|
-
if (git_repository__validate_ownership &&
|
|
981
|
-
(error = validate_ownership(validation_path)) < 0)
|
|
982
|
-
goto cleanup;
|
|
983
|
-
|
|
984
917
|
cleanup:
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
918
|
+
git_str_dispose(&gitdir);
|
|
919
|
+
git_str_dispose(&workdir);
|
|
920
|
+
git_str_dispose(&gitlink);
|
|
921
|
+
git_str_dispose(&commondir);
|
|
989
922
|
git_config_free(config);
|
|
990
923
|
|
|
991
924
|
if (error < 0)
|
|
@@ -1004,7 +937,7 @@ int git_repository_open(git_repository **repo_out, const char *path)
|
|
|
1004
937
|
|
|
1005
938
|
int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *wt)
|
|
1006
939
|
{
|
|
1007
|
-
|
|
940
|
+
git_str path = GIT_STR_INIT;
|
|
1008
941
|
git_repository *repo = NULL;
|
|
1009
942
|
size_t len;
|
|
1010
943
|
int err;
|
|
@@ -1020,7 +953,7 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
|
|
|
1020
953
|
goto out;
|
|
1021
954
|
}
|
|
1022
955
|
|
|
1023
|
-
if ((err =
|
|
956
|
+
if ((err = git_str_set(&path, wt->gitlink_path, len - 4)) < 0)
|
|
1024
957
|
goto out;
|
|
1025
958
|
|
|
1026
959
|
if ((err = git_repository_open(&repo, path.ptr)) < 0)
|
|
@@ -1029,7 +962,7 @@ int git_repository_open_from_worktree(git_repository **repo_out, git_worktree *w
|
|
|
1029
962
|
*repo_out = repo;
|
|
1030
963
|
|
|
1031
964
|
out:
|
|
1032
|
-
|
|
965
|
+
git_str_dispose(&path);
|
|
1033
966
|
|
|
1034
967
|
return err;
|
|
1035
968
|
}
|
|
@@ -1054,14 +987,10 @@ int git_repository_discover(
|
|
|
1054
987
|
const char *ceiling_dirs)
|
|
1055
988
|
{
|
|
1056
989
|
uint32_t flags = across_fs ? GIT_REPOSITORY_OPEN_CROSS_FS : 0;
|
|
1057
|
-
int error;
|
|
1058
990
|
|
|
1059
991
|
GIT_ASSERT_ARG(start_path);
|
|
1060
992
|
|
|
1061
|
-
|
|
1062
|
-
return error;
|
|
1063
|
-
|
|
1064
|
-
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);
|
|
1065
994
|
}
|
|
1066
995
|
|
|
1067
996
|
static int load_config(
|
|
@@ -1073,7 +1002,7 @@ static int load_config(
|
|
|
1073
1002
|
const char *programdata_path)
|
|
1074
1003
|
{
|
|
1075
1004
|
int error;
|
|
1076
|
-
|
|
1005
|
+
git_str config_path = GIT_STR_INIT;
|
|
1077
1006
|
git_config *cfg = NULL;
|
|
1078
1007
|
|
|
1079
1008
|
GIT_ASSERT_ARG(out);
|
|
@@ -1082,13 +1011,13 @@ static int load_config(
|
|
|
1082
1011
|
return error;
|
|
1083
1012
|
|
|
1084
1013
|
if (repo) {
|
|
1085
|
-
if ((error =
|
|
1014
|
+
if ((error = git_repository__item_path(&config_path, repo, GIT_REPOSITORY_ITEM_CONFIG)) == 0)
|
|
1086
1015
|
error = git_config_add_file_ondisk(cfg, config_path.ptr, GIT_CONFIG_LEVEL_LOCAL, repo, 0);
|
|
1087
1016
|
|
|
1088
1017
|
if (error && error != GIT_ENOTFOUND)
|
|
1089
1018
|
goto on_error;
|
|
1090
1019
|
|
|
1091
|
-
|
|
1020
|
+
git_str_dispose(&config_path);
|
|
1092
1021
|
}
|
|
1093
1022
|
|
|
1094
1023
|
if (global_config_path != NULL &&
|
|
@@ -1121,15 +1050,15 @@ static int load_config(
|
|
|
1121
1050
|
return 0;
|
|
1122
1051
|
|
|
1123
1052
|
on_error:
|
|
1124
|
-
|
|
1053
|
+
git_str_dispose(&config_path);
|
|
1125
1054
|
git_config_free(cfg);
|
|
1126
1055
|
*out = NULL;
|
|
1127
1056
|
return error;
|
|
1128
1057
|
}
|
|
1129
1058
|
|
|
1130
|
-
static const char *path_unless_empty(
|
|
1059
|
+
static const char *path_unless_empty(git_str *buf)
|
|
1131
1060
|
{
|
|
1132
|
-
return
|
|
1061
|
+
return git_str_len(buf) > 0 ? git_str_cstr(buf) : NULL;
|
|
1133
1062
|
}
|
|
1134
1063
|
|
|
1135
1064
|
int git_repository_config__weakptr(git_config **out, git_repository *repo)
|
|
@@ -1137,19 +1066,19 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
|
|
|
1137
1066
|
int error = 0;
|
|
1138
1067
|
|
|
1139
1068
|
if (repo->_config == NULL) {
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
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;
|
|
1144
1073
|
git_config *config;
|
|
1145
1074
|
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
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);
|
|
1150
1079
|
|
|
1151
1080
|
/* If there is no global file, open a backend for it anyway */
|
|
1152
|
-
if (
|
|
1081
|
+
if (git_str_len(&global_buf) == 0)
|
|
1153
1082
|
git_config__global_location(&global_buf);
|
|
1154
1083
|
|
|
1155
1084
|
error = load_config(
|
|
@@ -1167,10 +1096,10 @@ int git_repository_config__weakptr(git_config **out, git_repository *repo)
|
|
|
1167
1096
|
}
|
|
1168
1097
|
}
|
|
1169
1098
|
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1099
|
+
git_str_dispose(&global_buf);
|
|
1100
|
+
git_str_dispose(&xdg_buf);
|
|
1101
|
+
git_str_dispose(&system_buf);
|
|
1102
|
+
git_str_dispose(&programdata_buf);
|
|
1174
1103
|
}
|
|
1175
1104
|
|
|
1176
1105
|
*out = repo->_config;
|
|
@@ -1215,10 +1144,10 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
|
|
|
1215
1144
|
|
|
1216
1145
|
*out = git_atomic_load(repo->_odb);
|
|
1217
1146
|
if (*out == NULL) {
|
|
1218
|
-
|
|
1147
|
+
git_str odb_path = GIT_STR_INIT;
|
|
1219
1148
|
git_odb *odb;
|
|
1220
1149
|
|
|
1221
|
-
if ((error =
|
|
1150
|
+
if ((error = git_repository__item_path(&odb_path, repo,
|
|
1222
1151
|
GIT_REPOSITORY_ITEM_OBJECTS)) < 0 ||
|
|
1223
1152
|
(error = git_odb_new(&odb)) < 0)
|
|
1224
1153
|
return error;
|
|
@@ -1236,7 +1165,7 @@ int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
|
|
|
1236
1165
|
git_odb_free(odb);
|
|
1237
1166
|
}
|
|
1238
1167
|
|
|
1239
|
-
|
|
1168
|
+
git_str_dispose(&odb_path);
|
|
1240
1169
|
*out = git_atomic_load(repo->_odb);
|
|
1241
1170
|
}
|
|
1242
1171
|
|
|
@@ -1312,10 +1241,10 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
|
|
|
1312
1241
|
GIT_ASSERT_ARG(repo);
|
|
1313
1242
|
|
|
1314
1243
|
if (repo->_index == NULL) {
|
|
1315
|
-
|
|
1244
|
+
git_str index_path = GIT_STR_INIT;
|
|
1316
1245
|
git_index *index;
|
|
1317
1246
|
|
|
1318
|
-
if ((error =
|
|
1247
|
+
if ((error = git_str_joinpath(&index_path, repo->gitdir, GIT_INDEX_FILE)) < 0)
|
|
1319
1248
|
return error;
|
|
1320
1249
|
|
|
1321
1250
|
error = git_index_open(&index, index_path.ptr);
|
|
@@ -1331,7 +1260,7 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
|
|
|
1331
1260
|
GIT_INDEX_CAPABILITY_FROM_OWNER);
|
|
1332
1261
|
}
|
|
1333
1262
|
|
|
1334
|
-
|
|
1263
|
+
git_str_dispose(&index_path);
|
|
1335
1264
|
}
|
|
1336
1265
|
|
|
1337
1266
|
*out = repo->_index;
|
|
@@ -1379,7 +1308,7 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
|
|
|
1379
1308
|
const char *def_dot_git = DOT_GIT;
|
|
1380
1309
|
size_t name_len, def_len = CONST_STRLEN(GIT_DIR_SHORTNAME);
|
|
1381
1310
|
size_t def_dot_git_len = CONST_STRLEN(DOT_GIT);
|
|
1382
|
-
|
|
1311
|
+
git_str *buf;
|
|
1383
1312
|
|
|
1384
1313
|
if (!name)
|
|
1385
1314
|
return 0;
|
|
@@ -1395,17 +1324,17 @@ static int reserved_names_add8dot3(git_repository *repo, const char *path)
|
|
|
1395
1324
|
if ((buf = git_array_alloc(repo->reserved_names)) == NULL)
|
|
1396
1325
|
return -1;
|
|
1397
1326
|
|
|
1398
|
-
|
|
1327
|
+
git_str_attach(buf, name, name_len);
|
|
1399
1328
|
return true;
|
|
1400
1329
|
}
|
|
1401
1330
|
|
|
1402
1331
|
bool git_repository__reserved_names(
|
|
1403
|
-
|
|
1332
|
+
git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs)
|
|
1404
1333
|
{
|
|
1405
1334
|
GIT_UNUSED(include_ntfs);
|
|
1406
1335
|
|
|
1407
1336
|
if (repo->reserved_names.size == 0) {
|
|
1408
|
-
|
|
1337
|
+
git_str *buf;
|
|
1409
1338
|
size_t i;
|
|
1410
1339
|
|
|
1411
1340
|
/* Add the static defaults */
|
|
@@ -1457,7 +1386,7 @@ on_error:
|
|
|
1457
1386
|
}
|
|
1458
1387
|
#else
|
|
1459
1388
|
bool git_repository__reserved_names(
|
|
1460
|
-
|
|
1389
|
+
git_str **out, size_t *outlen, git_repository *repo, bool include_ntfs)
|
|
1461
1390
|
{
|
|
1462
1391
|
GIT_UNUSED(repo);
|
|
1463
1392
|
|
|
@@ -1503,7 +1432,7 @@ static git_vector user_extensions = GIT_VECTOR_INIT;
|
|
|
1503
1432
|
|
|
1504
1433
|
static int check_valid_extension(const git_config_entry *entry, void *payload)
|
|
1505
1434
|
{
|
|
1506
|
-
|
|
1435
|
+
git_str cfg = GIT_STR_INIT;
|
|
1507
1436
|
bool reject;
|
|
1508
1437
|
const char *extension;
|
|
1509
1438
|
size_t i;
|
|
@@ -1512,7 +1441,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
|
|
|
1512
1441
|
GIT_UNUSED(payload);
|
|
1513
1442
|
|
|
1514
1443
|
git_vector_foreach (&user_extensions, i, extension) {
|
|
1515
|
-
|
|
1444
|
+
git_str_clear(&cfg);
|
|
1516
1445
|
|
|
1517
1446
|
/*
|
|
1518
1447
|
* Users can specify that they don't want to support an
|
|
@@ -1521,7 +1450,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
|
|
|
1521
1450
|
if ((reject = (extension[0] == '!')) == true)
|
|
1522
1451
|
extension = &extension[1];
|
|
1523
1452
|
|
|
1524
|
-
if ((error =
|
|
1453
|
+
if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0)
|
|
1525
1454
|
goto done;
|
|
1526
1455
|
|
|
1527
1456
|
if (strcmp(entry->name, cfg.ptr) == 0) {
|
|
@@ -1535,7 +1464,7 @@ static int check_valid_extension(const git_config_entry *entry, void *payload)
|
|
|
1535
1464
|
for (i = 0; i < ARRAY_SIZE(builtin_extensions); i++) {
|
|
1536
1465
|
extension = builtin_extensions[i];
|
|
1537
1466
|
|
|
1538
|
-
if ((error =
|
|
1467
|
+
if ((error = git_str_printf(&cfg, "extensions.%s", extension)) < 0)
|
|
1539
1468
|
goto done;
|
|
1540
1469
|
|
|
1541
1470
|
if (strcmp(entry->name, cfg.ptr) == 0)
|
|
@@ -1547,7 +1476,7 @@ fail:
|
|
|
1547
1476
|
error = -1;
|
|
1548
1477
|
|
|
1549
1478
|
done:
|
|
1550
|
-
|
|
1479
|
+
git_str_dispose(&cfg);
|
|
1551
1480
|
return error;
|
|
1552
1481
|
}
|
|
1553
1482
|
|
|
@@ -1625,12 +1554,12 @@ void git_repository__free_extensions(void)
|
|
|
1625
1554
|
|
|
1626
1555
|
int git_repository_create_head(const char *git_dir, const char *ref_name)
|
|
1627
1556
|
{
|
|
1628
|
-
|
|
1557
|
+
git_str ref_path = GIT_STR_INIT;
|
|
1629
1558
|
git_filebuf ref = GIT_FILEBUF_INIT;
|
|
1630
1559
|
const char *fmt;
|
|
1631
1560
|
int error;
|
|
1632
1561
|
|
|
1633
|
-
if ((error =
|
|
1562
|
+
if ((error = git_str_joinpath(&ref_path, git_dir, GIT_HEAD_FILE)) < 0 ||
|
|
1634
1563
|
(error = git_filebuf_open(&ref, ref_path.ptr, 0, GIT_REFS_FILE_MODE)) < 0)
|
|
1635
1564
|
goto out;
|
|
1636
1565
|
|
|
@@ -1644,7 +1573,7 @@ int git_repository_create_head(const char *git_dir, const char *ref_name)
|
|
|
1644
1573
|
goto out;
|
|
1645
1574
|
|
|
1646
1575
|
out:
|
|
1647
|
-
|
|
1576
|
+
git_str_dispose(&ref_path);
|
|
1648
1577
|
git_filebuf_cleanup(&ref);
|
|
1649
1578
|
return error;
|
|
1650
1579
|
}
|
|
@@ -1667,50 +1596,23 @@ static bool is_chmod_supported(const char *file_path)
|
|
|
1667
1596
|
|
|
1668
1597
|
static bool is_filesystem_case_insensitive(const char *gitdir_path)
|
|
1669
1598
|
{
|
|
1670
|
-
|
|
1599
|
+
git_str path = GIT_STR_INIT;
|
|
1671
1600
|
int is_insensitive = -1;
|
|
1672
1601
|
|
|
1673
|
-
if (!
|
|
1674
|
-
is_insensitive =
|
|
1602
|
+
if (!git_str_joinpath(&path, gitdir_path, "CoNfIg"))
|
|
1603
|
+
is_insensitive = git_fs_path_exists(git_str_cstr(&path));
|
|
1675
1604
|
|
|
1676
|
-
|
|
1605
|
+
git_str_dispose(&path);
|
|
1677
1606
|
return is_insensitive;
|
|
1678
1607
|
}
|
|
1679
1608
|
|
|
1680
|
-
/*
|
|
1681
|
-
* Return a configuration object with only the global and system
|
|
1682
|
-
* configurations; no repository-level configuration.
|
|
1683
|
-
*/
|
|
1684
|
-
static int load_global_config(git_config **config)
|
|
1685
|
-
{
|
|
1686
|
-
git_buf global_buf = GIT_BUF_INIT;
|
|
1687
|
-
git_buf xdg_buf = GIT_BUF_INIT;
|
|
1688
|
-
git_buf system_buf = GIT_BUF_INIT;
|
|
1689
|
-
git_buf programdata_buf = GIT_BUF_INIT;
|
|
1690
|
-
int error;
|
|
1691
|
-
|
|
1692
|
-
git_config_find_global(&global_buf);
|
|
1693
|
-
git_config_find_xdg(&xdg_buf);
|
|
1694
|
-
git_config_find_system(&system_buf);
|
|
1695
|
-
git_config_find_programdata(&programdata_buf);
|
|
1696
|
-
|
|
1697
|
-
error = load_config(config, NULL,
|
|
1698
|
-
path_unless_empty(&global_buf),
|
|
1699
|
-
path_unless_empty(&xdg_buf),
|
|
1700
|
-
path_unless_empty(&system_buf),
|
|
1701
|
-
path_unless_empty(&programdata_buf));
|
|
1702
|
-
|
|
1703
|
-
git_buf_dispose(&global_buf);
|
|
1704
|
-
git_buf_dispose(&xdg_buf);
|
|
1705
|
-
git_buf_dispose(&system_buf);
|
|
1706
|
-
git_buf_dispose(&programdata_buf);
|
|
1707
|
-
|
|
1708
|
-
return error;
|
|
1709
|
-
}
|
|
1710
|
-
|
|
1711
1609
|
static bool are_symlinks_supported(const char *wd_path)
|
|
1712
1610
|
{
|
|
1713
1611
|
git_config *config = NULL;
|
|
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;
|
|
1714
1616
|
int symlinks = 0;
|
|
1715
1617
|
|
|
1716
1618
|
/*
|
|
@@ -1721,16 +1623,30 @@ static bool are_symlinks_supported(const char *wd_path)
|
|
|
1721
1623
|
* _not_ set, then we do not test or enable symlink support.
|
|
1722
1624
|
*/
|
|
1723
1625
|
#ifdef GIT_WIN32
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
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);
|
|
1630
|
+
|
|
1631
|
+
if (load_config(&config, NULL,
|
|
1632
|
+
path_unless_empty(&global_buf),
|
|
1633
|
+
path_unless_empty(&xdg_buf),
|
|
1634
|
+
path_unless_empty(&system_buf),
|
|
1635
|
+
path_unless_empty(&programdata_buf)) < 0)
|
|
1636
|
+
goto done;
|
|
1637
|
+
|
|
1638
|
+
if (git_config_get_bool(&symlinks, config, "core.symlinks") < 0 || !symlinks)
|
|
1727
1639
|
goto done;
|
|
1728
1640
|
#endif
|
|
1729
1641
|
|
|
1730
|
-
if (!(symlinks =
|
|
1642
|
+
if (!(symlinks = git_fs_path_supports_symlinks(wd_path)))
|
|
1731
1643
|
goto done;
|
|
1732
1644
|
|
|
1733
1645
|
done:
|
|
1646
|
+
git_str_dispose(&global_buf);
|
|
1647
|
+
git_str_dispose(&xdg_buf);
|
|
1648
|
+
git_str_dispose(&system_buf);
|
|
1649
|
+
git_str_dispose(&programdata_buf);
|
|
1734
1650
|
git_config_free(config);
|
|
1735
1651
|
return symlinks != 0;
|
|
1736
1652
|
}
|
|
@@ -1754,7 +1670,7 @@ static int create_empty_file(const char *path, mode_t mode)
|
|
|
1754
1670
|
|
|
1755
1671
|
static int repo_local_config(
|
|
1756
1672
|
git_config **out,
|
|
1757
|
-
|
|
1673
|
+
git_str *config_dir,
|
|
1758
1674
|
git_repository *repo,
|
|
1759
1675
|
const char *repo_dir)
|
|
1760
1676
|
{
|
|
@@ -1762,12 +1678,12 @@ static int repo_local_config(
|
|
|
1762
1678
|
git_config *parent;
|
|
1763
1679
|
const char *cfg_path;
|
|
1764
1680
|
|
|
1765
|
-
if (
|
|
1681
|
+
if (git_str_joinpath(config_dir, repo_dir, GIT_CONFIG_FILENAME_INREPO) < 0)
|
|
1766
1682
|
return -1;
|
|
1767
|
-
cfg_path =
|
|
1683
|
+
cfg_path = git_str_cstr(config_dir);
|
|
1768
1684
|
|
|
1769
1685
|
/* make LOCAL config if missing */
|
|
1770
|
-
if (!
|
|
1686
|
+
if (!git_fs_path_isfile(cfg_path) &&
|
|
1771
1687
|
(error = create_empty_file(cfg_path, GIT_CONFIG_FILE_MODE)) < 0)
|
|
1772
1688
|
return error;
|
|
1773
1689
|
|
|
@@ -1825,7 +1741,7 @@ static int repo_init_fs_configs(
|
|
|
1825
1741
|
#ifdef GIT_USE_ICONV
|
|
1826
1742
|
if ((error = git_config_set_bool(
|
|
1827
1743
|
cfg, "core.precomposeunicode",
|
|
1828
|
-
|
|
1744
|
+
git_fs_path_does_decompose_unicode(work_dir))) < 0)
|
|
1829
1745
|
return error;
|
|
1830
1746
|
/* on non-iconv platforms, don't even set core.precomposeunicode */
|
|
1831
1747
|
#endif
|
|
@@ -1840,7 +1756,7 @@ static int repo_init_config(
|
|
|
1840
1756
|
uint32_t mode)
|
|
1841
1757
|
{
|
|
1842
1758
|
int error = 0;
|
|
1843
|
-
|
|
1759
|
+
git_str cfg_path = GIT_STR_INIT, worktree_path = GIT_STR_INIT;
|
|
1844
1760
|
git_config *config = NULL;
|
|
1845
1761
|
bool is_bare = ((flags & GIT_REPOSITORY_INIT_BARE) != 0);
|
|
1846
1762
|
bool is_reinit = ((flags & GIT_REPOSITORY_INIT__IS_REINIT) != 0);
|
|
@@ -1870,11 +1786,11 @@ static int repo_init_config(
|
|
|
1870
1786
|
SET_REPO_CONFIG(bool, "core.logallrefupdates", true);
|
|
1871
1787
|
|
|
1872
1788
|
if (!(flags & GIT_REPOSITORY_INIT__NATURAL_WD)) {
|
|
1873
|
-
if ((error =
|
|
1789
|
+
if ((error = git_str_sets(&worktree_path, work_dir)) < 0)
|
|
1874
1790
|
goto cleanup;
|
|
1875
1791
|
|
|
1876
1792
|
if ((flags & GIT_REPOSITORY_INIT_RELATIVE_GITLINK))
|
|
1877
|
-
if ((error =
|
|
1793
|
+
if ((error = git_fs_path_make_relative(&worktree_path, repo_dir)) < 0)
|
|
1878
1794
|
goto cleanup;
|
|
1879
1795
|
|
|
1880
1796
|
SET_REPO_CONFIG(string, "core.worktree", worktree_path.ptr);
|
|
@@ -1894,8 +1810,8 @@ static int repo_init_config(
|
|
|
1894
1810
|
}
|
|
1895
1811
|
|
|
1896
1812
|
cleanup:
|
|
1897
|
-
|
|
1898
|
-
|
|
1813
|
+
git_str_dispose(&cfg_path);
|
|
1814
|
+
git_str_dispose(&worktree_path);
|
|
1899
1815
|
git_config_free(config);
|
|
1900
1816
|
|
|
1901
1817
|
return error;
|
|
@@ -1917,7 +1833,7 @@ static int repo_reinit_submodule_fs(git_submodule *sm, const char *n, void *p)
|
|
|
1917
1833
|
int git_repository_reinit_filesystem(git_repository *repo, int recurse)
|
|
1918
1834
|
{
|
|
1919
1835
|
int error = 0;
|
|
1920
|
-
|
|
1836
|
+
git_str path = GIT_STR_INIT;
|
|
1921
1837
|
git_config *config = NULL;
|
|
1922
1838
|
const char *repo_dir = git_repository_path(repo);
|
|
1923
1839
|
|
|
@@ -1926,7 +1842,7 @@ int git_repository_reinit_filesystem(git_repository *repo, int recurse)
|
|
|
1926
1842
|
config, path.ptr, repo_dir, git_repository_workdir(repo), true);
|
|
1927
1843
|
|
|
1928
1844
|
git_config_free(config);
|
|
1929
|
-
|
|
1845
|
+
git_str_dispose(&path);
|
|
1930
1846
|
|
|
1931
1847
|
git_repository__configmap_lookup_cache_clear(repo);
|
|
1932
1848
|
|
|
@@ -1944,10 +1860,10 @@ static int repo_write_template(
|
|
|
1944
1860
|
bool hidden,
|
|
1945
1861
|
const char *content)
|
|
1946
1862
|
{
|
|
1947
|
-
|
|
1863
|
+
git_str path = GIT_STR_INIT;
|
|
1948
1864
|
int fd, error = 0, flags;
|
|
1949
1865
|
|
|
1950
|
-
if (
|
|
1866
|
+
if (git_str_joinpath(&path, git_dir, file) < 0)
|
|
1951
1867
|
return -1;
|
|
1952
1868
|
|
|
1953
1869
|
if (allow_overwrite)
|
|
@@ -1955,7 +1871,7 @@ static int repo_write_template(
|
|
|
1955
1871
|
else
|
|
1956
1872
|
flags = O_WRONLY | O_CREAT | O_EXCL;
|
|
1957
1873
|
|
|
1958
|
-
fd = p_open(
|
|
1874
|
+
fd = p_open(git_str_cstr(&path), flags, mode);
|
|
1959
1875
|
|
|
1960
1876
|
if (fd >= 0) {
|
|
1961
1877
|
error = p_write(fd, content, strlen(content));
|
|
@@ -1974,7 +1890,7 @@ static int repo_write_template(
|
|
|
1974
1890
|
GIT_UNUSED(hidden);
|
|
1975
1891
|
#endif
|
|
1976
1892
|
|
|
1977
|
-
|
|
1893
|
+
git_str_dispose(&path);
|
|
1978
1894
|
|
|
1979
1895
|
if (error)
|
|
1980
1896
|
git_error_set(GIT_ERROR_OS,
|
|
@@ -1987,13 +1903,13 @@ static int repo_write_gitlink(
|
|
|
1987
1903
|
const char *in_dir, const char *to_repo, bool use_relative_path)
|
|
1988
1904
|
{
|
|
1989
1905
|
int error;
|
|
1990
|
-
|
|
1991
|
-
|
|
1906
|
+
git_str buf = GIT_STR_INIT;
|
|
1907
|
+
git_str path_to_repo = GIT_STR_INIT;
|
|
1992
1908
|
struct stat st;
|
|
1993
1909
|
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
if (
|
|
1910
|
+
git_fs_path_dirname_r(&buf, to_repo);
|
|
1911
|
+
git_fs_path_to_dir(&buf);
|
|
1912
|
+
if (git_str_oom(&buf))
|
|
1997
1913
|
return -1;
|
|
1998
1914
|
|
|
1999
1915
|
/* don't write gitlink to natural workdir */
|
|
@@ -2004,7 +1920,7 @@ static int repo_write_gitlink(
|
|
|
2004
1920
|
goto cleanup;
|
|
2005
1921
|
}
|
|
2006
1922
|
|
|
2007
|
-
if ((error =
|
|
1923
|
+
if ((error = git_str_joinpath(&buf, in_dir, DOT_GIT)) < 0)
|
|
2008
1924
|
goto cleanup;
|
|
2009
1925
|
|
|
2010
1926
|
if (!p_stat(buf.ptr, &st) && !S_ISREG(st.st_mode)) {
|
|
@@ -2014,22 +1930,22 @@ static int repo_write_gitlink(
|
|
|
2014
1930
|
goto cleanup;
|
|
2015
1931
|
}
|
|
2016
1932
|
|
|
2017
|
-
|
|
1933
|
+
git_str_clear(&buf);
|
|
2018
1934
|
|
|
2019
|
-
error =
|
|
1935
|
+
error = git_str_sets(&path_to_repo, to_repo);
|
|
2020
1936
|
|
|
2021
1937
|
if (!error && use_relative_path)
|
|
2022
|
-
error =
|
|
1938
|
+
error = git_fs_path_make_relative(&path_to_repo, in_dir);
|
|
2023
1939
|
|
|
2024
1940
|
if (!error)
|
|
2025
|
-
error =
|
|
1941
|
+
error = git_str_join(&buf, ' ', GIT_FILE_CONTENT_PREFIX, path_to_repo.ptr);
|
|
2026
1942
|
|
|
2027
1943
|
if (!error)
|
|
2028
1944
|
error = repo_write_template(in_dir, true, DOT_GIT, 0666, true, buf.ptr);
|
|
2029
1945
|
|
|
2030
1946
|
cleanup:
|
|
2031
|
-
|
|
2032
|
-
|
|
1947
|
+
git_str_dispose(&buf);
|
|
1948
|
+
git_str_dispose(&path_to_repo);
|
|
2033
1949
|
return error;
|
|
2034
1950
|
}
|
|
2035
1951
|
|
|
@@ -2082,12 +1998,12 @@ static int repo_init_structure(
|
|
|
2082
1998
|
git_config *cfg = NULL;
|
|
2083
1999
|
const char *tdir = NULL;
|
|
2084
2000
|
bool default_template = false;
|
|
2085
|
-
|
|
2001
|
+
git_str template_buf = GIT_STR_INIT;
|
|
2086
2002
|
|
|
2087
2003
|
if (opts->template_path)
|
|
2088
2004
|
tdir = opts->template_path;
|
|
2089
2005
|
else if ((error = git_config_open_default(&cfg)) >= 0) {
|
|
2090
|
-
if (!
|
|
2006
|
+
if (!git_config__get_path(&template_buf, cfg, "init.templatedir"))
|
|
2091
2007
|
tdir = template_buf.ptr;
|
|
2092
2008
|
git_error_clear();
|
|
2093
2009
|
}
|
|
@@ -2113,11 +2029,16 @@ static int repo_init_structure(
|
|
|
2113
2029
|
error = git_futils_cp_r(tdir, repo_dir, cpflags, dmode);
|
|
2114
2030
|
}
|
|
2115
2031
|
|
|
2116
|
-
|
|
2032
|
+
git_str_dispose(&template_buf);
|
|
2117
2033
|
git_config_free(cfg);
|
|
2118
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
|
+
*/
|
|
2119
2040
|
if (error < 0) {
|
|
2120
|
-
if (!default_template)
|
|
2041
|
+
if (!default_template && error != GIT_ENOTFOUND)
|
|
2121
2042
|
return error;
|
|
2122
2043
|
|
|
2123
2044
|
/* if template was default, ignore error and use internal */
|
|
@@ -2154,7 +2075,7 @@ static int repo_init_structure(
|
|
|
2154
2075
|
return error;
|
|
2155
2076
|
}
|
|
2156
2077
|
|
|
2157
|
-
static int mkdir_parent(
|
|
2078
|
+
static int mkdir_parent(git_str *buf, uint32_t mode, bool skip2)
|
|
2158
2079
|
{
|
|
2159
2080
|
/* When making parent directories during repository initialization
|
|
2160
2081
|
* don't try to set gid or grant world write access
|
|
@@ -2166,8 +2087,8 @@ static int mkdir_parent(git_buf *buf, uint32_t mode, bool skip2)
|
|
|
2166
2087
|
}
|
|
2167
2088
|
|
|
2168
2089
|
static int repo_init_directories(
|
|
2169
|
-
|
|
2170
|
-
|
|
2090
|
+
git_str *repo_path,
|
|
2091
|
+
git_str *wd_path,
|
|
2171
2092
|
const char *given_repo,
|
|
2172
2093
|
git_repository_init_options *opts)
|
|
2173
2094
|
{
|
|
@@ -2205,7 +2126,7 @@ static int repo_init_directories(
|
|
|
2205
2126
|
git__suffixcmp(given_repo, "/" DOT_GIT) != 0 &&
|
|
2206
2127
|
git__suffixcmp(given_repo, "/" GIT_DIR) != 0;
|
|
2207
2128
|
|
|
2208
|
-
if (
|
|
2129
|
+
if (git_str_joinpath(repo_path, given_repo, add_dotgit ? GIT_DIR : "") < 0)
|
|
2209
2130
|
return -1;
|
|
2210
2131
|
|
|
2211
2132
|
has_dotgit = (git__suffixcmp(repo_path->ptr, "/" GIT_DIR) == 0);
|
|
@@ -2216,11 +2137,11 @@ static int repo_init_directories(
|
|
|
2216
2137
|
|
|
2217
2138
|
if (!is_bare) {
|
|
2218
2139
|
if (opts->workdir_path) {
|
|
2219
|
-
if (
|
|
2140
|
+
if (git_fs_path_join_unrooted(
|
|
2220
2141
|
wd_path, opts->workdir_path, repo_path->ptr, NULL) < 0)
|
|
2221
2142
|
return -1;
|
|
2222
2143
|
} else if (has_dotgit) {
|
|
2223
|
-
if (
|
|
2144
|
+
if (git_fs_path_dirname_r(wd_path, repo_path->ptr) < 0)
|
|
2224
2145
|
return -1;
|
|
2225
2146
|
} else {
|
|
2226
2147
|
git_error_set(GIT_ERROR_REPOSITORY, "cannot pick working directory"
|
|
@@ -2228,10 +2149,10 @@ static int repo_init_directories(
|
|
|
2228
2149
|
return -1;
|
|
2229
2150
|
}
|
|
2230
2151
|
|
|
2231
|
-
if (
|
|
2152
|
+
if (git_fs_path_to_dir(wd_path) < 0)
|
|
2232
2153
|
return -1;
|
|
2233
2154
|
} else {
|
|
2234
|
-
|
|
2155
|
+
git_str_clear(wd_path);
|
|
2235
2156
|
}
|
|
2236
2157
|
|
|
2237
2158
|
natural_wd =
|
|
@@ -2288,10 +2209,10 @@ static int repo_init_directories(
|
|
|
2288
2209
|
/* prettify both directories now that they are created */
|
|
2289
2210
|
|
|
2290
2211
|
if (!error) {
|
|
2291
|
-
error =
|
|
2212
|
+
error = git_fs_path_prettify_dir(repo_path, repo_path->ptr, NULL);
|
|
2292
2213
|
|
|
2293
2214
|
if (!error && wd_path->size > 0)
|
|
2294
|
-
error =
|
|
2215
|
+
error = git_fs_path_prettify_dir(wd_path, wd_path->ptr, NULL);
|
|
2295
2216
|
}
|
|
2296
2217
|
|
|
2297
2218
|
return error;
|
|
@@ -2300,24 +2221,24 @@ static int repo_init_directories(
|
|
|
2300
2221
|
static int repo_init_head(const char *repo_dir, const char *given)
|
|
2301
2222
|
{
|
|
2302
2223
|
git_config *cfg = NULL;
|
|
2303
|
-
|
|
2224
|
+
git_str head_path = GIT_STR_INIT, cfg_branch = GIT_STR_INIT;
|
|
2304
2225
|
const char *initial_head = NULL;
|
|
2305
2226
|
int error;
|
|
2306
2227
|
|
|
2307
|
-
if ((error =
|
|
2228
|
+
if ((error = git_str_joinpath(&head_path, repo_dir, GIT_HEAD_FILE)) < 0)
|
|
2308
2229
|
goto out;
|
|
2309
2230
|
|
|
2310
2231
|
/*
|
|
2311
2232
|
* A template may have set a HEAD; use that unless it's been
|
|
2312
2233
|
* overridden by the caller's given initial head setting.
|
|
2313
2234
|
*/
|
|
2314
|
-
if (
|
|
2235
|
+
if (git_fs_path_exists(head_path.ptr) && !given)
|
|
2315
2236
|
goto out;
|
|
2316
2237
|
|
|
2317
2238
|
if (given) {
|
|
2318
2239
|
initial_head = given;
|
|
2319
2240
|
} else if ((error = git_config_open_default(&cfg)) >= 0 &&
|
|
2320
|
-
(error =
|
|
2241
|
+
(error = git_config__get_string_buf(&cfg_branch, cfg, "init.defaultbranch")) >= 0 &&
|
|
2321
2242
|
*cfg_branch.ptr) {
|
|
2322
2243
|
initial_head = cfg_branch.ptr;
|
|
2323
2244
|
}
|
|
@@ -2329,8 +2250,8 @@ static int repo_init_head(const char *repo_dir, const char *given)
|
|
|
2329
2250
|
|
|
2330
2251
|
out:
|
|
2331
2252
|
git_config_free(cfg);
|
|
2332
|
-
|
|
2333
|
-
|
|
2253
|
+
git_str_dispose(&head_path);
|
|
2254
|
+
git_str_dispose(&cfg_branch);
|
|
2334
2255
|
|
|
2335
2256
|
return error;
|
|
2336
2257
|
}
|
|
@@ -2364,8 +2285,8 @@ int git_repository_init_ext(
|
|
|
2364
2285
|
const char *given_repo,
|
|
2365
2286
|
git_repository_init_options *opts)
|
|
2366
2287
|
{
|
|
2367
|
-
|
|
2368
|
-
common_path =
|
|
2288
|
+
git_str repo_path = GIT_STR_INIT, wd_path = GIT_STR_INIT,
|
|
2289
|
+
common_path = GIT_STR_INIT;
|
|
2369
2290
|
const char *wd;
|
|
2370
2291
|
bool is_valid;
|
|
2371
2292
|
int error;
|
|
@@ -2379,7 +2300,7 @@ int git_repository_init_ext(
|
|
|
2379
2300
|
if ((error = repo_init_directories(&repo_path, &wd_path, given_repo, opts)) < 0)
|
|
2380
2301
|
goto out;
|
|
2381
2302
|
|
|
2382
|
-
wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL :
|
|
2303
|
+
wd = (opts->flags & GIT_REPOSITORY_INIT_BARE) ? NULL : git_str_cstr(&wd_path);
|
|
2383
2304
|
|
|
2384
2305
|
if ((error = is_valid_repository_path(&is_valid, &repo_path, &common_path)) < 0)
|
|
2385
2306
|
goto out;
|
|
@@ -2413,9 +2334,9 @@ int git_repository_init_ext(
|
|
|
2413
2334
|
goto out;
|
|
2414
2335
|
|
|
2415
2336
|
out:
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
|
|
2337
|
+
git_str_dispose(&common_path);
|
|
2338
|
+
git_str_dispose(&repo_path);
|
|
2339
|
+
git_str_dispose(&wd_path);
|
|
2419
2340
|
|
|
2420
2341
|
return error;
|
|
2421
2342
|
}
|
|
@@ -2603,7 +2524,7 @@ static int repo_contains_no_reference(git_repository *repo)
|
|
|
2603
2524
|
return error;
|
|
2604
2525
|
}
|
|
2605
2526
|
|
|
2606
|
-
int git_repository_initialbranch(
|
|
2527
|
+
int git_repository_initialbranch(git_str *out, git_repository *repo)
|
|
2607
2528
|
{
|
|
2608
2529
|
git_config *config;
|
|
2609
2530
|
git_config_entry *entry = NULL;
|
|
@@ -2624,8 +2545,8 @@ int git_repository_initialbranch(git_buf *out, git_repository *repo)
|
|
|
2624
2545
|
goto done;
|
|
2625
2546
|
}
|
|
2626
2547
|
|
|
2627
|
-
if ((error =
|
|
2628
|
-
(error =
|
|
2548
|
+
if ((error = git_str_puts(out, GIT_REFS_HEADS_DIR)) < 0 ||
|
|
2549
|
+
(error = git_str_puts(out, branch)) < 0 ||
|
|
2629
2550
|
(error = git_reference_name_is_valid(&valid, out->ptr)) < 0)
|
|
2630
2551
|
goto done;
|
|
2631
2552
|
|
|
@@ -2642,7 +2563,7 @@ done:
|
|
|
2642
2563
|
int git_repository_is_empty(git_repository *repo)
|
|
2643
2564
|
{
|
|
2644
2565
|
git_reference *head = NULL;
|
|
2645
|
-
|
|
2566
|
+
git_str initialbranch = GIT_STR_INIT;
|
|
2646
2567
|
int result = 0;
|
|
2647
2568
|
|
|
2648
2569
|
if ((result = git_reference_lookup(&head, repo, GIT_HEAD_FILE)) < 0 ||
|
|
@@ -2655,7 +2576,7 @@ int git_repository_is_empty(git_repository *repo)
|
|
|
2655
2576
|
|
|
2656
2577
|
done:
|
|
2657
2578
|
git_reference_free(head);
|
|
2658
|
-
|
|
2579
|
+
git_str_dispose(&initialbranch);
|
|
2659
2580
|
|
|
2660
2581
|
return result;
|
|
2661
2582
|
}
|
|
@@ -2684,7 +2605,18 @@ static const char *resolved_parent_path(const git_repository *repo, git_reposito
|
|
|
2684
2605
|
return parent;
|
|
2685
2606
|
}
|
|
2686
2607
|
|
|
2687
|
-
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)
|
|
2688
2620
|
{
|
|
2689
2621
|
const char *parent = resolved_parent_path(repo, items[item].parent, items[item].fallback);
|
|
2690
2622
|
if (parent == NULL) {
|
|
@@ -2692,16 +2624,16 @@ int git_repository_item_path(git_buf *out, const git_repository *repo, git_repos
|
|
|
2692
2624
|
return GIT_ENOTFOUND;
|
|
2693
2625
|
}
|
|
2694
2626
|
|
|
2695
|
-
if (
|
|
2627
|
+
if (git_str_sets(out, parent) < 0)
|
|
2696
2628
|
return -1;
|
|
2697
2629
|
|
|
2698
2630
|
if (items[item].name) {
|
|
2699
|
-
if (
|
|
2631
|
+
if (git_str_joinpath(out, parent, items[item].name) < 0)
|
|
2700
2632
|
return -1;
|
|
2701
2633
|
}
|
|
2702
2634
|
|
|
2703
2635
|
if (items[item].directory) {
|
|
2704
|
-
if (
|
|
2636
|
+
if (git_fs_path_to_dir(out) < 0)
|
|
2705
2637
|
return -1;
|
|
2706
2638
|
}
|
|
2707
2639
|
|
|
@@ -2725,7 +2657,7 @@ const char *git_repository_workdir(const git_repository *repo)
|
|
|
2725
2657
|
}
|
|
2726
2658
|
|
|
2727
2659
|
int git_repository_workdir_path(
|
|
2728
|
-
|
|
2660
|
+
git_str *out, git_repository *repo, const char *path)
|
|
2729
2661
|
{
|
|
2730
2662
|
int error;
|
|
2731
2663
|
|
|
@@ -2734,8 +2666,8 @@ int git_repository_workdir_path(
|
|
|
2734
2666
|
return GIT_EBAREREPO;
|
|
2735
2667
|
}
|
|
2736
2668
|
|
|
2737
|
-
if (!(error =
|
|
2738
|
-
error =
|
|
2669
|
+
if (!(error = git_str_joinpath(out, repo->workdir, path)))
|
|
2670
|
+
error = git_path_validate_str_length(repo, out);
|
|
2739
2671
|
|
|
2740
2672
|
return error;
|
|
2741
2673
|
}
|
|
@@ -2750,12 +2682,12 @@ int git_repository_set_workdir(
|
|
|
2750
2682
|
git_repository *repo, const char *workdir, int update_gitlink)
|
|
2751
2683
|
{
|
|
2752
2684
|
int error = 0;
|
|
2753
|
-
|
|
2685
|
+
git_str path = GIT_STR_INIT;
|
|
2754
2686
|
|
|
2755
2687
|
GIT_ASSERT_ARG(repo);
|
|
2756
2688
|
GIT_ASSERT_ARG(workdir);
|
|
2757
2689
|
|
|
2758
|
-
if (
|
|
2690
|
+
if (git_fs_path_prettify_dir(&path, workdir, NULL) < 0)
|
|
2759
2691
|
return -1;
|
|
2760
2692
|
|
|
2761
2693
|
if (repo->workdir && strcmp(repo->workdir, path.ptr) == 0)
|
|
@@ -2782,7 +2714,7 @@ int git_repository_set_workdir(
|
|
|
2782
2714
|
if (!error) {
|
|
2783
2715
|
char *old_workdir = repo->workdir;
|
|
2784
2716
|
|
|
2785
|
-
repo->workdir =
|
|
2717
|
+
repo->workdir = git_str_detach(&path);
|
|
2786
2718
|
repo->is_bare = 0;
|
|
2787
2719
|
|
|
2788
2720
|
git__free(old_workdir);
|
|
@@ -2851,13 +2783,13 @@ cleanup:
|
|
|
2851
2783
|
int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head)
|
|
2852
2784
|
{
|
|
2853
2785
|
git_filebuf file = GIT_FILEBUF_INIT;
|
|
2854
|
-
|
|
2786
|
+
git_str file_path = GIT_STR_INIT;
|
|
2855
2787
|
char orig_head_str[GIT_OID_HEXSZ];
|
|
2856
2788
|
int error = 0;
|
|
2857
2789
|
|
|
2858
2790
|
git_oid_fmt(orig_head_str, orig_head);
|
|
2859
2791
|
|
|
2860
|
-
if ((error =
|
|
2792
|
+
if ((error = git_str_joinpath(&file_path, repo->gitdir, GIT_ORIG_HEAD_FILE)) == 0 &&
|
|
2861
2793
|
(error = git_filebuf_open(&file, file_path.ptr, GIT_FILEBUF_CREATE_LEADING_DIRS, GIT_MERGE_FILE_MODE)) == 0 &&
|
|
2862
2794
|
(error = git_filebuf_printf(&file, "%.*s\n", GIT_OID_HEXSZ, orig_head_str)) == 0)
|
|
2863
2795
|
error = git_filebuf_commit(&file);
|
|
@@ -2865,46 +2797,48 @@ int git_repository__set_orig_head(git_repository *repo, const git_oid *orig_head
|
|
|
2865
2797
|
if (error < 0)
|
|
2866
2798
|
git_filebuf_cleanup(&file);
|
|
2867
2799
|
|
|
2868
|
-
|
|
2800
|
+
git_str_dispose(&file_path);
|
|
2869
2801
|
|
|
2870
2802
|
return error;
|
|
2871
2803
|
}
|
|
2872
2804
|
|
|
2873
|
-
int
|
|
2805
|
+
static int git_repository__message(git_str *out, git_repository *repo)
|
|
2874
2806
|
{
|
|
2875
|
-
|
|
2807
|
+
git_str path = GIT_STR_INIT;
|
|
2876
2808
|
struct stat st;
|
|
2877
2809
|
int error;
|
|
2878
2810
|
|
|
2879
|
-
if ((
|
|
2880
|
-
return error;
|
|
2881
|
-
|
|
2882
|
-
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)
|
|
2883
2812
|
return -1;
|
|
2884
2813
|
|
|
2885
|
-
if ((error = p_stat(
|
|
2814
|
+
if ((error = p_stat(git_str_cstr(&path), &st)) < 0) {
|
|
2886
2815
|
if (errno == ENOENT)
|
|
2887
2816
|
error = GIT_ENOTFOUND;
|
|
2888
2817
|
git_error_set(GIT_ERROR_OS, "could not access message file");
|
|
2889
2818
|
} else {
|
|
2890
|
-
error = git_futils_readbuffer(out,
|
|
2819
|
+
error = git_futils_readbuffer(out, git_str_cstr(&path));
|
|
2891
2820
|
}
|
|
2892
2821
|
|
|
2893
|
-
|
|
2822
|
+
git_str_dispose(&path);
|
|
2894
2823
|
|
|
2895
2824
|
return error;
|
|
2896
2825
|
}
|
|
2897
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
|
+
|
|
2898
2832
|
int git_repository_message_remove(git_repository *repo)
|
|
2899
2833
|
{
|
|
2900
|
-
|
|
2834
|
+
git_str path = GIT_STR_INIT;
|
|
2901
2835
|
int error;
|
|
2902
2836
|
|
|
2903
|
-
if (
|
|
2837
|
+
if (git_str_joinpath(&path, repo->gitdir, GIT_MERGE_MSG_FILE) < 0)
|
|
2904
2838
|
return -1;
|
|
2905
2839
|
|
|
2906
|
-
error = p_unlink(
|
|
2907
|
-
|
|
2840
|
+
error = p_unlink(git_str_cstr(&path));
|
|
2841
|
+
git_str_dispose(&path);
|
|
2908
2842
|
|
|
2909
2843
|
return error;
|
|
2910
2844
|
}
|
|
@@ -2920,7 +2854,7 @@ int git_repository_hashfile(
|
|
|
2920
2854
|
git_filter_list *fl = NULL;
|
|
2921
2855
|
git_file fd = -1;
|
|
2922
2856
|
uint64_t len;
|
|
2923
|
-
|
|
2857
|
+
git_str full_path = GIT_STR_INIT;
|
|
2924
2858
|
const char *workdir = git_repository_workdir(repo);
|
|
2925
2859
|
|
|
2926
2860
|
/* as_path can be NULL */
|
|
@@ -2928,8 +2862,8 @@ int git_repository_hashfile(
|
|
|
2928
2862
|
GIT_ASSERT_ARG(path);
|
|
2929
2863
|
GIT_ASSERT_ARG(repo);
|
|
2930
2864
|
|
|
2931
|
-
if ((error =
|
|
2932
|
-
(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)
|
|
2933
2867
|
return error;
|
|
2934
2868
|
|
|
2935
2869
|
/*
|
|
@@ -2976,30 +2910,30 @@ cleanup:
|
|
|
2976
2910
|
if (fd >= 0)
|
|
2977
2911
|
p_close(fd);
|
|
2978
2912
|
git_filter_list_free(fl);
|
|
2979
|
-
|
|
2913
|
+
git_str_dispose(&full_path);
|
|
2980
2914
|
|
|
2981
2915
|
return error;
|
|
2982
2916
|
}
|
|
2983
2917
|
|
|
2984
|
-
static int checkout_message(
|
|
2918
|
+
static int checkout_message(git_str *out, git_reference *old, const char *new)
|
|
2985
2919
|
{
|
|
2986
|
-
|
|
2920
|
+
git_str_puts(out, "checkout: moving from ");
|
|
2987
2921
|
|
|
2988
2922
|
if (git_reference_type(old) == GIT_REFERENCE_SYMBOLIC)
|
|
2989
|
-
|
|
2923
|
+
git_str_puts(out, git_reference__shorthand(git_reference_symbolic_target(old)));
|
|
2990
2924
|
else
|
|
2991
|
-
|
|
2925
|
+
git_str_puts(out, git_oid_tostr_s(git_reference_target(old)));
|
|
2992
2926
|
|
|
2993
|
-
|
|
2927
|
+
git_str_puts(out, " to ");
|
|
2994
2928
|
|
|
2995
2929
|
if (git_reference__is_branch(new) ||
|
|
2996
2930
|
git_reference__is_tag(new) ||
|
|
2997
2931
|
git_reference__is_remote(new))
|
|
2998
|
-
|
|
2932
|
+
git_str_puts(out, git_reference__shorthand(new));
|
|
2999
2933
|
else
|
|
3000
|
-
|
|
2934
|
+
git_str_puts(out, new);
|
|
3001
2935
|
|
|
3002
|
-
if (
|
|
2936
|
+
if (git_str_oom(out))
|
|
3003
2937
|
return -1;
|
|
3004
2938
|
|
|
3005
2939
|
return 0;
|
|
@@ -3008,7 +2942,7 @@ static int checkout_message(git_buf *out, git_reference *old, const char *new)
|
|
|
3008
2942
|
static int detach(git_repository *repo, const git_oid *id, const char *new)
|
|
3009
2943
|
{
|
|
3010
2944
|
int error;
|
|
3011
|
-
|
|
2945
|
+
git_str log_message = GIT_STR_INIT;
|
|
3012
2946
|
git_object *object = NULL, *peeled = NULL;
|
|
3013
2947
|
git_reference *new_head = NULL, *current = NULL;
|
|
3014
2948
|
|
|
@@ -3030,10 +2964,10 @@ static int detach(git_repository *repo, const git_oid *id, const char *new)
|
|
|
3030
2964
|
if ((error = checkout_message(&log_message, current, new)) < 0)
|
|
3031
2965
|
goto cleanup;
|
|
3032
2966
|
|
|
3033
|
-
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));
|
|
3034
2968
|
|
|
3035
2969
|
cleanup:
|
|
3036
|
-
|
|
2970
|
+
git_str_dispose(&log_message);
|
|
3037
2971
|
git_object_free(object);
|
|
3038
2972
|
git_object_free(peeled);
|
|
3039
2973
|
git_reference_free(current);
|
|
@@ -3046,7 +2980,7 @@ int git_repository_set_head(
|
|
|
3046
2980
|
const char *refname)
|
|
3047
2981
|
{
|
|
3048
2982
|
git_reference *ref = NULL, *current = NULL, *new_head = NULL;
|
|
3049
|
-
|
|
2983
|
+
git_str log_message = GIT_STR_INIT;
|
|
3050
2984
|
int error;
|
|
3051
2985
|
|
|
3052
2986
|
GIT_ASSERT_ARG(repo);
|
|
@@ -3073,18 +3007,18 @@ int git_repository_set_head(
|
|
|
3073
3007
|
if (!error) {
|
|
3074
3008
|
if (git_reference_is_branch(ref)) {
|
|
3075
3009
|
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE,
|
|
3076
|
-
git_reference_name(ref), true,
|
|
3010
|
+
git_reference_name(ref), true, git_str_cstr(&log_message));
|
|
3077
3011
|
} else {
|
|
3078
3012
|
error = detach(repo, git_reference_target(ref),
|
|
3079
3013
|
git_reference_is_tag(ref) || git_reference_is_remote(ref) ? refname : NULL);
|
|
3080
3014
|
}
|
|
3081
3015
|
} else if (git_reference__is_branch(refname)) {
|
|
3082
3016
|
error = git_reference_symbolic_create(&new_head, repo, GIT_HEAD_FILE, refname,
|
|
3083
|
-
true,
|
|
3017
|
+
true, git_str_cstr(&log_message));
|
|
3084
3018
|
}
|
|
3085
3019
|
|
|
3086
3020
|
cleanup:
|
|
3087
|
-
|
|
3021
|
+
git_str_dispose(&log_message);
|
|
3088
3022
|
git_reference_free(current);
|
|
3089
3023
|
git_reference_free(ref);
|
|
3090
3024
|
git_reference_free(new_head);
|
|
@@ -3093,26 +3027,26 @@ cleanup:
|
|
|
3093
3027
|
|
|
3094
3028
|
int git_repository_set_head_detached(
|
|
3095
3029
|
git_repository *repo,
|
|
3096
|
-
const git_oid *
|
|
3030
|
+
const git_oid *committish)
|
|
3097
3031
|
{
|
|
3098
|
-
return detach(repo,
|
|
3032
|
+
return detach(repo, committish, NULL);
|
|
3099
3033
|
}
|
|
3100
3034
|
|
|
3101
3035
|
int git_repository_set_head_detached_from_annotated(
|
|
3102
3036
|
git_repository *repo,
|
|
3103
|
-
const git_annotated_commit *
|
|
3037
|
+
const git_annotated_commit *committish)
|
|
3104
3038
|
{
|
|
3105
3039
|
GIT_ASSERT_ARG(repo);
|
|
3106
|
-
GIT_ASSERT_ARG(
|
|
3040
|
+
GIT_ASSERT_ARG(committish);
|
|
3107
3041
|
|
|
3108
|
-
return detach(repo, git_annotated_commit_id(
|
|
3042
|
+
return detach(repo, git_annotated_commit_id(committish), committish->description);
|
|
3109
3043
|
}
|
|
3110
3044
|
|
|
3111
3045
|
int git_repository_detach_head(git_repository *repo)
|
|
3112
3046
|
{
|
|
3113
3047
|
git_reference *old_head = NULL, *new_head = NULL, *current = NULL;
|
|
3114
3048
|
git_object *object = NULL;
|
|
3115
|
-
|
|
3049
|
+
git_str log_message = GIT_STR_INIT;
|
|
3116
3050
|
int error;
|
|
3117
3051
|
|
|
3118
3052
|
GIT_ASSERT_ARG(repo);
|
|
@@ -3130,10 +3064,10 @@ int git_repository_detach_head(git_repository *repo)
|
|
|
3130
3064
|
goto cleanup;
|
|
3131
3065
|
|
|
3132
3066
|
error = git_reference_create(&new_head, repo, GIT_HEAD_FILE, git_reference_target(old_head),
|
|
3133
|
-
1,
|
|
3067
|
+
1, git_str_cstr(&log_message));
|
|
3134
3068
|
|
|
3135
3069
|
cleanup:
|
|
3136
|
-
|
|
3070
|
+
git_str_dispose(&log_message);
|
|
3137
3071
|
git_object_free(object);
|
|
3138
3072
|
git_reference_free(old_head);
|
|
3139
3073
|
git_reference_free(new_head);
|
|
@@ -3147,69 +3081,69 @@ cleanup:
|
|
|
3147
3081
|
*/
|
|
3148
3082
|
int git_repository_state(git_repository *repo)
|
|
3149
3083
|
{
|
|
3150
|
-
|
|
3084
|
+
git_str repo_path = GIT_STR_INIT;
|
|
3151
3085
|
int state = GIT_REPOSITORY_STATE_NONE;
|
|
3152
3086
|
|
|
3153
3087
|
GIT_ASSERT_ARG(repo);
|
|
3154
3088
|
|
|
3155
|
-
if (
|
|
3089
|
+
if (git_str_puts(&repo_path, repo->gitdir) < 0)
|
|
3156
3090
|
return -1;
|
|
3157
3091
|
|
|
3158
|
-
if (
|
|
3092
|
+
if (git_fs_path_contains_file(&repo_path, GIT_REBASE_MERGE_INTERACTIVE_FILE))
|
|
3159
3093
|
state = GIT_REPOSITORY_STATE_REBASE_INTERACTIVE;
|
|
3160
|
-
else if (
|
|
3094
|
+
else if (git_fs_path_contains_dir(&repo_path, GIT_REBASE_MERGE_DIR))
|
|
3161
3095
|
state = GIT_REPOSITORY_STATE_REBASE_MERGE;
|
|
3162
|
-
else if (
|
|
3096
|
+
else if (git_fs_path_contains_file(&repo_path, GIT_REBASE_APPLY_REBASING_FILE))
|
|
3163
3097
|
state = GIT_REPOSITORY_STATE_REBASE;
|
|
3164
|
-
else if (
|
|
3098
|
+
else if (git_fs_path_contains_file(&repo_path, GIT_REBASE_APPLY_APPLYING_FILE))
|
|
3165
3099
|
state = GIT_REPOSITORY_STATE_APPLY_MAILBOX;
|
|
3166
|
-
else if (
|
|
3100
|
+
else if (git_fs_path_contains_dir(&repo_path, GIT_REBASE_APPLY_DIR))
|
|
3167
3101
|
state = GIT_REPOSITORY_STATE_APPLY_MAILBOX_OR_REBASE;
|
|
3168
|
-
else if (
|
|
3102
|
+
else if (git_fs_path_contains_file(&repo_path, GIT_MERGE_HEAD_FILE))
|
|
3169
3103
|
state = GIT_REPOSITORY_STATE_MERGE;
|
|
3170
|
-
else if (
|
|
3104
|
+
else if (git_fs_path_contains_file(&repo_path, GIT_REVERT_HEAD_FILE)) {
|
|
3171
3105
|
state = GIT_REPOSITORY_STATE_REVERT;
|
|
3172
|
-
if (
|
|
3106
|
+
if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
|
|
3173
3107
|
state = GIT_REPOSITORY_STATE_REVERT_SEQUENCE;
|
|
3174
3108
|
}
|
|
3175
|
-
} else if (
|
|
3109
|
+
} else if (git_fs_path_contains_file(&repo_path, GIT_CHERRYPICK_HEAD_FILE)) {
|
|
3176
3110
|
state = GIT_REPOSITORY_STATE_CHERRYPICK;
|
|
3177
|
-
if (
|
|
3111
|
+
if (git_fs_path_contains_file(&repo_path, GIT_SEQUENCER_TODO_FILE)) {
|
|
3178
3112
|
state = GIT_REPOSITORY_STATE_CHERRYPICK_SEQUENCE;
|
|
3179
3113
|
}
|
|
3180
|
-
} else if (
|
|
3114
|
+
} else if (git_fs_path_contains_file(&repo_path, GIT_BISECT_LOG_FILE))
|
|
3181
3115
|
state = GIT_REPOSITORY_STATE_BISECT;
|
|
3182
3116
|
|
|
3183
|
-
|
|
3117
|
+
git_str_dispose(&repo_path);
|
|
3184
3118
|
return state;
|
|
3185
3119
|
}
|
|
3186
3120
|
|
|
3187
3121
|
int git_repository__cleanup_files(
|
|
3188
3122
|
git_repository *repo, const char *files[], size_t files_len)
|
|
3189
3123
|
{
|
|
3190
|
-
|
|
3124
|
+
git_str buf = GIT_STR_INIT;
|
|
3191
3125
|
size_t i;
|
|
3192
3126
|
int error;
|
|
3193
3127
|
|
|
3194
3128
|
for (error = 0, i = 0; !error && i < files_len; ++i) {
|
|
3195
3129
|
const char *path;
|
|
3196
3130
|
|
|
3197
|
-
if (
|
|
3131
|
+
if (git_str_joinpath(&buf, repo->gitdir, files[i]) < 0)
|
|
3198
3132
|
return -1;
|
|
3199
3133
|
|
|
3200
|
-
path =
|
|
3134
|
+
path = git_str_cstr(&buf);
|
|
3201
3135
|
|
|
3202
|
-
if (
|
|
3136
|
+
if (git_fs_path_isfile(path)) {
|
|
3203
3137
|
error = p_unlink(path);
|
|
3204
|
-
} else if (
|
|
3138
|
+
} else if (git_fs_path_isdir(path)) {
|
|
3205
3139
|
error = git_futils_rmdir_r(path, NULL,
|
|
3206
3140
|
GIT_RMDIR_REMOVE_FILES | GIT_RMDIR_REMOVE_BLOCKERS);
|
|
3207
3141
|
}
|
|
3208
3142
|
|
|
3209
|
-
|
|
3143
|
+
git_str_clear(&buf);
|
|
3210
3144
|
}
|
|
3211
3145
|
|
|
3212
|
-
|
|
3146
|
+
git_str_dispose(&buf);
|
|
3213
3147
|
return error;
|
|
3214
3148
|
}
|
|
3215
3149
|
|
|
@@ -3234,15 +3168,15 @@ int git_repository_state_cleanup(git_repository *repo)
|
|
|
3234
3168
|
|
|
3235
3169
|
int git_repository_is_shallow(git_repository *repo)
|
|
3236
3170
|
{
|
|
3237
|
-
|
|
3171
|
+
git_str path = GIT_STR_INIT;
|
|
3238
3172
|
struct stat st;
|
|
3239
3173
|
int error;
|
|
3240
3174
|
|
|
3241
|
-
if ((error =
|
|
3175
|
+
if ((error = git_str_joinpath(&path, repo->gitdir, "shallow")) < 0)
|
|
3242
3176
|
return error;
|
|
3243
3177
|
|
|
3244
|
-
error =
|
|
3245
|
-
|
|
3178
|
+
error = git_fs_path_lstat(path.ptr, &st);
|
|
3179
|
+
git_str_dispose(&path);
|
|
3246
3180
|
|
|
3247
3181
|
if (error == GIT_ENOTFOUND) {
|
|
3248
3182
|
git_error_clear();
|