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/vector.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.
|
@@ -24,41 +24,38 @@ typedef struct git_vector {
|
|
24
24
|
int git_vector_init(git_vector *v, size_t initial_size, git_vector_cmp cmp);
|
25
25
|
void git_vector_free(git_vector *v);
|
26
26
|
void git_vector_clear(git_vector *v);
|
27
|
-
int git_vector_dup(git_vector *v, git_vector *src, git_vector_cmp cmp);
|
27
|
+
int git_vector_dup(git_vector *v, const git_vector *src, git_vector_cmp cmp);
|
28
28
|
void git_vector_swap(git_vector *a, git_vector *b);
|
29
29
|
|
30
30
|
void git_vector_sort(git_vector *v);
|
31
31
|
|
32
|
-
|
33
|
-
int
|
32
|
+
/** Linear search for matching entry using internal comparison function */
|
33
|
+
int git_vector_search(size_t *at_pos, const git_vector *v, const void *entry);
|
34
34
|
|
35
|
-
|
36
|
-
|
35
|
+
/** Linear search for matching entry using explicit comparison function */
|
36
|
+
int git_vector_search2(size_t *at_pos, const git_vector *v, git_vector_cmp cmp, const void *key);
|
37
37
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
git_vector *v, git_vector_cmp cmp, const void *key)
|
45
|
-
{
|
46
|
-
return git_vector_bsearch3(NULL, v, cmp, key);
|
47
|
-
}
|
38
|
+
/**
|
39
|
+
* Binary search for matching entry using explicit comparison function that
|
40
|
+
* returns position where item would go if not found.
|
41
|
+
*/
|
42
|
+
int git_vector_bsearch2(
|
43
|
+
size_t *at_pos, git_vector *v, git_vector_cmp cmp, const void *key);
|
48
44
|
|
49
|
-
|
45
|
+
/** Binary search for matching entry using internal comparison function */
|
46
|
+
GIT_INLINE(int) git_vector_bsearch(size_t *at_pos, git_vector *v, const void *key)
|
50
47
|
{
|
51
|
-
return (
|
48
|
+
return git_vector_bsearch2(at_pos, v, v->_cmp, key);
|
52
49
|
}
|
53
50
|
|
54
|
-
GIT_INLINE(
|
51
|
+
GIT_INLINE(void *) git_vector_get(const git_vector *v, size_t position)
|
55
52
|
{
|
56
53
|
return (position < v->length) ? v->contents[position] : NULL;
|
57
54
|
}
|
58
55
|
|
59
56
|
#define GIT_VECTOR_GET(V,I) ((I) < (V)->length ? (V)->contents[(I)] : NULL)
|
60
57
|
|
61
|
-
GIT_INLINE(void *) git_vector_last(git_vector *v)
|
58
|
+
GIT_INLINE(void *) git_vector_last(const git_vector *v)
|
62
59
|
{
|
63
60
|
return (v->length > 0) ? git_vector_get(v, v->length - 1) : NULL;
|
64
61
|
}
|
@@ -67,13 +64,18 @@ GIT_INLINE(void *) git_vector_last(git_vector *v)
|
|
67
64
|
for ((iter) = 0; (iter) < (v)->length && ((elem) = (v)->contents[(iter)], 1); (iter)++ )
|
68
65
|
|
69
66
|
#define git_vector_rforeach(v, iter, elem) \
|
70
|
-
for ((iter) = (v)->length; (iter)
|
67
|
+
for ((iter) = (v)->length - 1; (iter) < SIZE_MAX && ((elem) = (v)->contents[(iter)], 1); (iter)-- )
|
71
68
|
|
72
69
|
int git_vector_insert(git_vector *v, void *element);
|
73
70
|
int git_vector_insert_sorted(git_vector *v, void *element,
|
74
71
|
int (*on_dup)(void **old, void *new));
|
75
|
-
int git_vector_remove(git_vector *v,
|
72
|
+
int git_vector_remove(git_vector *v, size_t idx);
|
76
73
|
void git_vector_pop(git_vector *v);
|
77
74
|
void git_vector_uniq(git_vector *v);
|
75
|
+
void git_vector_remove_matching(
|
76
|
+
git_vector *v, int (*match)(const git_vector *v, size_t idx));
|
77
|
+
|
78
|
+
int git_vector_resize_to(git_vector *v, size_t new_length);
|
79
|
+
int git_vector_set(void **old, git_vector *v, size_t position, void *value);
|
78
80
|
|
79
81
|
#endif
|
@@ -0,0 +1,77 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) the libgit2 contributors. All rights reserved.
|
3
|
+
*
|
4
|
+
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
|
+
* a Linking Exception. For full terms see the included COPYING file.
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include "common.h"
|
9
|
+
#include "error.h"
|
10
|
+
|
11
|
+
#ifdef GIT_WINHTTP
|
12
|
+
# include <winhttp.h>
|
13
|
+
#endif
|
14
|
+
|
15
|
+
#define WC_ERR_INVALID_CHARS 0x80
|
16
|
+
|
17
|
+
char *git_win32_get_error_message(DWORD error_code)
|
18
|
+
{
|
19
|
+
LPWSTR lpMsgBuf = NULL;
|
20
|
+
HMODULE hModule = NULL;
|
21
|
+
char *utf8_msg = NULL;
|
22
|
+
int utf8_size;
|
23
|
+
DWORD dwFlags =
|
24
|
+
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS;
|
25
|
+
|
26
|
+
if (!error_code)
|
27
|
+
return NULL;
|
28
|
+
|
29
|
+
#ifdef GIT_WINHTTP
|
30
|
+
/* Errors raised by WinHTTP are not in the system resource table */
|
31
|
+
if (error_code >= WINHTTP_ERROR_BASE &&
|
32
|
+
error_code <= WINHTTP_ERROR_LAST)
|
33
|
+
hModule = GetModuleHandleW(L"winhttp");
|
34
|
+
#endif
|
35
|
+
|
36
|
+
GIT_UNUSED(hModule);
|
37
|
+
|
38
|
+
if (hModule)
|
39
|
+
dwFlags |= FORMAT_MESSAGE_FROM_HMODULE;
|
40
|
+
else
|
41
|
+
dwFlags |= FORMAT_MESSAGE_FROM_SYSTEM;
|
42
|
+
|
43
|
+
if (FormatMessageW(dwFlags, hModule, error_code,
|
44
|
+
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
45
|
+
(LPWSTR)&lpMsgBuf, 0, NULL)) {
|
46
|
+
|
47
|
+
/* Invalid code point check supported on Vista+ only */
|
48
|
+
if (git_has_win32_version(6, 0))
|
49
|
+
dwFlags = WC_ERR_INVALID_CHARS;
|
50
|
+
else
|
51
|
+
dwFlags = 0;
|
52
|
+
|
53
|
+
utf8_size = WideCharToMultiByte(CP_UTF8, dwFlags,
|
54
|
+
lpMsgBuf, -1, NULL, 0, NULL, NULL);
|
55
|
+
|
56
|
+
if (!utf8_size) {
|
57
|
+
assert(0);
|
58
|
+
goto on_error;
|
59
|
+
}
|
60
|
+
|
61
|
+
utf8_msg = git__malloc(utf8_size);
|
62
|
+
|
63
|
+
if (!utf8_msg)
|
64
|
+
goto on_error;
|
65
|
+
|
66
|
+
if (!WideCharToMultiByte(CP_UTF8, dwFlags,
|
67
|
+
lpMsgBuf, -1, utf8_msg, utf8_size, NULL, NULL)) {
|
68
|
+
git__free(utf8_msg);
|
69
|
+
goto on_error;
|
70
|
+
}
|
71
|
+
|
72
|
+
on_error:
|
73
|
+
LocalFree(lpMsgBuf);
|
74
|
+
}
|
75
|
+
|
76
|
+
return utf8_msg;
|
77
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) the libgit2 contributors. All rights reserved.
|
3
|
+
*
|
4
|
+
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
|
+
* a Linking Exception. For full terms see the included COPYING file.
|
6
|
+
*/
|
7
|
+
|
8
|
+
#ifndef INCLUDE_git_win32_error_h__
|
9
|
+
#define INCLUDE_git_win32_error_h__
|
10
|
+
|
11
|
+
extern char *git_win32_get_error_message(DWORD error_code);
|
12
|
+
|
13
|
+
#endif
|
@@ -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,23 +9,35 @@
|
|
9
9
|
#include "path.h"
|
10
10
|
#include "findfile.h"
|
11
11
|
|
12
|
+
#define REG_MSYSGIT_INSTALL_LOCAL L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1"
|
13
|
+
|
12
14
|
#ifndef _WIN64
|
13
|
-
#define REG_MSYSGIT_INSTALL
|
15
|
+
#define REG_MSYSGIT_INSTALL REG_MSYSGIT_INSTALL_LOCAL
|
14
16
|
#else
|
15
17
|
#define REG_MSYSGIT_INSTALL L"SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Git_is1"
|
16
18
|
#endif
|
17
19
|
|
18
|
-
int
|
20
|
+
int git_win32__expand_path(struct git_win32__path *s_root, const wchar_t *templ)
|
19
21
|
{
|
20
22
|
s_root->len = ExpandEnvironmentStringsW(templ, s_root->path, MAX_PATH);
|
21
23
|
return s_root->len ? 0 : -1;
|
22
24
|
}
|
23
25
|
|
24
|
-
int
|
26
|
+
static int win32_path_utf16_to_8(git_buf *path_utf8, const wchar_t *path_utf16)
|
27
|
+
{
|
28
|
+
char temp_utf8[GIT_PATH_MAX];
|
29
|
+
|
30
|
+
git__utf16_to_8(temp_utf8, path_utf16);
|
31
|
+
git_path_mkposix(temp_utf8);
|
32
|
+
|
33
|
+
return git_buf_sets(path_utf8, temp_utf8);
|
34
|
+
}
|
35
|
+
|
36
|
+
int git_win32__find_file(
|
37
|
+
git_buf *path, const struct git_win32__path *root, const char *filename)
|
25
38
|
{
|
26
39
|
size_t len, alloc_len;
|
27
40
|
wchar_t *file_utf16 = NULL;
|
28
|
-
char file_utf8[GIT_PATH_MAX];
|
29
41
|
|
30
42
|
if (!root || !filename || (len = strlen(filename)) == 0)
|
31
43
|
return GIT_ENOTFOUND;
|
@@ -49,15 +61,13 @@ int win32_find_file(git_buf *path, const struct win32_path *root, const char *fi
|
|
49
61
|
return GIT_ENOTFOUND;
|
50
62
|
}
|
51
63
|
|
52
|
-
|
53
|
-
git_path_mkposix(file_utf8);
|
54
|
-
git_buf_sets(path, file_utf8);
|
55
|
-
|
64
|
+
win32_path_utf16_to_8(path, file_utf16);
|
56
65
|
git__free(file_utf16);
|
66
|
+
|
57
67
|
return 0;
|
58
68
|
}
|
59
69
|
|
60
|
-
wchar_t*
|
70
|
+
static wchar_t* win32_walkpath(wchar_t *path, wchar_t *buf, size_t buflen)
|
61
71
|
{
|
62
72
|
wchar_t term, *base = path;
|
63
73
|
|
@@ -76,74 +86,153 @@ wchar_t* win32_nextpath(wchar_t *path, wchar_t *buf, size_t buflen)
|
|
76
86
|
return (path != base) ? path : NULL;
|
77
87
|
}
|
78
88
|
|
79
|
-
int
|
89
|
+
static int win32_find_git_in_path(git_buf *buf, const wchar_t *gitexe)
|
80
90
|
{
|
81
|
-
wchar_t *
|
82
|
-
struct
|
91
|
+
wchar_t *env = _wgetenv(L"PATH"), lastch;
|
92
|
+
struct git_win32__path root;
|
93
|
+
size_t gitexe_len = wcslen(gitexe);
|
83
94
|
|
84
|
-
env = _wgetenv(L"PATH");
|
85
95
|
if (!env)
|
86
96
|
return -1;
|
87
97
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
98
|
+
while ((env = win32_walkpath(env, root.path, MAX_PATH-1)) && *root.path) {
|
99
|
+
root.len = (DWORD)wcslen(root.path);
|
100
|
+
lastch = root.path[root.len - 1];
|
101
|
+
|
102
|
+
/* ensure trailing slash (MAX_PATH-1 to walkpath guarantees space) */
|
103
|
+
if (lastch != L'/' && lastch != L'\\') {
|
104
|
+
root.path[root.len++] = L'\\';
|
105
|
+
root.path[root.len] = L'\0';
|
106
|
+
}
|
92
107
|
|
93
|
-
|
94
|
-
|
95
|
-
|
108
|
+
if (root.len + gitexe_len >= MAX_PATH)
|
109
|
+
continue;
|
110
|
+
wcscpy(&root.path[root.len], gitexe);
|
96
111
|
|
97
|
-
|
112
|
+
if (_waccess(root.path, F_OK) == 0 && root.len > 5) {
|
113
|
+
/* replace "bin\\" or "cmd\\" with "etc\\" */
|
114
|
+
wcscpy(&root.path[root.len - 4], L"etc\\");
|
98
115
|
|
99
|
-
|
100
|
-
|
101
|
-
if (root.len > 5) {
|
102
|
-
wcscpy(root.path + wcslen(root.path) - 4, L"etc\\");
|
103
|
-
if (win32_find_file(path, &root, filename) == 0)
|
104
|
-
return 0;
|
105
|
-
}
|
116
|
+
win32_path_utf16_to_8(buf, root.path);
|
117
|
+
return 0;
|
106
118
|
}
|
107
119
|
}
|
108
|
-
|
120
|
+
|
109
121
|
return GIT_ENOTFOUND;
|
110
122
|
}
|
111
123
|
|
112
|
-
int
|
124
|
+
static int win32_find_git_in_registry(
|
125
|
+
git_buf *buf, const HKEY hieve, const wchar_t *key)
|
113
126
|
{
|
114
|
-
struct win32_path root;
|
115
|
-
|
116
127
|
HKEY hKey;
|
117
128
|
DWORD dwType = REG_SZ;
|
118
|
-
|
129
|
+
struct git_win32__path path16;
|
130
|
+
|
131
|
+
assert(buf);
|
132
|
+
|
133
|
+
path16.len = 0;
|
119
134
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
if (RegQueryValueExW(hKey, L"InstallLocation", NULL, &dwType,(LPBYTE)&root.path, &dwSize) == ERROR_SUCCESS)
|
135
|
+
if (RegOpenKeyExW(hieve, key, 0, KEY_ALL_ACCESS, &hKey) == ERROR_SUCCESS) {
|
136
|
+
if (RegQueryValueExW(hKey, L"InstallLocation", NULL, &dwType,
|
137
|
+
(LPBYTE)&path16.path, &path16.len) == ERROR_SUCCESS)
|
124
138
|
{
|
125
|
-
|
126
|
-
|
127
|
-
{
|
128
|
-
giterr_set(GITERR_OS, "Cannot locate
|
139
|
+
/* InstallLocation points to the root of the git directory */
|
140
|
+
|
141
|
+
if (path16.len + 4 > MAX_PATH) { /* 4 = wcslen(L"etc\\") */
|
142
|
+
giterr_set(GITERR_OS, "Cannot locate git - path too long");
|
129
143
|
return -1;
|
130
144
|
}
|
131
|
-
|
132
|
-
|
145
|
+
|
146
|
+
wcscat(path16.path, L"etc\\");
|
147
|
+
path16.len += 4;
|
148
|
+
|
149
|
+
win32_path_utf16_to_8(buf, path16.path);
|
133
150
|
}
|
134
|
-
}
|
135
|
-
RegCloseKey(hKey);
|
136
151
|
|
137
|
-
|
138
|
-
giterr_set(GITERR_OS, "Cannot locate the system's msysgit directory");
|
139
|
-
return -1;
|
152
|
+
RegCloseKey(hKey);
|
140
153
|
}
|
141
154
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
155
|
+
return path16.len ? 0 : GIT_ENOTFOUND;
|
156
|
+
}
|
157
|
+
|
158
|
+
static int win32_find_existing_dirs(
|
159
|
+
git_buf *out, const wchar_t *tmpl[], char *temp[])
|
160
|
+
{
|
161
|
+
struct git_win32__path path16;
|
162
|
+
git_buf buf = GIT_BUF_INIT;
|
163
|
+
|
164
|
+
git_buf_clear(out);
|
165
|
+
|
166
|
+
for (; *tmpl != NULL; tmpl++) {
|
167
|
+
if (!git_win32__expand_path(&path16, *tmpl) &&
|
168
|
+
path16.path[0] != L'%' &&
|
169
|
+
!_waccess(path16.path, F_OK))
|
170
|
+
{
|
171
|
+
win32_path_utf16_to_8(&buf, path16.path);
|
172
|
+
|
173
|
+
if (buf.size)
|
174
|
+
git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
|
175
|
+
}
|
146
176
|
}
|
147
177
|
|
148
|
-
|
178
|
+
git_buf_free(&buf);
|
179
|
+
|
180
|
+
return (git_buf_oom(out) ? -1 : 0);
|
149
181
|
}
|
182
|
+
|
183
|
+
int git_win32__find_system_dirs(git_buf *out)
|
184
|
+
{
|
185
|
+
git_buf buf = GIT_BUF_INIT;
|
186
|
+
|
187
|
+
/* directories where git.exe & git.cmd are found */
|
188
|
+
if (!win32_find_git_in_path(&buf, L"git.exe") && buf.size)
|
189
|
+
git_buf_set(out, buf.ptr, buf.size);
|
190
|
+
else
|
191
|
+
git_buf_clear(out);
|
192
|
+
|
193
|
+
if (!win32_find_git_in_path(&buf, L"git.cmd") && buf.size)
|
194
|
+
git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
|
195
|
+
|
196
|
+
/* directories where git is installed according to registry */
|
197
|
+
if (!win32_find_git_in_registry(
|
198
|
+
&buf, HKEY_CURRENT_USER, REG_MSYSGIT_INSTALL_LOCAL) && buf.size)
|
199
|
+
git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
|
200
|
+
|
201
|
+
if (!win32_find_git_in_registry(
|
202
|
+
&buf, HKEY_LOCAL_MACHINE, REG_MSYSGIT_INSTALL) && buf.size)
|
203
|
+
git_buf_join(out, GIT_PATH_LIST_SEPARATOR, out->ptr, buf.ptr);
|
204
|
+
|
205
|
+
git_buf_free(&buf);
|
206
|
+
|
207
|
+
return (git_buf_oom(out) ? -1 : 0);
|
208
|
+
}
|
209
|
+
|
210
|
+
int git_win32__find_global_dirs(git_buf *out)
|
211
|
+
{
|
212
|
+
char *temp[3];
|
213
|
+
static const wchar_t *global_tmpls[4] = {
|
214
|
+
L"%HOME%\\",
|
215
|
+
L"%HOMEDRIVE%%HOMEPATH%\\",
|
216
|
+
L"%USERPROFILE%\\",
|
217
|
+
NULL,
|
218
|
+
};
|
219
|
+
|
220
|
+
return win32_find_existing_dirs(out, global_tmpls, temp);
|
221
|
+
}
|
222
|
+
|
223
|
+
int git_win32__find_xdg_dirs(git_buf *out)
|
224
|
+
{
|
225
|
+
char *temp[6];
|
226
|
+
static const wchar_t *global_tmpls[7] = {
|
227
|
+
L"%XDG_CONFIG_HOME%\\git",
|
228
|
+
L"%APPDATA%\\git",
|
229
|
+
L"%LOCALAPPDATA%\\git",
|
230
|
+
L"%HOME%\\.config\\git",
|
231
|
+
L"%HOMEDRIVE%%HOMEPATH%\\.config\\git",
|
232
|
+
L"%USERPROFILE%\\.config\\git",
|
233
|
+
NULL,
|
234
|
+
};
|
235
|
+
|
236
|
+
return win32_find_existing_dirs(out, global_tmpls, temp);
|
237
|
+
}
|
238
|
+
|