rugged 1.3.2.3 → 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/deps/zlib/adler32.c +0 -7
- data/vendor/libgit2/deps/zlib/crc32.c +288 -975
- data/vendor/libgit2/deps/zlib/crc32.h +436 -9441
- data/vendor/libgit2/deps/zlib/deflate.c +31 -83
- data/vendor/libgit2/deps/zlib/deflate.h +15 -12
- data/vendor/libgit2/deps/zlib/gzguts.h +2 -3
- data/vendor/libgit2/deps/zlib/infback.c +1 -2
- data/vendor/libgit2/deps/zlib/inffast.c +14 -14
- data/vendor/libgit2/deps/zlib/inflate.c +8 -39
- data/vendor/libgit2/deps/zlib/inflate.h +2 -3
- data/vendor/libgit2/deps/zlib/inftrees.c +3 -3
- data/vendor/libgit2/deps/zlib/trees.c +48 -27
- data/vendor/libgit2/deps/zlib/zlib.h +100 -126
- data/vendor/libgit2/deps/zlib/zutil.c +2 -2
- data/vendor/libgit2/deps/zlib/zutil.h +9 -12
- 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 +3 -3
- 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 -77
- 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 -1951
- data/vendor/libgit2/src/path.h +34 -741
- 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 -467
- 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
data/vendor/libgit2/src/path.h
CHANGED
@@ -9,767 +9,60 @@
|
|
9
9
|
|
10
10
|
#include "common.h"
|
11
11
|
|
12
|
-
#include "
|
13
|
-
#include
|
14
|
-
#include "vector.h"
|
12
|
+
#include "fs_path.h"
|
13
|
+
#include <git2/sys/path.h>
|
15
14
|
|
16
|
-
#
|
15
|
+
#define GIT_PATH_REJECT_DOT_GIT (GIT_FS_PATH_REJECT_MAX << 1)
|
16
|
+
#define GIT_PATH_REJECT_DOT_GIT_LITERAL (GIT_FS_PATH_REJECT_MAX << 2)
|
17
|
+
#define GIT_PATH_REJECT_DOT_GIT_HFS (GIT_FS_PATH_REJECT_MAX << 3)
|
18
|
+
#define GIT_PATH_REJECT_DOT_GIT_NTFS (GIT_FS_PATH_REJECT_MAX << 4)
|
17
19
|
|
18
|
-
|
19
|
-
* Path manipulation utils
|
20
|
-
*
|
21
|
-
* These are path utilities that munge paths without actually
|
22
|
-
* looking at the real filesystem.
|
23
|
-
*/
|
24
|
-
|
25
|
-
/*
|
26
|
-
* The dirname() function shall take a pointer to a character string
|
27
|
-
* that contains a pathname, and return a pointer to a string that is a
|
28
|
-
* pathname of the parent directory of that file. Trailing '/' characters
|
29
|
-
* in the path are not counted as part of the path.
|
30
|
-
*
|
31
|
-
* If path does not contain a '/', then dirname() shall return a pointer to
|
32
|
-
* the string ".". If path is a null pointer or points to an empty string,
|
33
|
-
* dirname() shall return a pointer to the string "." .
|
34
|
-
*
|
35
|
-
* The `git_path_dirname` implementation is thread safe. The returned
|
36
|
-
* string must be manually free'd.
|
37
|
-
*
|
38
|
-
* The `git_path_dirname_r` implementation writes the dirname to a `git_buf`
|
39
|
-
* if the buffer pointer is not NULL.
|
40
|
-
* It returns an error code < 0 if there is an allocation error, otherwise
|
41
|
-
* the length of the dirname (which will be > 0).
|
42
|
-
*/
|
43
|
-
extern char *git_path_dirname(const char *path);
|
44
|
-
extern int git_path_dirname_r(git_buf *buffer, const char *path);
|
45
|
-
|
46
|
-
/*
|
47
|
-
* This function returns the basename of the file, which is the last
|
48
|
-
* part of its full name given by fname, with the drive letter and
|
49
|
-
* leading directories stripped off. For example, the basename of
|
50
|
-
* c:/foo/bar/file.ext is file.ext, and the basename of a:foo is foo.
|
51
|
-
*
|
52
|
-
* Trailing slashes and backslashes are significant: the basename of
|
53
|
-
* c:/foo/bar/ is an empty string after the rightmost slash.
|
54
|
-
*
|
55
|
-
* The `git_path_basename` implementation is thread safe. The returned
|
56
|
-
* string must be manually free'd.
|
57
|
-
*
|
58
|
-
* The `git_path_basename_r` implementation writes the basename to a `git_buf`.
|
59
|
-
* It returns an error code < 0 if there is an allocation error, otherwise
|
60
|
-
* the length of the basename (which will be >= 0).
|
61
|
-
*/
|
62
|
-
extern char *git_path_basename(const char *path);
|
63
|
-
extern int git_path_basename_r(git_buf *buffer, const char *path);
|
64
|
-
|
65
|
-
/* Return the offset of the start of the basename. Unlike the other
|
66
|
-
* basename functions, this returns 0 if the path is empty.
|
67
|
-
*/
|
68
|
-
extern size_t git_path_basename_offset(git_buf *buffer);
|
69
|
-
|
70
|
-
/**
|
71
|
-
* Find offset to root of path if path has one.
|
72
|
-
*
|
73
|
-
* This will return a number >= 0 which is the offset to the start of the
|
74
|
-
* path, if the path is rooted (i.e. "/rooted/path" returns 0 and
|
75
|
-
* "c:/windows/rooted/path" returns 2). If the path is not rooted, this
|
76
|
-
* returns -1.
|
77
|
-
*/
|
78
|
-
extern int git_path_root(const char *path);
|
79
|
-
|
80
|
-
/**
|
81
|
-
* Ensure path has a trailing '/'.
|
82
|
-
*/
|
83
|
-
extern int git_path_to_dir(git_buf *path);
|
84
|
-
|
85
|
-
/**
|
86
|
-
* Ensure string has a trailing '/' if there is space for it.
|
87
|
-
*/
|
88
|
-
extern void git_path_string_to_dir(char *path, size_t size);
|
89
|
-
|
90
|
-
/**
|
91
|
-
* Taken from git.git; returns nonzero if the given path is "." or "..".
|
92
|
-
*/
|
93
|
-
GIT_INLINE(int) git_path_is_dot_or_dotdot(const char *name)
|
94
|
-
{
|
95
|
-
return (name[0] == '.' &&
|
96
|
-
(name[1] == '\0' ||
|
97
|
-
(name[1] == '.' && name[2] == '\0')));
|
98
|
-
}
|
99
|
-
|
100
|
-
#ifdef GIT_WIN32
|
101
|
-
GIT_INLINE(int) git_path_is_dot_or_dotdotW(const wchar_t *name)
|
102
|
-
{
|
103
|
-
return (name[0] == L'.' &&
|
104
|
-
(name[1] == L'\0' ||
|
105
|
-
(name[1] == L'.' && name[2] == L'\0')));
|
106
|
-
}
|
107
|
-
|
108
|
-
#define git_path_is_absolute(p) \
|
109
|
-
(git__isalpha((p)[0]) && (p)[1] == ':' && ((p)[2] == '\\' || (p)[2] == '/'))
|
110
|
-
|
111
|
-
#define git_path_is_dirsep(p) \
|
112
|
-
((p) == '/' || (p) == '\\')
|
113
|
-
|
114
|
-
/**
|
115
|
-
* Convert backslashes in path to forward slashes.
|
116
|
-
*/
|
117
|
-
GIT_INLINE(void) git_path_mkposix(char *path)
|
118
|
-
{
|
119
|
-
while (*path) {
|
120
|
-
if (*path == '\\')
|
121
|
-
*path = '/';
|
122
|
-
|
123
|
-
path++;
|
124
|
-
}
|
125
|
-
}
|
126
|
-
#else
|
127
|
-
# define git_path_mkposix(p) /* blank */
|
128
|
-
|
129
|
-
#define git_path_is_absolute(p) \
|
130
|
-
((p)[0] == '/')
|
131
|
-
|
132
|
-
#define git_path_is_dirsep(p) \
|
133
|
-
((p) == '/')
|
134
|
-
|
135
|
-
#endif
|
136
|
-
|
137
|
-
/**
|
138
|
-
* Check if string is a relative path (i.e. starts with "./" or "../")
|
139
|
-
*/
|
140
|
-
GIT_INLINE(int) git_path_is_relative(const char *p)
|
141
|
-
{
|
142
|
-
return (p[0] == '.' && (p[1] == '/' || (p[1] == '.' && p[2] == '/')));
|
143
|
-
}
|
144
|
-
|
145
|
-
/**
|
146
|
-
* Check if string is at end of path segment (i.e. looking at '/' or '\0')
|
147
|
-
*/
|
148
|
-
GIT_INLINE(int) git_path_at_end_of_segment(const char *p)
|
149
|
-
{
|
150
|
-
return !*p || *p == '/';
|
151
|
-
}
|
152
|
-
|
153
|
-
extern int git__percent_decode(git_buf *decoded_out, const char *input);
|
154
|
-
|
155
|
-
/**
|
156
|
-
* Extract path from file:// URL.
|
157
|
-
*/
|
158
|
-
extern int git_path_fromurl(git_buf *local_path_out, const char *file_url);
|
159
|
-
|
160
|
-
|
161
|
-
/**
|
162
|
-
* Path filesystem utils
|
163
|
-
*
|
164
|
-
* These are path utilities that actually access the filesystem.
|
165
|
-
*/
|
166
|
-
|
167
|
-
/**
|
168
|
-
* Check if a file exists and can be accessed.
|
169
|
-
* @return true or false
|
170
|
-
*/
|
171
|
-
extern bool git_path_exists(const char *path);
|
172
|
-
|
173
|
-
/**
|
174
|
-
* Check if the given path points to a directory.
|
175
|
-
* @return true or false
|
176
|
-
*/
|
177
|
-
extern bool git_path_isdir(const char *path);
|
178
|
-
|
179
|
-
/**
|
180
|
-
* Check if the given path points to a regular file.
|
181
|
-
* @return true or false
|
182
|
-
*/
|
183
|
-
extern bool git_path_isfile(const char *path);
|
184
|
-
|
185
|
-
/**
|
186
|
-
* Check if the given path points to a symbolic link.
|
187
|
-
* @return true or false
|
188
|
-
*/
|
189
|
-
extern bool git_path_islink(const char *path);
|
190
|
-
|
191
|
-
/**
|
192
|
-
* Check if the given path is a directory, and is empty.
|
193
|
-
*/
|
194
|
-
extern bool git_path_is_empty_dir(const char *path);
|
195
|
-
|
196
|
-
/**
|
197
|
-
* Stat a file and/or link and set error if needed.
|
198
|
-
*/
|
199
|
-
extern int git_path_lstat(const char *path, struct stat *st);
|
200
|
-
|
201
|
-
/**
|
202
|
-
* Check if the parent directory contains the item.
|
203
|
-
*
|
204
|
-
* @param dir Directory to check.
|
205
|
-
* @param item Item that might be in the directory.
|
206
|
-
* @return 0 if item exists in directory, <0 otherwise.
|
207
|
-
*/
|
208
|
-
extern bool git_path_contains(git_buf *dir, const char *item);
|
209
|
-
|
210
|
-
/**
|
211
|
-
* Check if the given path contains the given subdirectory.
|
212
|
-
*
|
213
|
-
* @param parent Directory path that might contain subdir
|
214
|
-
* @param subdir Subdirectory name to look for in parent
|
215
|
-
* @return true if subdirectory exists, false otherwise.
|
216
|
-
*/
|
217
|
-
extern bool git_path_contains_dir(git_buf *parent, const char *subdir);
|
218
|
-
|
219
|
-
/**
|
220
|
-
* Determine the common directory length between two paths, including
|
221
|
-
* the final path separator. For example, given paths 'a/b/c/1.txt
|
222
|
-
* and 'a/b/c/d/2.txt', the common directory is 'a/b/c/', and this
|
223
|
-
* will return the length of the string 'a/b/c/', which is 6.
|
224
|
-
*
|
225
|
-
* @param one The first path
|
226
|
-
* @param two The second path
|
227
|
-
* @return The length of the common directory
|
228
|
-
*/
|
229
|
-
extern size_t git_path_common_dirlen(const char *one, const char *two);
|
230
|
-
|
231
|
-
/**
|
232
|
-
* Make the path relative to the given parent path.
|
233
|
-
*
|
234
|
-
* @param path The path to make relative
|
235
|
-
* @param parent The parent path to make path relative to
|
236
|
-
* @return 0 if path was made relative, GIT_ENOTFOUND
|
237
|
-
* if there was not common root between the paths,
|
238
|
-
* or <0.
|
239
|
-
*/
|
240
|
-
extern int git_path_make_relative(git_buf *path, const char *parent);
|
241
|
-
|
242
|
-
/**
|
243
|
-
* Check if the given path contains the given file.
|
244
|
-
*
|
245
|
-
* @param dir Directory path that might contain file
|
246
|
-
* @param file File name to look for in parent
|
247
|
-
* @return true if file exists, false otherwise.
|
248
|
-
*/
|
249
|
-
extern bool git_path_contains_file(git_buf *dir, const char *file);
|
250
|
-
|
251
|
-
/**
|
252
|
-
* Prepend base to unrooted path or just copy path over.
|
253
|
-
*
|
254
|
-
* This will optionally return the index into the path where the "root"
|
255
|
-
* is, either the end of the base directory prefix or the path root.
|
256
|
-
*/
|
257
|
-
extern int git_path_join_unrooted(
|
258
|
-
git_buf *path_out, const char *path, const char *base, ssize_t *root_at);
|
259
|
-
|
260
|
-
/**
|
261
|
-
* Removes multiple occurrences of '/' in a row, squashing them into a
|
262
|
-
* single '/'.
|
263
|
-
*/
|
264
|
-
extern void git_path_squash_slashes(git_buf *path);
|
265
|
-
|
266
|
-
/**
|
267
|
-
* Clean up path, prepending base if it is not already rooted.
|
268
|
-
*/
|
269
|
-
extern int git_path_prettify(git_buf *path_out, const char *path, const char *base);
|
270
|
-
|
271
|
-
/**
|
272
|
-
* Clean up path, prepending base if it is not already rooted and
|
273
|
-
* appending a slash.
|
274
|
-
*/
|
275
|
-
extern int git_path_prettify_dir(git_buf *path_out, const char *path, const char *base);
|
276
|
-
|
277
|
-
/**
|
278
|
-
* Get a directory from a path.
|
279
|
-
*
|
280
|
-
* If path is a directory, this acts like `git_path_prettify_dir`
|
281
|
-
* (cleaning up path and appending a '/'). If path is a normal file,
|
282
|
-
* this prettifies it, then removed the filename a la dirname and
|
283
|
-
* appends the trailing '/'. If the path does not exist, it is
|
284
|
-
* treated like a regular filename.
|
285
|
-
*/
|
286
|
-
extern int git_path_find_dir(git_buf *dir);
|
287
|
-
|
288
|
-
/**
|
289
|
-
* Resolve relative references within a path.
|
290
|
-
*
|
291
|
-
* This eliminates "./" and "../" relative references inside a path,
|
292
|
-
* as well as condensing multiple slashes into single ones. It will
|
293
|
-
* not touch the path before the "ceiling" length.
|
294
|
-
*
|
295
|
-
* Additionally, this will recognize an "c:/" drive prefix or a "xyz://" URL
|
296
|
-
* prefix and not touch that part of the path.
|
297
|
-
*/
|
298
|
-
extern int git_path_resolve_relative(git_buf *path, size_t ceiling);
|
299
|
-
|
300
|
-
/**
|
301
|
-
* Apply a relative path to base path.
|
302
|
-
*
|
303
|
-
* Note that the base path could be a filename or a URL and this
|
304
|
-
* should still work. The relative path is walked segment by segment
|
305
|
-
* with three rules: series of slashes will be condensed to a single
|
306
|
-
* slash, "." will be eaten with no change, and ".." will remove a
|
307
|
-
* segment from the base path.
|
308
|
-
*/
|
309
|
-
extern int git_path_apply_relative(git_buf *target, const char *relpath);
|
310
|
-
|
311
|
-
enum {
|
312
|
-
GIT_PATH_DIR_IGNORE_CASE = (1u << 0),
|
313
|
-
GIT_PATH_DIR_PRECOMPOSE_UNICODE = (1u << 1),
|
314
|
-
GIT_PATH_DIR_INCLUDE_DOT_AND_DOTDOT = (1u << 2),
|
315
|
-
};
|
316
|
-
|
317
|
-
/**
|
318
|
-
* Walk each directory entry, except '.' and '..', calling fn(state).
|
319
|
-
*
|
320
|
-
* @param pathbuf Buffer the function reads the initial directory
|
321
|
-
* path from, and updates with each successive entry's name.
|
322
|
-
* @param flags Combination of GIT_PATH_DIR flags.
|
323
|
-
* @param callback Callback for each entry. Passed the `payload` and each
|
324
|
-
* successive path inside the directory as a full path. This may
|
325
|
-
* safely append text to the pathbuf if needed. Return non-zero to
|
326
|
-
* cancel iteration (and return value will be propagated back).
|
327
|
-
* @param payload Passed to callback as first argument.
|
328
|
-
* @return 0 on success or error code from OS error or from callback
|
329
|
-
*/
|
330
|
-
extern int git_path_direach(
|
331
|
-
git_buf *pathbuf,
|
332
|
-
uint32_t flags,
|
333
|
-
int (*callback)(void *payload, git_buf *path),
|
334
|
-
void *payload);
|
335
|
-
|
336
|
-
/**
|
337
|
-
* Sort function to order two paths
|
338
|
-
*/
|
339
|
-
extern int git_path_cmp(
|
340
|
-
const char *name1, size_t len1, int isdir1,
|
341
|
-
const char *name2, size_t len2, int isdir2,
|
342
|
-
int (*compare)(const char *, const char *, size_t));
|
343
|
-
|
344
|
-
/**
|
345
|
-
* Invoke callback up path directory by directory until the ceiling is
|
346
|
-
* reached (inclusive of a final call at the root_path).
|
347
|
-
*
|
348
|
-
* Returning anything other than 0 from the callback function
|
349
|
-
* will stop the iteration and propagate the error to the caller.
|
350
|
-
*
|
351
|
-
* @param pathbuf Buffer the function reads the directory from and
|
352
|
-
* and updates with each successive name.
|
353
|
-
* @param ceiling Prefix of path at which to stop walking up. If NULL,
|
354
|
-
* this will walk all the way up to the root. If not a prefix of
|
355
|
-
* pathbuf, the callback will be invoked a single time on the
|
356
|
-
* original input path.
|
357
|
-
* @param callback Function to invoke on each path. Passed the `payload`
|
358
|
-
* and the buffer containing the current path. The path should not
|
359
|
-
* be modified in any way. Return non-zero to stop iteration.
|
360
|
-
* @param payload Passed to fn as the first ath.
|
361
|
-
*/
|
362
|
-
extern int git_path_walk_up(
|
363
|
-
git_buf *pathbuf,
|
364
|
-
const char *ceiling,
|
365
|
-
int (*callback)(void *payload, const char *path),
|
366
|
-
void *payload);
|
367
|
-
|
368
|
-
|
369
|
-
enum { GIT_PATH_NOTEQUAL = 0, GIT_PATH_EQUAL = 1, GIT_PATH_PREFIX = 2 };
|
370
|
-
|
371
|
-
/*
|
372
|
-
* Determines if a path is equal to or potentially a child of another.
|
373
|
-
* @param parent The possible parent
|
374
|
-
* @param child The possible child
|
375
|
-
*/
|
376
|
-
GIT_INLINE(int) git_path_equal_or_prefixed(
|
377
|
-
const char *parent,
|
378
|
-
const char *child,
|
379
|
-
ssize_t *prefixlen)
|
380
|
-
{
|
381
|
-
const char *p = parent, *c = child;
|
382
|
-
int lastslash = 0;
|
383
|
-
|
384
|
-
while (*p && *c) {
|
385
|
-
lastslash = (*p == '/');
|
386
|
-
|
387
|
-
if (*p++ != *c++)
|
388
|
-
return GIT_PATH_NOTEQUAL;
|
389
|
-
}
|
390
|
-
|
391
|
-
if (*p != '\0')
|
392
|
-
return GIT_PATH_NOTEQUAL;
|
393
|
-
|
394
|
-
if (*c == '\0') {
|
395
|
-
if (prefixlen)
|
396
|
-
*prefixlen = p - parent;
|
397
|
-
|
398
|
-
return GIT_PATH_EQUAL;
|
399
|
-
}
|
400
|
-
|
401
|
-
if (*c == '/' || lastslash) {
|
402
|
-
if (prefixlen)
|
403
|
-
*prefixlen = (p - parent) - lastslash;
|
404
|
-
|
405
|
-
return GIT_PATH_PREFIX;
|
406
|
-
}
|
407
|
-
|
408
|
-
return GIT_PATH_NOTEQUAL;
|
409
|
-
}
|
410
|
-
|
411
|
-
/* translate errno to libgit2 error code and set error message */
|
412
|
-
extern int git_path_set_error(
|
413
|
-
int errno_value, const char *path, const char *action);
|
414
|
-
|
415
|
-
/* check if non-ascii characters are present in filename */
|
416
|
-
extern bool git_path_has_non_ascii(const char *path, size_t pathlen);
|
417
|
-
|
418
|
-
#define GIT_PATH_REPO_ENCODING "UTF-8"
|
419
|
-
|
420
|
-
#ifdef __APPLE__
|
421
|
-
#define GIT_PATH_NATIVE_ENCODING "UTF-8-MAC"
|
422
|
-
#else
|
423
|
-
#define GIT_PATH_NATIVE_ENCODING "UTF-8"
|
424
|
-
#endif
|
425
|
-
|
426
|
-
#ifdef GIT_USE_ICONV
|
427
|
-
|
428
|
-
#include <iconv.h>
|
429
|
-
|
430
|
-
typedef struct {
|
431
|
-
iconv_t map;
|
432
|
-
git_buf buf;
|
433
|
-
} git_path_iconv_t;
|
434
|
-
|
435
|
-
#define GIT_PATH_ICONV_INIT { (iconv_t)-1, GIT_BUF_INIT }
|
436
|
-
|
437
|
-
/* Init iconv data for converting decomposed UTF-8 to precomposed */
|
438
|
-
extern int git_path_iconv_init_precompose(git_path_iconv_t *ic);
|
439
|
-
|
440
|
-
/* Clear allocated iconv data */
|
441
|
-
extern void git_path_iconv_clear(git_path_iconv_t *ic);
|
442
|
-
|
443
|
-
/*
|
444
|
-
* Rewrite `in` buffer using iconv map if necessary, replacing `in`
|
445
|
-
* pointer internal iconv buffer if rewrite happened. The `in` pointer
|
446
|
-
* will be left unchanged if no rewrite was needed.
|
447
|
-
*/
|
448
|
-
extern int git_path_iconv(git_path_iconv_t *ic, const char **in, size_t *inlen);
|
449
|
-
|
450
|
-
#endif /* GIT_USE_ICONV */
|
451
|
-
|
452
|
-
extern bool git_path_does_fs_decompose_unicode(const char *root);
|
453
|
-
|
454
|
-
|
455
|
-
typedef struct git_path_diriter git_path_diriter;
|
456
|
-
|
457
|
-
#if defined(GIT_WIN32) && !defined(__MINGW32__)
|
458
|
-
|
459
|
-
struct git_path_diriter
|
460
|
-
{
|
461
|
-
git_win32_path path;
|
462
|
-
size_t parent_len;
|
463
|
-
|
464
|
-
git_buf path_utf8;
|
465
|
-
size_t parent_utf8_len;
|
466
|
-
|
467
|
-
HANDLE handle;
|
468
|
-
|
469
|
-
unsigned int flags;
|
470
|
-
|
471
|
-
WIN32_FIND_DATAW current;
|
472
|
-
unsigned int needs_next;
|
473
|
-
};
|
474
|
-
|
475
|
-
#define GIT_PATH_DIRITER_INIT { {0}, 0, GIT_BUF_INIT, 0, INVALID_HANDLE_VALUE }
|
476
|
-
|
477
|
-
#else
|
478
|
-
|
479
|
-
struct git_path_diriter
|
480
|
-
{
|
481
|
-
git_buf path;
|
482
|
-
size_t parent_len;
|
483
|
-
|
484
|
-
unsigned int flags;
|
485
|
-
|
486
|
-
DIR *dir;
|
487
|
-
|
488
|
-
#ifdef GIT_USE_ICONV
|
489
|
-
git_path_iconv_t ic;
|
490
|
-
#endif
|
491
|
-
};
|
492
|
-
|
493
|
-
#define GIT_PATH_DIRITER_INIT { GIT_BUF_INIT }
|
494
|
-
|
495
|
-
#endif
|
496
|
-
|
497
|
-
/**
|
498
|
-
* Initialize a directory iterator.
|
499
|
-
*
|
500
|
-
* @param diriter Pointer to a diriter structure that will be setup.
|
501
|
-
* @param path The path that will be iterated over
|
502
|
-
* @param flags Directory reader flags
|
503
|
-
* @return 0 or an error code
|
504
|
-
*/
|
505
|
-
extern int git_path_diriter_init(
|
506
|
-
git_path_diriter *diriter,
|
507
|
-
const char *path,
|
508
|
-
unsigned int flags);
|
509
|
-
|
510
|
-
/**
|
511
|
-
* Advance the directory iterator. Will return GIT_ITEROVER when
|
512
|
-
* the iteration has completed successfully.
|
513
|
-
*
|
514
|
-
* @param diriter The directory iterator
|
515
|
-
* @return 0, GIT_ITEROVER, or an error code
|
516
|
-
*/
|
517
|
-
extern int git_path_diriter_next(git_path_diriter *diriter);
|
518
|
-
|
519
|
-
/**
|
520
|
-
* Returns the file name of the current item in the iterator.
|
521
|
-
*
|
522
|
-
* @param out Pointer to store the path in
|
523
|
-
* @param out_len Pointer to store the length of the path in
|
524
|
-
* @param diriter The directory iterator
|
525
|
-
* @return 0 or an error code
|
526
|
-
*/
|
527
|
-
extern int git_path_diriter_filename(
|
528
|
-
const char **out,
|
529
|
-
size_t *out_len,
|
530
|
-
git_path_diriter *diriter);
|
531
|
-
|
532
|
-
/**
|
533
|
-
* Returns the full path of the current item in the iterator; that
|
534
|
-
* is the current filename plus the path of the directory that the
|
535
|
-
* iterator was constructed with.
|
536
|
-
*
|
537
|
-
* @param out Pointer to store the path in
|
538
|
-
* @param out_len Pointer to store the length of the path in
|
539
|
-
* @param diriter The directory iterator
|
540
|
-
* @return 0 or an error code
|
541
|
-
*/
|
542
|
-
extern int git_path_diriter_fullpath(
|
543
|
-
const char **out,
|
544
|
-
size_t *out_len,
|
545
|
-
git_path_diriter *diriter);
|
546
|
-
|
547
|
-
/**
|
548
|
-
* Performs an `lstat` on the current item in the iterator.
|
549
|
-
*
|
550
|
-
* @param out Pointer to store the stat data in
|
551
|
-
* @param diriter The directory iterator
|
552
|
-
* @return 0 or an error code
|
553
|
-
*/
|
554
|
-
extern int git_path_diriter_stat(struct stat *out, git_path_diriter *diriter);
|
555
|
-
|
556
|
-
/**
|
557
|
-
* Closes the directory iterator.
|
558
|
-
*
|
559
|
-
* @param diriter The directory iterator
|
560
|
-
*/
|
561
|
-
extern void git_path_diriter_free(git_path_diriter *diriter);
|
562
|
-
|
563
|
-
/**
|
564
|
-
* Load all directory entries (except '.' and '..') into a vector.
|
565
|
-
*
|
566
|
-
* For cases where `git_path_direach()` is not appropriate, this
|
567
|
-
* allows you to load the filenames in a directory into a vector
|
568
|
-
* of strings. That vector can then be sorted, iterated, or whatever.
|
569
|
-
* Remember to free alloc of the allocated strings when you are done.
|
570
|
-
*
|
571
|
-
* @param contents Vector to fill with directory entry names.
|
572
|
-
* @param path The directory to read from.
|
573
|
-
* @param prefix_len When inserting entries, the trailing part of path
|
574
|
-
* will be prefixed after this length. I.e. given path "/a/b" and
|
575
|
-
* prefix_len 3, the entries will look like "b/e1", "b/e2", etc.
|
576
|
-
* @param flags Combination of GIT_PATH_DIR flags.
|
577
|
-
*/
|
578
|
-
extern int git_path_dirload(
|
579
|
-
git_vector *contents,
|
580
|
-
const char *path,
|
581
|
-
size_t prefix_len,
|
582
|
-
uint32_t flags);
|
583
|
-
|
584
|
-
|
585
|
-
/* Used for paths to repositories on the filesystem */
|
586
|
-
extern bool git_path_is_local_file_url(const char *file_url);
|
587
|
-
extern int git_path_from_url_or_path(git_buf *local_path_out, const char *url_or_path);
|
588
|
-
|
589
|
-
/* Flags to determine path validity in `git_path_isvalid` */
|
590
|
-
#define GIT_PATH_REJECT_TRAVERSAL (1 << 0)
|
591
|
-
#define GIT_PATH_REJECT_DOT_GIT (1 << 1)
|
592
|
-
#define GIT_PATH_REJECT_SLASH (1 << 2)
|
593
|
-
#define GIT_PATH_REJECT_BACKSLASH (1 << 3)
|
594
|
-
#define GIT_PATH_REJECT_TRAILING_DOT (1 << 4)
|
595
|
-
#define GIT_PATH_REJECT_TRAILING_SPACE (1 << 5)
|
596
|
-
#define GIT_PATH_REJECT_TRAILING_COLON (1 << 6)
|
597
|
-
#define GIT_PATH_REJECT_DOS_PATHS (1 << 7)
|
598
|
-
#define GIT_PATH_REJECT_NT_CHARS (1 << 8)
|
599
|
-
#define GIT_PATH_REJECT_DOT_GIT_LITERAL (1 << 9)
|
600
|
-
#define GIT_PATH_REJECT_DOT_GIT_HFS (1 << 10)
|
601
|
-
#define GIT_PATH_REJECT_DOT_GIT_NTFS (1 << 11)
|
602
|
-
|
603
|
-
/* Default path safety for writing files to disk: since we use the
|
604
|
-
* Win32 "File Namespace" APIs ("\\?\") we need to protect from
|
605
|
-
* paths that the normal Win32 APIs would not write.
|
606
|
-
*/
|
607
|
-
#ifdef GIT_WIN32
|
608
|
-
# define GIT_PATH_REJECT_FILESYSTEM_DEFAULTS \
|
609
|
-
GIT_PATH_REJECT_TRAVERSAL | \
|
610
|
-
GIT_PATH_REJECT_BACKSLASH | \
|
611
|
-
GIT_PATH_REJECT_TRAILING_DOT | \
|
612
|
-
GIT_PATH_REJECT_TRAILING_SPACE | \
|
613
|
-
GIT_PATH_REJECT_TRAILING_COLON | \
|
614
|
-
GIT_PATH_REJECT_DOS_PATHS | \
|
615
|
-
GIT_PATH_REJECT_NT_CHARS
|
616
|
-
#else
|
617
|
-
# define GIT_PATH_REJECT_FILESYSTEM_DEFAULTS \
|
618
|
-
GIT_PATH_REJECT_TRAVERSAL
|
619
|
-
#endif
|
620
|
-
|
621
|
-
/* Paths that should never be written into the working directory. */
|
20
|
+
/* Paths that should never be written into the working directory. */
|
622
21
|
#define GIT_PATH_REJECT_WORKDIR_DEFAULTS \
|
623
|
-
|
22
|
+
GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS | GIT_PATH_REJECT_DOT_GIT
|
624
23
|
|
625
24
|
/* Paths that should never be written to the index. */
|
626
25
|
#define GIT_PATH_REJECT_INDEX_DEFAULTS \
|
627
|
-
|
26
|
+
GIT_FS_PATH_REJECT_TRAVERSAL | GIT_PATH_REJECT_DOT_GIT
|
628
27
|
|
629
|
-
|
630
|
-
* Validate a "bare" git path. This ensures that the given path is legal
|
631
|
-
* to place in the index or a tree. This should be checked by mechanisms
|
632
|
-
* like `git_index_add` and `git_treebuilder_insert` when taking user
|
633
|
-
* data, and by `git_checkout` before constructing on-disk paths.
|
634
|
-
*
|
635
|
-
* This will ensure that a git path does not contain any "unsafe" components,
|
636
|
-
* a '.' or '..' component, or a component that is ".git" (in any case).
|
637
|
-
*
|
638
|
-
* (Note: if you take or construct an on-disk path -- a workdir path,
|
639
|
-
* a path to a git repository or a reference name that could be a loose
|
640
|
-
* ref -- you should _also_ validate that with `git_path_validate_workdir`.)
|
641
|
-
*
|
642
|
-
* `repo` is optional. If specified, it will be used to determine the short
|
643
|
-
* path name to reject (if `GIT_PATH_REJECT_DOS_SHORTNAME` is specified),
|
644
|
-
* in addition to the default of "git~1".
|
645
|
-
*/
|
646
|
-
extern bool git_path_validate(
|
28
|
+
extern bool git_path_str_is_valid(
|
647
29
|
git_repository *repo,
|
648
|
-
const
|
649
|
-
uint16_t
|
30
|
+
const git_str *path,
|
31
|
+
uint16_t file_mode,
|
650
32
|
unsigned int flags);
|
651
33
|
|
652
|
-
|
653
|
-
*
|
654
|
-
* suffix appended (eg, `.lock`).
|
655
|
-
*/
|
656
|
-
GIT_INLINE(int) git_path_validate_filesystem_with_suffix(
|
34
|
+
GIT_INLINE(bool) git_path_is_valid(
|
35
|
+
git_repository *repo,
|
657
36
|
const char *path,
|
658
|
-
|
659
|
-
|
37
|
+
uint16_t file_mode,
|
38
|
+
unsigned int flags)
|
660
39
|
{
|
661
|
-
|
662
|
-
|
40
|
+
git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX);
|
41
|
+
return git_path_str_is_valid(repo, &str, file_mode, flags);
|
42
|
+
}
|
663
43
|
|
664
|
-
|
44
|
+
GIT_INLINE(int) git_path_validate_str_length(
|
45
|
+
git_repository *repo,
|
46
|
+
const git_str *path)
|
47
|
+
{
|
48
|
+
if (!git_path_str_is_valid(repo, path, 0, GIT_FS_PATH_REJECT_LONG_PATHS)) {
|
49
|
+
if (path->size == SIZE_MAX)
|
50
|
+
git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%s'", path->ptr);
|
51
|
+
else
|
52
|
+
git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%.*s'", (int)path->size, path->ptr);
|
665
53
|
|
666
|
-
if (GIT_ADD_SIZET_OVERFLOW(&total_chars, path_chars, suffix_len) ||
|
667
|
-
total_chars > MAX_PATH) {
|
668
|
-
git_error_set(GIT_ERROR_FILESYSTEM, "path too long: '%s'", path);
|
669
54
|
return -1;
|
670
55
|
}
|
56
|
+
|
671
57
|
return 0;
|
672
|
-
#else
|
673
|
-
GIT_UNUSED(path);
|
674
|
-
GIT_UNUSED(path_len);
|
675
|
-
GIT_UNUSED(suffix_len);
|
676
|
-
return 0;
|
677
|
-
#endif
|
678
58
|
}
|
679
59
|
|
680
|
-
|
681
|
-
*
|
682
|
-
*
|
683
|
-
* will ensure that the given absolute path is smaller than MAX_PATH on
|
684
|
-
* Windows.
|
685
|
-
*
|
686
|
-
* For paths within the working directory, you should use ensure that
|
687
|
-
* `core.longpaths` is obeyed. Use `git_path_validate_workdir`.
|
688
|
-
*/
|
689
|
-
GIT_INLINE(int) git_path_validate_filesystem(
|
690
|
-
const char *path,
|
691
|
-
size_t path_len)
|
60
|
+
GIT_INLINE(int) git_path_validate_length(
|
61
|
+
git_repository *repo,
|
62
|
+
const char *path)
|
692
63
|
{
|
693
|
-
|
64
|
+
git_str str = GIT_STR_INIT_CONST(path, SIZE_MAX);
|
65
|
+
return git_path_validate_str_length(repo, &str);
|
694
66
|
}
|
695
67
|
|
696
|
-
/**
|
697
|
-
* Validate a path relative to the repo's worktree. This ensures that
|
698
|
-
* the given working tree path is valid for the operating system/platform.
|
699
|
-
* This will ensure that an absolute path is smaller than MAX_PATH on
|
700
|
-
* Windows, while keeping `core.longpaths` configuration settings in mind.
|
701
|
-
*
|
702
|
-
* This should be checked by mechamisms like `git_checkout` after
|
703
|
-
* contructing on-disk paths and before trying to write them.
|
704
|
-
*
|
705
|
-
* If the repository is null, no repository configuration is applied.
|
706
|
-
*/
|
707
|
-
extern int git_path_validate_workdir(
|
708
|
-
git_repository *repo,
|
709
|
-
const char *path);
|
710
|
-
extern int git_path_validate_workdir_with_len(
|
711
|
-
git_repository *repo,
|
712
|
-
const char *path,
|
713
|
-
size_t path_len);
|
714
|
-
extern int git_path_validate_workdir_buf(
|
715
|
-
git_repository *repo,
|
716
|
-
git_buf *buf);
|
717
|
-
|
718
|
-
/**
|
719
|
-
* Convert any backslashes into slashes
|
720
|
-
*/
|
721
|
-
int git_path_normalize_slashes(git_buf *out, const char *path);
|
722
|
-
|
723
|
-
bool git_path_supports_symlinks(const char *dir);
|
724
|
-
|
725
|
-
typedef enum {
|
726
|
-
GIT_PATH_OWNER_NONE = 0,
|
727
|
-
|
728
|
-
/** The file must be owned by the current user. */
|
729
|
-
GIT_PATH_OWNER_CURRENT_USER = (1 << 0),
|
730
|
-
|
731
|
-
/** The file must be owned by the system account. */
|
732
|
-
GIT_PATH_OWNER_ADMINISTRATOR = (1 << 1),
|
733
|
-
|
734
|
-
/**
|
735
|
-
* The file may be owned by a system account if the current
|
736
|
-
* user is in an administrator group. Windows only; this is
|
737
|
-
* a noop on non-Windows systems.
|
738
|
-
*/
|
739
|
-
GIT_PATH_USER_IS_ADMINISTRATOR = (1 << 2),
|
740
|
-
|
741
|
-
/**
|
742
|
-
* The file is owned by the current user, who is running `sudo`.
|
743
|
-
*/
|
744
|
-
GIT_PATH_OWNER_RUNNING_SUDO = (1 << 3),
|
745
|
-
|
746
|
-
/** The file may be owned by another user. */
|
747
|
-
GIT_PATH_OWNER_OTHER = (1 << 4)
|
748
|
-
} git_path_owner_t;
|
749
|
-
|
750
|
-
/**
|
751
|
-
* Sets the mock ownership for files; subsequent calls to
|
752
|
-
* `git_path_owner_is_*` functions will return this data until
|
753
|
-
* cleared with `GIT_FS_PATH_OWNER_NONE`.
|
754
|
-
*/
|
755
|
-
void git_path__set_owner(git_path_owner_t owner);
|
756
|
-
|
757
|
-
/** Verify that the file in question is owned by the given owner. */
|
758
|
-
int git_path_owner_is(
|
759
|
-
bool *out,
|
760
|
-
const char *path,
|
761
|
-
git_path_owner_t owner_type);
|
762
|
-
|
763
|
-
/**
|
764
|
-
* Verify that the file in question is owned by an administrator or system
|
765
|
-
* account.
|
766
|
-
*/
|
767
|
-
int git_path_owner_is_system(bool *out, const char *path);
|
768
|
-
|
769
|
-
/**
|
770
|
-
* Verify that the file in question is owned by the current user;
|
771
|
-
*/
|
772
|
-
|
773
|
-
int git_path_owner_is_current_user(bool *out, const char *path);
|
774
|
-
|
775
68
|
#endif
|