rugged 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +1 -0
- data/README.md +1 -1
- data/ext/rugged/rugged.c +7 -4
- data/ext/rugged/rugged_object.c +1 -1
- data/ext/rugged/rugged_repo.c +3 -3
- data/lib/rugged/repository.rb +2 -2
- data/lib/rugged/version.rb +1 -1
- data/vendor/libgit2/CMakeLists.txt +11 -6
- data/vendor/libgit2/COPYING +109 -1
- data/vendor/libgit2/cmake/Findfutimens.cmake +14 -0
- data/vendor/libgit2/cmake/SelectHTTPSBackend.cmake +4 -0
- data/vendor/libgit2/cmake/SelectHashes.cmake +1 -0
- data/vendor/libgit2/deps/chromium-zlib/CMakeLists.txt +101 -0
- data/vendor/libgit2/deps/ntlmclient/CMakeLists.txt +18 -5
- data/vendor/libgit2/deps/ntlmclient/compat.h +0 -34
- data/vendor/libgit2/deps/ntlmclient/crypt.h +14 -9
- data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.c +20 -20
- data/vendor/libgit2/deps/ntlmclient/crypt_commoncrypto.h +3 -3
- data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.c +37 -36
- data/vendor/libgit2/deps/ntlmclient/crypt_mbedtls.h +4 -3
- data/vendor/libgit2/deps/ntlmclient/crypt_openssl.c +178 -51
- data/vendor/libgit2/deps/ntlmclient/crypt_openssl.h +74 -5
- data/vendor/libgit2/deps/ntlmclient/ntlm.c +156 -124
- data/vendor/libgit2/deps/ntlmclient/ntlm.h +13 -9
- data/vendor/libgit2/deps/ntlmclient/ntlmclient.h +16 -3
- data/vendor/libgit2/deps/ntlmclient/unicode.h +10 -4
- data/vendor/libgit2/deps/ntlmclient/unicode_builtin.c +16 -27
- data/vendor/libgit2/deps/ntlmclient/unicode_builtin.h +20 -0
- data/vendor/libgit2/deps/ntlmclient/unicode_iconv.c +28 -52
- data/vendor/libgit2/deps/ntlmclient/unicode_iconv.h +22 -0
- data/vendor/libgit2/deps/ntlmclient/util.c +15 -1
- data/vendor/libgit2/deps/ntlmclient/util.h +2 -1
- data/vendor/libgit2/include/git2/apply.h +2 -0
- data/vendor/libgit2/include/git2/attr.h +89 -0
- data/vendor/libgit2/include/git2/blame.h +93 -42
- data/vendor/libgit2/include/git2/blob.h +31 -3
- data/vendor/libgit2/include/git2/branch.h +25 -0
- data/vendor/libgit2/include/git2/cert.h +42 -5
- data/vendor/libgit2/include/git2/checkout.h +28 -12
- data/vendor/libgit2/include/git2/commit.h +35 -19
- data/vendor/libgit2/include/git2/common.h +19 -4
- data/vendor/libgit2/include/git2/config.h +1 -1
- data/vendor/libgit2/include/git2/deprecated.h +206 -6
- data/vendor/libgit2/include/git2/diff.h +35 -20
- data/vendor/libgit2/include/git2/errors.h +6 -6
- data/vendor/libgit2/include/git2/filter.h +57 -17
- data/vendor/libgit2/include/git2/graph.h +20 -2
- data/vendor/libgit2/include/git2/index.h +3 -3
- data/vendor/libgit2/include/git2/indexer.h +2 -1
- data/vendor/libgit2/include/git2/odb.h +44 -20
- data/vendor/libgit2/include/git2/patch.h +8 -0
- data/vendor/libgit2/include/git2/rebase.h +25 -1
- data/vendor/libgit2/include/git2/refs.h +9 -5
- data/vendor/libgit2/include/git2/remote.h +59 -6
- data/vendor/libgit2/include/git2/repository.h +95 -52
- data/vendor/libgit2/include/git2/revparse.h +5 -5
- data/vendor/libgit2/include/git2/status.h +115 -59
- data/vendor/libgit2/include/git2/submodule.h +9 -0
- data/vendor/libgit2/include/git2/sys/commit_graph.h +174 -0
- data/vendor/libgit2/include/git2/sys/filter.h +49 -28
- data/vendor/libgit2/include/git2/sys/midx.h +74 -0
- data/vendor/libgit2/include/git2/sys/odb_backend.h +7 -0
- data/vendor/libgit2/include/git2/sys/transport.h +1 -0
- data/vendor/libgit2/include/git2/tag.h +12 -0
- data/vendor/libgit2/include/git2/transport.h +1 -1
- data/vendor/libgit2/include/git2/tree.h +2 -14
- data/vendor/libgit2/include/git2/types.h +9 -0
- data/vendor/libgit2/include/git2/version.h +3 -3
- data/vendor/libgit2/include/git2/worktree.h +1 -0
- data/vendor/libgit2/src/CMakeLists.txt +25 -4
- data/vendor/libgit2/src/alloc.c +21 -8
- data/vendor/libgit2/src/allocators/failalloc.c +92 -0
- data/vendor/libgit2/src/allocators/failalloc.h +23 -0
- data/vendor/libgit2/src/allocators/stdalloc.c +41 -10
- data/vendor/libgit2/src/allocators/win32_leakcheck.c +118 -0
- data/vendor/libgit2/src/allocators/{win32_crtdbg.h → win32_leakcheck.h} +3 -3
- data/vendor/libgit2/src/annotated_commit.c +21 -9
- data/vendor/libgit2/src/apply.c +16 -7
- data/vendor/libgit2/src/array.h +11 -11
- data/vendor/libgit2/src/attr.c +181 -74
- data/vendor/libgit2/src/attr_file.c +84 -39
- data/vendor/libgit2/src/attr_file.h +32 -11
- data/vendor/libgit2/src/attrcache.c +42 -37
- data/vendor/libgit2/src/attrcache.h +4 -5
- data/vendor/libgit2/src/blame.c +26 -15
- data/vendor/libgit2/src/blob.c +44 -24
- data/vendor/libgit2/src/branch.c +69 -17
- data/vendor/libgit2/src/buffer.c +334 -25
- data/vendor/libgit2/src/buffer.h +153 -2
- data/vendor/libgit2/src/cache.c +2 -2
- data/vendor/libgit2/src/cache.h +7 -7
- data/vendor/libgit2/src/cc-compat.h +10 -2
- data/vendor/libgit2/src/checkout.c +48 -26
- data/vendor/libgit2/src/cherrypick.c +6 -2
- data/vendor/libgit2/src/clone.c +26 -11
- data/vendor/libgit2/src/commit.c +41 -28
- data/vendor/libgit2/src/commit_graph.c +1209 -0
- data/vendor/libgit2/src/commit_graph.h +162 -0
- data/vendor/libgit2/src/commit_list.c +46 -0
- data/vendor/libgit2/src/commit_list.h +2 -0
- data/vendor/libgit2/src/common.h +25 -2
- data/vendor/libgit2/src/config.c +37 -15
- data/vendor/libgit2/src/config_cache.c +9 -4
- data/vendor/libgit2/src/config_file.c +16 -8
- data/vendor/libgit2/src/config_parse.c +4 -6
- data/vendor/libgit2/src/crlf.c +16 -6
- data/vendor/libgit2/src/date.c +4 -3
- data/vendor/libgit2/src/delta.c +1 -1
- data/vendor/libgit2/src/describe.c +6 -3
- data/vendor/libgit2/src/diff.c +11 -8
- data/vendor/libgit2/src/diff_driver.c +21 -17
- data/vendor/libgit2/src/diff_file.c +2 -6
- data/vendor/libgit2/src/diff_generate.c +46 -17
- data/vendor/libgit2/src/diff_print.c +19 -6
- data/vendor/libgit2/src/diff_stats.c +7 -5
- data/vendor/libgit2/src/diff_tform.c +11 -10
- data/vendor/libgit2/src/diff_xdiff.c +4 -2
- data/vendor/libgit2/src/diff_xdiff.h +1 -1
- data/vendor/libgit2/src/errors.c +24 -19
- data/vendor/libgit2/src/features.h.in +5 -1
- data/vendor/libgit2/src/fetch.c +5 -2
- data/vendor/libgit2/src/fetchhead.c +8 -4
- data/vendor/libgit2/src/filebuf.c +9 -7
- data/vendor/libgit2/src/filter.c +206 -110
- data/vendor/libgit2/src/filter.h +24 -5
- data/vendor/libgit2/src/futils.c +5 -5
- data/vendor/libgit2/src/futils.h +1 -1
- data/vendor/libgit2/src/graph.c +64 -9
- data/vendor/libgit2/src/hash/sha1/collisiondetect.c +3 -3
- data/vendor/libgit2/src/hash/sha1/common_crypto.c +3 -3
- data/vendor/libgit2/src/hash/sha1/generic.h +1 -1
- data/vendor/libgit2/src/hash/sha1/mbedtls.c +12 -12
- data/vendor/libgit2/src/hash/sha1/openssl.c +3 -3
- data/vendor/libgit2/src/hash/sha1/sha1dc/sha1.c +0 -2
- data/vendor/libgit2/src/hash/sha1/win32.c +15 -11
- data/vendor/libgit2/src/hash.c +16 -13
- data/vendor/libgit2/src/hash.h +1 -1
- data/vendor/libgit2/src/hashsig.c +23 -10
- data/vendor/libgit2/src/ident.c +13 -3
- data/vendor/libgit2/src/ignore.c +35 -19
- data/vendor/libgit2/src/index.c +112 -75
- data/vendor/libgit2/src/index.h +1 -1
- data/vendor/libgit2/src/indexer.c +50 -32
- data/vendor/libgit2/src/integer.h +79 -2
- data/vendor/libgit2/src/iterator.c +36 -24
- data/vendor/libgit2/src/iterator.h +1 -1
- data/vendor/libgit2/src/khash.h +2 -11
- data/vendor/libgit2/src/{settings.c → libgit2.c} +117 -50
- data/vendor/libgit2/src/libgit2.h +15 -0
- data/vendor/libgit2/src/mailmap.c +23 -10
- data/vendor/libgit2/src/map.h +3 -3
- data/vendor/libgit2/src/merge.c +75 -32
- data/vendor/libgit2/src/merge.h +2 -1
- data/vendor/libgit2/src/merge_driver.c +19 -13
- data/vendor/libgit2/src/merge_file.c +11 -3
- data/vendor/libgit2/src/message.c +3 -1
- data/vendor/libgit2/src/midx.c +471 -10
- data/vendor/libgit2/src/midx.h +28 -1
- data/vendor/libgit2/src/mwindow.c +106 -60
- data/vendor/libgit2/src/mwindow.h +3 -3
- data/vendor/libgit2/src/net.c +127 -3
- data/vendor/libgit2/src/net.h +16 -2
- data/vendor/libgit2/src/netops.c +6 -4
- data/vendor/libgit2/src/netops.h +2 -2
- data/vendor/libgit2/src/notes.c +10 -10
- data/vendor/libgit2/src/object.c +22 -14
- data/vendor/libgit2/src/odb.c +289 -51
- data/vendor/libgit2/src/odb.h +16 -2
- data/vendor/libgit2/src/odb_loose.c +28 -18
- data/vendor/libgit2/src/odb_mempack.c +1 -1
- data/vendor/libgit2/src/odb_pack.c +391 -114
- data/vendor/libgit2/src/oid.c +5 -4
- data/vendor/libgit2/src/pack-objects.c +54 -48
- data/vendor/libgit2/src/pack.c +339 -125
- data/vendor/libgit2/src/pack.h +25 -7
- data/vendor/libgit2/src/patch.c +14 -7
- data/vendor/libgit2/src/patch_generate.c +2 -2
- data/vendor/libgit2/src/patch_parse.c +2 -1
- data/vendor/libgit2/src/path.c +98 -53
- data/vendor/libgit2/src/path.h +79 -6
- data/vendor/libgit2/src/pathspec.c +8 -8
- data/vendor/libgit2/src/pool.c +13 -7
- data/vendor/libgit2/src/posix.c +43 -12
- data/vendor/libgit2/src/posix.h +9 -0
- data/vendor/libgit2/src/reader.c +10 -6
- data/vendor/libgit2/src/rebase.c +93 -49
- data/vendor/libgit2/src/refdb.c +30 -13
- data/vendor/libgit2/src/refdb_fs.c +125 -71
- data/vendor/libgit2/src/reflog.c +19 -14
- data/vendor/libgit2/src/refs.c +91 -43
- data/vendor/libgit2/src/refs.h +1 -1
- data/vendor/libgit2/src/refspec.c +80 -44
- data/vendor/libgit2/src/remote.c +281 -105
- data/vendor/libgit2/src/remote.h +2 -1
- data/vendor/libgit2/src/repository.c +191 -118
- data/vendor/libgit2/src/repository.h +13 -2
- data/vendor/libgit2/src/reset.c +7 -6
- data/vendor/libgit2/src/revert.c +6 -2
- data/vendor/libgit2/src/revparse.c +14 -9
- data/vendor/libgit2/src/revwalk.c +32 -15
- data/vendor/libgit2/src/runtime.c +162 -0
- data/vendor/libgit2/src/runtime.h +62 -0
- data/vendor/libgit2/src/settings.h +11 -0
- data/vendor/libgit2/src/signature.c +6 -5
- data/vendor/libgit2/src/sortedcache.h +10 -8
- data/vendor/libgit2/src/stash.c +3 -1
- data/vendor/libgit2/src/status.c +7 -4
- data/vendor/libgit2/src/strarray.c +2 -1
- data/vendor/libgit2/src/streams/mbedtls.c +14 -17
- data/vendor/libgit2/src/streams/mbedtls.h +1 -1
- data/vendor/libgit2/src/streams/openssl.c +101 -201
- data/vendor/libgit2/src/streams/openssl.h +9 -1
- data/vendor/libgit2/src/streams/openssl_dynamic.c +309 -0
- data/vendor/libgit2/src/streams/openssl_dynamic.h +348 -0
- data/vendor/libgit2/src/streams/openssl_legacy.c +203 -0
- data/vendor/libgit2/src/streams/openssl_legacy.h +63 -0
- data/vendor/libgit2/src/streams/registry.c +5 -6
- data/vendor/libgit2/src/streams/socket.c +6 -2
- data/vendor/libgit2/src/streams/stransport.c +6 -3
- data/vendor/libgit2/src/streams/tls.c +5 -3
- data/vendor/libgit2/src/submodule.c +128 -62
- data/vendor/libgit2/src/submodule.h +9 -9
- data/vendor/libgit2/src/sysdir.c +4 -6
- data/vendor/libgit2/src/tag.c +47 -11
- data/vendor/libgit2/src/thread.c +140 -0
- data/vendor/libgit2/src/thread.h +479 -0
- data/vendor/libgit2/src/threadstate.c +83 -0
- data/vendor/libgit2/src/threadstate.h +24 -0
- data/vendor/libgit2/src/trace.c +2 -2
- data/vendor/libgit2/src/trace.h +17 -13
- data/vendor/libgit2/src/transaction.c +19 -8
- data/vendor/libgit2/src/transport.c +3 -3
- data/vendor/libgit2/src/transports/auth.c +1 -1
- data/vendor/libgit2/src/transports/auth_negotiate.c +11 -4
- data/vendor/libgit2/src/transports/auth_ntlm.c +10 -6
- data/vendor/libgit2/src/transports/credential.c +15 -7
- data/vendor/libgit2/src/transports/git.c +1 -3
- data/vendor/libgit2/src/transports/http.c +19 -17
- data/vendor/libgit2/src/transports/http.h +1 -0
- data/vendor/libgit2/src/transports/httpclient.c +62 -30
- data/vendor/libgit2/src/transports/httpclient.h +1 -1
- data/vendor/libgit2/src/transports/local.c +3 -3
- data/vendor/libgit2/src/transports/smart.c +12 -7
- data/vendor/libgit2/src/transports/smart.h +1 -1
- data/vendor/libgit2/src/transports/smart_protocol.c +11 -5
- data/vendor/libgit2/src/transports/ssh.c +51 -17
- data/vendor/libgit2/src/transports/winhttp.c +138 -81
- data/vendor/libgit2/src/tree.c +100 -77
- data/vendor/libgit2/src/tree.h +1 -0
- data/vendor/libgit2/src/tsort.c +0 -2
- data/vendor/libgit2/src/unix/map.c +3 -1
- data/vendor/libgit2/src/unix/posix.h +3 -0
- data/vendor/libgit2/src/unix/pthread.h +2 -1
- data/vendor/libgit2/src/utf8.c +150 -0
- data/vendor/libgit2/src/utf8.h +52 -0
- data/vendor/libgit2/src/util.c +53 -129
- data/vendor/libgit2/src/util.h +33 -39
- data/vendor/libgit2/src/vector.c +23 -19
- data/vendor/libgit2/src/vector.h +4 -2
- data/vendor/libgit2/src/win32/findfile.c +4 -2
- data/vendor/libgit2/src/win32/map.c +1 -1
- data/vendor/libgit2/src/win32/msvc-compat.h +9 -1
- data/vendor/libgit2/src/win32/path_w32.c +22 -24
- data/vendor/libgit2/src/win32/path_w32.h +0 -1
- data/vendor/libgit2/src/win32/posix_w32.c +77 -1
- data/vendor/libgit2/src/win32/precompiled.h +0 -1
- data/vendor/libgit2/src/win32/reparse.h +4 -4
- data/vendor/libgit2/src/win32/thread.c +24 -15
- data/vendor/libgit2/src/win32/thread.h +1 -1
- data/vendor/libgit2/src/win32/w32_buffer.c +3 -3
- data/vendor/libgit2/src/win32/w32_common.h +18 -9
- data/vendor/libgit2/src/win32/{w32_crtdbg_stacktrace.c → w32_leakcheck.c} +269 -33
- data/vendor/libgit2/src/win32/w32_leakcheck.h +222 -0
- data/vendor/libgit2/src/win32/w32_util.h +6 -6
- data/vendor/libgit2/src/worktree.c +32 -14
- data/vendor/libgit2/src/zstream.c +1 -1
- metadata +32 -16
- data/vendor/libgit2/src/allocators/win32_crtdbg.c +0 -118
- data/vendor/libgit2/src/buf_text.c +0 -316
- data/vendor/libgit2/src/buf_text.h +0 -122
- data/vendor/libgit2/src/global.c +0 -363
- data/vendor/libgit2/src/global.h +0 -41
- data/vendor/libgit2/src/thread-utils.c +0 -58
- data/vendor/libgit2/src/thread-utils.h +0 -364
- data/vendor/libgit2/src/win32/w32_crtdbg_stacktrace.h +0 -127
- data/vendor/libgit2/src/win32/w32_stack.c +0 -188
- data/vendor/libgit2/src/win32/w32_stack.h +0 -140
@@ -8,7 +8,7 @@
|
|
8
8
|
#include "merge_driver.h"
|
9
9
|
|
10
10
|
#include "vector.h"
|
11
|
-
#include "
|
11
|
+
#include "runtime.h"
|
12
12
|
#include "merge.h"
|
13
13
|
#include "git2/merge.h"
|
14
14
|
#include "git2/sys/merge.h"
|
@@ -32,33 +32,38 @@ static struct merge_driver_registry merge_driver_registry;
|
|
32
32
|
|
33
33
|
static void git_merge_driver_global_shutdown(void);
|
34
34
|
|
35
|
-
git_repository*
|
35
|
+
git_repository *git_merge_driver_source_repo(
|
36
|
+
const git_merge_driver_source *src)
|
36
37
|
{
|
37
|
-
|
38
|
+
GIT_ASSERT_ARG_WITH_RETVAL(src, NULL);
|
38
39
|
return src->repo;
|
39
40
|
}
|
40
41
|
|
41
|
-
const git_index_entry*
|
42
|
+
const git_index_entry *git_merge_driver_source_ancestor(
|
43
|
+
const git_merge_driver_source *src)
|
42
44
|
{
|
43
|
-
|
45
|
+
GIT_ASSERT_ARG_WITH_RETVAL(src, NULL);
|
44
46
|
return src->ancestor;
|
45
47
|
}
|
46
48
|
|
47
|
-
const git_index_entry*
|
49
|
+
const git_index_entry *git_merge_driver_source_ours(
|
50
|
+
const git_merge_driver_source *src)
|
48
51
|
{
|
49
|
-
|
52
|
+
GIT_ASSERT_ARG_WITH_RETVAL(src, NULL);
|
50
53
|
return src->ours;
|
51
54
|
}
|
52
55
|
|
53
|
-
const git_index_entry*
|
56
|
+
const git_index_entry *git_merge_driver_source_theirs(
|
57
|
+
const git_merge_driver_source *src)
|
54
58
|
{
|
55
|
-
|
59
|
+
GIT_ASSERT_ARG_WITH_RETVAL(src, NULL);
|
56
60
|
return src->theirs;
|
57
61
|
}
|
58
62
|
|
59
|
-
const git_merge_file_options*
|
63
|
+
const git_merge_file_options *git_merge_driver_source_file_options(
|
64
|
+
const git_merge_driver_source *src)
|
60
65
|
{
|
61
|
-
|
66
|
+
GIT_ASSERT_ARG_WITH_RETVAL(src, NULL);
|
62
67
|
return src->file_opts;
|
63
68
|
}
|
64
69
|
|
@@ -209,7 +214,7 @@ int git_merge_driver_global_init(void)
|
|
209
214
|
merge_driver_name__binary, &git_merge_driver__binary)) < 0)
|
210
215
|
goto done;
|
211
216
|
|
212
|
-
|
217
|
+
error = git_runtime_shutdown_register(git_merge_driver_global_shutdown);
|
213
218
|
|
214
219
|
done:
|
215
220
|
if (error < 0)
|
@@ -262,7 +267,8 @@ int git_merge_driver_register(const char *name, git_merge_driver *driver)
|
|
262
267
|
{
|
263
268
|
int error;
|
264
269
|
|
265
|
-
|
270
|
+
GIT_ASSERT_ARG(name);
|
271
|
+
GIT_ASSERT_ARG(driver);
|
266
272
|
|
267
273
|
if (git_rwlock_wrlock(&merge_driver_registry.lock) < 0) {
|
268
274
|
git_error_set(GIT_ERROR_OS, "failed to lock merge driver registry");
|
@@ -36,7 +36,10 @@ static int merge_file_input_from_index(
|
|
36
36
|
{
|
37
37
|
int error = 0;
|
38
38
|
|
39
|
-
|
39
|
+
GIT_ASSERT_ARG(input_out);
|
40
|
+
GIT_ASSERT_ARG(odb_object_out);
|
41
|
+
GIT_ASSERT_ARG(odb);
|
42
|
+
GIT_ASSERT_ARG(entry);
|
40
43
|
|
41
44
|
if ((error = git_odb_read(odb_object_out, odb, &entry->id)) < 0)
|
42
45
|
goto done;
|
@@ -241,7 +244,9 @@ int git_merge_file(
|
|
241
244
|
{
|
242
245
|
git_merge_file_input inputs[3] = { {0} };
|
243
246
|
|
244
|
-
|
247
|
+
GIT_ASSERT_ARG(out);
|
248
|
+
GIT_ASSERT_ARG(ours);
|
249
|
+
GIT_ASSERT_ARG(theirs);
|
245
250
|
|
246
251
|
memset(out, 0x0, sizeof(git_merge_file_result));
|
247
252
|
|
@@ -268,7 +273,10 @@ int git_merge_file_from_index(
|
|
268
273
|
git_odb_object *odb_object[3] = { 0 };
|
269
274
|
int error = 0;
|
270
275
|
|
271
|
-
|
276
|
+
GIT_ASSERT_ARG(out);
|
277
|
+
GIT_ASSERT_ARG(repo);
|
278
|
+
GIT_ASSERT_ARG(ours);
|
279
|
+
GIT_ASSERT_ARG(theirs);
|
272
280
|
|
273
281
|
memset(out, 0x0, sizeof(git_merge_file_result));
|
274
282
|
|
@@ -28,8 +28,10 @@ int git_message_prettify(git_buf *message_out, const char *message, int strip_co
|
|
28
28
|
int consecutive_empty_lines = 0;
|
29
29
|
size_t i, line_length, rtrimmed_line_length;
|
30
30
|
char *next_newline;
|
31
|
+
int error;
|
31
32
|
|
32
|
-
git_buf_sanitize(message_out)
|
33
|
+
if ((error = git_buf_sanitize(message_out)) < 0)
|
34
|
+
return error;
|
33
35
|
|
34
36
|
for (i = 0; i < strlen(message); i += line_length) {
|
35
37
|
next_newline = memchr(message + i, '\n', message_len - i);
|
data/vendor/libgit2/src/midx.c
CHANGED
@@ -7,13 +7,15 @@
|
|
7
7
|
|
8
8
|
#include "midx.h"
|
9
9
|
|
10
|
+
#include "array.h"
|
10
11
|
#include "buffer.h"
|
12
|
+
#include "filebuf.h"
|
11
13
|
#include "futils.h"
|
12
14
|
#include "hash.h"
|
13
15
|
#include "odb.h"
|
14
16
|
#include "pack.h"
|
15
|
-
|
16
|
-
#
|
17
|
+
#include "path.h"
|
18
|
+
#include "repository.h"
|
17
19
|
|
18
20
|
#define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */
|
19
21
|
#define MIDX_VERSION 1
|
@@ -38,6 +40,8 @@ struct git_midx_chunk {
|
|
38
40
|
size_t length;
|
39
41
|
};
|
40
42
|
|
43
|
+
typedef int (*midx_write_cb)(const char *buf, size_t size, void *cb_data);
|
44
|
+
|
41
45
|
static int midx_error(const char *message)
|
42
46
|
{
|
43
47
|
git_error_set(GIT_ERROR_ODB, "invalid multi-pack-index file - %s", message);
|
@@ -116,7 +120,7 @@ static int midx_parse_oid_lookup(
|
|
116
120
|
return midx_error("missing OID Lookup chunk");
|
117
121
|
if (chunk_oid_lookup->length == 0)
|
118
122
|
return midx_error("empty OID Lookup chunk");
|
119
|
-
if (chunk_oid_lookup->length != idx->num_objects *
|
123
|
+
if (chunk_oid_lookup->length != idx->num_objects * GIT_OID_RAWSZ)
|
120
124
|
return midx_error("OID Lookup chunk has wrong length");
|
121
125
|
|
122
126
|
idx->oid_lookup = oid = (git_oid *)(data + chunk_oid_lookup->offset);
|
@@ -181,9 +185,9 @@ int git_midx_parse(
|
|
181
185
|
chunk_object_offsets = {0},
|
182
186
|
chunk_object_large_offsets = {0};
|
183
187
|
|
184
|
-
|
188
|
+
GIT_ASSERT_ARG(idx);
|
185
189
|
|
186
|
-
if (size < sizeof(struct git_midx_header) +
|
190
|
+
if (size < sizeof(struct git_midx_header) + GIT_OID_RAWSZ)
|
187
191
|
return midx_error("multi-pack index is too short");
|
188
192
|
|
189
193
|
hdr = ((struct git_midx_header *)data);
|
@@ -203,7 +207,7 @@ int git_midx_parse(
|
|
203
207
|
last_chunk_offset =
|
204
208
|
sizeof(struct git_midx_header) +
|
205
209
|
(1 + hdr->chunks) * 12;
|
206
|
-
trailer_offset = size -
|
210
|
+
trailer_offset = size - GIT_OID_RAWSZ;
|
207
211
|
if (trailer_offset < last_chunk_offset)
|
208
212
|
return midx_error("wrong index size");
|
209
213
|
git_oid_cpy(&idx->checksum, (git_oid *)(data + trailer_offset));
|
@@ -309,6 +313,10 @@ int git_midx_open(
|
|
309
313
|
idx = git__calloc(1, sizeof(git_midx_file));
|
310
314
|
GIT_ERROR_CHECK_ALLOC(idx);
|
311
315
|
|
316
|
+
error = git_buf_sets(&idx->filename, path);
|
317
|
+
if (error < 0)
|
318
|
+
return error;
|
319
|
+
|
312
320
|
error = git_futils_mmap_ro(&idx->index_map, fd, 0, idx_size);
|
313
321
|
p_close(fd);
|
314
322
|
if (error < 0) {
|
@@ -325,6 +333,41 @@ int git_midx_open(
|
|
325
333
|
return 0;
|
326
334
|
}
|
327
335
|
|
336
|
+
bool git_midx_needs_refresh(
|
337
|
+
const git_midx_file *idx,
|
338
|
+
const char *path)
|
339
|
+
{
|
340
|
+
git_file fd = -1;
|
341
|
+
struct stat st;
|
342
|
+
ssize_t bytes_read;
|
343
|
+
git_oid idx_checksum = {{0}};
|
344
|
+
|
345
|
+
/* TODO: properly open the file without access time using O_NOATIME */
|
346
|
+
fd = git_futils_open_ro(path);
|
347
|
+
if (fd < 0)
|
348
|
+
return true;
|
349
|
+
|
350
|
+
if (p_fstat(fd, &st) < 0) {
|
351
|
+
p_close(fd);
|
352
|
+
return true;
|
353
|
+
}
|
354
|
+
|
355
|
+
if (!S_ISREG(st.st_mode) ||
|
356
|
+
!git__is_sizet(st.st_size) ||
|
357
|
+
(size_t)st.st_size != idx->index_map.len) {
|
358
|
+
p_close(fd);
|
359
|
+
return true;
|
360
|
+
}
|
361
|
+
|
362
|
+
bytes_read = p_pread(fd, &idx_checksum, GIT_OID_RAWSZ, st.st_size - GIT_OID_RAWSZ);
|
363
|
+
p_close(fd);
|
364
|
+
|
365
|
+
if (bytes_read != GIT_OID_RAWSZ)
|
366
|
+
return true;
|
367
|
+
|
368
|
+
return !git_oid_equal(&idx_checksum, &idx->checksum);
|
369
|
+
}
|
370
|
+
|
328
371
|
int git_midx_entry_find(
|
329
372
|
git_midx_entry *e,
|
330
373
|
git_midx_file *idx,
|
@@ -338,12 +381,12 @@ int git_midx_entry_find(
|
|
338
381
|
const unsigned char *object_offset;
|
339
382
|
off64_t offset;
|
340
383
|
|
341
|
-
|
384
|
+
GIT_ASSERT_ARG(idx);
|
342
385
|
|
343
386
|
hi = ntohl(idx->oid_fanout[(int)short_oid->id[0]]);
|
344
387
|
lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(idx->oid_fanout[(int)short_oid->id[0] - 1]));
|
345
388
|
|
346
|
-
pos = git_pack__lookup_sha1(idx->oid_lookup,
|
389
|
+
pos = git_pack__lookup_sha1(idx->oid_lookup, GIT_OID_RAWSZ, lo, hi, short_oid->id);
|
347
390
|
|
348
391
|
if (pos >= 0) {
|
349
392
|
/* An object matching exactly the oid was found */
|
@@ -399,13 +442,34 @@ int git_midx_entry_find(
|
|
399
442
|
return 0;
|
400
443
|
}
|
401
444
|
|
402
|
-
|
445
|
+
int git_midx_foreach_entry(
|
446
|
+
git_midx_file *idx,
|
447
|
+
git_odb_foreach_cb cb,
|
448
|
+
void *data)
|
403
449
|
{
|
404
|
-
|
450
|
+
size_t i;
|
451
|
+
int error;
|
452
|
+
|
453
|
+
GIT_ASSERT_ARG(idx);
|
454
|
+
|
455
|
+
for (i = 0; i < idx->num_objects; ++i) {
|
456
|
+
if ((error = cb(&idx->oid_lookup[i], data)) != 0)
|
457
|
+
return git_error_set_after_callback(error);
|
458
|
+
}
|
459
|
+
|
460
|
+
return error;
|
461
|
+
}
|
462
|
+
|
463
|
+
int git_midx_close(git_midx_file *idx)
|
464
|
+
{
|
465
|
+
GIT_ASSERT_ARG(idx);
|
405
466
|
|
406
467
|
if (idx->index_map.data)
|
407
468
|
git_futils_mmap_free(&idx->index_map);
|
469
|
+
|
408
470
|
git_vector_free(&idx->packfile_names);
|
471
|
+
|
472
|
+
return 0;
|
409
473
|
}
|
410
474
|
|
411
475
|
void git_midx_free(git_midx_file *idx)
|
@@ -413,6 +477,403 @@ void git_midx_free(git_midx_file *idx)
|
|
413
477
|
if (!idx)
|
414
478
|
return;
|
415
479
|
|
480
|
+
git_buf_dispose(&idx->filename);
|
416
481
|
git_midx_close(idx);
|
417
482
|
git__free(idx);
|
418
483
|
}
|
484
|
+
|
485
|
+
static int packfile__cmp(const void *a_, const void *b_)
|
486
|
+
{
|
487
|
+
const struct git_pack_file *a = a_;
|
488
|
+
const struct git_pack_file *b = b_;
|
489
|
+
|
490
|
+
return strcmp(a->pack_name, b->pack_name);
|
491
|
+
}
|
492
|
+
|
493
|
+
int git_midx_writer_new(
|
494
|
+
git_midx_writer **out,
|
495
|
+
const char *pack_dir)
|
496
|
+
{
|
497
|
+
git_midx_writer *w = git__calloc(1, sizeof(git_midx_writer));
|
498
|
+
GIT_ERROR_CHECK_ALLOC(w);
|
499
|
+
|
500
|
+
if (git_buf_sets(&w->pack_dir, pack_dir) < 0) {
|
501
|
+
git__free(w);
|
502
|
+
return -1;
|
503
|
+
}
|
504
|
+
git_path_squash_slashes(&w->pack_dir);
|
505
|
+
|
506
|
+
if (git_vector_init(&w->packs, 0, packfile__cmp) < 0) {
|
507
|
+
git_buf_dispose(&w->pack_dir);
|
508
|
+
git__free(w);
|
509
|
+
return -1;
|
510
|
+
}
|
511
|
+
|
512
|
+
*out = w;
|
513
|
+
return 0;
|
514
|
+
}
|
515
|
+
|
516
|
+
void git_midx_writer_free(git_midx_writer *w)
|
517
|
+
{
|
518
|
+
struct git_pack_file *p;
|
519
|
+
size_t i;
|
520
|
+
|
521
|
+
if (!w)
|
522
|
+
return;
|
523
|
+
|
524
|
+
git_vector_foreach (&w->packs, i, p)
|
525
|
+
git_mwindow_put_pack(p);
|
526
|
+
git_vector_free(&w->packs);
|
527
|
+
git_buf_dispose(&w->pack_dir);
|
528
|
+
git__free(w);
|
529
|
+
}
|
530
|
+
|
531
|
+
int git_midx_writer_add(
|
532
|
+
git_midx_writer *w,
|
533
|
+
const char *idx_path)
|
534
|
+
{
|
535
|
+
git_buf idx_path_buf = GIT_BUF_INIT;
|
536
|
+
int error;
|
537
|
+
struct git_pack_file *p;
|
538
|
+
|
539
|
+
error = git_path_prettify(&idx_path_buf, idx_path, git_buf_cstr(&w->pack_dir));
|
540
|
+
if (error < 0)
|
541
|
+
return error;
|
542
|
+
|
543
|
+
error = git_mwindow_get_pack(&p, git_buf_cstr(&idx_path_buf));
|
544
|
+
git_buf_dispose(&idx_path_buf);
|
545
|
+
if (error < 0)
|
546
|
+
return error;
|
547
|
+
|
548
|
+
error = git_vector_insert(&w->packs, p);
|
549
|
+
if (error < 0) {
|
550
|
+
git_mwindow_put_pack(p);
|
551
|
+
return error;
|
552
|
+
}
|
553
|
+
|
554
|
+
return 0;
|
555
|
+
}
|
556
|
+
|
557
|
+
typedef git_array_t(git_midx_entry) object_entry_array_t;
|
558
|
+
|
559
|
+
struct object_entry_cb_state {
|
560
|
+
uint32_t pack_index;
|
561
|
+
object_entry_array_t *object_entries_array;
|
562
|
+
};
|
563
|
+
|
564
|
+
static int object_entry__cb(const git_oid *oid, off64_t offset, void *data)
|
565
|
+
{
|
566
|
+
struct object_entry_cb_state *state = (struct object_entry_cb_state *)data;
|
567
|
+
|
568
|
+
git_midx_entry *entry = git_array_alloc(*state->object_entries_array);
|
569
|
+
GIT_ERROR_CHECK_ALLOC(entry);
|
570
|
+
|
571
|
+
git_oid_cpy(&entry->sha1, oid);
|
572
|
+
entry->offset = offset;
|
573
|
+
entry->pack_index = state->pack_index;
|
574
|
+
|
575
|
+
return 0;
|
576
|
+
}
|
577
|
+
|
578
|
+
static int object_entry__cmp(const void *a_, const void *b_)
|
579
|
+
{
|
580
|
+
const git_midx_entry *a = (const git_midx_entry *)a_;
|
581
|
+
const git_midx_entry *b = (const git_midx_entry *)b_;
|
582
|
+
|
583
|
+
return git_oid_cmp(&a->sha1, &b->sha1);
|
584
|
+
}
|
585
|
+
|
586
|
+
static int write_offset(off64_t offset, midx_write_cb write_cb, void *cb_data)
|
587
|
+
{
|
588
|
+
int error;
|
589
|
+
uint32_t word;
|
590
|
+
|
591
|
+
word = htonl((uint32_t)((offset >> 32) & 0xffffffffu));
|
592
|
+
error = write_cb((const char *)&word, sizeof(word), cb_data);
|
593
|
+
if (error < 0)
|
594
|
+
return error;
|
595
|
+
word = htonl((uint32_t)((offset >> 0) & 0xffffffffu));
|
596
|
+
error = write_cb((const char *)&word, sizeof(word), cb_data);
|
597
|
+
if (error < 0)
|
598
|
+
return error;
|
599
|
+
|
600
|
+
return 0;
|
601
|
+
}
|
602
|
+
|
603
|
+
static int write_chunk_header(int chunk_id, off64_t offset, midx_write_cb write_cb, void *cb_data)
|
604
|
+
{
|
605
|
+
uint32_t word = htonl(chunk_id);
|
606
|
+
int error = write_cb((const char *)&word, sizeof(word), cb_data);
|
607
|
+
if (error < 0)
|
608
|
+
return error;
|
609
|
+
return write_offset(offset, write_cb, cb_data);
|
610
|
+
|
611
|
+
return 0;
|
612
|
+
}
|
613
|
+
|
614
|
+
static int midx_write_buf(const char *buf, size_t size, void *data)
|
615
|
+
{
|
616
|
+
git_buf *b = (git_buf *)data;
|
617
|
+
return git_buf_put(b, buf, size);
|
618
|
+
}
|
619
|
+
|
620
|
+
struct midx_write_hash_context {
|
621
|
+
midx_write_cb write_cb;
|
622
|
+
void *cb_data;
|
623
|
+
git_hash_ctx *ctx;
|
624
|
+
};
|
625
|
+
|
626
|
+
static int midx_write_hash(const char *buf, size_t size, void *data)
|
627
|
+
{
|
628
|
+
struct midx_write_hash_context *ctx = (struct midx_write_hash_context *)data;
|
629
|
+
int error;
|
630
|
+
|
631
|
+
error = git_hash_update(ctx->ctx, buf, size);
|
632
|
+
if (error < 0)
|
633
|
+
return error;
|
634
|
+
|
635
|
+
return ctx->write_cb(buf, size, ctx->cb_data);
|
636
|
+
}
|
637
|
+
|
638
|
+
static int midx_write(
|
639
|
+
git_midx_writer *w,
|
640
|
+
midx_write_cb write_cb,
|
641
|
+
void *cb_data)
|
642
|
+
{
|
643
|
+
int error = 0;
|
644
|
+
size_t i;
|
645
|
+
struct git_pack_file *p;
|
646
|
+
struct git_midx_header hdr = {0};
|
647
|
+
uint32_t oid_fanout_count;
|
648
|
+
uint32_t object_large_offsets_count;
|
649
|
+
uint32_t oid_fanout[256];
|
650
|
+
off64_t offset;
|
651
|
+
git_buf packfile_names = GIT_BUF_INIT,
|
652
|
+
oid_lookup = GIT_BUF_INIT,
|
653
|
+
object_offsets = GIT_BUF_INIT,
|
654
|
+
object_large_offsets = GIT_BUF_INIT;
|
655
|
+
git_oid idx_checksum = {{0}};
|
656
|
+
git_midx_entry *entry;
|
657
|
+
object_entry_array_t object_entries_array = GIT_ARRAY_INIT;
|
658
|
+
git_vector object_entries = GIT_VECTOR_INIT;
|
659
|
+
git_hash_ctx ctx;
|
660
|
+
struct midx_write_hash_context hash_cb_data = {0};
|
661
|
+
|
662
|
+
hdr.signature = htonl(MIDX_SIGNATURE);
|
663
|
+
hdr.version = MIDX_VERSION;
|
664
|
+
hdr.object_id_version = MIDX_OBJECT_ID_VERSION;
|
665
|
+
hdr.base_midx_files = 0;
|
666
|
+
|
667
|
+
hash_cb_data.write_cb = write_cb;
|
668
|
+
hash_cb_data.cb_data = cb_data;
|
669
|
+
hash_cb_data.ctx = &ctx;
|
670
|
+
|
671
|
+
error = git_hash_ctx_init(&ctx);
|
672
|
+
if (error < 0)
|
673
|
+
return error;
|
674
|
+
cb_data = &hash_cb_data;
|
675
|
+
write_cb = midx_write_hash;
|
676
|
+
|
677
|
+
git_vector_sort(&w->packs);
|
678
|
+
git_vector_foreach (&w->packs, i, p) {
|
679
|
+
git_buf relative_index = GIT_BUF_INIT;
|
680
|
+
struct object_entry_cb_state state = {0};
|
681
|
+
size_t path_len;
|
682
|
+
|
683
|
+
state.pack_index = (uint32_t)i;
|
684
|
+
state.object_entries_array = &object_entries_array;
|
685
|
+
|
686
|
+
error = git_buf_sets(&relative_index, p->pack_name);
|
687
|
+
if (error < 0)
|
688
|
+
goto cleanup;
|
689
|
+
error = git_path_make_relative(&relative_index, git_buf_cstr(&w->pack_dir));
|
690
|
+
if (error < 0) {
|
691
|
+
git_buf_dispose(&relative_index);
|
692
|
+
goto cleanup;
|
693
|
+
}
|
694
|
+
path_len = git_buf_len(&relative_index);
|
695
|
+
if (path_len <= strlen(".pack") || git__suffixcmp(git_buf_cstr(&relative_index), ".pack") != 0) {
|
696
|
+
git_buf_dispose(&relative_index);
|
697
|
+
git_error_set(GIT_ERROR_INVALID, "invalid packfile name: '%s'", p->pack_name);
|
698
|
+
error = -1;
|
699
|
+
goto cleanup;
|
700
|
+
}
|
701
|
+
path_len -= strlen(".pack");
|
702
|
+
|
703
|
+
git_buf_put(&packfile_names, git_buf_cstr(&relative_index), path_len);
|
704
|
+
git_buf_puts(&packfile_names, ".idx");
|
705
|
+
git_buf_putc(&packfile_names, '\0');
|
706
|
+
git_buf_dispose(&relative_index);
|
707
|
+
|
708
|
+
error = git_pack_foreach_entry_offset(p, object_entry__cb, &state);
|
709
|
+
if (error < 0)
|
710
|
+
goto cleanup;
|
711
|
+
}
|
712
|
+
|
713
|
+
/* Sort the object entries. */
|
714
|
+
error = git_vector_init(&object_entries, git_array_size(object_entries_array), object_entry__cmp);
|
715
|
+
if (error < 0)
|
716
|
+
goto cleanup;
|
717
|
+
git_array_foreach (object_entries_array, i, entry) {
|
718
|
+
if ((error = git_vector_set(NULL, &object_entries, i, entry)) < 0)
|
719
|
+
goto cleanup;
|
720
|
+
}
|
721
|
+
git_vector_set_sorted(&object_entries, 0);
|
722
|
+
git_vector_sort(&object_entries);
|
723
|
+
git_vector_uniq(&object_entries, NULL);
|
724
|
+
|
725
|
+
/* Pad the packfile names so it is a multiple of four. */
|
726
|
+
while (git_buf_len(&packfile_names) & 3)
|
727
|
+
git_buf_putc(&packfile_names, '\0');
|
728
|
+
|
729
|
+
/* Fill the OID Fanout table. */
|
730
|
+
oid_fanout_count = 0;
|
731
|
+
for (i = 0; i < 256; i++) {
|
732
|
+
while (oid_fanout_count < git_vector_length(&object_entries) &&
|
733
|
+
((const git_midx_entry *)git_vector_get(&object_entries, oid_fanout_count))->sha1.id[0] <= i)
|
734
|
+
++oid_fanout_count;
|
735
|
+
oid_fanout[i] = htonl(oid_fanout_count);
|
736
|
+
}
|
737
|
+
|
738
|
+
/* Fill the OID Lookup table. */
|
739
|
+
git_vector_foreach (&object_entries, i, entry) {
|
740
|
+
error = git_buf_put(&oid_lookup, (const char *)&entry->sha1, sizeof(entry->sha1));
|
741
|
+
if (error < 0)
|
742
|
+
goto cleanup;
|
743
|
+
}
|
744
|
+
|
745
|
+
/* Fill the Object Offsets and Object Large Offsets tables. */
|
746
|
+
object_large_offsets_count = 0;
|
747
|
+
git_vector_foreach (&object_entries, i, entry) {
|
748
|
+
uint32_t word;
|
749
|
+
|
750
|
+
word = htonl((uint32_t)entry->pack_index);
|
751
|
+
error = git_buf_put(&object_offsets, (const char *)&word, sizeof(word));
|
752
|
+
if (error < 0)
|
753
|
+
goto cleanup;
|
754
|
+
if (entry->offset >= 0x80000000l) {
|
755
|
+
word = htonl(0x80000000u | object_large_offsets_count++);
|
756
|
+
if ((error = write_offset(entry->offset, midx_write_buf, &object_large_offsets)) < 0)
|
757
|
+
goto cleanup;
|
758
|
+
} else {
|
759
|
+
word = htonl((uint32_t)entry->offset & 0x7fffffffu);
|
760
|
+
}
|
761
|
+
|
762
|
+
error = git_buf_put(&object_offsets, (const char *)&word, sizeof(word));
|
763
|
+
if (error < 0)
|
764
|
+
goto cleanup;
|
765
|
+
}
|
766
|
+
|
767
|
+
/* Write the header. */
|
768
|
+
hdr.packfiles = htonl((uint32_t)git_vector_length(&w->packs));
|
769
|
+
hdr.chunks = 4;
|
770
|
+
if (git_buf_len(&object_large_offsets) > 0)
|
771
|
+
hdr.chunks++;
|
772
|
+
error = write_cb((const char *)&hdr, sizeof(hdr), cb_data);
|
773
|
+
if (error < 0)
|
774
|
+
goto cleanup;
|
775
|
+
|
776
|
+
/* Write the chunk headers. */
|
777
|
+
offset = sizeof(hdr) + (hdr.chunks + 1) * 12;
|
778
|
+
error = write_chunk_header(MIDX_PACKFILE_NAMES_ID, offset, write_cb, cb_data);
|
779
|
+
if (error < 0)
|
780
|
+
goto cleanup;
|
781
|
+
offset += git_buf_len(&packfile_names);
|
782
|
+
error = write_chunk_header(MIDX_OID_FANOUT_ID, offset, write_cb, cb_data);
|
783
|
+
if (error < 0)
|
784
|
+
goto cleanup;
|
785
|
+
offset += sizeof(oid_fanout);
|
786
|
+
error = write_chunk_header(MIDX_OID_LOOKUP_ID, offset, write_cb, cb_data);
|
787
|
+
if (error < 0)
|
788
|
+
goto cleanup;
|
789
|
+
offset += git_buf_len(&oid_lookup);
|
790
|
+
error = write_chunk_header(MIDX_OBJECT_OFFSETS_ID, offset, write_cb, cb_data);
|
791
|
+
if (error < 0)
|
792
|
+
goto cleanup;
|
793
|
+
offset += git_buf_len(&object_offsets);
|
794
|
+
if (git_buf_len(&object_large_offsets) > 0) {
|
795
|
+
error = write_chunk_header(MIDX_OBJECT_LARGE_OFFSETS_ID, offset, write_cb, cb_data);
|
796
|
+
if (error < 0)
|
797
|
+
goto cleanup;
|
798
|
+
offset += git_buf_len(&object_large_offsets);
|
799
|
+
}
|
800
|
+
error = write_chunk_header(0, offset, write_cb, cb_data);
|
801
|
+
if (error < 0)
|
802
|
+
goto cleanup;
|
803
|
+
|
804
|
+
/* Write all the chunks. */
|
805
|
+
error = write_cb(git_buf_cstr(&packfile_names), git_buf_len(&packfile_names), cb_data);
|
806
|
+
if (error < 0)
|
807
|
+
goto cleanup;
|
808
|
+
error = write_cb((const char *)oid_fanout, sizeof(oid_fanout), cb_data);
|
809
|
+
if (error < 0)
|
810
|
+
goto cleanup;
|
811
|
+
error = write_cb(git_buf_cstr(&oid_lookup), git_buf_len(&oid_lookup), cb_data);
|
812
|
+
if (error < 0)
|
813
|
+
goto cleanup;
|
814
|
+
error = write_cb(git_buf_cstr(&object_offsets), git_buf_len(&object_offsets), cb_data);
|
815
|
+
if (error < 0)
|
816
|
+
goto cleanup;
|
817
|
+
error = write_cb(git_buf_cstr(&object_large_offsets), git_buf_len(&object_large_offsets), cb_data);
|
818
|
+
if (error < 0)
|
819
|
+
goto cleanup;
|
820
|
+
|
821
|
+
/* Finalize the checksum and write the trailer. */
|
822
|
+
error = git_hash_final(&idx_checksum, &ctx);
|
823
|
+
if (error < 0)
|
824
|
+
goto cleanup;
|
825
|
+
error = write_cb((const char *)&idx_checksum, sizeof(idx_checksum), cb_data);
|
826
|
+
if (error < 0)
|
827
|
+
goto cleanup;
|
828
|
+
|
829
|
+
cleanup:
|
830
|
+
git_array_clear(object_entries_array);
|
831
|
+
git_vector_free(&object_entries);
|
832
|
+
git_buf_dispose(&packfile_names);
|
833
|
+
git_buf_dispose(&oid_lookup);
|
834
|
+
git_buf_dispose(&object_offsets);
|
835
|
+
git_buf_dispose(&object_large_offsets);
|
836
|
+
git_hash_ctx_cleanup(&ctx);
|
837
|
+
return error;
|
838
|
+
}
|
839
|
+
|
840
|
+
static int midx_write_filebuf(const char *buf, size_t size, void *data)
|
841
|
+
{
|
842
|
+
git_filebuf *f = (git_filebuf *)data;
|
843
|
+
return git_filebuf_write(f, buf, size);
|
844
|
+
}
|
845
|
+
|
846
|
+
int git_midx_writer_commit(
|
847
|
+
git_midx_writer *w)
|
848
|
+
{
|
849
|
+
int error;
|
850
|
+
int filebuf_flags = GIT_FILEBUF_DO_NOT_BUFFER;
|
851
|
+
git_buf midx_path = GIT_BUF_INIT;
|
852
|
+
git_filebuf output = GIT_FILEBUF_INIT;
|
853
|
+
|
854
|
+
error = git_buf_joinpath(&midx_path, git_buf_cstr(&w->pack_dir), "multi-pack-index");
|
855
|
+
if (error < 0)
|
856
|
+
return error;
|
857
|
+
|
858
|
+
if (git_repository__fsync_gitdir)
|
859
|
+
filebuf_flags |= GIT_FILEBUF_FSYNC;
|
860
|
+
error = git_filebuf_open(&output, git_buf_cstr(&midx_path), filebuf_flags, 0644);
|
861
|
+
git_buf_dispose(&midx_path);
|
862
|
+
if (error < 0)
|
863
|
+
return error;
|
864
|
+
|
865
|
+
error = midx_write(w, midx_write_filebuf, &output);
|
866
|
+
if (error < 0) {
|
867
|
+
git_filebuf_cleanup(&output);
|
868
|
+
return error;
|
869
|
+
}
|
870
|
+
|
871
|
+
return git_filebuf_commit(&output);
|
872
|
+
}
|
873
|
+
|
874
|
+
int git_midx_writer_dump(
|
875
|
+
git_buf *midx,
|
876
|
+
git_midx_writer *w)
|
877
|
+
{
|
878
|
+
return midx_write(w, midx_write_buf, midx);
|
879
|
+
}
|