rugged 0.17.0.b7 → 0.18.0.b1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +1 -1
- data/README.md +88 -32
- data/ext/rugged/extconf.rb +4 -2
- data/ext/rugged/rugged.c +72 -10
- data/ext/rugged/rugged.h +14 -10
- data/ext/rugged/rugged_blob.c +8 -10
- data/ext/rugged/rugged_branch.c +11 -14
- data/ext/rugged/rugged_commit.c +31 -24
- data/ext/rugged/rugged_config.c +2 -2
- data/ext/rugged/rugged_index.c +133 -198
- data/ext/rugged/rugged_note.c +372 -0
- data/ext/rugged/rugged_object.c +50 -22
- data/ext/rugged/rugged_reference.c +122 -130
- data/ext/rugged/rugged_remote.c +72 -29
- data/ext/rugged/rugged_repo.c +402 -20
- data/ext/rugged/rugged_revwalk.c +7 -3
- data/ext/rugged/rugged_settings.c +110 -0
- data/ext/rugged/rugged_signature.c +23 -7
- data/ext/rugged/rugged_tag.c +32 -16
- data/ext/rugged/rugged_tree.c +44 -15
- data/lib/rugged.rb +1 -0
- data/lib/rugged/index.rb +8 -0
- data/lib/rugged/remote.rb +13 -0
- data/lib/rugged/repository.rb +3 -3
- data/lib/rugged/version.rb +1 -1
- data/test/blob_test.rb +13 -15
- data/test/branch_test.rb +32 -67
- data/test/commit_test.rb +50 -12
- data/test/config_test.rb +12 -11
- data/test/coverage/HEAD.json +1 -1
- data/test/coverage/cover.rb +40 -21
- data/test/errors_test.rb +34 -0
- data/test/fixtures/alternate/objects/14/6ae76773c91e3b1d00cf7a338ec55ae58297e2 +0 -0
- data/test/fixtures/alternate/objects/14/9c32d47e99d0a3572ff1e70a2e0051bbf347a9 +0 -0
- data/test/fixtures/alternate/objects/14/fb3108588f9421bf764041e5e3ac305eb6277f +0 -0
- data/test/fixtures/testrepo.git/logs/refs/notes/commits +1 -0
- data/test/fixtures/testrepo.git/objects/44/1034f860c1d5d90e4188d11ae0d325176869a8 +1 -0
- data/test/fixtures/testrepo.git/objects/60/d415052a33de2150bf68757f6461df4f563ae4 +0 -0
- data/test/fixtures/testrepo.git/objects/68/8a8f4ef7496901d15322972f96e212a9e466cc +1 -0
- data/test/fixtures/testrepo.git/objects/94/eca2de348d5f672faf56b0decafa5937e3235e +0 -0
- data/test/fixtures/testrepo.git/objects/9b/7384fe1676186192842f5d3e129457b62db9e3 +0 -0
- data/test/fixtures/testrepo.git/objects/b7/4713326bc972cc15751ed504dca6f6f3b91f7a +3 -0
- data/test/fixtures/testrepo.git/refs/notes/commits +1 -0
- data/test/index_test.rb +65 -69
- data/test/lib_test.rb +76 -11
- data/test/note_test.rb +158 -0
- data/test/object_test.rb +8 -11
- data/test/reference_test.rb +77 -85
- data/test/remote_test.rb +86 -8
- data/test/repo_pack_test.rb +9 -7
- data/test/repo_reset_test.rb +80 -0
- data/test/repo_test.rb +176 -53
- data/test/tag_test.rb +44 -7
- data/test/test_helper.rb +63 -35
- data/test/tree_test.rb +34 -13
- data/test/walker_test.rb +14 -14
- data/vendor/libgit2/Makefile.embed +1 -1
- data/vendor/libgit2/deps/http-parser/http_parser.c +974 -578
- data/vendor/libgit2/deps/http-parser/http_parser.h +106 -70
- data/vendor/libgit2/deps/regex/regcomp.c +7 -6
- data/vendor/libgit2/deps/regex/regex_internal.c +1 -1
- data/vendor/libgit2/deps/regex/regex_internal.h +12 -3
- data/vendor/libgit2/deps/regex/regexec.c +5 -5
- data/vendor/libgit2/include/git2.h +5 -1
- data/vendor/libgit2/include/git2/attr.h +4 -2
- data/vendor/libgit2/include/git2/blob.h +39 -12
- data/vendor/libgit2/include/git2/branch.h +123 -35
- data/vendor/libgit2/include/git2/checkout.h +206 -48
- data/vendor/libgit2/include/git2/clone.h +72 -27
- data/vendor/libgit2/include/git2/commit.h +20 -17
- data/vendor/libgit2/include/git2/common.h +67 -1
- data/vendor/libgit2/include/git2/config.h +81 -60
- data/vendor/libgit2/include/git2/cred_helpers.h +53 -0
- data/vendor/libgit2/include/git2/diff.h +459 -150
- data/vendor/libgit2/include/git2/errors.h +9 -1
- data/vendor/libgit2/include/git2/graph.h +41 -0
- data/vendor/libgit2/include/git2/ignore.h +7 -6
- data/vendor/libgit2/include/git2/index.h +323 -97
- data/vendor/libgit2/include/git2/indexer.h +27 -59
- data/vendor/libgit2/include/git2/inttypes.h +4 -0
- data/vendor/libgit2/include/git2/merge.h +13 -3
- data/vendor/libgit2/include/git2/message.h +14 -8
- data/vendor/libgit2/include/git2/net.h +9 -7
- data/vendor/libgit2/include/git2/notes.h +88 -29
- data/vendor/libgit2/include/git2/object.h +16 -6
- data/vendor/libgit2/include/git2/odb.h +80 -17
- data/vendor/libgit2/include/git2/odb_backend.h +47 -11
- data/vendor/libgit2/include/git2/oid.h +26 -17
- data/vendor/libgit2/include/git2/pack.h +62 -8
- data/vendor/libgit2/include/git2/push.h +131 -0
- data/vendor/libgit2/include/git2/refdb.h +103 -0
- data/vendor/libgit2/include/git2/refdb_backend.h +109 -0
- data/vendor/libgit2/include/git2/reflog.h +30 -21
- data/vendor/libgit2/include/git2/refs.h +215 -193
- data/vendor/libgit2/include/git2/refspec.h +22 -2
- data/vendor/libgit2/include/git2/remote.h +158 -37
- data/vendor/libgit2/include/git2/repository.h +150 -31
- data/vendor/libgit2/include/git2/reset.h +43 -9
- data/vendor/libgit2/include/git2/revparse.h +48 -4
- data/vendor/libgit2/include/git2/revwalk.h +25 -10
- data/vendor/libgit2/include/git2/signature.h +20 -12
- data/vendor/libgit2/include/git2/stash.h +121 -0
- data/vendor/libgit2/include/git2/status.h +122 -53
- data/vendor/libgit2/include/git2/strarray.h +17 -11
- data/vendor/libgit2/include/git2/submodule.h +42 -7
- data/vendor/libgit2/include/git2/tag.h +72 -59
- data/vendor/libgit2/include/git2/threads.h +4 -2
- data/vendor/libgit2/include/git2/trace.h +68 -0
- data/vendor/libgit2/include/git2/transport.h +328 -0
- data/vendor/libgit2/include/git2/tree.h +149 -120
- data/vendor/libgit2/include/git2/types.h +13 -12
- data/vendor/libgit2/include/git2/version.h +3 -3
- data/vendor/libgit2/src/amiga/map.c +2 -2
- data/vendor/libgit2/src/attr.c +58 -48
- data/vendor/libgit2/src/attr.h +4 -18
- data/vendor/libgit2/src/attr_file.c +30 -6
- data/vendor/libgit2/src/attr_file.h +6 -8
- data/vendor/libgit2/src/attrcache.h +24 -0
- data/vendor/libgit2/src/blob.c +30 -7
- data/vendor/libgit2/src/blob.h +1 -1
- data/vendor/libgit2/src/branch.c +361 -68
- data/vendor/libgit2/src/branch.h +17 -0
- data/vendor/libgit2/src/bswap.h +1 -1
- data/vendor/libgit2/src/buf_text.c +291 -0
- data/vendor/libgit2/src/buf_text.h +122 -0
- data/vendor/libgit2/src/buffer.c +27 -101
- data/vendor/libgit2/src/buffer.h +54 -39
- data/vendor/libgit2/src/cache.c +15 -6
- data/vendor/libgit2/src/cache.h +1 -1
- data/vendor/libgit2/src/cc-compat.h +3 -1
- data/vendor/libgit2/src/checkout.c +1165 -222
- data/vendor/libgit2/src/checkout.h +24 -0
- data/vendor/libgit2/src/clone.c +171 -86
- data/vendor/libgit2/src/commit.c +44 -45
- data/vendor/libgit2/src/commit.h +3 -3
- data/vendor/libgit2/src/commit_list.c +194 -0
- data/vendor/libgit2/src/commit_list.h +49 -0
- data/vendor/libgit2/src/common.h +44 -10
- data/vendor/libgit2/src/compress.c +1 -1
- data/vendor/libgit2/src/compress.h +1 -1
- data/vendor/libgit2/src/config.c +211 -124
- data/vendor/libgit2/src/config.h +23 -4
- data/vendor/libgit2/src/config_cache.c +2 -2
- data/vendor/libgit2/src/config_file.c +129 -53
- data/vendor/libgit2/src/config_file.h +10 -8
- data/vendor/libgit2/src/crlf.c +66 -67
- data/vendor/libgit2/src/date.c +12 -12
- data/vendor/libgit2/src/delta-apply.c +14 -1
- data/vendor/libgit2/src/delta-apply.h +18 -1
- data/vendor/libgit2/src/delta.c +40 -107
- data/vendor/libgit2/src/delta.h +19 -17
- data/vendor/libgit2/src/diff.c +347 -496
- data/vendor/libgit2/src/diff.h +27 -1
- data/vendor/libgit2/src/diff_output.c +564 -249
- data/vendor/libgit2/src/diff_output.h +15 -8
- data/vendor/libgit2/src/diff_tform.c +687 -0
- data/vendor/libgit2/src/errors.c +27 -36
- data/vendor/libgit2/src/fetch.c +13 -351
- data/vendor/libgit2/src/fetch.h +13 -3
- data/vendor/libgit2/src/fetchhead.c +295 -0
- data/vendor/libgit2/src/fetchhead.h +34 -0
- data/vendor/libgit2/src/filebuf.c +42 -15
- data/vendor/libgit2/src/filebuf.h +4 -2
- data/vendor/libgit2/src/fileops.c +466 -113
- data/vendor/libgit2/src/fileops.h +154 -28
- data/vendor/libgit2/src/filter.c +3 -75
- data/vendor/libgit2/src/filter.h +1 -29
- data/vendor/libgit2/src/fnmatch.c +1 -1
- data/vendor/libgit2/src/fnmatch.h +1 -1
- data/vendor/libgit2/src/global.c +54 -10
- data/vendor/libgit2/src/global.h +10 -1
- data/vendor/libgit2/src/graph.c +178 -0
- data/vendor/libgit2/src/hash.c +25 -52
- data/vendor/libgit2/src/hash.h +21 -9
- data/vendor/libgit2/src/{sha1/sha1.c → hash/hash_generic.c} +20 -12
- data/vendor/libgit2/src/hash/hash_generic.h +24 -0
- data/vendor/libgit2/src/hash/hash_openssl.h +45 -0
- data/vendor/libgit2/src/hash/hash_win32.c +291 -0
- data/vendor/libgit2/src/hash/hash_win32.h +140 -0
- data/vendor/libgit2/src/hashsig.c +368 -0
- data/vendor/libgit2/src/hashsig.h +72 -0
- data/vendor/libgit2/src/ignore.c +22 -15
- data/vendor/libgit2/src/ignore.h +6 -1
- data/vendor/libgit2/src/index.c +770 -171
- data/vendor/libgit2/src/index.h +13 -5
- data/vendor/libgit2/src/indexer.c +286 -431
- data/vendor/libgit2/src/iterator.c +854 -466
- data/vendor/libgit2/src/iterator.h +134 -109
- data/vendor/libgit2/src/map.h +1 -1
- data/vendor/libgit2/src/merge.c +296 -0
- data/vendor/libgit2/src/merge.h +22 -0
- data/vendor/libgit2/src/message.c +1 -1
- data/vendor/libgit2/src/message.h +1 -1
- data/vendor/libgit2/src/mwindow.c +35 -30
- data/vendor/libgit2/src/mwindow.h +2 -2
- data/vendor/libgit2/src/netops.c +162 -98
- data/vendor/libgit2/src/netops.h +50 -15
- data/vendor/libgit2/src/notes.c +109 -58
- data/vendor/libgit2/src/notes.h +2 -1
- data/vendor/libgit2/src/object.c +46 -57
- data/vendor/libgit2/src/object.h +1 -8
- data/vendor/libgit2/src/odb.c +151 -40
- data/vendor/libgit2/src/odb.h +5 -1
- data/vendor/libgit2/src/odb_loose.c +4 -5
- data/vendor/libgit2/src/odb_pack.c +122 -80
- data/vendor/libgit2/src/offmap.h +65 -0
- data/vendor/libgit2/src/oid.c +12 -4
- data/vendor/libgit2/src/oidmap.h +1 -1
- data/vendor/libgit2/src/pack-objects.c +88 -61
- data/vendor/libgit2/src/pack-objects.h +8 -8
- data/vendor/libgit2/src/pack.c +293 -28
- data/vendor/libgit2/src/pack.h +49 -4
- data/vendor/libgit2/src/path.c +103 -14
- data/vendor/libgit2/src/path.h +23 -7
- data/vendor/libgit2/src/pathspec.c +168 -0
- data/vendor/libgit2/src/pathspec.h +40 -0
- data/vendor/libgit2/src/pool.c +29 -4
- data/vendor/libgit2/src/pool.h +8 -1
- data/vendor/libgit2/src/posix.c +26 -27
- data/vendor/libgit2/src/posix.h +2 -3
- data/vendor/libgit2/src/pqueue.c +23 -1
- data/vendor/libgit2/src/pqueue.h +23 -1
- data/vendor/libgit2/src/push.c +653 -0
- data/vendor/libgit2/src/push.h +51 -0
- data/vendor/libgit2/src/refdb.c +185 -0
- data/vendor/libgit2/src/refdb.h +46 -0
- data/vendor/libgit2/src/refdb_fs.c +1024 -0
- data/vendor/libgit2/src/refdb_fs.h +15 -0
- data/vendor/libgit2/src/reflog.c +77 -45
- data/vendor/libgit2/src/reflog.h +1 -3
- data/vendor/libgit2/src/refs.c +366 -1326
- data/vendor/libgit2/src/refs.h +22 -13
- data/vendor/libgit2/src/refspec.c +46 -7
- data/vendor/libgit2/src/refspec.h +11 -1
- data/vendor/libgit2/src/remote.c +758 -120
- data/vendor/libgit2/src/remote.h +10 -5
- data/vendor/libgit2/src/repo_template.h +6 -6
- data/vendor/libgit2/src/repository.c +315 -96
- data/vendor/libgit2/src/repository.h +5 -3
- data/vendor/libgit2/src/reset.c +99 -81
- data/vendor/libgit2/src/revparse.c +157 -84
- data/vendor/libgit2/src/revwalk.c +68 -470
- data/vendor/libgit2/src/revwalk.h +44 -0
- data/vendor/libgit2/src/sha1_lookup.c +1 -1
- data/vendor/libgit2/src/sha1_lookup.h +1 -1
- data/vendor/libgit2/src/signature.c +68 -200
- data/vendor/libgit2/src/signature.h +1 -1
- data/vendor/libgit2/src/stash.c +663 -0
- data/vendor/libgit2/src/status.c +101 -79
- data/vendor/libgit2/src/strmap.h +1 -1
- data/vendor/libgit2/src/submodule.c +67 -51
- data/vendor/libgit2/src/submodule.h +1 -1
- data/vendor/libgit2/src/tag.c +35 -29
- data/vendor/libgit2/src/tag.h +1 -1
- data/vendor/libgit2/src/thread-utils.c +1 -1
- data/vendor/libgit2/src/thread-utils.h +2 -2
- data/vendor/libgit2/src/trace.c +39 -0
- data/vendor/libgit2/src/trace.h +56 -0
- data/vendor/libgit2/src/transport.c +81 -34
- data/vendor/libgit2/src/transports/cred.c +60 -0
- data/vendor/libgit2/src/transports/cred_helpers.c +49 -0
- data/vendor/libgit2/src/transports/git.c +234 -127
- data/vendor/libgit2/src/transports/http.c +761 -433
- data/vendor/libgit2/src/transports/local.c +460 -64
- data/vendor/libgit2/src/transports/smart.c +345 -0
- data/vendor/libgit2/src/transports/smart.h +179 -0
- data/vendor/libgit2/src/{pkt.c → transports/smart_pkt.c} +131 -12
- data/vendor/libgit2/src/transports/smart_protocol.c +856 -0
- data/vendor/libgit2/src/transports/winhttp.c +1136 -0
- data/vendor/libgit2/src/tree-cache.c +2 -2
- data/vendor/libgit2/src/tree-cache.h +1 -1
- data/vendor/libgit2/src/tree.c +239 -166
- data/vendor/libgit2/src/tree.h +11 -2
- data/vendor/libgit2/src/tsort.c +39 -23
- data/vendor/libgit2/src/unix/map.c +1 -1
- data/vendor/libgit2/src/unix/posix.h +12 -2
- data/vendor/libgit2/src/unix/realpath.c +30 -0
- data/vendor/libgit2/src/util.c +250 -13
- data/vendor/libgit2/src/util.h +71 -14
- data/vendor/libgit2/src/vector.c +123 -60
- data/vendor/libgit2/src/vector.h +24 -22
- data/vendor/libgit2/src/win32/dir.c +1 -1
- data/vendor/libgit2/src/win32/dir.h +1 -1
- data/vendor/libgit2/src/win32/error.c +77 -0
- data/vendor/libgit2/src/win32/error.h +13 -0
- data/vendor/libgit2/src/win32/findfile.c +143 -54
- data/vendor/libgit2/src/win32/findfile.h +10 -6
- data/vendor/libgit2/src/win32/map.c +1 -1
- data/vendor/libgit2/src/win32/mingw-compat.h +1 -1
- data/vendor/libgit2/src/win32/msvc-compat.h +10 -1
- data/vendor/libgit2/src/win32/posix.h +10 -1
- data/vendor/libgit2/src/win32/posix_w32.c +132 -63
- data/vendor/libgit2/src/win32/precompiled.c +1 -1
- data/vendor/libgit2/src/win32/pthread.c +1 -1
- data/vendor/libgit2/src/win32/pthread.h +1 -1
- data/vendor/libgit2/src/win32/utf-conv.c +5 -5
- data/vendor/libgit2/src/win32/utf-conv.h +3 -3
- data/vendor/libgit2/src/win32/version.h +20 -0
- metadata +308 -252
- data/test/fixtures/testrepo.git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
- data/test/fixtures/testrepo.git/objects/7f/043268ea43ce18e3540acaabf9e090c91965b0 +0 -0
- data/test/fixtures/testrepo.git/objects/a3/e05719b428a2d0ed7a55c4ce53dcc5768c6d5e +0 -0
- data/test/index_test.rb~ +0 -218
- data/vendor/libgit2/src/pkt.h +0 -91
- data/vendor/libgit2/src/ppc/sha1.c +0 -70
- data/vendor/libgit2/src/ppc/sha1.h +0 -26
- data/vendor/libgit2/src/protocol.c +0 -110
- data/vendor/libgit2/src/protocol.h +0 -21
- data/vendor/libgit2/src/sha1.h +0 -33
- data/vendor/libgit2/src/transport.h +0 -148
data/vendor/libgit2/src/util.h
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (C)
|
2
|
+
* Copyright (C) the libgit2 contributors. All rights reserved.
|
3
3
|
*
|
4
4
|
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
5
|
* a Linking Exception. For full terms see the included COPYING file.
|
@@ -13,6 +13,9 @@
|
|
13
13
|
#ifndef min
|
14
14
|
# define min(a,b) ((a) < (b) ? (a) : (b))
|
15
15
|
#endif
|
16
|
+
#ifndef max
|
17
|
+
# define max(a,b) ((a) > (b) ? (a) : (b))
|
18
|
+
#endif
|
16
19
|
|
17
20
|
/*
|
18
21
|
* Custom memory allocation wrappers
|
@@ -42,25 +45,31 @@ GIT_INLINE(char *) git__strdup(const char *str)
|
|
42
45
|
|
43
46
|
GIT_INLINE(char *) git__strndup(const char *str, size_t n)
|
44
47
|
{
|
45
|
-
size_t length;
|
48
|
+
size_t length = 0;
|
46
49
|
char *ptr;
|
47
50
|
|
48
|
-
length
|
49
|
-
|
50
|
-
length = n;
|
51
|
+
while (length < n && str[length])
|
52
|
+
++length;
|
51
53
|
|
52
|
-
ptr = (char*)
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
}
|
54
|
+
ptr = (char*)git__malloc(length + 1);
|
55
|
+
|
56
|
+
if (length)
|
57
|
+
memcpy(ptr, str, length);
|
57
58
|
|
58
|
-
memcpy(ptr, str, length);
|
59
59
|
ptr[length] = '\0';
|
60
60
|
|
61
61
|
return ptr;
|
62
62
|
}
|
63
63
|
|
64
|
+
/* NOTE: This doesn't do null or '\0' checking. Watch those boundaries! */
|
65
|
+
GIT_INLINE(char *) git__substrdup(const char *start, size_t n)
|
66
|
+
{
|
67
|
+
char *ptr = (char*)git__malloc(n+1);
|
68
|
+
memcpy(ptr, start, n);
|
69
|
+
ptr[n] = '\0';
|
70
|
+
return ptr;
|
71
|
+
}
|
72
|
+
|
64
73
|
GIT_INLINE(void *) git__realloc(void *ptr, size_t size)
|
65
74
|
{
|
66
75
|
void *new_ptr = realloc(ptr, size);
|
@@ -80,6 +89,11 @@ extern int git__prefixcmp(const char *str, const char *prefix);
|
|
80
89
|
extern int git__prefixcmp_icase(const char *str, const char *prefix);
|
81
90
|
extern int git__suffixcmp(const char *str, const char *suffix);
|
82
91
|
|
92
|
+
GIT_INLINE(int) git__signum(int val)
|
93
|
+
{
|
94
|
+
return ((val > 0) - (val < 0));
|
95
|
+
}
|
96
|
+
|
83
97
|
extern int git__strtol32(int32_t *n, const char *buff, const char **end_buf, int base);
|
84
98
|
extern int git__strtol64(int64_t *n, const char *buff, const char **end_buf, int base);
|
85
99
|
|
@@ -101,6 +115,7 @@ GIT_INLINE(int) git__is_sizet(git_off_t p)
|
|
101
115
|
#endif
|
102
116
|
|
103
117
|
extern char *git__strtok(char **end, const char *sep);
|
118
|
+
extern char *git__strsep(char **end, const char *sep);
|
104
119
|
|
105
120
|
extern void git__strntolower(char *str, size_t len);
|
106
121
|
extern void git__strtolower(char *str);
|
@@ -112,22 +127,64 @@ GIT_INLINE(const char *) git__next_line(const char *s)
|
|
112
127
|
return s;
|
113
128
|
}
|
114
129
|
|
115
|
-
|
130
|
+
GIT_INLINE(const void *) git__memrchr(const void *s, int c, size_t n)
|
131
|
+
{
|
132
|
+
const unsigned char *cp;
|
133
|
+
|
134
|
+
if (n != 0) {
|
135
|
+
cp = (unsigned char *)s + n;
|
136
|
+
do {
|
137
|
+
if (*(--cp) == (unsigned char)c)
|
138
|
+
return cp;
|
139
|
+
} while (--n != 0);
|
140
|
+
}
|
141
|
+
|
142
|
+
return NULL;
|
143
|
+
}
|
144
|
+
|
145
|
+
typedef int (*git__tsort_cmp)(const void *a, const void *b);
|
146
|
+
|
147
|
+
extern void git__tsort(void **dst, size_t size, git__tsort_cmp cmp);
|
148
|
+
|
149
|
+
typedef int (*git__sort_r_cmp)(const void *a, const void *b, void *payload);
|
150
|
+
|
151
|
+
extern void git__tsort_r(
|
152
|
+
void **dst, size_t size, git__sort_r_cmp cmp, void *payload);
|
153
|
+
|
154
|
+
extern void git__qsort_r(
|
155
|
+
void *els, size_t nel, size_t elsize, git__sort_r_cmp cmp, void *payload);
|
156
|
+
|
157
|
+
extern void git__insertsort_r(
|
158
|
+
void *els, size_t nel, size_t elsize, void *swapel,
|
159
|
+
git__sort_r_cmp cmp, void *payload);
|
116
160
|
|
117
161
|
/**
|
118
162
|
* @param position If non-NULL, this will be set to the position where the
|
119
163
|
* element is or would be inserted if not found.
|
120
|
-
* @return
|
164
|
+
* @return 0 if found; GIT_ENOTFOUND if not found
|
121
165
|
*/
|
122
166
|
extern int git__bsearch(
|
123
167
|
void **array,
|
124
168
|
size_t array_len,
|
125
169
|
const void *key,
|
126
|
-
int (*compare)(const void
|
170
|
+
int (*compare)(const void *key, const void *element),
|
171
|
+
size_t *position);
|
172
|
+
|
173
|
+
extern int git__bsearch_r(
|
174
|
+
void **array,
|
175
|
+
size_t array_len,
|
176
|
+
const void *key,
|
177
|
+
int (*compare_r)(const void *key, const void *element, void *payload),
|
178
|
+
void *payload,
|
127
179
|
size_t *position);
|
128
180
|
|
129
181
|
extern int git__strcmp_cb(const void *a, const void *b);
|
130
182
|
|
183
|
+
extern int git__strcmp(const char *a, const char *b);
|
184
|
+
extern int git__strcasecmp(const char *a, const char *b);
|
185
|
+
extern int git__strncmp(const char *a, const char *b, size_t sz);
|
186
|
+
extern int git__strncasecmp(const char *a, const char *b, size_t sz);
|
187
|
+
|
131
188
|
typedef struct {
|
132
189
|
short refcount;
|
133
190
|
void *owner;
|
data/vendor/libgit2/src/vector.c
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* Copyright (C)
|
2
|
+
* Copyright (C) the libgit2 contributors. All rights reserved.
|
3
3
|
*
|
4
4
|
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
5
|
* a Linking Exception. For full terms see the included COPYING file.
|
@@ -9,33 +9,59 @@
|
|
9
9
|
#include "repository.h"
|
10
10
|
#include "vector.h"
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
/* In elements, not bytes */
|
13
|
+
#define MIN_ALLOCSIZE 8
|
14
14
|
|
15
|
-
|
15
|
+
GIT_INLINE(size_t) compute_new_size(git_vector *v)
|
16
16
|
{
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
size_t new_size = v->_alloc_size;
|
18
|
+
|
19
|
+
/* Use a resize factor of 1.5, which is quick to compute using integer
|
20
|
+
* instructions and less than the golden ratio (1.618...) */
|
21
|
+
if (new_size < MIN_ALLOCSIZE)
|
22
|
+
new_size = MIN_ALLOCSIZE;
|
23
|
+
else if (new_size <= (SIZE_MAX / 3) * 2)
|
24
|
+
new_size += new_size / 2;
|
25
|
+
else
|
26
|
+
new_size = SIZE_MAX;
|
27
|
+
|
28
|
+
return new_size;
|
29
|
+
}
|
20
30
|
|
21
|
-
|
22
|
-
|
31
|
+
GIT_INLINE(int) resize_vector(git_vector *v, size_t new_size)
|
32
|
+
{
|
33
|
+
size_t new_bytes = new_size * sizeof(void *);
|
34
|
+
void *new_contents;
|
35
|
+
|
36
|
+
/* Check for overflow */
|
37
|
+
if (new_bytes / sizeof(void *) != new_size)
|
38
|
+
GITERR_CHECK_ALLOC(NULL);
|
39
|
+
|
40
|
+
new_contents = git__realloc(v->contents, new_bytes);
|
41
|
+
GITERR_CHECK_ALLOC(new_contents);
|
42
|
+
|
43
|
+
v->_alloc_size = new_size;
|
44
|
+
v->contents = new_contents;
|
23
45
|
|
24
46
|
return 0;
|
25
47
|
}
|
26
48
|
|
27
|
-
int git_vector_dup(git_vector *v, git_vector *src, git_vector_cmp cmp)
|
49
|
+
int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp)
|
28
50
|
{
|
51
|
+
size_t bytes;
|
52
|
+
|
29
53
|
assert(v && src);
|
30
54
|
|
55
|
+
bytes = src->length * sizeof(void *);
|
56
|
+
|
31
57
|
v->_alloc_size = src->length;
|
32
58
|
v->_cmp = cmp;
|
33
59
|
v->length = src->length;
|
34
60
|
v->sorted = src->sorted && cmp == src->_cmp;
|
35
|
-
v->contents = git__malloc(
|
61
|
+
v->contents = git__malloc(bytes);
|
36
62
|
GITERR_CHECK_ALLOC(v->contents);
|
37
63
|
|
38
|
-
memcpy(v->contents, src->contents,
|
64
|
+
memcpy(v->contents, src->contents, bytes);
|
39
65
|
|
40
66
|
return 0;
|
41
67
|
}
|
@@ -55,21 +81,13 @@ int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp)
|
|
55
81
|
{
|
56
82
|
assert(v);
|
57
83
|
|
58
|
-
|
59
|
-
|
60
|
-
if (initial_size == 0)
|
61
|
-
initial_size = minimum_size;
|
62
|
-
|
63
|
-
v->_alloc_size = initial_size;
|
84
|
+
v->_alloc_size = 0;
|
64
85
|
v->_cmp = cmp;
|
65
|
-
|
66
86
|
v->length = 0;
|
67
87
|
v->sorted = 1;
|
88
|
+
v->contents = NULL;
|
68
89
|
|
69
|
-
|
70
|
-
GITERR_CHECK_ALLOC(v->contents);
|
71
|
-
|
72
|
-
return 0;
|
90
|
+
return resize_vector(v, max(initial_size, MIN_ALLOCSIZE));
|
73
91
|
}
|
74
92
|
|
75
93
|
int git_vector_insert(git_vector *v, void *element)
|
@@ -77,7 +95,7 @@ int git_vector_insert(git_vector *v, void *element)
|
|
77
95
|
assert(v);
|
78
96
|
|
79
97
|
if (v->length >= v->_alloc_size &&
|
80
|
-
resize_vector(v) < 0)
|
98
|
+
resize_vector(v, compute_new_size(v)) < 0)
|
81
99
|
return -1;
|
82
100
|
|
83
101
|
v->contents[v->length++] = element;
|
@@ -98,26 +116,25 @@ int git_vector_insert_sorted(
|
|
98
116
|
git_vector_sort(v);
|
99
117
|
|
100
118
|
if (v->length >= v->_alloc_size &&
|
101
|
-
resize_vector(v) < 0)
|
119
|
+
resize_vector(v, compute_new_size(v)) < 0)
|
102
120
|
return -1;
|
103
121
|
|
104
122
|
/* If we find the element and have a duplicate handler callback,
|
105
123
|
* invoke it. If it returns non-zero, then cancel insert, otherwise
|
106
124
|
* proceed with normal insert.
|
107
125
|
*/
|
108
|
-
if (git__bsearch(v->contents, v->length, element, v->_cmp, &pos)
|
109
|
-
on_dup
|
110
|
-
(result = on_dup(&v->contents[pos], element)) < 0)
|
126
|
+
if (!git__bsearch(v->contents, v->length, element, v->_cmp, &pos) &&
|
127
|
+
on_dup && (result = on_dup(&v->contents[pos], element)) < 0)
|
111
128
|
return result;
|
112
129
|
|
113
130
|
/* shift elements to the right */
|
114
|
-
if (pos < v->length)
|
131
|
+
if (pos < v->length)
|
115
132
|
memmove(v->contents + pos + 1, v->contents + pos,
|
116
133
|
(v->length - pos) * sizeof(void *));
|
117
|
-
}
|
118
134
|
|
119
135
|
v->contents[pos] = element;
|
120
136
|
v->length++;
|
137
|
+
|
121
138
|
return 0;
|
122
139
|
}
|
123
140
|
|
@@ -125,47 +142,44 @@ void git_vector_sort(git_vector *v)
|
|
125
142
|
{
|
126
143
|
assert(v);
|
127
144
|
|
128
|
-
if (v->sorted || v->_cmp
|
145
|
+
if (v->sorted || !v->_cmp)
|
129
146
|
return;
|
130
147
|
|
131
148
|
git__tsort(v->contents, v->length, v->_cmp);
|
132
149
|
v->sorted = 1;
|
133
150
|
}
|
134
151
|
|
135
|
-
int
|
136
|
-
|
152
|
+
int git_vector_bsearch2(
|
153
|
+
size_t *at_pos,
|
137
154
|
git_vector *v,
|
138
155
|
git_vector_cmp key_lookup,
|
139
156
|
const void *key)
|
140
157
|
{
|
141
|
-
int rval;
|
142
|
-
size_t pos;
|
143
|
-
|
144
158
|
assert(v && key && key_lookup);
|
145
159
|
|
146
160
|
/* need comparison function to sort the vector */
|
147
|
-
|
161
|
+
if (!v->_cmp)
|
162
|
+
return -1;
|
148
163
|
|
149
164
|
git_vector_sort(v);
|
150
165
|
|
151
|
-
|
152
|
-
|
153
|
-
if (at_pos != NULL)
|
154
|
-
*at_pos = (unsigned int)pos;
|
155
|
-
|
156
|
-
return (rval >= 0) ? (int)pos : GIT_ENOTFOUND;
|
166
|
+
return git__bsearch(v->contents, v->length, key, key_lookup, at_pos);
|
157
167
|
}
|
158
168
|
|
159
169
|
int git_vector_search2(
|
160
|
-
git_vector *v, git_vector_cmp key_lookup, const void *key)
|
170
|
+
size_t *at_pos, const git_vector *v, git_vector_cmp key_lookup, const void *key)
|
161
171
|
{
|
162
|
-
|
172
|
+
size_t i;
|
163
173
|
|
164
174
|
assert(v && key && key_lookup);
|
165
175
|
|
166
176
|
for (i = 0; i < v->length; ++i) {
|
167
|
-
if (key_lookup(key, v->contents[i]) == 0)
|
168
|
-
|
177
|
+
if (key_lookup(key, v->contents[i]) == 0) {
|
178
|
+
if (at_pos)
|
179
|
+
*at_pos = i;
|
180
|
+
|
181
|
+
return 0;
|
182
|
+
}
|
169
183
|
}
|
170
184
|
|
171
185
|
return GIT_ENOTFOUND;
|
@@ -176,22 +190,25 @@ static int strict_comparison(const void *a, const void *b)
|
|
176
190
|
return (a == b) ? 0 : -1;
|
177
191
|
}
|
178
192
|
|
179
|
-
int git_vector_search(git_vector *v, const void *entry)
|
193
|
+
int git_vector_search(size_t *at_pos, const git_vector *v, const void *entry)
|
180
194
|
{
|
181
|
-
return git_vector_search2(v, v->_cmp ? v->_cmp : strict_comparison, entry);
|
195
|
+
return git_vector_search2(at_pos, v, v->_cmp ? v->_cmp : strict_comparison, entry);
|
182
196
|
}
|
183
197
|
|
184
|
-
int git_vector_remove(git_vector *v,
|
198
|
+
int git_vector_remove(git_vector *v, size_t idx)
|
185
199
|
{
|
186
|
-
|
200
|
+
size_t shift_count;
|
187
201
|
|
188
202
|
assert(v);
|
189
203
|
|
190
|
-
if (idx >= v->length
|
204
|
+
if (idx >= v->length)
|
191
205
|
return GIT_ENOTFOUND;
|
192
206
|
|
193
|
-
|
194
|
-
|
207
|
+
shift_count = v->length - idx - 1;
|
208
|
+
|
209
|
+
if (shift_count)
|
210
|
+
memmove(&v->contents[idx], &v->contents[idx + 1],
|
211
|
+
shift_count * sizeof(void *));
|
195
212
|
|
196
213
|
v->length--;
|
197
214
|
return 0;
|
@@ -206,7 +223,7 @@ void git_vector_pop(git_vector *v)
|
|
206
223
|
void git_vector_uniq(git_vector *v)
|
207
224
|
{
|
208
225
|
git_vector_cmp cmp;
|
209
|
-
|
226
|
+
size_t i, j;
|
210
227
|
|
211
228
|
if (v->length <= 1)
|
212
229
|
return;
|
@@ -223,6 +240,21 @@ void git_vector_uniq(git_vector *v)
|
|
223
240
|
v->length -= j - i - 1;
|
224
241
|
}
|
225
242
|
|
243
|
+
void git_vector_remove_matching(
|
244
|
+
git_vector *v, int (*match)(const git_vector *v, size_t idx))
|
245
|
+
{
|
246
|
+
size_t i, j;
|
247
|
+
|
248
|
+
for (i = 0, j = 0; j < v->length; ++j) {
|
249
|
+
v->contents[i] = v->contents[j];
|
250
|
+
|
251
|
+
if (!match(v, i))
|
252
|
+
i++;
|
253
|
+
}
|
254
|
+
|
255
|
+
v->length = i;
|
256
|
+
}
|
257
|
+
|
226
258
|
void git_vector_clear(git_vector *v)
|
227
259
|
{
|
228
260
|
assert(v);
|
@@ -234,10 +266,41 @@ void git_vector_swap(git_vector *a, git_vector *b)
|
|
234
266
|
{
|
235
267
|
git_vector t;
|
236
268
|
|
237
|
-
|
238
|
-
return;
|
269
|
+
assert(a && b);
|
239
270
|
|
240
|
-
|
241
|
-
|
242
|
-
|
271
|
+
if (a != b) {
|
272
|
+
memcpy(&t, a, sizeof(t));
|
273
|
+
memcpy(a, b, sizeof(t));
|
274
|
+
memcpy(b, &t, sizeof(t));
|
275
|
+
}
|
276
|
+
}
|
277
|
+
|
278
|
+
int git_vector_resize_to(git_vector *v, size_t new_length)
|
279
|
+
{
|
280
|
+
if (new_length <= v->length)
|
281
|
+
return 0;
|
282
|
+
|
283
|
+
if (new_length > v->_alloc_size &&
|
284
|
+
resize_vector(v, new_length) < 0)
|
285
|
+
return -1;
|
286
|
+
|
287
|
+
memset(&v->contents[v->length], 0,
|
288
|
+
sizeof(void *) * (new_length - v->length));
|
289
|
+
|
290
|
+
v->length = new_length;
|
291
|
+
|
292
|
+
return 0;
|
293
|
+
}
|
294
|
+
|
295
|
+
int git_vector_set(void **old, git_vector *v, size_t position, void *value)
|
296
|
+
{
|
297
|
+
if (git_vector_resize_to(v, position + 1) < 0)
|
298
|
+
return -1;
|
299
|
+
|
300
|
+
if (old != NULL)
|
301
|
+
*old = v->contents[position];
|
302
|
+
|
303
|
+
v->contents[position] = value;
|
304
|
+
|
305
|
+
return 0;
|
243
306
|
}
|