rugged 0.17.0.b7 → 0.18.0.b1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/path.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.
|
|
@@ -19,9 +19,53 @@
|
|
|
19
19
|
|
|
20
20
|
#define LOOKS_LIKE_DRIVE_PREFIX(S) (git__isalpha((S)[0]) && (S)[1] == ':')
|
|
21
21
|
|
|
22
|
+
#ifdef GIT_WIN32
|
|
23
|
+
static bool looks_like_network_computer_name(const char *path, int pos)
|
|
24
|
+
{
|
|
25
|
+
if (pos < 3)
|
|
26
|
+
return false;
|
|
27
|
+
|
|
28
|
+
if (path[0] != '/' || path[1] != '/')
|
|
29
|
+
return false;
|
|
30
|
+
|
|
31
|
+
while (pos-- > 2) {
|
|
32
|
+
if (path[pos] == '/')
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
#endif
|
|
39
|
+
|
|
22
40
|
/*
|
|
23
41
|
* Based on the Android implementation, BSD licensed.
|
|
24
|
-
*
|
|
42
|
+
* http://android.git.kernel.org/
|
|
43
|
+
*
|
|
44
|
+
* Copyright (C) 2008 The Android Open Source Project
|
|
45
|
+
* All rights reserved.
|
|
46
|
+
*
|
|
47
|
+
* Redistribution and use in source and binary forms, with or without
|
|
48
|
+
* modification, are permitted provided that the following conditions
|
|
49
|
+
* are met:
|
|
50
|
+
* * Redistributions of source code must retain the above copyright
|
|
51
|
+
* notice, this list of conditions and the following disclaimer.
|
|
52
|
+
* * Redistributions in binary form must reproduce the above copyright
|
|
53
|
+
* notice, this list of conditions and the following disclaimer in
|
|
54
|
+
* the documentation and/or other materials provided with the
|
|
55
|
+
* distribution.
|
|
56
|
+
*
|
|
57
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
58
|
+
* AS IS AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
59
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
60
|
+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
61
|
+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
62
|
+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
63
|
+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
64
|
+
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
65
|
+
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
66
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
|
|
67
|
+
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
68
|
+
* SUCH DAMAGE.
|
|
25
69
|
*/
|
|
26
70
|
int git_path_basename_r(git_buf *buffer, const char *path)
|
|
27
71
|
{
|
|
@@ -111,6 +155,15 @@ int git_path_dirname_r(git_buf *buffer, const char *path)
|
|
|
111
155
|
len = 3;
|
|
112
156
|
goto Exit;
|
|
113
157
|
}
|
|
158
|
+
|
|
159
|
+
/* Similarly checks if we're dealing with a network computer name
|
|
160
|
+
'//computername/.git' will return '//computername/' */
|
|
161
|
+
|
|
162
|
+
if (looks_like_network_computer_name(path, len)) {
|
|
163
|
+
len++;
|
|
164
|
+
goto Exit;
|
|
165
|
+
}
|
|
166
|
+
|
|
114
167
|
#endif
|
|
115
168
|
|
|
116
169
|
Exit:
|
|
@@ -347,7 +400,7 @@ int git_path_fromurl(git_buf *local_path_out, const char *file_url)
|
|
|
347
400
|
if (offset >= len || file_url[offset] == '/')
|
|
348
401
|
return error_invalid_local_file_uri(file_url);
|
|
349
402
|
|
|
350
|
-
#ifndef
|
|
403
|
+
#ifndef GIT_WIN32
|
|
351
404
|
offset--; /* A *nix absolute path starts with a forward slash */
|
|
352
405
|
#endif
|
|
353
406
|
|
|
@@ -382,9 +435,10 @@ int git_path_walk_up(
|
|
|
382
435
|
iter.asize = path->asize;
|
|
383
436
|
|
|
384
437
|
while (scan >= stop) {
|
|
385
|
-
|
|
386
|
-
break;
|
|
438
|
+
error = cb(data, &iter);
|
|
387
439
|
iter.ptr[scan] = oldc;
|
|
440
|
+
if (error < 0)
|
|
441
|
+
break;
|
|
388
442
|
scan = git_buf_rfind_next(&iter, '/');
|
|
389
443
|
if (scan >= 0) {
|
|
390
444
|
scan++;
|
|
@@ -510,7 +564,7 @@ static bool _check_dir_contents(
|
|
|
510
564
|
size_t sub_size = strlen(sub);
|
|
511
565
|
|
|
512
566
|
/* leave base valid even if we could not make space for subdir */
|
|
513
|
-
if (git_buf_try_grow(dir, dir_size + sub_size + 2) < 0)
|
|
567
|
+
if (git_buf_try_grow(dir, dir_size + sub_size + 2, false) < 0)
|
|
514
568
|
return false;
|
|
515
569
|
|
|
516
570
|
/* save excursion */
|
|
@@ -625,13 +679,14 @@ int git_path_apply_relative(git_buf *target, const char *relpath)
|
|
|
625
679
|
|
|
626
680
|
int git_path_cmp(
|
|
627
681
|
const char *name1, size_t len1, int isdir1,
|
|
628
|
-
const char *name2, size_t len2, int isdir2
|
|
682
|
+
const char *name2, size_t len2, int isdir2,
|
|
683
|
+
int (*compare)(const char *, const char *, size_t))
|
|
629
684
|
{
|
|
630
685
|
unsigned char c1, c2;
|
|
631
686
|
size_t len = len1 < len2 ? len1 : len2;
|
|
632
687
|
int cmp;
|
|
633
688
|
|
|
634
|
-
cmp =
|
|
689
|
+
cmp = compare(name1, name2, len);
|
|
635
690
|
if (cmp)
|
|
636
691
|
return cmp;
|
|
637
692
|
|
|
@@ -769,18 +824,30 @@ int git_path_dirload(
|
|
|
769
824
|
int git_path_with_stat_cmp(const void *a, const void *b)
|
|
770
825
|
{
|
|
771
826
|
const git_path_with_stat *psa = a, *psb = b;
|
|
772
|
-
return
|
|
827
|
+
return strcmp(psa->path, psb->path);
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
int git_path_with_stat_cmp_icase(const void *a, const void *b)
|
|
831
|
+
{
|
|
832
|
+
const git_path_with_stat *psa = a, *psb = b;
|
|
833
|
+
return strcasecmp(psa->path, psb->path);
|
|
773
834
|
}
|
|
774
835
|
|
|
775
836
|
int git_path_dirload_with_stat(
|
|
776
837
|
const char *path,
|
|
777
838
|
size_t prefix_len,
|
|
839
|
+
bool ignore_case,
|
|
840
|
+
const char *start_stat,
|
|
841
|
+
const char *end_stat,
|
|
778
842
|
git_vector *contents)
|
|
779
843
|
{
|
|
780
844
|
int error;
|
|
781
845
|
unsigned int i;
|
|
782
846
|
git_path_with_stat *ps;
|
|
783
847
|
git_buf full = GIT_BUF_INIT;
|
|
848
|
+
int (*strncomp)(const char *a, const char *b, size_t sz);
|
|
849
|
+
size_t start_len = start_stat ? strlen(start_stat) : 0;
|
|
850
|
+
size_t end_len = end_stat ? strlen(end_stat) : 0, cmp_len;
|
|
784
851
|
|
|
785
852
|
if (git_buf_set(&full, path, prefix_len) < 0)
|
|
786
853
|
return -1;
|
|
@@ -792,24 +859,46 @@ int git_path_dirload_with_stat(
|
|
|
792
859
|
return error;
|
|
793
860
|
}
|
|
794
861
|
|
|
862
|
+
strncomp = ignore_case ? git__strncasecmp : git__strncmp;
|
|
863
|
+
|
|
864
|
+
/* stat struct at start of git_path_with_stat, so shift path text */
|
|
795
865
|
git_vector_foreach(contents, i, ps) {
|
|
796
866
|
size_t path_len = strlen((char *)ps);
|
|
797
|
-
|
|
798
867
|
memmove(ps->path, ps, path_len + 1);
|
|
799
868
|
ps->path_len = path_len;
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
git_vector_foreach(contents, i, ps) {
|
|
872
|
+
/* skip if before start_stat or after end_stat */
|
|
873
|
+
cmp_len = min(start_len, ps->path_len);
|
|
874
|
+
if (cmp_len && strncomp(ps->path, start_stat, cmp_len) < 0)
|
|
875
|
+
continue;
|
|
876
|
+
cmp_len = min(end_len, ps->path_len);
|
|
877
|
+
if (cmp_len && strncomp(ps->path, end_stat, cmp_len) > 0)
|
|
878
|
+
continue;
|
|
879
|
+
|
|
880
|
+
git_buf_truncate(&full, prefix_len);
|
|
800
881
|
|
|
801
882
|
if ((error = git_buf_joinpath(&full, full.ptr, ps->path)) < 0 ||
|
|
802
883
|
(error = git_path_lstat(full.ptr, &ps->st)) < 0)
|
|
803
884
|
break;
|
|
804
885
|
|
|
805
|
-
git_buf_truncate(&full, prefix_len);
|
|
806
|
-
|
|
807
886
|
if (S_ISDIR(ps->st.st_mode)) {
|
|
808
|
-
|
|
809
|
-
|
|
887
|
+
if ((error = git_buf_joinpath(&full, full.ptr, ".git")) < 0)
|
|
888
|
+
break;
|
|
889
|
+
|
|
890
|
+
if (p_access(full.ptr, F_OK) == 0) {
|
|
891
|
+
ps->st.st_mode = GIT_FILEMODE_COMMIT;
|
|
892
|
+
} else {
|
|
893
|
+
ps->path[ps->path_len++] = '/';
|
|
894
|
+
ps->path[ps->path_len] = '\0';
|
|
895
|
+
}
|
|
810
896
|
}
|
|
811
897
|
}
|
|
812
898
|
|
|
899
|
+
/* sort now that directory suffix is added */
|
|
900
|
+
git_vector_sort(contents);
|
|
901
|
+
|
|
813
902
|
git_buf_free(&full);
|
|
814
903
|
|
|
815
904
|
return error;
|
data/vendor/libgit2/src/path.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.
|
|
@@ -261,11 +261,12 @@ extern int git_path_direach(
|
|
|
261
261
|
void *state);
|
|
262
262
|
|
|
263
263
|
/**
|
|
264
|
-
* Sort function to order two paths
|
|
264
|
+
* Sort function to order two paths
|
|
265
265
|
*/
|
|
266
266
|
extern int git_path_cmp(
|
|
267
267
|
const char *name1, size_t len1, int isdir1,
|
|
268
|
-
const char *name2, size_t len2, int isdir2
|
|
268
|
+
const char *name2, size_t len2, int isdir2,
|
|
269
|
+
int (*compare)(const char *, const char *, size_t));
|
|
269
270
|
|
|
270
271
|
/**
|
|
271
272
|
* Invoke callback up path directory by directory until the ceiling is
|
|
@@ -321,18 +322,33 @@ typedef struct {
|
|
|
321
322
|
} git_path_with_stat;
|
|
322
323
|
|
|
323
324
|
extern int git_path_with_stat_cmp(const void *a, const void *b);
|
|
325
|
+
extern int git_path_with_stat_cmp_icase(const void *a, const void *b);
|
|
324
326
|
|
|
325
327
|
/**
|
|
326
328
|
* Load all directory entries along with stat info into a vector.
|
|
327
329
|
*
|
|
328
|
-
* This
|
|
329
|
-
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
330
|
+
* This adds four things on top of plain `git_path_dirload`:
|
|
331
|
+
*
|
|
332
|
+
* 1. Each entry in the vector is a `git_path_with_stat` struct that
|
|
333
|
+
* contains both the path and the stat info
|
|
334
|
+
* 2. The entries will be sorted alphabetically
|
|
335
|
+
* 3. Entries that are directories will be suffixed with a '/'
|
|
336
|
+
* 4. Optionally, you can be a start and end prefix and only elements
|
|
337
|
+
* after the start and before the end (inclusively) will be stat'ed.
|
|
338
|
+
*
|
|
339
|
+
* @param path The directory to read from
|
|
340
|
+
* @param prefix_len The trailing part of path to prefix to entry paths
|
|
341
|
+
* @param ignore_case How to sort and compare paths with start/end limits
|
|
342
|
+
* @param start_stat As optimization, only stat values after this prefix
|
|
343
|
+
* @param end_stat As optimization, only stat values before this prefix
|
|
344
|
+
* @param contents Vector to fill with git_path_with_stat structures
|
|
332
345
|
*/
|
|
333
346
|
extern int git_path_dirload_with_stat(
|
|
334
347
|
const char *path,
|
|
335
348
|
size_t prefix_len,
|
|
349
|
+
bool ignore_case,
|
|
350
|
+
const char *start_stat,
|
|
351
|
+
const char *end_stat,
|
|
336
352
|
git_vector *contents);
|
|
337
353
|
|
|
338
354
|
#endif
|
|
@@ -0,0 +1,168 @@
|
|
|
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 "pathspec.h"
|
|
9
|
+
#include "buf_text.h"
|
|
10
|
+
#include "attr_file.h"
|
|
11
|
+
|
|
12
|
+
/* what is the common non-wildcard prefix for all items in the pathspec */
|
|
13
|
+
char *git_pathspec_prefix(const git_strarray *pathspec)
|
|
14
|
+
{
|
|
15
|
+
git_buf prefix = GIT_BUF_INIT;
|
|
16
|
+
const char *scan;
|
|
17
|
+
|
|
18
|
+
if (!pathspec || !pathspec->count ||
|
|
19
|
+
git_buf_text_common_prefix(&prefix, pathspec) < 0)
|
|
20
|
+
return NULL;
|
|
21
|
+
|
|
22
|
+
/* diff prefix will only be leading non-wildcards */
|
|
23
|
+
for (scan = prefix.ptr; *scan; ++scan) {
|
|
24
|
+
if (git__iswildcard(*scan) &&
|
|
25
|
+
(scan == prefix.ptr || (*(scan - 1) != '\\')))
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
git_buf_truncate(&prefix, scan - prefix.ptr);
|
|
29
|
+
|
|
30
|
+
if (prefix.size <= 0) {
|
|
31
|
+
git_buf_free(&prefix);
|
|
32
|
+
return NULL;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
git_buf_text_unescape(&prefix);
|
|
36
|
+
|
|
37
|
+
return git_buf_detach(&prefix);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* is there anything in the spec that needs to be filtered on */
|
|
41
|
+
bool git_pathspec_is_empty(const git_strarray *pathspec)
|
|
42
|
+
{
|
|
43
|
+
size_t i;
|
|
44
|
+
|
|
45
|
+
if (pathspec == NULL)
|
|
46
|
+
return true;
|
|
47
|
+
|
|
48
|
+
for (i = 0; i < pathspec->count; ++i) {
|
|
49
|
+
const char *str = pathspec->strings[i];
|
|
50
|
+
|
|
51
|
+
if (str && str[0])
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/* build a vector of fnmatch patterns to evaluate efficiently */
|
|
59
|
+
int git_pathspec_init(
|
|
60
|
+
git_vector *vspec, const git_strarray *strspec, git_pool *strpool)
|
|
61
|
+
{
|
|
62
|
+
size_t i;
|
|
63
|
+
|
|
64
|
+
memset(vspec, 0, sizeof(*vspec));
|
|
65
|
+
|
|
66
|
+
if (git_pathspec_is_empty(strspec))
|
|
67
|
+
return 0;
|
|
68
|
+
|
|
69
|
+
if (git_vector_init(vspec, strspec->count, NULL) < 0)
|
|
70
|
+
return -1;
|
|
71
|
+
|
|
72
|
+
for (i = 0; i < strspec->count; ++i) {
|
|
73
|
+
int ret;
|
|
74
|
+
const char *pattern = strspec->strings[i];
|
|
75
|
+
git_attr_fnmatch *match = git__calloc(1, sizeof(git_attr_fnmatch));
|
|
76
|
+
if (!match)
|
|
77
|
+
return -1;
|
|
78
|
+
|
|
79
|
+
match->flags = GIT_ATTR_FNMATCH_ALLOWSPACE;
|
|
80
|
+
|
|
81
|
+
ret = git_attr_fnmatch__parse(match, strpool, NULL, &pattern);
|
|
82
|
+
if (ret == GIT_ENOTFOUND) {
|
|
83
|
+
git__free(match);
|
|
84
|
+
continue;
|
|
85
|
+
} else if (ret < 0)
|
|
86
|
+
return ret;
|
|
87
|
+
|
|
88
|
+
if (git_vector_insert(vspec, match) < 0)
|
|
89
|
+
return -1;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/* free data from the pathspec vector */
|
|
96
|
+
void git_pathspec_free(git_vector *vspec)
|
|
97
|
+
{
|
|
98
|
+
git_attr_fnmatch *match;
|
|
99
|
+
unsigned int i;
|
|
100
|
+
|
|
101
|
+
git_vector_foreach(vspec, i, match) {
|
|
102
|
+
git__free(match);
|
|
103
|
+
vspec->contents[i] = NULL;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
git_vector_free(vspec);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/* match a path against the vectorized pathspec */
|
|
110
|
+
bool git_pathspec_match_path(
|
|
111
|
+
git_vector *vspec,
|
|
112
|
+
const char *path,
|
|
113
|
+
bool disable_fnmatch,
|
|
114
|
+
bool casefold,
|
|
115
|
+
const char **matched_pathspec)
|
|
116
|
+
{
|
|
117
|
+
size_t i;
|
|
118
|
+
git_attr_fnmatch *match;
|
|
119
|
+
int fnmatch_flags = 0;
|
|
120
|
+
int (*use_strcmp)(const char *, const char *);
|
|
121
|
+
int (*use_strncmp)(const char *, const char *, size_t);
|
|
122
|
+
|
|
123
|
+
if (matched_pathspec)
|
|
124
|
+
*matched_pathspec = NULL;
|
|
125
|
+
|
|
126
|
+
if (!vspec || !vspec->length)
|
|
127
|
+
return true;
|
|
128
|
+
|
|
129
|
+
if (disable_fnmatch)
|
|
130
|
+
fnmatch_flags = -1;
|
|
131
|
+
else if (casefold)
|
|
132
|
+
fnmatch_flags = FNM_CASEFOLD;
|
|
133
|
+
|
|
134
|
+
if (casefold) {
|
|
135
|
+
use_strcmp = git__strcasecmp;
|
|
136
|
+
use_strncmp = git__strncasecmp;
|
|
137
|
+
} else {
|
|
138
|
+
use_strcmp = git__strcmp;
|
|
139
|
+
use_strncmp = git__strncmp;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
git_vector_foreach(vspec, i, match) {
|
|
143
|
+
int result = (match->flags & GIT_ATTR_FNMATCH_MATCH_ALL) ? 0 : FNM_NOMATCH;
|
|
144
|
+
|
|
145
|
+
if (result == FNM_NOMATCH)
|
|
146
|
+
result = use_strcmp(match->pattern, path) ? FNM_NOMATCH : 0;
|
|
147
|
+
|
|
148
|
+
if (fnmatch_flags >= 0 && result == FNM_NOMATCH)
|
|
149
|
+
result = p_fnmatch(match->pattern, path, fnmatch_flags);
|
|
150
|
+
|
|
151
|
+
/* if we didn't match, look for exact dirname prefix match */
|
|
152
|
+
if (result == FNM_NOMATCH &&
|
|
153
|
+
(match->flags & GIT_ATTR_FNMATCH_HASWILD) == 0 &&
|
|
154
|
+
use_strncmp(path, match->pattern, match->length) == 0 &&
|
|
155
|
+
path[match->length] == '/')
|
|
156
|
+
result = 0;
|
|
157
|
+
|
|
158
|
+
if (result == 0) {
|
|
159
|
+
if (matched_pathspec)
|
|
160
|
+
*matched_pathspec = match->pattern;
|
|
161
|
+
|
|
162
|
+
return (match->flags & GIT_ATTR_FNMATCH_NEGATIVE) ? false : true;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
#ifndef INCLUDE_pathspec_h__
|
|
8
|
+
#define INCLUDE_pathspec_h__
|
|
9
|
+
|
|
10
|
+
#include "common.h"
|
|
11
|
+
#include "buffer.h"
|
|
12
|
+
#include "vector.h"
|
|
13
|
+
#include "pool.h"
|
|
14
|
+
|
|
15
|
+
/* what is the common non-wildcard prefix for all items in the pathspec */
|
|
16
|
+
extern char *git_pathspec_prefix(const git_strarray *pathspec);
|
|
17
|
+
|
|
18
|
+
/* is there anything in the spec that needs to be filtered on */
|
|
19
|
+
extern bool git_pathspec_is_empty(const git_strarray *pathspec);
|
|
20
|
+
|
|
21
|
+
/* build a vector of fnmatch patterns to evaluate efficiently */
|
|
22
|
+
extern int git_pathspec_init(
|
|
23
|
+
git_vector *vspec, const git_strarray *strspec, git_pool *strpool);
|
|
24
|
+
|
|
25
|
+
/* free data from the pathspec vector */
|
|
26
|
+
extern void git_pathspec_free(git_vector *vspec);
|
|
27
|
+
|
|
28
|
+
/*
|
|
29
|
+
* Match a path against the vectorized pathspec.
|
|
30
|
+
* The matched pathspec is passed back into the `matched_pathspec` parameter,
|
|
31
|
+
* unless it is passed as NULL by the caller.
|
|
32
|
+
*/
|
|
33
|
+
extern bool git_pathspec_match_path(
|
|
34
|
+
git_vector *vspec,
|
|
35
|
+
const char *path,
|
|
36
|
+
bool disable_fnmatch,
|
|
37
|
+
bool casefold,
|
|
38
|
+
const char **matched_pathspec);
|
|
39
|
+
|
|
40
|
+
#endif
|