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
@@ -18,6 +18,7 @@
|
|
18
18
|
#include "sortedcache.h"
|
19
19
|
#include "signature.h"
|
20
20
|
#include "wildmatch.h"
|
21
|
+
#include "path.h"
|
21
22
|
|
22
23
|
#include <git2/tag.h>
|
23
24
|
#include <git2/object.h>
|
@@ -34,7 +35,7 @@ enum {
|
|
34
35
|
PACKREF_HAS_PEEL = 1,
|
35
36
|
PACKREF_WAS_LOOSE = 2,
|
36
37
|
PACKREF_CANNOT_PEEL = 4,
|
37
|
-
PACKREF_SHADOWED = 8
|
38
|
+
PACKREF_SHADOWED = 8
|
38
39
|
};
|
39
40
|
|
40
41
|
enum {
|
@@ -64,24 +65,29 @@ typedef struct refdb_fs_backend {
|
|
64
65
|
git_iterator_flag_t iterator_flags;
|
65
66
|
uint32_t direach_flags;
|
66
67
|
int fsync;
|
68
|
+
git_map packed_refs_map;
|
69
|
+
git_mutex prlock; /* protect packed_refs_map */
|
70
|
+
git_futils_filestamp packed_refs_stamp;
|
71
|
+
bool sorted;
|
67
72
|
} refdb_fs_backend;
|
68
73
|
|
69
74
|
static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name);
|
75
|
+
static char *packed_set_peeling_mode(char *data, size_t data_sz, refdb_fs_backend *backend);
|
70
76
|
|
71
77
|
GIT_INLINE(int) loose_path(
|
72
|
-
|
78
|
+
git_str *out,
|
73
79
|
const char *base,
|
74
80
|
const char *refname)
|
75
81
|
{
|
76
|
-
if (
|
82
|
+
if (git_str_joinpath(out, base, refname) < 0)
|
77
83
|
return -1;
|
78
84
|
|
79
|
-
return
|
85
|
+
return git_fs_path_validate_str_length_with_suffix(out,
|
80
86
|
CONST_STRLEN(".lock"));
|
81
87
|
}
|
82
88
|
|
83
89
|
GIT_INLINE(int) reflog_path(
|
84
|
-
|
90
|
+
git_str *out,
|
85
91
|
git_repository *repo,
|
86
92
|
const char *refname)
|
87
93
|
{
|
@@ -91,7 +97,7 @@ GIT_INLINE(int) reflog_path(
|
|
91
97
|
base = (strcmp(refname, GIT_HEAD_FILE) == 0) ? repo->gitdir :
|
92
98
|
repo->commondir;
|
93
99
|
|
94
|
-
if ((error =
|
100
|
+
if ((error = git_str_joinpath(out, base, GIT_REFLOG_DIR)) < 0)
|
95
101
|
return error;
|
96
102
|
|
97
103
|
return loose_path(out, out->ptr, refname);
|
@@ -106,7 +112,7 @@ static int packref_cmp(const void *a_, const void *b_)
|
|
106
112
|
static int packed_reload(refdb_fs_backend *backend)
|
107
113
|
{
|
108
114
|
int error;
|
109
|
-
|
115
|
+
git_str packedrefs = GIT_STR_INIT;
|
110
116
|
char *scan, *eof, *eol;
|
111
117
|
|
112
118
|
if (!backend->gitpath)
|
@@ -133,31 +139,12 @@ static int packed_reload(refdb_fs_backend *backend)
|
|
133
139
|
|
134
140
|
GIT_UNUSED(git_sortedcache_clear(backend->refcache, false));
|
135
141
|
|
136
|
-
scan =
|
142
|
+
scan = packedrefs.ptr;
|
137
143
|
eof = scan + packedrefs.size;
|
138
144
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
static const char *traits_header = "# pack-refs with: ";
|
143
|
-
|
144
|
-
if (git__prefixcmp(scan, traits_header) == 0) {
|
145
|
-
scan += strlen(traits_header);
|
146
|
-
eol = strchr(scan, '\n');
|
147
|
-
|
148
|
-
if (!eol)
|
149
|
-
goto parse_failed;
|
150
|
-
*eol = '\0';
|
151
|
-
|
152
|
-
if (strstr(scan, " fully-peeled ") != NULL) {
|
153
|
-
backend->peeling_mode = PEELING_FULL;
|
154
|
-
} else if (strstr(scan, " peeled ") != NULL) {
|
155
|
-
backend->peeling_mode = PEELING_STANDARD;
|
156
|
-
}
|
157
|
-
|
158
|
-
scan = eol + 1;
|
159
|
-
}
|
160
|
-
}
|
145
|
+
scan = packed_set_peeling_mode(scan, packedrefs.size, backend);
|
146
|
+
if (!scan)
|
147
|
+
goto parse_failed;
|
161
148
|
|
162
149
|
while (scan < eof && *scan == '#') {
|
163
150
|
if (!(eol = strchr(scan, '\n')))
|
@@ -212,7 +199,7 @@ static int packed_reload(refdb_fs_backend *backend)
|
|
212
199
|
}
|
213
200
|
|
214
201
|
git_sortedcache_wunlock(backend->refcache);
|
215
|
-
|
202
|
+
git_str_dispose(&packedrefs);
|
216
203
|
|
217
204
|
return 0;
|
218
205
|
|
@@ -221,17 +208,17 @@ parse_failed:
|
|
221
208
|
|
222
209
|
GIT_UNUSED(git_sortedcache_clear(backend->refcache, false));
|
223
210
|
git_sortedcache_wunlock(backend->refcache);
|
224
|
-
|
211
|
+
git_str_dispose(&packedrefs);
|
225
212
|
|
226
213
|
return -1;
|
227
214
|
}
|
228
215
|
|
229
216
|
static int loose_parse_oid(
|
230
|
-
git_oid *oid, const char *filename,
|
217
|
+
git_oid *oid, const char *filename, git_str *file_content)
|
231
218
|
{
|
232
|
-
const char *str =
|
219
|
+
const char *str = git_str_cstr(file_content);
|
233
220
|
|
234
|
-
if (
|
221
|
+
if (git_str_len(file_content) < GIT_OID_HEXSZ)
|
235
222
|
goto corrupted;
|
236
223
|
|
237
224
|
/* we need to get 40 OID characters from the file */
|
@@ -248,13 +235,13 @@ corrupted:
|
|
248
235
|
return -1;
|
249
236
|
}
|
250
237
|
|
251
|
-
static int loose_readbuffer(
|
238
|
+
static int loose_readbuffer(git_str *buf, const char *base, const char *path)
|
252
239
|
{
|
253
240
|
int error;
|
254
241
|
|
255
242
|
if ((error = loose_path(buf, base, path)) < 0 ||
|
256
243
|
(error = git_futils_readbuffer(buf, buf->ptr)) < 0)
|
257
|
-
|
244
|
+
git_str_dispose(buf);
|
258
245
|
|
259
246
|
return error;
|
260
247
|
}
|
@@ -262,7 +249,7 @@ static int loose_readbuffer(git_buf *buf, const char *base, const char *path)
|
|
262
249
|
static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
|
263
250
|
{
|
264
251
|
int error = 0;
|
265
|
-
|
252
|
+
git_str ref_file = GIT_STR_INIT;
|
266
253
|
struct packref *ref = NULL;
|
267
254
|
git_oid oid;
|
268
255
|
|
@@ -275,7 +262,7 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
|
|
275
262
|
}
|
276
263
|
|
277
264
|
/* skip symbolic refs */
|
278
|
-
if (!git__prefixcmp(
|
265
|
+
if (!git__prefixcmp(git_str_cstr(&ref_file), GIT_SYMREF))
|
279
266
|
goto done;
|
280
267
|
|
281
268
|
/* parse OID from file */
|
@@ -295,11 +282,11 @@ static int loose_lookup_to_packfile(refdb_fs_backend *backend, const char *name)
|
|
295
282
|
git_sortedcache_wunlock(backend->refcache);
|
296
283
|
|
297
284
|
done:
|
298
|
-
|
285
|
+
git_str_dispose(&ref_file);
|
299
286
|
return error;
|
300
287
|
}
|
301
288
|
|
302
|
-
static int _dirent_loose_load(void *payload,
|
289
|
+
static int _dirent_loose_load(void *payload, git_str *full_path)
|
303
290
|
{
|
304
291
|
refdb_fs_backend *backend = payload;
|
305
292
|
const char *file_path;
|
@@ -307,8 +294,8 @@ static int _dirent_loose_load(void *payload, git_buf *full_path)
|
|
307
294
|
if (git__suffixcmp(full_path->ptr, ".lock") == 0)
|
308
295
|
return 0;
|
309
296
|
|
310
|
-
if (
|
311
|
-
int error =
|
297
|
+
if (git_fs_path_isdir(full_path->ptr)) {
|
298
|
+
int error = git_fs_path_direach(
|
312
299
|
full_path, backend->direach_flags, _dirent_loose_load, backend);
|
313
300
|
/* Race with the filesystem, ignore it */
|
314
301
|
if (error == GIT_ENOTFOUND) {
|
@@ -333,9 +320,9 @@ static int _dirent_loose_load(void *payload, git_buf *full_path)
|
|
333
320
|
static int packed_loadloose(refdb_fs_backend *backend)
|
334
321
|
{
|
335
322
|
int error;
|
336
|
-
|
323
|
+
git_str refs_path = GIT_STR_INIT;
|
337
324
|
|
338
|
-
if (
|
325
|
+
if (git_str_joinpath(&refs_path, backend->gitpath, GIT_REFS_DIR) < 0)
|
339
326
|
return -1;
|
340
327
|
|
341
328
|
/*
|
@@ -343,10 +330,10 @@ static int packed_loadloose(refdb_fs_backend *backend)
|
|
343
330
|
* This will overwrite any old packed entries with their
|
344
331
|
* updated loose versions
|
345
332
|
*/
|
346
|
-
error =
|
333
|
+
error = git_fs_path_direach(
|
347
334
|
&refs_path, backend->direach_flags, _dirent_loose_load, backend);
|
348
335
|
|
349
|
-
|
336
|
+
git_str_dispose(&refs_path);
|
350
337
|
|
351
338
|
return error;
|
352
339
|
}
|
@@ -357,7 +344,7 @@ static int refdb_fs_backend__exists(
|
|
357
344
|
const char *ref_name)
|
358
345
|
{
|
359
346
|
refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
|
360
|
-
|
347
|
+
git_str ref_path = GIT_STR_INIT;
|
361
348
|
int error;
|
362
349
|
|
363
350
|
GIT_ASSERT_ARG(backend);
|
@@ -367,7 +354,7 @@ static int refdb_fs_backend__exists(
|
|
367
354
|
if ((error = loose_path(&ref_path, backend->gitpath, ref_name)) < 0)
|
368
355
|
goto out;
|
369
356
|
|
370
|
-
if (
|
357
|
+
if (git_fs_path_isfile(ref_path.ptr)) {
|
371
358
|
*exists = 1;
|
372
359
|
goto out;
|
373
360
|
}
|
@@ -381,18 +368,18 @@ static int refdb_fs_backend__exists(
|
|
381
368
|
}
|
382
369
|
|
383
370
|
out:
|
384
|
-
|
371
|
+
git_str_dispose(&ref_path);
|
385
372
|
return error;
|
386
373
|
}
|
387
374
|
|
388
|
-
static const char *loose_parse_symbolic(
|
375
|
+
static const char *loose_parse_symbolic(git_str *file_content)
|
389
376
|
{
|
390
377
|
const unsigned int header_len = (unsigned int)strlen(GIT_SYMREF);
|
391
378
|
const char *refname_start;
|
392
379
|
|
393
380
|
refname_start = (const char *)file_content->ptr;
|
394
381
|
|
395
|
-
if (
|
382
|
+
if (git_str_len(file_content) < header_len + 1) {
|
396
383
|
git_error_set(GIT_ERROR_REFERENCE, "corrupted loose reference file");
|
397
384
|
return NULL;
|
398
385
|
}
|
@@ -424,7 +411,7 @@ static int loose_lookup(
|
|
424
411
|
refdb_fs_backend *backend,
|
425
412
|
const char *ref_name)
|
426
413
|
{
|
427
|
-
|
414
|
+
git_str ref_file = GIT_STR_INIT;
|
428
415
|
int error = 0;
|
429
416
|
const char *ref_dir;
|
430
417
|
|
@@ -438,10 +425,10 @@ static int loose_lookup(
|
|
438
425
|
|
439
426
|
if ((error = loose_readbuffer(&ref_file, ref_dir, ref_name)) < 0)
|
440
427
|
/* cannot read loose ref file - gah */;
|
441
|
-
else if (git__prefixcmp(
|
428
|
+
else if (git__prefixcmp(git_str_cstr(&ref_file), GIT_SYMREF) == 0) {
|
442
429
|
const char *target;
|
443
430
|
|
444
|
-
|
431
|
+
git_str_rtrim(&ref_file);
|
445
432
|
|
446
433
|
if (!(target = loose_parse_symbolic(&ref_file)))
|
447
434
|
error = -1;
|
@@ -455,7 +442,7 @@ static int loose_lookup(
|
|
455
442
|
*out = git_reference__alloc(ref_name, &oid, NULL);
|
456
443
|
}
|
457
444
|
|
458
|
-
|
445
|
+
git_str_dispose(&ref_file);
|
459
446
|
return error;
|
460
447
|
}
|
461
448
|
|
@@ -465,10 +452,198 @@ static int ref_error_notfound(const char *name)
|
|
465
452
|
return GIT_ENOTFOUND;
|
466
453
|
}
|
467
454
|
|
468
|
-
static
|
469
|
-
|
470
|
-
|
471
|
-
|
455
|
+
static char *packed_set_peeling_mode(
|
456
|
+
char *data,
|
457
|
+
size_t data_sz,
|
458
|
+
refdb_fs_backend *backend)
|
459
|
+
{
|
460
|
+
static const char *traits_header = "# pack-refs with:";
|
461
|
+
char *eol;
|
462
|
+
backend->peeling_mode = PEELING_NONE;
|
463
|
+
|
464
|
+
if (git__prefixncmp(data, data_sz, traits_header) == 0) {
|
465
|
+
size_t hdr_sz = strlen(traits_header);
|
466
|
+
const char *sorted = " sorted ";
|
467
|
+
const char *peeled = " peeled ";
|
468
|
+
const char *fully_peeled = " fully-peeled ";
|
469
|
+
data += hdr_sz;
|
470
|
+
data_sz -= hdr_sz;
|
471
|
+
|
472
|
+
eol = memchr(data, '\n', data_sz);
|
473
|
+
|
474
|
+
if (!eol)
|
475
|
+
return NULL;
|
476
|
+
|
477
|
+
if (git__memmem(data, eol - data, fully_peeled, strlen(fully_peeled)))
|
478
|
+
backend->peeling_mode = PEELING_FULL;
|
479
|
+
else if (git__memmem(data, eol - data, peeled, strlen(peeled)))
|
480
|
+
backend->peeling_mode = PEELING_STANDARD;
|
481
|
+
|
482
|
+
backend->sorted = NULL != git__memmem(data, eol - data, sorted, strlen(sorted));
|
483
|
+
|
484
|
+
return eol + 1;
|
485
|
+
}
|
486
|
+
return data;
|
487
|
+
}
|
488
|
+
|
489
|
+
static void packed_map_free(refdb_fs_backend *backend)
|
490
|
+
{
|
491
|
+
if (backend->packed_refs_map.data) {
|
492
|
+
#ifdef GIT_WIN32
|
493
|
+
git__free(backend->packed_refs_map.data);
|
494
|
+
#else
|
495
|
+
git_futils_mmap_free(&backend->packed_refs_map);
|
496
|
+
#endif
|
497
|
+
backend->packed_refs_map.data = NULL;
|
498
|
+
backend->packed_refs_map.len = 0;
|
499
|
+
git_futils_filestamp_set(&backend->packed_refs_stamp, NULL);
|
500
|
+
}
|
501
|
+
}
|
502
|
+
|
503
|
+
static int packed_map_check(refdb_fs_backend *backend)
|
504
|
+
{
|
505
|
+
int error = 0;
|
506
|
+
git_file fd = -1;
|
507
|
+
struct stat st;
|
508
|
+
|
509
|
+
if ((error = git_mutex_lock(&backend->prlock)) < 0)
|
510
|
+
return error;
|
511
|
+
|
512
|
+
if (backend->packed_refs_map.data &&
|
513
|
+
!git_futils_filestamp_check(
|
514
|
+
&backend->packed_refs_stamp, backend->refcache->path)) {
|
515
|
+
git_mutex_unlock(&backend->prlock);
|
516
|
+
return error;
|
517
|
+
}
|
518
|
+
packed_map_free(backend);
|
519
|
+
|
520
|
+
fd = git_futils_open_ro(backend->refcache->path);
|
521
|
+
if (fd < 0) {
|
522
|
+
git_mutex_unlock(&backend->prlock);
|
523
|
+
if (fd == GIT_ENOTFOUND) {
|
524
|
+
git_error_clear();
|
525
|
+
return 0;
|
526
|
+
}
|
527
|
+
return fd;
|
528
|
+
}
|
529
|
+
|
530
|
+
if (p_fstat(fd, &st) < 0) {
|
531
|
+
p_close(fd);
|
532
|
+
git_mutex_unlock(&backend->prlock);
|
533
|
+
git_error_set(GIT_ERROR_OS, "unable to stat packed-refs '%s'", backend->refcache->path);
|
534
|
+
return -1;
|
535
|
+
}
|
536
|
+
|
537
|
+
if (st.st_size == 0) {
|
538
|
+
p_close(fd);
|
539
|
+
git_mutex_unlock(&backend->prlock);
|
540
|
+
return 0;
|
541
|
+
}
|
542
|
+
|
543
|
+
git_futils_filestamp_set_from_stat(&backend->packed_refs_stamp, &st);
|
544
|
+
|
545
|
+
#ifdef GIT_WIN32
|
546
|
+
/* on windows, we copy the entire file into memory rather than using
|
547
|
+
* mmap() because using mmap() on windows also locks the file and this
|
548
|
+
* map is long-lived. */
|
549
|
+
backend->packed_refs_map.len = (size_t)st.st_size;
|
550
|
+
backend->packed_refs_map.data =
|
551
|
+
git__malloc(backend->packed_refs_map.len);
|
552
|
+
GIT_ERROR_CHECK_ALLOC(backend->packed_refs_map.data);
|
553
|
+
{
|
554
|
+
ssize_t bytesread =
|
555
|
+
p_read(fd, backend->packed_refs_map.data,
|
556
|
+
backend->packed_refs_map.len);
|
557
|
+
error = (bytesread == (ssize_t)backend->packed_refs_map.len) ? 0 : -1;
|
558
|
+
}
|
559
|
+
#else
|
560
|
+
error = git_futils_mmap_ro(&backend->packed_refs_map, fd, 0, (size_t)st.st_size);
|
561
|
+
#endif
|
562
|
+
p_close(fd);
|
563
|
+
if (error < 0) {
|
564
|
+
git_mutex_unlock(&backend->prlock);
|
565
|
+
return error;
|
566
|
+
}
|
567
|
+
|
568
|
+
packed_set_peeling_mode(
|
569
|
+
backend->packed_refs_map.data, backend->packed_refs_map.len,
|
570
|
+
backend);
|
571
|
+
|
572
|
+
git_mutex_unlock(&backend->prlock);
|
573
|
+
return error;
|
574
|
+
}
|
575
|
+
|
576
|
+
/*
|
577
|
+
* Find beginning of packed-ref record pointed to by p.
|
578
|
+
* buf - a lower-bound pointer to some memory buffer
|
579
|
+
* p - an upper-bound pointer to the same memory buffer
|
580
|
+
*/
|
581
|
+
static const char *start_of_record(const char *buf, const char *p)
|
582
|
+
{
|
583
|
+
const char *nl = p;
|
584
|
+
while (true) {
|
585
|
+
nl = git__memrchr(buf, '\n', nl - buf);
|
586
|
+
if (!nl)
|
587
|
+
return buf;
|
588
|
+
|
589
|
+
if (nl[1] == '^' && nl > buf)
|
590
|
+
--nl;
|
591
|
+
else
|
592
|
+
break;
|
593
|
+
};
|
594
|
+
return nl + 1;
|
595
|
+
}
|
596
|
+
|
597
|
+
/*
|
598
|
+
* Find end of packed-ref record pointed to by p.
|
599
|
+
* end - an upper-bound pointer to some memory buffer
|
600
|
+
* p - a lower-bound pointer to the same memory buffer
|
601
|
+
*/
|
602
|
+
static const char *end_of_record(const char *p, const char *end)
|
603
|
+
{
|
604
|
+
while (1) {
|
605
|
+
size_t sz = end - p;
|
606
|
+
p = memchr(p, '\n', sz);
|
607
|
+
if (!p)
|
608
|
+
return end;
|
609
|
+
++p;
|
610
|
+
if (p < end && p[0] == '^')
|
611
|
+
++p;
|
612
|
+
else
|
613
|
+
break;
|
614
|
+
}
|
615
|
+
return p;
|
616
|
+
}
|
617
|
+
|
618
|
+
static int
|
619
|
+
cmp_record_to_refname(const char *rec, size_t data_end, const char *ref_name)
|
620
|
+
{
|
621
|
+
const size_t ref_len = strlen(ref_name);
|
622
|
+
int cmp_val;
|
623
|
+
const char *end;
|
624
|
+
|
625
|
+
rec += GIT_OID_HEXSZ + 1; /* <oid> + space */
|
626
|
+
if (data_end < GIT_OID_HEXSZ + 3) {
|
627
|
+
/* an incomplete (corrupt) record is treated as less than ref_name */
|
628
|
+
return -1;
|
629
|
+
}
|
630
|
+
data_end -= GIT_OID_HEXSZ + 1;
|
631
|
+
|
632
|
+
end = memchr(rec, '\n', data_end);
|
633
|
+
if (end)
|
634
|
+
data_end = end - rec;
|
635
|
+
|
636
|
+
cmp_val = memcmp(rec, ref_name, min(ref_len, data_end));
|
637
|
+
|
638
|
+
if (cmp_val == 0 && data_end != ref_len)
|
639
|
+
return (data_end > ref_len) ? 1 : -1;
|
640
|
+
return cmp_val;
|
641
|
+
}
|
642
|
+
|
643
|
+
static int packed_unsorted_lookup(
|
644
|
+
git_reference **out,
|
645
|
+
refdb_fs_backend *backend,
|
646
|
+
const char *ref_name)
|
472
647
|
{
|
473
648
|
int error = 0;
|
474
649
|
struct packref *entry;
|
@@ -493,6 +668,85 @@ static int packed_lookup(
|
|
493
668
|
return error;
|
494
669
|
}
|
495
670
|
|
671
|
+
static int packed_lookup(
|
672
|
+
git_reference **out,
|
673
|
+
refdb_fs_backend *backend,
|
674
|
+
const char *ref_name)
|
675
|
+
{
|
676
|
+
int error = 0;
|
677
|
+
const char *left, *right, *data_end;
|
678
|
+
|
679
|
+
if ((error = packed_map_check(backend)) < 0)
|
680
|
+
return error;
|
681
|
+
|
682
|
+
if (!backend->sorted)
|
683
|
+
return packed_unsorted_lookup(out, backend, ref_name);
|
684
|
+
|
685
|
+
left = backend->packed_refs_map.data;
|
686
|
+
right = data_end = (const char *) backend->packed_refs_map.data +
|
687
|
+
backend->packed_refs_map.len;
|
688
|
+
|
689
|
+
while (left < right && *left == '#') {
|
690
|
+
if (!(left = memchr(left, '\n', data_end - left)))
|
691
|
+
goto parse_failed;
|
692
|
+
left++;
|
693
|
+
}
|
694
|
+
|
695
|
+
while (left < right) {
|
696
|
+
const char *mid, *rec;
|
697
|
+
int compare;
|
698
|
+
|
699
|
+
mid = left + (right - left) / 2;
|
700
|
+
rec = start_of_record(left, mid);
|
701
|
+
compare = cmp_record_to_refname(rec, data_end - rec, ref_name);
|
702
|
+
|
703
|
+
if (compare < 0) {
|
704
|
+
left = end_of_record(mid, right);
|
705
|
+
} else if (compare > 0) {
|
706
|
+
right = rec;
|
707
|
+
} else {
|
708
|
+
const char *eol;
|
709
|
+
git_oid oid, peel, *peel_ptr = NULL;
|
710
|
+
|
711
|
+
if (data_end - rec < GIT_OID_HEXSZ ||
|
712
|
+
git_oid_fromstr(&oid, rec) < 0) {
|
713
|
+
goto parse_failed;
|
714
|
+
}
|
715
|
+
rec += GIT_OID_HEXSZ + 1;
|
716
|
+
if (!(eol = memchr(rec, '\n', data_end - rec))) {
|
717
|
+
goto parse_failed;
|
718
|
+
}
|
719
|
+
|
720
|
+
/* look for optional "^<OID>\n" */
|
721
|
+
|
722
|
+
if (eol + 1 < data_end) {
|
723
|
+
rec = eol + 1;
|
724
|
+
|
725
|
+
if (*rec == '^') {
|
726
|
+
rec++;
|
727
|
+
if (data_end - rec < GIT_OID_HEXSZ ||
|
728
|
+
git_oid_fromstr(&peel, rec) < 0) {
|
729
|
+
goto parse_failed;
|
730
|
+
}
|
731
|
+
peel_ptr = &peel;
|
732
|
+
}
|
733
|
+
}
|
734
|
+
|
735
|
+
*out = git_reference__alloc(ref_name, &oid, peel_ptr);
|
736
|
+
if (!*out) {
|
737
|
+
return -1;
|
738
|
+
}
|
739
|
+
|
740
|
+
return 0;
|
741
|
+
}
|
742
|
+
}
|
743
|
+
return GIT_ENOTFOUND;
|
744
|
+
|
745
|
+
parse_failed:
|
746
|
+
git_error_set(GIT_ERROR_REFERENCE, "corrupted packed references file");
|
747
|
+
return -1;
|
748
|
+
}
|
749
|
+
|
496
750
|
static int refdb_fs_backend__lookup(
|
497
751
|
git_reference **out,
|
498
752
|
git_refdb_backend *_backend,
|
@@ -512,7 +766,6 @@ static int refdb_fs_backend__lookup(
|
|
512
766
|
git_error_clear();
|
513
767
|
error = packed_lookup(out, backend, ref_name);
|
514
768
|
}
|
515
|
-
|
516
769
|
return error;
|
517
770
|
}
|
518
771
|
|
@@ -542,7 +795,7 @@ static void refdb_fs_backend__iterator_free(git_reference_iterator *_iter)
|
|
542
795
|
static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
|
543
796
|
{
|
544
797
|
int error = 0;
|
545
|
-
|
798
|
+
git_str path = GIT_STR_INIT;
|
546
799
|
git_iterator *fsit = NULL;
|
547
800
|
git_iterator_options fsit_opts = GIT_ITERATOR_OPTIONS_INIT;
|
548
801
|
const git_index_entry *entry = NULL;
|
@@ -578,26 +831,26 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
|
|
578
831
|
}
|
579
832
|
}
|
580
833
|
|
581
|
-
if ((error =
|
582
|
-
(error =
|
583
|
-
|
834
|
+
if ((error = git_str_puts(&path, backend->commonpath)) < 0 ||
|
835
|
+
(error = git_str_put(&path, ref_prefix, ref_prefix_len)) < 0) {
|
836
|
+
git_str_dispose(&path);
|
584
837
|
return error;
|
585
838
|
}
|
586
839
|
|
587
840
|
if ((error = git_iterator_for_filesystem(&fsit, path.ptr, &fsit_opts)) < 0) {
|
588
|
-
|
841
|
+
git_str_dispose(&path);
|
589
842
|
return (iter->glob && error == GIT_ENOTFOUND)? 0 : error;
|
590
843
|
}
|
591
844
|
|
592
|
-
error =
|
845
|
+
error = git_str_sets(&path, ref_prefix);
|
593
846
|
|
594
847
|
while (!error && !git_iterator_advance(&entry, fsit)) {
|
595
848
|
const char *ref_name;
|
596
849
|
char *ref_dup;
|
597
850
|
|
598
|
-
|
599
|
-
|
600
|
-
ref_name =
|
851
|
+
git_str_truncate(&path, ref_prefix_len);
|
852
|
+
git_str_puts(&path, entry->path);
|
853
|
+
ref_name = git_str_cstr(&path);
|
601
854
|
|
602
855
|
if (git__suffixcmp(ref_name, ".lock") == 0 ||
|
603
856
|
(iter->glob && wildmatch(iter->glob, ref_name, 0) != 0))
|
@@ -611,7 +864,7 @@ static int iter_load_loose_paths(refdb_fs_backend *backend, refdb_fs_iter *iter)
|
|
611
864
|
}
|
612
865
|
|
613
866
|
git_iterator_free(fsit);
|
614
|
-
|
867
|
+
git_str_dispose(&path);
|
615
868
|
|
616
869
|
return error;
|
617
870
|
}
|
@@ -810,14 +1063,14 @@ static int reference_path_available(
|
|
810
1063
|
static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *name)
|
811
1064
|
{
|
812
1065
|
int error, filebuf_flags;
|
813
|
-
|
1066
|
+
git_str ref_path = GIT_STR_INIT;
|
814
1067
|
const char *basedir;
|
815
1068
|
|
816
1069
|
GIT_ASSERT_ARG(file);
|
817
1070
|
GIT_ASSERT_ARG(backend);
|
818
1071
|
GIT_ASSERT_ARG(name);
|
819
1072
|
|
820
|
-
if (!
|
1073
|
+
if (!git_path_is_valid(backend->repo, name, 0, GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
|
821
1074
|
git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", name);
|
822
1075
|
return GIT_EINVALIDSPEC;
|
823
1076
|
}
|
@@ -845,7 +1098,7 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
|
|
845
1098
|
if (error == GIT_EDIRECTORY)
|
846
1099
|
git_error_set(GIT_ERROR_REFERENCE, "cannot lock ref '%s', there are refs beneath that folder", name);
|
847
1100
|
|
848
|
-
|
1101
|
+
git_str_dispose(&ref_path);
|
849
1102
|
return error;
|
850
1103
|
}
|
851
1104
|
|
@@ -1013,7 +1266,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
|
|
1013
1266
|
{
|
1014
1267
|
size_t i;
|
1015
1268
|
git_filebuf lock = GIT_FILEBUF_INIT;
|
1016
|
-
|
1269
|
+
git_str ref_content = GIT_STR_INIT;
|
1017
1270
|
int error = 0;
|
1018
1271
|
|
1019
1272
|
/* backend->refcache is already locked when this is called */
|
@@ -1034,7 +1287,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
|
|
1034
1287
|
continue;
|
1035
1288
|
|
1036
1289
|
if (error < 0) {
|
1037
|
-
|
1290
|
+
git_str_dispose(&ref_content);
|
1038
1291
|
git_error_set(GIT_ERROR_REFERENCE, "failed to lock loose reference '%s'", ref->name);
|
1039
1292
|
return error;
|
1040
1293
|
}
|
@@ -1065,7 +1318,7 @@ static int packed_remove_loose(refdb_fs_backend *backend)
|
|
1065
1318
|
p_unlink(lock.path_original);
|
1066
1319
|
}
|
1067
1320
|
|
1068
|
-
|
1321
|
+
git_str_dispose(&ref_content);
|
1069
1322
|
git_filebuf_cleanup(&lock);
|
1070
1323
|
return 0;
|
1071
1324
|
}
|
@@ -1080,6 +1333,15 @@ static int packed_write(refdb_fs_backend *backend)
|
|
1080
1333
|
int error, open_flags = 0;
|
1081
1334
|
size_t i;
|
1082
1335
|
|
1336
|
+
/* take lock and close up packed-refs mmap if open */
|
1337
|
+
if ((error = git_mutex_lock(&backend->prlock)) < 0) {
|
1338
|
+
return error;
|
1339
|
+
}
|
1340
|
+
|
1341
|
+
packed_map_free(backend);
|
1342
|
+
|
1343
|
+
git_mutex_unlock(&backend->prlock);
|
1344
|
+
|
1083
1345
|
/* lock the cache to updates while we do this */
|
1084
1346
|
if ((error = git_sortedcache_wlock(refcache)) < 0)
|
1085
1347
|
return error;
|
@@ -1333,41 +1595,41 @@ static int refdb_fs_backend__prune_refs(
|
|
1333
1595
|
const char *ref_name,
|
1334
1596
|
const char *prefix)
|
1335
1597
|
{
|
1336
|
-
|
1337
|
-
|
1598
|
+
git_str relative_path = GIT_STR_INIT;
|
1599
|
+
git_str base_path = GIT_STR_INIT;
|
1338
1600
|
size_t commonlen;
|
1339
1601
|
int error;
|
1340
1602
|
|
1341
1603
|
GIT_ASSERT_ARG(backend);
|
1342
1604
|
GIT_ASSERT_ARG(ref_name);
|
1343
1605
|
|
1344
|
-
if ((error =
|
1606
|
+
if ((error = git_str_sets(&relative_path, ref_name)) < 0)
|
1345
1607
|
goto cleanup;
|
1346
1608
|
|
1347
|
-
|
1348
|
-
if ((commonlen =
|
1349
|
-
(commonlen =
|
1350
|
-
(commonlen =
|
1609
|
+
git_fs_path_squash_slashes(&relative_path);
|
1610
|
+
if ((commonlen = git_fs_path_common_dirlen("refs/heads/", git_str_cstr(&relative_path))) == strlen("refs/heads/") ||
|
1611
|
+
(commonlen = git_fs_path_common_dirlen("refs/tags/", git_str_cstr(&relative_path))) == strlen("refs/tags/") ||
|
1612
|
+
(commonlen = git_fs_path_common_dirlen("refs/remotes/", git_str_cstr(&relative_path))) == strlen("refs/remotes/")) {
|
1351
1613
|
|
1352
|
-
|
1614
|
+
git_str_truncate(&relative_path, commonlen);
|
1353
1615
|
|
1354
1616
|
if (prefix)
|
1355
|
-
error =
|
1617
|
+
error = git_str_join3(&base_path, '/',
|
1356
1618
|
backend->commonpath, prefix,
|
1357
|
-
|
1619
|
+
git_str_cstr(&relative_path));
|
1358
1620
|
else
|
1359
|
-
error =
|
1621
|
+
error = git_str_joinpath(&base_path,
|
1360
1622
|
backend->commonpath,
|
1361
|
-
|
1623
|
+
git_str_cstr(&relative_path));
|
1362
1624
|
|
1363
1625
|
if (!error)
|
1364
|
-
error =
|
1626
|
+
error = git_path_validate_str_length(NULL, &base_path);
|
1365
1627
|
|
1366
1628
|
if (error < 0)
|
1367
1629
|
goto cleanup;
|
1368
1630
|
|
1369
1631
|
error = git_futils_rmdir_r(ref_name + commonlen,
|
1370
|
-
|
1632
|
+
git_str_cstr(&base_path),
|
1371
1633
|
GIT_RMDIR_EMPTY_PARENTS | GIT_RMDIR_SKIP_ROOT);
|
1372
1634
|
|
1373
1635
|
if (error == GIT_ENOTFOUND)
|
@@ -1375,8 +1637,8 @@ static int refdb_fs_backend__prune_refs(
|
|
1375
1637
|
}
|
1376
1638
|
|
1377
1639
|
cleanup:
|
1378
|
-
|
1379
|
-
|
1640
|
+
git_str_dispose(&relative_path);
|
1641
|
+
git_str_dispose(&base_path);
|
1380
1642
|
return error;
|
1381
1643
|
}
|
1382
1644
|
|
@@ -1405,7 +1667,7 @@ static int refdb_fs_backend__delete(
|
|
1405
1667
|
|
1406
1668
|
static int loose_delete(refdb_fs_backend *backend, const char *ref_name)
|
1407
1669
|
{
|
1408
|
-
|
1670
|
+
git_str path = GIT_STR_INIT;
|
1409
1671
|
int error = 0;
|
1410
1672
|
|
1411
1673
|
if ((error = loose_path(&path, backend->commonpath, ref_name)) < 0)
|
@@ -1417,7 +1679,7 @@ static int loose_delete(refdb_fs_backend *backend, const char *ref_name)
|
|
1417
1679
|
else if (error != 0)
|
1418
1680
|
error = -1;
|
1419
1681
|
|
1420
|
-
|
1682
|
+
git_str_dispose(&path);
|
1421
1683
|
|
1422
1684
|
return error;
|
1423
1685
|
}
|
@@ -1567,6 +1829,12 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
|
|
1567
1829
|
return;
|
1568
1830
|
|
1569
1831
|
git_sortedcache_free(backend->refcache);
|
1832
|
+
|
1833
|
+
git_mutex_lock(&backend->prlock);
|
1834
|
+
packed_map_free(backend);
|
1835
|
+
git_mutex_unlock(&backend->prlock);
|
1836
|
+
git_mutex_free(&backend->prlock);
|
1837
|
+
|
1570
1838
|
git__free(backend->gitpath);
|
1571
1839
|
git__free(backend->commonpath);
|
1572
1840
|
git__free(backend);
|
@@ -1574,17 +1842,17 @@ static void refdb_fs_backend__free(git_refdb_backend *_backend)
|
|
1574
1842
|
|
1575
1843
|
static char *setup_namespace(git_repository *repo, const char *in)
|
1576
1844
|
{
|
1577
|
-
|
1845
|
+
git_str path = GIT_STR_INIT;
|
1578
1846
|
char *parts, *start, *end, *out = NULL;
|
1579
1847
|
|
1580
1848
|
if (!in)
|
1581
1849
|
goto done;
|
1582
1850
|
|
1583
|
-
|
1851
|
+
git_str_puts(&path, in);
|
1584
1852
|
|
1585
1853
|
/* if the repo is not namespaced, nothing else to do */
|
1586
1854
|
if (repo->namespace == NULL) {
|
1587
|
-
out =
|
1855
|
+
out = git_str_detach(&path);
|
1588
1856
|
goto done;
|
1589
1857
|
}
|
1590
1858
|
|
@@ -1599,23 +1867,23 @@ static char *setup_namespace(git_repository *repo, const char *in)
|
|
1599
1867
|
* refs under refs/namespaces/foo/refs/namespaces/bar/
|
1600
1868
|
*/
|
1601
1869
|
while ((start = git__strsep(&end, "/")) != NULL)
|
1602
|
-
|
1870
|
+
git_str_printf(&path, "refs/namespaces/%s/", start);
|
1603
1871
|
|
1604
|
-
|
1872
|
+
git_str_printf(&path, "refs/namespaces/%s/refs", end);
|
1605
1873
|
git__free(parts);
|
1606
1874
|
|
1607
1875
|
/* Make sure that the folder with the namespace exists */
|
1608
|
-
if (git_futils_mkdir_relative(
|
1876
|
+
if (git_futils_mkdir_relative(git_str_cstr(&path), in, 0777,
|
1609
1877
|
GIT_MKDIR_PATH, NULL) < 0)
|
1610
1878
|
goto done;
|
1611
1879
|
|
1612
1880
|
/* Return root of the namespaced gitpath, i.e. without the trailing 'refs' */
|
1613
|
-
|
1614
|
-
|
1615
|
-
out =
|
1881
|
+
git_str_rtruncate_at_char(&path, '/');
|
1882
|
+
git_str_putc(&path, '/');
|
1883
|
+
out = git_str_detach(&path);
|
1616
1884
|
|
1617
1885
|
done:
|
1618
|
-
|
1886
|
+
git_str_dispose(&path);
|
1619
1887
|
return out;
|
1620
1888
|
}
|
1621
1889
|
|
@@ -1716,7 +1984,7 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
|
|
1716
1984
|
{
|
1717
1985
|
refdb_fs_backend *backend;
|
1718
1986
|
git_repository *repo;
|
1719
|
-
|
1987
|
+
git_str path = GIT_STR_INIT;
|
1720
1988
|
int error;
|
1721
1989
|
|
1722
1990
|
GIT_ASSERT_ARG(_backend && name);
|
@@ -1727,8 +1995,8 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
|
|
1727
1995
|
if ((error = reflog_path(&path, repo, name)) < 0)
|
1728
1996
|
return error;
|
1729
1997
|
|
1730
|
-
error = create_new_reflog_file(
|
1731
|
-
|
1998
|
+
error = create_new_reflog_file(git_str_cstr(&path));
|
1999
|
+
git_str_dispose(&path);
|
1732
2000
|
|
1733
2001
|
return error;
|
1734
2002
|
}
|
@@ -1736,15 +2004,15 @@ static int refdb_reflog_fs__ensure_log(git_refdb_backend *_backend, const char *
|
|
1736
2004
|
static int has_reflog(git_repository *repo, const char *name)
|
1737
2005
|
{
|
1738
2006
|
int ret = 0;
|
1739
|
-
|
2007
|
+
git_str path = GIT_STR_INIT;
|
1740
2008
|
|
1741
2009
|
if (reflog_path(&path, repo, name) < 0)
|
1742
2010
|
goto cleanup;
|
1743
2011
|
|
1744
|
-
ret =
|
2012
|
+
ret = git_fs_path_isfile(git_str_cstr(&path));
|
1745
2013
|
|
1746
2014
|
cleanup:
|
1747
|
-
|
2015
|
+
git_str_dispose(&path);
|
1748
2016
|
return ret;
|
1749
2017
|
}
|
1750
2018
|
|
@@ -1763,8 +2031,8 @@ static int refdb_reflog_fs__has_log(git_refdb_backend *_backend, const char *nam
|
|
1763
2031
|
static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend, const char *name)
|
1764
2032
|
{
|
1765
2033
|
int error = -1;
|
1766
|
-
|
1767
|
-
|
2034
|
+
git_str log_path = GIT_STR_INIT;
|
2035
|
+
git_str log_file = GIT_STR_INIT;
|
1768
2036
|
git_reflog *log = NULL;
|
1769
2037
|
git_repository *repo;
|
1770
2038
|
refdb_fs_backend *backend;
|
@@ -1782,16 +2050,16 @@ static int refdb_reflog_fs__read(git_reflog **out, git_refdb_backend *_backend,
|
|
1782
2050
|
if (reflog_path(&log_path, repo, name) < 0)
|
1783
2051
|
goto cleanup;
|
1784
2052
|
|
1785
|
-
error = git_futils_readbuffer(&log_file,
|
2053
|
+
error = git_futils_readbuffer(&log_file, git_str_cstr(&log_path));
|
1786
2054
|
if (error < 0 && error != GIT_ENOTFOUND)
|
1787
2055
|
goto cleanup;
|
1788
2056
|
|
1789
2057
|
if ((error == GIT_ENOTFOUND) &&
|
1790
|
-
((error = create_new_reflog_file(
|
2058
|
+
((error = create_new_reflog_file(git_str_cstr(&log_path))) < 0))
|
1791
2059
|
goto cleanup;
|
1792
2060
|
|
1793
2061
|
if ((error = reflog_parse(log,
|
1794
|
-
|
2062
|
+
git_str_cstr(&log_file), git_str_len(&log_file))) < 0)
|
1795
2063
|
goto cleanup;
|
1796
2064
|
|
1797
2065
|
*out = log;
|
@@ -1801,14 +2069,14 @@ cleanup:
|
|
1801
2069
|
git_reflog_free(log);
|
1802
2070
|
|
1803
2071
|
success:
|
1804
|
-
|
1805
|
-
|
2072
|
+
git_str_dispose(&log_file);
|
2073
|
+
git_str_dispose(&log_path);
|
1806
2074
|
|
1807
2075
|
return error;
|
1808
2076
|
}
|
1809
2077
|
|
1810
2078
|
static int serialize_reflog_entry(
|
1811
|
-
|
2079
|
+
git_str *buf,
|
1812
2080
|
const git_oid *oid_old,
|
1813
2081
|
const git_oid *oid_new,
|
1814
2082
|
const git_signature *committer,
|
@@ -1820,43 +2088,43 @@ static int serialize_reflog_entry(
|
|
1820
2088
|
git_oid_tostr(raw_old, GIT_OID_HEXSZ+1, oid_old);
|
1821
2089
|
git_oid_tostr(raw_new, GIT_OID_HEXSZ+1, oid_new);
|
1822
2090
|
|
1823
|
-
|
2091
|
+
git_str_clear(buf);
|
1824
2092
|
|
1825
|
-
|
1826
|
-
|
1827
|
-
|
2093
|
+
git_str_puts(buf, raw_old);
|
2094
|
+
git_str_putc(buf, ' ');
|
2095
|
+
git_str_puts(buf, raw_new);
|
1828
2096
|
|
1829
2097
|
git_signature__writebuf(buf, " ", committer);
|
1830
2098
|
|
1831
2099
|
/* drop trailing LF */
|
1832
|
-
|
2100
|
+
git_str_rtrim(buf);
|
1833
2101
|
|
1834
2102
|
if (msg) {
|
1835
2103
|
size_t i;
|
1836
2104
|
|
1837
|
-
|
1838
|
-
|
2105
|
+
git_str_putc(buf, '\t');
|
2106
|
+
git_str_puts(buf, msg);
|
1839
2107
|
|
1840
2108
|
for (i = 0; i < buf->size - 2; i++)
|
1841
2109
|
if (buf->ptr[i] == '\n')
|
1842
2110
|
buf->ptr[i] = ' ';
|
1843
|
-
|
2111
|
+
git_str_rtrim(buf);
|
1844
2112
|
}
|
1845
2113
|
|
1846
|
-
|
2114
|
+
git_str_putc(buf, '\n');
|
1847
2115
|
|
1848
|
-
return
|
2116
|
+
return git_str_oom(buf);
|
1849
2117
|
}
|
1850
2118
|
|
1851
2119
|
static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char *refname)
|
1852
2120
|
{
|
1853
2121
|
git_repository *repo;
|
1854
|
-
|
2122
|
+
git_str log_path = GIT_STR_INIT;
|
1855
2123
|
int error;
|
1856
2124
|
|
1857
2125
|
repo = backend->repo;
|
1858
2126
|
|
1859
|
-
if (!
|
2127
|
+
if (!git_path_is_valid(backend->repo, refname, 0, GIT_FS_PATH_REJECT_FILESYSTEM_DEFAULTS)) {
|
1860
2128
|
git_error_set(GIT_ERROR_INVALID, "invalid reference name '%s'", refname);
|
1861
2129
|
return GIT_EINVALIDSPEC;
|
1862
2130
|
}
|
@@ -1864,17 +2132,17 @@ static int lock_reflog(git_filebuf *file, refdb_fs_backend *backend, const char
|
|
1864
2132
|
if (reflog_path(&log_path, repo, refname) < 0)
|
1865
2133
|
return -1;
|
1866
2134
|
|
1867
|
-
if (!
|
2135
|
+
if (!git_fs_path_isfile(git_str_cstr(&log_path))) {
|
1868
2136
|
git_error_set(GIT_ERROR_INVALID,
|
1869
2137
|
"log file for reference '%s' doesn't exist", refname);
|
1870
2138
|
error = -1;
|
1871
2139
|
goto cleanup;
|
1872
2140
|
}
|
1873
2141
|
|
1874
|
-
error = git_filebuf_open(file,
|
2142
|
+
error = git_filebuf_open(file, git_str_cstr(&log_path), 0, GIT_REFLOG_FILE_MODE);
|
1875
2143
|
|
1876
2144
|
cleanup:
|
1877
|
-
|
2145
|
+
git_str_dispose(&log_path);
|
1878
2146
|
|
1879
2147
|
return error;
|
1880
2148
|
}
|
@@ -1885,7 +2153,7 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
|
|
1885
2153
|
unsigned int i;
|
1886
2154
|
git_reflog_entry *entry;
|
1887
2155
|
refdb_fs_backend *backend;
|
1888
|
-
|
2156
|
+
git_str log = GIT_STR_INIT;
|
1889
2157
|
git_filebuf fbuf = GIT_FILEBUF_INIT;
|
1890
2158
|
|
1891
2159
|
GIT_ASSERT_ARG(_backend);
|
@@ -1911,7 +2179,7 @@ cleanup:
|
|
1911
2179
|
git_filebuf_cleanup(&fbuf);
|
1912
2180
|
|
1913
2181
|
success:
|
1914
|
-
|
2182
|
+
git_str_dispose(&log);
|
1915
2183
|
|
1916
2184
|
return error;
|
1917
2185
|
}
|
@@ -1921,7 +2189,7 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
|
|
1921
2189
|
{
|
1922
2190
|
int error, is_symbolic, open_flags;
|
1923
2191
|
git_oid old_id = {{0}}, new_id = {{0}};
|
1924
|
-
|
2192
|
+
git_str buf = GIT_STR_INIT, path = GIT_STR_INIT;
|
1925
2193
|
git_repository *repo = backend->repo;
|
1926
2194
|
|
1927
2195
|
is_symbolic = ref->type == GIT_REFERENCE_SYMBOLIC;
|
@@ -1965,7 +2233,7 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
|
|
1965
2233
|
if ((error = reflog_path(&path, repo, ref->name)) < 0)
|
1966
2234
|
goto cleanup;
|
1967
2235
|
|
1968
|
-
if (((error = git_futils_mkpath2file(
|
2236
|
+
if (((error = git_futils_mkpath2file(git_str_cstr(&path), 0777)) < 0) &&
|
1969
2237
|
(error != GIT_EEXISTS)) {
|
1970
2238
|
goto cleanup;
|
1971
2239
|
}
|
@@ -1973,11 +2241,11 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
|
|
1973
2241
|
/* If the new branch matches part of the namespace of a previously deleted branch,
|
1974
2242
|
* there maybe an obsolete/unused directory (or directory hierarchy) in the way.
|
1975
2243
|
*/
|
1976
|
-
if (
|
1977
|
-
if ((error = git_futils_rmdir_r(
|
2244
|
+
if (git_fs_path_isdir(git_str_cstr(&path))) {
|
2245
|
+
if ((error = git_futils_rmdir_r(git_str_cstr(&path), NULL, GIT_RMDIR_SKIP_NONEMPTY)) < 0) {
|
1978
2246
|
if (error == GIT_ENOTFOUND)
|
1979
2247
|
error = 0;
|
1980
|
-
} else if (
|
2248
|
+
} else if (git_fs_path_isdir(git_str_cstr(&path))) {
|
1981
2249
|
git_error_set(GIT_ERROR_REFERENCE, "cannot create reflog at '%s', there are reflogs beneath that folder",
|
1982
2250
|
ref->name);
|
1983
2251
|
error = GIT_EDIRECTORY;
|
@@ -1992,11 +2260,11 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
|
|
1992
2260
|
if (backend->fsync)
|
1993
2261
|
open_flags |= O_FSYNC;
|
1994
2262
|
|
1995
|
-
error = git_futils_writebuffer(&buf,
|
2263
|
+
error = git_futils_writebuffer(&buf, git_str_cstr(&path), open_flags, GIT_REFLOG_FILE_MODE);
|
1996
2264
|
|
1997
2265
|
cleanup:
|
1998
|
-
|
1999
|
-
|
2266
|
+
git_str_dispose(&buf);
|
2267
|
+
git_str_dispose(&path);
|
2000
2268
|
|
2001
2269
|
return error;
|
2002
2270
|
}
|
@@ -2004,10 +2272,10 @@ cleanup:
|
|
2004
2272
|
static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_name, const char *new_name)
|
2005
2273
|
{
|
2006
2274
|
int error = 0, fd;
|
2007
|
-
|
2008
|
-
|
2009
|
-
|
2010
|
-
|
2275
|
+
git_str old_path = GIT_STR_INIT;
|
2276
|
+
git_str new_path = GIT_STR_INIT;
|
2277
|
+
git_str temp_path = GIT_STR_INIT;
|
2278
|
+
git_str normalized = GIT_STR_INIT;
|
2011
2279
|
git_repository *repo;
|
2012
2280
|
refdb_fs_backend *backend;
|
2013
2281
|
|
@@ -2022,16 +2290,16 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
|
|
2022
2290
|
&normalized, new_name, GIT_REFERENCE_FORMAT_ALLOW_ONELEVEL)) < 0)
|
2023
2291
|
return error;
|
2024
2292
|
|
2025
|
-
if (
|
2293
|
+
if (git_str_joinpath(&temp_path, repo->gitdir, GIT_REFLOG_DIR) < 0)
|
2026
2294
|
return -1;
|
2027
2295
|
|
2028
|
-
if ((error = loose_path(&old_path,
|
2296
|
+
if ((error = loose_path(&old_path, git_str_cstr(&temp_path), old_name)) < 0)
|
2029
2297
|
return error;
|
2030
2298
|
|
2031
|
-
if ((error = loose_path(&new_path,
|
2299
|
+
if ((error = loose_path(&new_path, git_str_cstr(&temp_path), git_str_cstr(&normalized))) < 0)
|
2032
2300
|
return error;
|
2033
2301
|
|
2034
|
-
if (!
|
2302
|
+
if (!git_fs_path_exists(git_str_cstr(&old_path))) {
|
2035
2303
|
error = GIT_ENOTFOUND;
|
2036
2304
|
goto cleanup;
|
2037
2305
|
}
|
@@ -2043,43 +2311,43 @@ static int refdb_reflog_fs__rename(git_refdb_backend *_backend, const char *old_
|
|
2043
2311
|
* - a/b -> a/b/c
|
2044
2312
|
* - a/b/c/d -> a/b/c
|
2045
2313
|
*/
|
2046
|
-
if ((error = loose_path(&temp_path,
|
2314
|
+
if ((error = loose_path(&temp_path, git_str_cstr(&temp_path), "temp_reflog")) < 0)
|
2047
2315
|
return error;
|
2048
2316
|
|
2049
|
-
if ((fd = git_futils_mktmp(&temp_path,
|
2317
|
+
if ((fd = git_futils_mktmp(&temp_path, git_str_cstr(&temp_path), GIT_REFLOG_FILE_MODE)) < 0) {
|
2050
2318
|
error = -1;
|
2051
2319
|
goto cleanup;
|
2052
2320
|
}
|
2053
2321
|
|
2054
2322
|
p_close(fd);
|
2055
2323
|
|
2056
|
-
if (p_rename(
|
2324
|
+
if (p_rename(git_str_cstr(&old_path), git_str_cstr(&temp_path)) < 0) {
|
2057
2325
|
git_error_set(GIT_ERROR_OS, "failed to rename reflog for %s", new_name);
|
2058
2326
|
error = -1;
|
2059
2327
|
goto cleanup;
|
2060
2328
|
}
|
2061
2329
|
|
2062
|
-
if (
|
2063
|
-
(git_futils_rmdir_r(
|
2330
|
+
if (git_fs_path_isdir(git_str_cstr(&new_path)) &&
|
2331
|
+
(git_futils_rmdir_r(git_str_cstr(&new_path), NULL, GIT_RMDIR_SKIP_NONEMPTY) < 0)) {
|
2064
2332
|
error = -1;
|
2065
2333
|
goto cleanup;
|
2066
2334
|
}
|
2067
2335
|
|
2068
|
-
if (git_futils_mkpath2file(
|
2336
|
+
if (git_futils_mkpath2file(git_str_cstr(&new_path), GIT_REFLOG_DIR_MODE) < 0) {
|
2069
2337
|
error = -1;
|
2070
2338
|
goto cleanup;
|
2071
2339
|
}
|
2072
2340
|
|
2073
|
-
if (p_rename(
|
2341
|
+
if (p_rename(git_str_cstr(&temp_path), git_str_cstr(&new_path)) < 0) {
|
2074
2342
|
git_error_set(GIT_ERROR_OS, "failed to rename reflog for %s", new_name);
|
2075
2343
|
error = -1;
|
2076
2344
|
}
|
2077
2345
|
|
2078
2346
|
cleanup:
|
2079
|
-
|
2080
|
-
|
2081
|
-
|
2082
|
-
|
2347
|
+
git_str_dispose(&temp_path);
|
2348
|
+
git_str_dispose(&old_path);
|
2349
|
+
git_str_dispose(&new_path);
|
2350
|
+
git_str_dispose(&normalized);
|
2083
2351
|
|
2084
2352
|
return error;
|
2085
2353
|
}
|
@@ -2087,7 +2355,7 @@ cleanup:
|
|
2087
2355
|
static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name)
|
2088
2356
|
{
|
2089
2357
|
refdb_fs_backend *backend = GIT_CONTAINER_OF(_backend, refdb_fs_backend, parent);
|
2090
|
-
|
2358
|
+
git_str path = GIT_STR_INIT;
|
2091
2359
|
int error;
|
2092
2360
|
|
2093
2361
|
GIT_ASSERT_ARG(_backend);
|
@@ -2096,7 +2364,7 @@ static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name
|
|
2096
2364
|
if ((error = reflog_path(&path, backend->repo, name)) < 0)
|
2097
2365
|
goto out;
|
2098
2366
|
|
2099
|
-
if (!
|
2367
|
+
if (!git_fs_path_exists(path.ptr))
|
2100
2368
|
goto out;
|
2101
2369
|
|
2102
2370
|
if ((error = p_unlink(path.ptr)) < 0)
|
@@ -2105,7 +2373,7 @@ static int refdb_reflog_fs__delete(git_refdb_backend *_backend, const char *name
|
|
2105
2373
|
error = refdb_fs_backend__prune_refs(backend, name, GIT_REFLOG_DIR);
|
2106
2374
|
|
2107
2375
|
out:
|
2108
|
-
|
2376
|
+
git_str_dispose(&path);
|
2109
2377
|
|
2110
2378
|
return error;
|
2111
2379
|
}
|
@@ -2115,11 +2383,16 @@ int git_refdb_backend_fs(
|
|
2115
2383
|
git_repository *repository)
|
2116
2384
|
{
|
2117
2385
|
int t = 0;
|
2118
|
-
|
2386
|
+
git_str gitpath = GIT_STR_INIT;
|
2119
2387
|
refdb_fs_backend *backend;
|
2120
2388
|
|
2121
2389
|
backend = git__calloc(1, sizeof(refdb_fs_backend));
|
2122
2390
|
GIT_ERROR_CHECK_ALLOC(backend);
|
2391
|
+
if (git_mutex_init(&backend->prlock) < 0) {
|
2392
|
+
git__free(backend);
|
2393
|
+
return -1;
|
2394
|
+
}
|
2395
|
+
|
2123
2396
|
|
2124
2397
|
if (git_refdb_init_backend(&backend->parent, GIT_REFDB_BACKEND_VERSION) < 0)
|
2125
2398
|
goto fail;
|
@@ -2140,21 +2413,21 @@ int git_refdb_backend_fs(
|
|
2140
2413
|
goto fail;
|
2141
2414
|
}
|
2142
2415
|
|
2143
|
-
if (
|
2416
|
+
if (git_str_joinpath(&gitpath, backend->commonpath, GIT_PACKEDREFS_FILE) < 0 ||
|
2144
2417
|
git_sortedcache_new(
|
2145
2418
|
&backend->refcache, offsetof(struct packref, name),
|
2146
|
-
NULL, NULL, packref_cmp,
|
2419
|
+
NULL, NULL, packref_cmp, git_str_cstr(&gitpath)) < 0)
|
2147
2420
|
goto fail;
|
2148
2421
|
|
2149
|
-
|
2422
|
+
git_str_dispose(&gitpath);
|
2150
2423
|
|
2151
2424
|
if (!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_IGNORECASE) && t) {
|
2152
2425
|
backend->iterator_flags |= GIT_ITERATOR_IGNORE_CASE;
|
2153
|
-
backend->direach_flags |=
|
2426
|
+
backend->direach_flags |= GIT_FS_PATH_DIR_IGNORE_CASE;
|
2154
2427
|
}
|
2155
2428
|
if (!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_PRECOMPOSE) && t) {
|
2156
2429
|
backend->iterator_flags |= GIT_ITERATOR_PRECOMPOSE_UNICODE;
|
2157
|
-
backend->direach_flags |=
|
2430
|
+
backend->direach_flags |= GIT_FS_PATH_DIR_PRECOMPOSE_UNICODE;
|
2158
2431
|
}
|
2159
2432
|
if ((!git_repository__configmap_lookup(&t, backend->repo, GIT_CONFIGMAP_FSYNCOBJECTFILES) && t) ||
|
2160
2433
|
git_repository__fsync_gitdir)
|
@@ -2182,7 +2455,8 @@ int git_refdb_backend_fs(
|
|
2182
2455
|
return 0;
|
2183
2456
|
|
2184
2457
|
fail:
|
2185
|
-
|
2458
|
+
git_mutex_free(&backend->prlock);
|
2459
|
+
git_str_dispose(&gitpath);
|
2186
2460
|
git__free(backend->gitpath);
|
2187
2461
|
git__free(backend->commonpath);
|
2188
2462
|
git__free(backend);
|