rugged 0.19.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +1 -1
- data/README.md +151 -25
- data/ext/rugged/extconf.rb +48 -27
- data/ext/rugged/rugged.c +107 -35
- data/ext/rugged/rugged.h +44 -8
- data/ext/rugged/rugged_blame.c +292 -0
- data/ext/rugged/rugged_blob.c +84 -31
- data/ext/rugged/rugged_branch.c +90 -223
- data/ext/rugged/rugged_branch_collection.c +445 -0
- data/ext/rugged/rugged_commit.c +190 -9
- data/ext/rugged/rugged_config.c +1 -1
- data/ext/rugged/rugged_cred.c +125 -0
- data/ext/rugged/rugged_diff.c +267 -94
- data/ext/rugged/rugged_diff_delta.c +14 -3
- data/ext/rugged/rugged_diff_hunk.c +31 -28
- data/ext/rugged/rugged_diff_line.c +21 -17
- data/ext/rugged/rugged_index.c +326 -6
- data/ext/rugged/rugged_note.c +39 -34
- data/ext/rugged/rugged_object.c +9 -9
- data/ext/rugged/rugged_patch.c +245 -0
- data/ext/rugged/rugged_reference.c +67 -332
- data/ext/rugged/rugged_reference_collection.c +490 -0
- data/ext/rugged/rugged_remote.c +447 -351
- data/ext/rugged/rugged_remote_collection.c +285 -0
- data/ext/rugged/rugged_repo.c +752 -203
- data/ext/rugged/rugged_revwalk.c +119 -27
- data/ext/rugged/rugged_settings.c +48 -1
- data/ext/rugged/rugged_signature.c +30 -16
- data/ext/rugged/rugged_tag.c +86 -191
- data/ext/rugged/rugged_tag_collection.c +279 -0
- data/ext/rugged/rugged_tree.c +159 -22
- data/lib/rugged/branch.rb +8 -17
- data/lib/rugged/credentials.rb +43 -0
- data/lib/rugged/diff/delta.rb +1 -2
- data/lib/rugged/diff/hunk.rb +4 -9
- data/lib/rugged/diff/line.rb +23 -3
- data/lib/rugged/diff.rb +3 -1
- data/lib/rugged/patch.rb +26 -0
- data/lib/rugged/reference.rb +1 -3
- data/lib/rugged/remote.rb +0 -9
- data/lib/rugged/repository.rb +70 -13
- data/lib/rugged/tag.rb +23 -18
- data/lib/rugged/tree.rb +7 -0
- data/lib/rugged/version.rb +1 -1
- data/lib/rugged.rb +8 -1
- data/vendor/libgit2/AUTHORS +75 -0
- data/vendor/libgit2/CMakeLists.txt +490 -0
- data/vendor/libgit2/COPYING +920 -0
- data/vendor/libgit2/Makefile.embed +25 -7
- data/vendor/libgit2/cmake/Modules/AddCFlagIfSupported.cmake +16 -0
- data/vendor/libgit2/cmake/Modules/FindHTTP_Parser.cmake +39 -0
- data/vendor/libgit2/cmake/Modules/FindIconv.cmake +43 -0
- data/vendor/libgit2/cmake/Modules/FindLIBSSH2.cmake +44 -0
- data/vendor/libgit2/deps/http-parser/LICENSE-MIT +23 -0
- data/vendor/libgit2/deps/regex/regex.c +10 -3
- data/vendor/libgit2/include/git2/attr.h +2 -1
- data/vendor/libgit2/include/git2/blame.h +213 -0
- data/vendor/libgit2/include/git2/blob.h +57 -29
- data/vendor/libgit2/include/git2/branch.h +56 -44
- data/vendor/libgit2/include/git2/buffer.h +112 -0
- data/vendor/libgit2/include/git2/checkout.h +72 -37
- data/vendor/libgit2/include/git2/cherrypick.h +87 -0
- data/vendor/libgit2/include/git2/clone.h +153 -56
- data/vendor/libgit2/include/git2/commit.h +82 -12
- data/vendor/libgit2/include/git2/common.h +31 -19
- data/vendor/libgit2/include/git2/config.h +124 -19
- data/vendor/libgit2/include/git2/cred_helpers.h +1 -1
- data/vendor/libgit2/include/git2/diff.h +636 -494
- data/vendor/libgit2/include/git2/errors.h +48 -15
- data/vendor/libgit2/include/git2/filter.h +149 -0
- data/vendor/libgit2/include/git2/graph.h +14 -0
- data/vendor/libgit2/include/git2/index.h +95 -54
- data/vendor/libgit2/include/git2/indexer.h +15 -9
- data/vendor/libgit2/include/git2/merge.h +402 -39
- data/vendor/libgit2/include/git2/message.h +9 -14
- data/vendor/libgit2/include/git2/net.h +5 -0
- data/vendor/libgit2/include/git2/notes.h +6 -6
- data/vendor/libgit2/include/git2/object.h +34 -2
- data/vendor/libgit2/include/git2/odb.h +77 -14
- data/vendor/libgit2/include/git2/odb_backend.h +50 -6
- data/vendor/libgit2/include/git2/oid.h +4 -8
- data/vendor/libgit2/include/git2/pack.h +58 -4
- data/vendor/libgit2/include/git2/patch.h +277 -0
- data/vendor/libgit2/include/git2/pathspec.h +263 -0
- data/vendor/libgit2/include/git2/push.h +55 -5
- data/vendor/libgit2/include/git2/reflog.h +11 -8
- data/vendor/libgit2/include/git2/refs.h +219 -33
- data/vendor/libgit2/include/git2/refspec.h +3 -4
- data/vendor/libgit2/include/git2/remote.h +216 -76
- data/vendor/libgit2/include/git2/repository.h +85 -40
- data/vendor/libgit2/include/git2/reset.h +15 -4
- data/vendor/libgit2/include/git2/revert.h +86 -0
- data/vendor/libgit2/include/git2/revparse.h +27 -16
- data/vendor/libgit2/include/git2/revwalk.h +44 -6
- data/vendor/libgit2/include/git2/signature.h +17 -3
- data/vendor/libgit2/include/git2/stash.h +8 -12
- data/vendor/libgit2/include/git2/status.h +67 -18
- data/vendor/libgit2/include/git2/submodule.h +100 -85
- data/vendor/libgit2/include/git2/sys/commit.h +38 -4
- data/vendor/libgit2/include/git2/sys/config.h +44 -3
- data/vendor/libgit2/include/git2/sys/diff.h +91 -0
- data/vendor/libgit2/include/git2/sys/filter.h +301 -0
- data/vendor/libgit2/include/git2/sys/index.h +0 -2
- data/vendor/libgit2/include/git2/sys/mempack.h +85 -0
- data/vendor/libgit2/include/git2/sys/odb_backend.h +33 -11
- data/vendor/libgit2/include/git2/sys/refdb_backend.h +51 -5
- data/vendor/libgit2/include/git2/sys/reflog.h +21 -0
- data/vendor/libgit2/include/git2/sys/refs.h +2 -2
- data/vendor/libgit2/include/git2/sys/repository.h +19 -1
- data/vendor/libgit2/include/git2/transport.h +216 -75
- data/vendor/libgit2/include/git2/tree.h +32 -11
- data/vendor/libgit2/include/git2/types.h +124 -10
- data/vendor/libgit2/include/git2/version.h +4 -2
- data/vendor/libgit2/include/git2.h +41 -40
- data/vendor/libgit2/libgit2.pc.in +10 -0
- data/vendor/libgit2/src/array.h +16 -8
- data/vendor/libgit2/src/attr.c +140 -402
- data/vendor/libgit2/src/attr.h +1 -33
- data/vendor/libgit2/src/attr_file.c +298 -135
- data/vendor/libgit2/src/attr_file.h +61 -22
- data/vendor/libgit2/src/attrcache.c +449 -0
- data/vendor/libgit2/src/attrcache.h +38 -6
- data/vendor/libgit2/src/bitvec.h +75 -0
- data/vendor/libgit2/src/blame.c +488 -0
- data/vendor/libgit2/src/blame.h +93 -0
- data/vendor/libgit2/src/blame_git.c +624 -0
- data/vendor/libgit2/src/blame_git.h +20 -0
- data/vendor/libgit2/src/blob.c +137 -92
- data/vendor/libgit2/src/blob.h +9 -0
- data/vendor/libgit2/src/branch.c +175 -156
- data/vendor/libgit2/src/buf_text.c +29 -14
- data/vendor/libgit2/src/buf_text.h +5 -4
- data/vendor/libgit2/src/buffer.c +158 -15
- data/vendor/libgit2/src/buffer.h +33 -20
- data/vendor/libgit2/src/cc-compat.h +8 -2
- data/vendor/libgit2/src/checkout.c +1081 -287
- data/vendor/libgit2/src/checkout.h +1 -1
- data/vendor/libgit2/src/cherrypick.c +226 -0
- data/vendor/libgit2/src/clone.c +297 -245
- data/vendor/libgit2/src/{compress.h → clone.h} +4 -8
- data/vendor/libgit2/src/commit.c +313 -101
- data/vendor/libgit2/src/commit.h +6 -3
- data/vendor/libgit2/src/commit_list.c +3 -3
- data/vendor/libgit2/src/commit_list.h +1 -1
- data/vendor/libgit2/src/common.h +74 -1
- data/vendor/libgit2/src/config.c +570 -145
- data/vendor/libgit2/src/config.h +39 -6
- data/vendor/libgit2/src/config_cache.c +32 -18
- data/vendor/libgit2/src/config_file.c +711 -424
- data/vendor/libgit2/src/config_file.h +4 -3
- data/vendor/libgit2/src/crlf.c +149 -109
- data/vendor/libgit2/src/date.c +35 -7
- data/vendor/libgit2/src/delta.c +1 -1
- data/vendor/libgit2/src/diff.c +719 -414
- data/vendor/libgit2/src/diff.h +52 -7
- data/vendor/libgit2/src/diff_driver.c +183 -85
- data/vendor/libgit2/src/diff_driver.h +1 -1
- data/vendor/libgit2/src/diff_file.c +65 -84
- data/vendor/libgit2/src/diff_file.h +12 -10
- data/vendor/libgit2/src/diff_patch.c +274 -333
- data/vendor/libgit2/src/diff_patch.h +10 -9
- data/vendor/libgit2/src/diff_print.c +381 -179
- data/vendor/libgit2/src/diff_stats.c +336 -0
- data/vendor/libgit2/src/diff_tform.c +393 -215
- data/vendor/libgit2/src/diff_xdiff.c +117 -42
- data/vendor/libgit2/src/errors.c +59 -4
- data/vendor/libgit2/src/fetch.c +40 -34
- data/vendor/libgit2/src/fetch.h +2 -5
- data/vendor/libgit2/src/fetchhead.c +14 -7
- data/vendor/libgit2/src/filebuf.c +13 -24
- data/vendor/libgit2/src/filebuf.h +3 -3
- data/vendor/libgit2/src/fileops.c +104 -296
- data/vendor/libgit2/src/fileops.h +23 -94
- data/vendor/libgit2/src/filter.c +642 -43
- data/vendor/libgit2/src/filter.h +7 -66
- data/vendor/libgit2/src/fnmatch.c +46 -3
- data/vendor/libgit2/src/fnmatch.h +24 -3
- data/vendor/libgit2/src/global.c +158 -42
- data/vendor/libgit2/src/global.h +9 -0
- data/vendor/libgit2/src/graph.c +34 -20
- data/vendor/libgit2/src/hash/hash_generic.h +0 -1
- data/vendor/libgit2/src/hash/hash_openssl.h +0 -1
- data/vendor/libgit2/src/hash/hash_win32.c +14 -29
- data/vendor/libgit2/src/hash.h +0 -2
- data/vendor/libgit2/src/hashsig.c +97 -117
- data/vendor/libgit2/src/ident.c +125 -0
- data/vendor/libgit2/src/ignore.c +159 -110
- data/vendor/libgit2/src/ignore.h +13 -3
- data/vendor/libgit2/src/index.c +803 -445
- data/vendor/libgit2/src/index.h +43 -6
- data/vendor/libgit2/src/indexer.c +475 -157
- data/vendor/libgit2/src/iterator.c +198 -55
- data/vendor/libgit2/src/iterator.h +28 -4
- data/vendor/libgit2/src/map.h +1 -0
- data/vendor/libgit2/src/merge.c +849 -142
- data/vendor/libgit2/src/merge.h +11 -4
- data/vendor/libgit2/src/merge_file.c +183 -78
- data/vendor/libgit2/src/merge_file.h +0 -57
- data/vendor/libgit2/src/message.c +4 -28
- data/vendor/libgit2/src/mwindow.c +117 -8
- data/vendor/libgit2/src/mwindow.h +9 -1
- data/vendor/libgit2/src/netops.c +164 -59
- data/vendor/libgit2/src/netops.h +37 -1
- data/vendor/libgit2/src/notes.c +9 -18
- data/vendor/libgit2/src/notes.h +1 -1
- data/vendor/libgit2/src/object.c +78 -2
- data/vendor/libgit2/src/odb.c +191 -59
- data/vendor/libgit2/src/odb.h +2 -1
- data/vendor/libgit2/src/odb_loose.c +66 -51
- data/vendor/libgit2/src/odb_mempack.c +182 -0
- data/vendor/libgit2/src/odb_pack.c +151 -61
- data/vendor/libgit2/src/oid.c +30 -19
- data/vendor/libgit2/src/oid.h +13 -10
- data/vendor/libgit2/src/pack-objects.c +198 -147
- data/vendor/libgit2/src/pack-objects.h +7 -0
- data/vendor/libgit2/src/pack.c +272 -101
- data/vendor/libgit2/src/pack.h +15 -1
- data/vendor/libgit2/src/path.c +359 -117
- data/vendor/libgit2/src/path.h +110 -20
- data/vendor/libgit2/src/pathspec.c +583 -57
- data/vendor/libgit2/src/pathspec.h +36 -15
- data/vendor/libgit2/src/pool.c +4 -5
- data/vendor/libgit2/src/posix.c +45 -2
- data/vendor/libgit2/src/posix.h +13 -5
- data/vendor/libgit2/src/pqueue.c +73 -119
- data/vendor/libgit2/src/pqueue.h +35 -82
- data/vendor/libgit2/src/push.c +116 -48
- data/vendor/libgit2/src/push.h +5 -0
- data/vendor/libgit2/src/refdb.c +45 -6
- data/vendor/libgit2/src/refdb.h +13 -3
- data/vendor/libgit2/src/refdb_fs.c +1130 -551
- data/vendor/libgit2/src/reflog.c +36 -327
- data/vendor/libgit2/src/reflog.h +6 -1
- data/vendor/libgit2/src/refs.c +345 -142
- data/vendor/libgit2/src/refs.h +9 -2
- data/vendor/libgit2/src/refspec.c +90 -62
- data/vendor/libgit2/src/refspec.h +7 -24
- data/vendor/libgit2/src/remote.c +815 -415
- data/vendor/libgit2/src/remote.h +3 -4
- data/vendor/libgit2/src/repository.c +360 -207
- data/vendor/libgit2/src/repository.h +16 -10
- data/vendor/libgit2/src/reset.c +28 -13
- data/vendor/libgit2/src/revert.c +228 -0
- data/vendor/libgit2/src/revparse.c +29 -30
- data/vendor/libgit2/src/revwalk.c +141 -96
- data/vendor/libgit2/src/revwalk.h +6 -1
- data/vendor/libgit2/src/settings.c +140 -0
- data/vendor/libgit2/src/sha1_lookup.c +71 -0
- data/vendor/libgit2/src/sha1_lookup.h +5 -0
- data/vendor/libgit2/src/signature.c +38 -10
- data/vendor/libgit2/src/sortedcache.c +378 -0
- data/vendor/libgit2/src/sortedcache.h +178 -0
- data/vendor/libgit2/src/stash.c +98 -116
- data/vendor/libgit2/src/status.c +88 -60
- data/vendor/libgit2/src/status.h +2 -2
- data/vendor/libgit2/src/strmap.c +32 -0
- data/vendor/libgit2/src/strmap.h +14 -1
- data/vendor/libgit2/src/strnlen.h +23 -0
- data/vendor/libgit2/src/submodule.c +1073 -615
- data/vendor/libgit2/src/submodule.h +89 -21
- data/vendor/libgit2/src/sysdir.c +252 -0
- data/vendor/libgit2/src/sysdir.h +101 -0
- data/vendor/libgit2/src/tag.c +31 -20
- data/vendor/libgit2/src/thread-utils.h +98 -17
- data/vendor/libgit2/src/trace.h +0 -2
- data/vendor/libgit2/src/transport.c +76 -6
- data/vendor/libgit2/src/transports/cred.c +164 -61
- data/vendor/libgit2/src/transports/git.c +41 -48
- data/vendor/libgit2/src/transports/http.c +65 -109
- data/vendor/libgit2/src/transports/local.c +88 -65
- data/vendor/libgit2/src/transports/smart.c +91 -19
- data/vendor/libgit2/src/transports/smart.h +13 -5
- data/vendor/libgit2/src/transports/smart_pkt.c +24 -14
- data/vendor/libgit2/src/transports/smart_protocol.c +268 -113
- data/vendor/libgit2/src/transports/ssh.c +284 -186
- data/vendor/libgit2/src/transports/winhttp.c +279 -198
- data/vendor/libgit2/src/tree-cache.c +21 -23
- data/vendor/libgit2/src/tree-cache.h +1 -0
- data/vendor/libgit2/src/tree.c +109 -92
- data/vendor/libgit2/src/tree.h +2 -3
- data/vendor/libgit2/src/unix/map.c +7 -1
- data/vendor/libgit2/src/unix/posix.h +0 -1
- data/vendor/libgit2/src/userdiff.h +208 -0
- data/vendor/libgit2/src/util.c +16 -112
- data/vendor/libgit2/src/util.h +107 -3
- data/vendor/libgit2/src/vector.c +72 -17
- data/vendor/libgit2/src/vector.h +32 -5
- data/vendor/libgit2/src/win32/dir.c +15 -40
- data/vendor/libgit2/src/win32/dir.h +3 -2
- data/vendor/libgit2/src/win32/error.c +5 -31
- data/vendor/libgit2/src/win32/findfile.c +47 -66
- data/vendor/libgit2/src/win32/findfile.h +1 -12
- data/vendor/libgit2/src/win32/git2.rc +40 -0
- data/vendor/libgit2/src/win32/map.c +7 -1
- data/vendor/libgit2/src/win32/mingw-compat.h +3 -0
- data/vendor/libgit2/src/win32/posix.h +17 -11
- data/vendor/libgit2/src/win32/posix_w32.c +424 -292
- data/vendor/libgit2/src/win32/precompiled.h +6 -2
- data/vendor/libgit2/src/win32/pthread.c +141 -18
- data/vendor/libgit2/src/win32/pthread.h +50 -8
- data/vendor/libgit2/src/win32/reparse.h +57 -0
- data/vendor/libgit2/src/win32/utf-conv.c +117 -60
- data/vendor/libgit2/src/win32/utf-conv.h +81 -6
- data/vendor/libgit2/src/win32/version.h +21 -4
- data/vendor/libgit2/src/win32/w32_util.c +139 -0
- data/vendor/libgit2/src/win32/w32_util.h +54 -0
- data/vendor/libgit2/src/zstream.c +156 -0
- data/vendor/libgit2/src/zstream.h +39 -0
- metadata +84 -167
- data/Rakefile +0 -61
- data/ext/rugged/rugged_diff_patch.c +0 -169
- data/lib/rugged/diff/patch.rb +0 -28
- data/test/blob_test.rb +0 -341
- data/test/branch_test.rb +0 -199
- data/test/commit_test.rb +0 -104
- data/test/config_test.rb +0 -45
- data/test/coverage/cover.rb +0 -133
- data/test/diff_test.rb +0 -777
- data/test/errors_test.rb +0 -34
- 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/archive.tar.gz +0 -0
- data/test/fixtures/attr/attr0 +0 -1
- data/test/fixtures/attr/attr1 +0 -29
- data/test/fixtures/attr/attr2 +0 -21
- data/test/fixtures/attr/attr3 +0 -4
- data/test/fixtures/attr/binfile +0 -1
- data/test/fixtures/attr/dir/file +0 -0
- data/test/fixtures/attr/file +0 -1
- data/test/fixtures/attr/gitattributes +0 -29
- data/test/fixtures/attr/gitignore +0 -2
- data/test/fixtures/attr/ign +0 -1
- data/test/fixtures/attr/macro_bad +0 -1
- data/test/fixtures/attr/macro_test +0 -1
- data/test/fixtures/attr/root_test1 +0 -1
- data/test/fixtures/attr/root_test2 +0 -6
- data/test/fixtures/attr/root_test3 +0 -19
- data/test/fixtures/attr/root_test4.txt +0 -14
- data/test/fixtures/attr/sub/abc +0 -37
- data/test/fixtures/attr/sub/dir/file +0 -0
- data/test/fixtures/attr/sub/file +0 -1
- data/test/fixtures/attr/sub/ign/file +0 -1
- data/test/fixtures/attr/sub/ign/sub/file +0 -1
- data/test/fixtures/attr/sub/sub/dir +0 -0
- data/test/fixtures/attr/sub/sub/file +0 -1
- data/test/fixtures/attr/sub/sub/subsub.txt +0 -1
- data/test/fixtures/attr/sub/subdir_test1 +0 -2
- data/test/fixtures/attr/sub/subdir_test2.txt +0 -1
- data/test/fixtures/diff/another.txt +0 -38
- data/test/fixtures/diff/readme.txt +0 -36
- data/test/fixtures/mergedrepo/conflicts-one.txt +0 -5
- data/test/fixtures/mergedrepo/conflicts-two.txt +0 -5
- data/test/fixtures/mergedrepo/one.txt +0 -10
- data/test/fixtures/mergedrepo/two.txt +0 -12
- data/test/fixtures/status/current_file +0 -1
- data/test/fixtures/status/ignored_file +0 -1
- data/test/fixtures/status/modified_file +0 -2
- data/test/fixtures/status/new_file +0 -1
- data/test/fixtures/status/staged_changes +0 -2
- data/test/fixtures/status/staged_changes_modified_file +0 -3
- data/test/fixtures/status/staged_delete_modified_file +0 -1
- data/test/fixtures/status/staged_new_file +0 -1
- data/test/fixtures/status/staged_new_file_modified_file +0 -2
- data/test/fixtures/status/subdir/current_file +0 -1
- data/test/fixtures/status/subdir/modified_file +0 -2
- data/test/fixtures/status/subdir/new_file +0 -1
- data/test/fixtures/status/subdir.txt +0 -2
- data/test/fixtures/status//350/277/231 +0 -1
- data/test/fixtures/testrepo.git/HEAD +0 -1
- data/test/fixtures/testrepo.git/config +0 -13
- data/test/fixtures/testrepo.git/description +0 -1
- data/test/fixtures/testrepo.git/index +0 -0
- data/test/fixtures/testrepo.git/info/exclude +0 -6
- data/test/fixtures/testrepo.git/logs/HEAD +0 -3
- data/test/fixtures/testrepo.git/logs/refs/heads/master +0 -3
- data/test/fixtures/testrepo.git/logs/refs/notes/commits +0 -1
- data/test/fixtures/testrepo.git/objects/0c/37a5391bbff43c37f0d0371823a5509eed5b1d +0 -0
- data/test/fixtures/testrepo.git/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08 +0 -0
- data/test/fixtures/testrepo.git/objects/18/1037049a54a1eb5fab404658a3a250b44335d7 +0 -0
- data/test/fixtures/testrepo.git/objects/18/10dff58d8a660512d4832e740f692884338ccd +0 -0
- data/test/fixtures/testrepo.git/objects/2d/2eff63372b08adf0a9eb84109ccf7d19e2f3a2 +0 -0
- data/test/fixtures/testrepo.git/objects/36/060c58702ed4c2a40832c51758d5344201d89a +0 -2
- data/test/fixtures/testrepo.git/objects/44/1034f860c1d5d90e4188d11ae0d325176869a8 +0 -1
- data/test/fixtures/testrepo.git/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 +0 -0
- data/test/fixtures/testrepo.git/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 +0 -2
- data/test/fixtures/testrepo.git/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644 +0 -2
- data/test/fixtures/testrepo.git/objects/60/d415052a33de2150bf68757f6461df4f563ae4 +0 -0
- data/test/fixtures/testrepo.git/objects/61/9f9935957e010c419cb9d15621916ddfcc0b96 +0 -0
- data/test/fixtures/testrepo.git/objects/68/8a8f4ef7496901d15322972f96e212a9e466cc +0 -1
- data/test/fixtures/testrepo.git/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a +0 -0
- data/test/fixtures/testrepo.git/objects/77/71329dfa3002caf8c61a0ceb62a31d09023f37 +0 -0
- data/test/fixtures/testrepo.git/objects/81/4889a078c031f61ed08ab5fa863aea9314344d +0 -0
- data/test/fixtures/testrepo.git/objects/84/96071c1b46c854b31185ea97743be6a8774479 +0 -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/9f/d738e8f7967c078dceed8190330fc8648ee56a +0 -3
- data/test/fixtures/testrepo.git/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f +0 -2
- data/test/fixtures/testrepo.git/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd +0 -0
- data/test/fixtures/testrepo.git/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 +0 -0
- data/test/fixtures/testrepo.git/objects/b7/4713326bc972cc15751ed504dca6f6f3b91f7a +0 -3
- data/test/fixtures/testrepo.git/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 +0 -3
- data/test/fixtures/testrepo.git/objects/c4/7800c7266a2be04c571c04d5a6614691ea99bd +0 -3
- data/test/fixtures/testrepo.git/objects/c4/dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b +0 -0
- data/test/fixtures/testrepo.git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +0 -0
- data/test/fixtures/testrepo.git/objects/f6/0079018b664e4e79329a7ef9559c8d9e0378d1 +0 -0
- data/test/fixtures/testrepo.git/objects/fa/49b077972391ad58037050f2a75f74e3671e92 +0 -0
- data/test/fixtures/testrepo.git/objects/fd/093bff70906175335656e6ce6ae05783708765 +0 -0
- data/test/fixtures/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.idx +0 -0
- data/test/fixtures/testrepo.git/objects/pack/pack-d7c6adf9f61318f041845b01440d09aa7a91e1b5.pack +0 -0
- data/test/fixtures/testrepo.git/packed-refs +0 -2
- data/test/fixtures/testrepo.git/refs/heads/master +0 -1
- data/test/fixtures/testrepo.git/refs/notes/commits +0 -1
- data/test/fixtures/testrepo.git/refs/tags/v0.9 +0 -1
- data/test/fixtures/testrepo.git/refs/tags/v1.0 +0 -1
- data/test/fixtures/text_file.md +0 -464
- data/test/fixtures/unsymlinked.git/HEAD +0 -1
- data/test/fixtures/unsymlinked.git/config +0 -6
- data/test/fixtures/unsymlinked.git/description +0 -1
- data/test/fixtures/unsymlinked.git/info/exclude +0 -2
- data/test/fixtures/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf +0 -0
- data/test/fixtures/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30b +0 -0
- data/test/fixtures/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c +0 -0
- data/test/fixtures/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773 +0 -0
- data/test/fixtures/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c +0 -0
- data/test/fixtures/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 +0 -0
- data/test/fixtures/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d +0 -0
- data/test/fixtures/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3 +0 -0
- data/test/fixtures/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230 +0 -0
- data/test/fixtures/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b6 +0 -2
- data/test/fixtures/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7 +0 -0
- data/test/fixtures/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a +0 -0
- data/test/fixtures/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9 +0 -0
- data/test/fixtures/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006 +0 -0
- data/test/fixtures/unsymlinked.git/refs/heads/exe-file +0 -1
- data/test/fixtures/unsymlinked.git/refs/heads/master +0 -1
- data/test/fixtures/unsymlinked.git/refs/heads/reg-file +0 -1
- data/test/index_test.rb +0 -333
- data/test/lib_test.rb +0 -127
- data/test/note_test.rb +0 -158
- data/test/object_test.rb +0 -43
- data/test/reference_test.rb +0 -207
- data/test/remote_test.rb +0 -324
- data/test/repo_pack_test.rb +0 -24
- data/test/repo_reset_test.rb +0 -82
- data/test/repo_test.rb +0 -402
- data/test/tag_test.rb +0 -68
- data/test/test_helper.rb +0 -92
- data/test/tree_test.rb +0 -91
- data/test/walker_test.rb +0 -88
- data/vendor/libgit2/src/amiga/map.c +0 -48
- data/vendor/libgit2/src/compress.c +0 -53
@@ -6,6 +6,7 @@
|
|
6
6
|
*/
|
7
7
|
#include "common.h"
|
8
8
|
#include "fileops.h"
|
9
|
+
#include "global.h"
|
9
10
|
#include <ctype.h>
|
10
11
|
#if GIT_WIN32
|
11
12
|
#include "win32/findfile.h"
|
@@ -18,9 +19,12 @@ int git_futils_mkpath2file(const char *file_path, const mode_t mode)
|
|
18
19
|
GIT_MKDIR_PATH | GIT_MKDIR_SKIP_LAST | GIT_MKDIR_VERIFY_DIR);
|
19
20
|
}
|
20
21
|
|
21
|
-
int git_futils_mktmp(git_buf *path_out, const char *filename)
|
22
|
+
int git_futils_mktmp(git_buf *path_out, const char *filename, mode_t mode)
|
22
23
|
{
|
23
24
|
int fd;
|
25
|
+
mode_t mask;
|
26
|
+
|
27
|
+
p_umask(mask = p_umask(0));
|
24
28
|
|
25
29
|
git_buf_sets(path_out, filename);
|
26
30
|
git_buf_puts(path_out, "_git2_XXXXXX");
|
@@ -34,6 +38,12 @@ int git_futils_mktmp(git_buf *path_out, const char *filename)
|
|
34
38
|
return -1;
|
35
39
|
}
|
36
40
|
|
41
|
+
if (p_chmod(path_out->ptr, (mode & ~mask))) {
|
42
|
+
giterr_set(GITERR_OS,
|
43
|
+
"Failed to set permissions on file '%s'", path_out->ptr);
|
44
|
+
return -1;
|
45
|
+
}
|
46
|
+
|
37
47
|
return fd;
|
38
48
|
}
|
39
49
|
|
@@ -55,22 +65,12 @@ int git_futils_creat_withpath(const char *path, const mode_t dirmode, const mode
|
|
55
65
|
|
56
66
|
int git_futils_creat_locked(const char *path, const mode_t mode)
|
57
67
|
{
|
58
|
-
int fd
|
59
|
-
|
60
|
-
#ifdef GIT_WIN32
|
61
|
-
wchar_t buf[GIT_WIN_PATH];
|
62
|
-
|
63
|
-
git__utf8_to_16(buf, GIT_WIN_PATH, path);
|
64
|
-
fd = _wopen(buf, O_WRONLY | O_CREAT | O_TRUNC |
|
68
|
+
int fd = p_open(path, O_WRONLY | O_CREAT | O_TRUNC |
|
65
69
|
O_EXCL | O_BINARY | O_CLOEXEC, mode);
|
66
|
-
#else
|
67
|
-
fd = open(path, O_WRONLY | O_CREAT | O_TRUNC |
|
68
|
-
O_EXCL | O_BINARY | O_CLOEXEC, mode);
|
69
|
-
#endif
|
70
70
|
|
71
71
|
if (fd < 0) {
|
72
72
|
giterr_set(GITERR_OS, "Failed to create locked file '%s'", path);
|
73
|
-
return -1;
|
73
|
+
return errno == EEXIST ? GIT_ELOCKED : -1;
|
74
74
|
}
|
75
75
|
|
76
76
|
return fd;
|
@@ -87,11 +87,8 @@ int git_futils_creat_locked_withpath(const char *path, const mode_t dirmode, con
|
|
87
87
|
int git_futils_open_ro(const char *path)
|
88
88
|
{
|
89
89
|
int fd = p_open(path, O_RDONLY);
|
90
|
-
if (fd < 0)
|
91
|
-
|
92
|
-
fd = GIT_ENOTFOUND;
|
93
|
-
giterr_set(GITERR_OS, "Failed to open '%s'", path);
|
94
|
-
}
|
90
|
+
if (fd < 0)
|
91
|
+
return git_path_set_error(errno, path, "open");
|
95
92
|
return fd;
|
96
93
|
}
|
97
94
|
|
@@ -110,7 +107,7 @@ git_off_t git_futils_filesize(git_file fd)
|
|
110
107
|
mode_t git_futils_canonical_mode(mode_t raw_mode)
|
111
108
|
{
|
112
109
|
if (S_ISREG(raw_mode))
|
113
|
-
return S_IFREG |
|
110
|
+
return S_IFREG | GIT_PERMS_CANONICAL(raw_mode);
|
114
111
|
else if (S_ISLNK(raw_mode))
|
115
112
|
return S_IFLNK;
|
116
113
|
else if (S_ISGITLINK(raw_mode))
|
@@ -135,6 +132,7 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
|
|
135
132
|
|
136
133
|
if (read_size != (ssize_t)len) {
|
137
134
|
giterr_set(GITERR_OS, "Failed to read descriptor");
|
135
|
+
git_buf_free(buf);
|
138
136
|
return -1;
|
139
137
|
}
|
140
138
|
|
@@ -156,11 +154,16 @@ int git_futils_readbuffer_updated(
|
|
156
154
|
if (updated != NULL)
|
157
155
|
*updated = 0;
|
158
156
|
|
159
|
-
if ((
|
160
|
-
return
|
157
|
+
if (p_stat(path, &st) < 0)
|
158
|
+
return git_path_set_error(errno, path, "stat");
|
161
159
|
|
162
|
-
|
163
|
-
|
160
|
+
|
161
|
+
if (S_ISDIR(st.st_mode)) {
|
162
|
+
giterr_set(GITERR_INVALID, "requested file is a directory");
|
163
|
+
return GIT_ENOTFOUND;
|
164
|
+
}
|
165
|
+
|
166
|
+
if (!git__is_sizet(st.st_size+1)) {
|
164
167
|
giterr_set(GITERR_OS, "Invalid regular file stat for '%s'", path);
|
165
168
|
return -1;
|
166
169
|
}
|
@@ -177,7 +180,6 @@ int git_futils_readbuffer_updated(
|
|
177
180
|
changed = true;
|
178
181
|
|
179
182
|
if (!changed) {
|
180
|
-
p_close(fd);
|
181
183
|
return 0;
|
182
184
|
}
|
183
185
|
|
@@ -186,6 +188,9 @@ int git_futils_readbuffer_updated(
|
|
186
188
|
if (size != NULL)
|
187
189
|
*size = (size_t)st.st_size;
|
188
190
|
|
191
|
+
if ((fd = git_futils_open_ro(path)) < 0)
|
192
|
+
return fd;
|
193
|
+
|
189
194
|
if (git_futils_readbuffer_fd(buf, fd, (size_t)st.st_size) < 0) {
|
190
195
|
p_close(fd);
|
191
196
|
return -1;
|
@@ -222,6 +227,7 @@ int git_futils_writebuffer(
|
|
222
227
|
if ((error = p_write(fd, git_buf_cstr(buf), git_buf_len(buf))) < 0) {
|
223
228
|
giterr_set(GITERR_OS, "Could not write to '%s'", path);
|
224
229
|
(void)p_close(fd);
|
230
|
+
return error;
|
225
231
|
}
|
226
232
|
|
227
233
|
if ((error = p_close(fd)) < 0)
|
@@ -347,11 +353,11 @@ int git_futils_mkdir(
|
|
347
353
|
|
348
354
|
/* make directory */
|
349
355
|
if (p_mkdir(make_path.ptr, mode) < 0) {
|
350
|
-
int tmp_errno =
|
356
|
+
int tmp_errno = giterr_system_last();
|
351
357
|
|
352
358
|
/* ignore error if directory already exists */
|
353
359
|
if (p_stat(make_path.ptr, &st) < 0 || !S_ISDIR(st.st_mode)) {
|
354
|
-
|
360
|
+
giterr_system_set(tmp_errno);
|
355
361
|
giterr_set(GITERR_OS, "Failed to make directory '%s'", make_path.ptr);
|
356
362
|
goto done;
|
357
363
|
}
|
@@ -398,9 +404,11 @@ typedef struct {
|
|
398
404
|
const char *base;
|
399
405
|
size_t baselen;
|
400
406
|
uint32_t flags;
|
401
|
-
int
|
407
|
+
int depth;
|
402
408
|
} futils__rmdir_data;
|
403
409
|
|
410
|
+
#define FUTILS_MAX_DEPTH 100
|
411
|
+
|
404
412
|
static int futils__error_cannot_rmdir(const char *path, const char *filemsg)
|
405
413
|
{
|
406
414
|
if (filemsg)
|
@@ -439,74 +447,79 @@ static int futils__rm_first_parent(git_buf *path, const char *ceiling)
|
|
439
447
|
|
440
448
|
static int futils__rmdir_recurs_foreach(void *opaque, git_buf *path)
|
441
449
|
{
|
442
|
-
|
450
|
+
int error = 0;
|
443
451
|
futils__rmdir_data *data = opaque;
|
452
|
+
struct stat st;
|
453
|
+
|
454
|
+
if (data->depth > FUTILS_MAX_DEPTH)
|
455
|
+
error = futils__error_cannot_rmdir(
|
456
|
+
path->ptr, "directory nesting too deep");
|
444
457
|
|
445
|
-
if ((
|
458
|
+
else if ((error = p_lstat_posixly(path->ptr, &st)) < 0) {
|
446
459
|
if (errno == ENOENT)
|
447
|
-
|
460
|
+
error = 0;
|
448
461
|
else if (errno == ENOTDIR) {
|
449
462
|
/* asked to remove a/b/c/d/e and a/b is a normal file */
|
450
463
|
if ((data->flags & GIT_RMDIR_REMOVE_BLOCKERS) != 0)
|
451
|
-
|
464
|
+
error = futils__rm_first_parent(path, data->base);
|
452
465
|
else
|
453
466
|
futils__error_cannot_rmdir(
|
454
467
|
path->ptr, "parent is not directory");
|
455
468
|
}
|
456
469
|
else
|
457
|
-
|
470
|
+
error = git_path_set_error(errno, path->ptr, "rmdir");
|
458
471
|
}
|
459
472
|
|
460
473
|
else if (S_ISDIR(st.st_mode)) {
|
461
|
-
|
474
|
+
data->depth++;
|
475
|
+
|
476
|
+
error = git_path_direach(path, 0, futils__rmdir_recurs_foreach, data);
|
477
|
+
|
478
|
+
data->depth--;
|
479
|
+
|
462
480
|
if (error < 0)
|
463
|
-
return
|
481
|
+
return error;
|
464
482
|
|
465
|
-
data->
|
483
|
+
if (data->depth == 0 && (data->flags & GIT_RMDIR_SKIP_ROOT) != 0)
|
484
|
+
return error;
|
466
485
|
|
467
|
-
if (
|
486
|
+
if ((error = p_rmdir(path->ptr)) < 0) {
|
468
487
|
if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) != 0 &&
|
469
488
|
(errno == ENOTEMPTY || errno == EEXIST || errno == EBUSY))
|
470
|
-
|
489
|
+
error = 0;
|
471
490
|
else
|
472
|
-
|
491
|
+
error = git_path_set_error(errno, path->ptr, "rmdir");
|
473
492
|
}
|
474
493
|
}
|
475
494
|
|
476
495
|
else if ((data->flags & GIT_RMDIR_REMOVE_FILES) != 0) {
|
477
|
-
|
478
|
-
|
479
|
-
if (data->error < 0)
|
480
|
-
futils__error_cannot_rmdir(path->ptr, "cannot be removed");
|
496
|
+
if (p_unlink(path->ptr) < 0)
|
497
|
+
error = git_path_set_error(errno, path->ptr, "remove");
|
481
498
|
}
|
482
499
|
|
483
500
|
else if ((data->flags & GIT_RMDIR_SKIP_NONEMPTY) == 0)
|
484
|
-
|
501
|
+
error = futils__error_cannot_rmdir(path->ptr, "still present");
|
485
502
|
|
486
|
-
return
|
503
|
+
return error;
|
487
504
|
}
|
488
505
|
|
489
506
|
static int futils__rmdir_empty_parent(void *opaque, git_buf *path)
|
490
507
|
{
|
491
508
|
futils__rmdir_data *data = opaque;
|
492
|
-
int error;
|
509
|
+
int error = 0;
|
493
510
|
|
494
511
|
if (git_buf_len(path) <= data->baselen)
|
495
|
-
|
496
|
-
|
497
|
-
error = p_rmdir(git_buf_cstr(path));
|
512
|
+
error = GIT_ITEROVER;
|
498
513
|
|
499
|
-
if (
|
514
|
+
else if (p_rmdir(git_buf_cstr(path)) < 0) {
|
500
515
|
int en = errno;
|
501
516
|
|
502
517
|
if (en == ENOENT || en == ENOTDIR) {
|
503
|
-
|
504
|
-
error = 0;
|
518
|
+
/* do nothing */
|
505
519
|
} else if (en == ENOTEMPTY || en == EEXIST || en == EBUSY) {
|
506
|
-
giterr_clear();
|
507
520
|
error = GIT_ITEROVER;
|
508
521
|
} else {
|
509
|
-
|
522
|
+
error = git_path_set_error(errno, git_buf_cstr(path), "rmdir");
|
510
523
|
}
|
511
524
|
}
|
512
525
|
|
@@ -524,20 +537,21 @@ int git_futils_rmdir_r(
|
|
524
537
|
if (git_path_join_unrooted(&fullpath, path, base, NULL) < 0)
|
525
538
|
return -1;
|
526
539
|
|
540
|
+
memset(&data, 0, sizeof(data));
|
527
541
|
data.base = base ? base : "";
|
528
542
|
data.baselen = base ? strlen(base) : 0;
|
529
543
|
data.flags = flags;
|
530
|
-
data.error = 0;
|
531
544
|
|
532
545
|
error = futils__rmdir_recurs_foreach(&data, &fullpath);
|
533
546
|
|
534
547
|
/* remove now-empty parents if requested */
|
535
|
-
if (!error && (flags & GIT_RMDIR_EMPTY_PARENTS) != 0)
|
548
|
+
if (!error && (flags & GIT_RMDIR_EMPTY_PARENTS) != 0)
|
536
549
|
error = git_path_walk_up(
|
537
550
|
&fullpath, base, futils__rmdir_empty_parent, &data);
|
538
551
|
|
539
|
-
|
540
|
-
|
552
|
+
if (error == GIT_ITEROVER) {
|
553
|
+
giterr_clear();
|
554
|
+
error = 0;
|
541
555
|
}
|
542
556
|
|
543
557
|
git_buf_free(&fullpath);
|
@@ -545,223 +559,6 @@ int git_futils_rmdir_r(
|
|
545
559
|
return error;
|
546
560
|
}
|
547
561
|
|
548
|
-
int git_futils_cleanupdir_r(const char *path)
|
549
|
-
{
|
550
|
-
int error;
|
551
|
-
git_buf fullpath = GIT_BUF_INIT;
|
552
|
-
futils__rmdir_data data;
|
553
|
-
|
554
|
-
if ((error = git_buf_put(&fullpath, path, strlen(path))) < 0)
|
555
|
-
goto clean_up;
|
556
|
-
|
557
|
-
data.base = "";
|
558
|
-
data.baselen = 0;
|
559
|
-
data.flags = GIT_RMDIR_REMOVE_FILES;
|
560
|
-
data.error = 0;
|
561
|
-
|
562
|
-
if (!git_path_exists(path)) {
|
563
|
-
giterr_set(GITERR_OS, "Path does not exist: %s" , path);
|
564
|
-
error = GIT_ERROR;
|
565
|
-
goto clean_up;
|
566
|
-
}
|
567
|
-
|
568
|
-
if (!git_path_isdir(path)) {
|
569
|
-
giterr_set(GITERR_OS, "Path is not a directory: %s" , path);
|
570
|
-
error = GIT_ERROR;
|
571
|
-
goto clean_up;
|
572
|
-
}
|
573
|
-
|
574
|
-
error = git_path_direach(&fullpath, futils__rmdir_recurs_foreach, &data);
|
575
|
-
if (error == GIT_EUSER)
|
576
|
-
error = data.error;
|
577
|
-
|
578
|
-
clean_up:
|
579
|
-
git_buf_free(&fullpath);
|
580
|
-
return error;
|
581
|
-
}
|
582
|
-
|
583
|
-
|
584
|
-
static int git_futils_guess_system_dirs(git_buf *out)
|
585
|
-
{
|
586
|
-
#ifdef GIT_WIN32
|
587
|
-
return git_win32__find_system_dirs(out);
|
588
|
-
#else
|
589
|
-
return git_buf_sets(out, "/etc");
|
590
|
-
#endif
|
591
|
-
}
|
592
|
-
|
593
|
-
static int git_futils_guess_global_dirs(git_buf *out)
|
594
|
-
{
|
595
|
-
#ifdef GIT_WIN32
|
596
|
-
return git_win32__find_global_dirs(out);
|
597
|
-
#else
|
598
|
-
return git_buf_sets(out, getenv("HOME"));
|
599
|
-
#endif
|
600
|
-
}
|
601
|
-
|
602
|
-
static int git_futils_guess_xdg_dirs(git_buf *out)
|
603
|
-
{
|
604
|
-
#ifdef GIT_WIN32
|
605
|
-
return git_win32__find_xdg_dirs(out);
|
606
|
-
#else
|
607
|
-
const char *env = NULL;
|
608
|
-
|
609
|
-
if ((env = getenv("XDG_CONFIG_HOME")) != NULL)
|
610
|
-
return git_buf_joinpath(out, env, "git");
|
611
|
-
else if ((env = getenv("HOME")) != NULL)
|
612
|
-
return git_buf_joinpath(out, env, ".config/git");
|
613
|
-
|
614
|
-
git_buf_clear(out);
|
615
|
-
return 0;
|
616
|
-
#endif
|
617
|
-
}
|
618
|
-
|
619
|
-
typedef int (*git_futils_dirs_guess_cb)(git_buf *out);
|
620
|
-
|
621
|
-
static git_buf git_futils__dirs[GIT_FUTILS_DIR__MAX] =
|
622
|
-
{ GIT_BUF_INIT, GIT_BUF_INIT, GIT_BUF_INIT };
|
623
|
-
|
624
|
-
static git_futils_dirs_guess_cb git_futils__dir_guess[GIT_FUTILS_DIR__MAX] = {
|
625
|
-
git_futils_guess_system_dirs,
|
626
|
-
git_futils_guess_global_dirs,
|
627
|
-
git_futils_guess_xdg_dirs,
|
628
|
-
};
|
629
|
-
|
630
|
-
static int git_futils_check_selector(git_futils_dir_t which)
|
631
|
-
{
|
632
|
-
if (which < GIT_FUTILS_DIR__MAX)
|
633
|
-
return 0;
|
634
|
-
giterr_set(GITERR_INVALID, "config directory selector out of range");
|
635
|
-
return -1;
|
636
|
-
}
|
637
|
-
|
638
|
-
int git_futils_dirs_get(const git_buf **out, git_futils_dir_t which)
|
639
|
-
{
|
640
|
-
assert(out);
|
641
|
-
|
642
|
-
*out = NULL;
|
643
|
-
|
644
|
-
GITERR_CHECK_ERROR(git_futils_check_selector(which));
|
645
|
-
|
646
|
-
if (!git_buf_len(&git_futils__dirs[which]))
|
647
|
-
GITERR_CHECK_ERROR(
|
648
|
-
git_futils__dir_guess[which](&git_futils__dirs[which]));
|
649
|
-
|
650
|
-
*out = &git_futils__dirs[which];
|
651
|
-
return 0;
|
652
|
-
}
|
653
|
-
|
654
|
-
int git_futils_dirs_get_str(char *out, size_t outlen, git_futils_dir_t which)
|
655
|
-
{
|
656
|
-
const git_buf *path = NULL;
|
657
|
-
|
658
|
-
GITERR_CHECK_ERROR(git_futils_check_selector(which));
|
659
|
-
GITERR_CHECK_ERROR(git_futils_dirs_get(&path, which));
|
660
|
-
|
661
|
-
if (!out || path->size >= outlen) {
|
662
|
-
giterr_set(GITERR_NOMEMORY, "Buffer is too short for the path");
|
663
|
-
return GIT_EBUFS;
|
664
|
-
}
|
665
|
-
|
666
|
-
git_buf_copy_cstr(out, outlen, path);
|
667
|
-
return 0;
|
668
|
-
}
|
669
|
-
|
670
|
-
#define PATH_MAGIC "$PATH"
|
671
|
-
|
672
|
-
int git_futils_dirs_set(git_futils_dir_t which, const char *search_path)
|
673
|
-
{
|
674
|
-
const char *expand_path = NULL;
|
675
|
-
git_buf merge = GIT_BUF_INIT;
|
676
|
-
|
677
|
-
GITERR_CHECK_ERROR(git_futils_check_selector(which));
|
678
|
-
|
679
|
-
if (search_path != NULL)
|
680
|
-
expand_path = strstr(search_path, PATH_MAGIC);
|
681
|
-
|
682
|
-
/* init with default if not yet done and needed (ignoring error) */
|
683
|
-
if ((!search_path || expand_path) &&
|
684
|
-
!git_buf_len(&git_futils__dirs[which]))
|
685
|
-
git_futils__dir_guess[which](&git_futils__dirs[which]);
|
686
|
-
|
687
|
-
/* if $PATH is not referenced, then just set the path */
|
688
|
-
if (!expand_path)
|
689
|
-
return git_buf_sets(&git_futils__dirs[which], search_path);
|
690
|
-
|
691
|
-
/* otherwise set to join(before $PATH, old value, after $PATH) */
|
692
|
-
if (expand_path > search_path)
|
693
|
-
git_buf_set(&merge, search_path, expand_path - search_path);
|
694
|
-
|
695
|
-
if (git_buf_len(&git_futils__dirs[which]))
|
696
|
-
git_buf_join(&merge, GIT_PATH_LIST_SEPARATOR,
|
697
|
-
merge.ptr, git_futils__dirs[which].ptr);
|
698
|
-
|
699
|
-
expand_path += strlen(PATH_MAGIC);
|
700
|
-
if (*expand_path)
|
701
|
-
git_buf_join(&merge, GIT_PATH_LIST_SEPARATOR, merge.ptr, expand_path);
|
702
|
-
|
703
|
-
git_buf_swap(&git_futils__dirs[which], &merge);
|
704
|
-
git_buf_free(&merge);
|
705
|
-
|
706
|
-
return git_buf_oom(&git_futils__dirs[which]) ? -1 : 0;
|
707
|
-
}
|
708
|
-
|
709
|
-
void git_futils_dirs_free(void)
|
710
|
-
{
|
711
|
-
int i;
|
712
|
-
for (i = 0; i < GIT_FUTILS_DIR__MAX; ++i)
|
713
|
-
git_buf_free(&git_futils__dirs[i]);
|
714
|
-
}
|
715
|
-
|
716
|
-
static int git_futils_find_in_dirlist(
|
717
|
-
git_buf *path, const char *name, git_futils_dir_t which, const char *label)
|
718
|
-
{
|
719
|
-
size_t len;
|
720
|
-
const char *scan, *next = NULL;
|
721
|
-
const git_buf *syspath;
|
722
|
-
|
723
|
-
GITERR_CHECK_ERROR(git_futils_dirs_get(&syspath, which));
|
724
|
-
|
725
|
-
for (scan = git_buf_cstr(syspath); scan; scan = next) {
|
726
|
-
for (next = strchr(scan, GIT_PATH_LIST_SEPARATOR);
|
727
|
-
next && next > scan && next[-1] == '\\';
|
728
|
-
next = strchr(next + 1, GIT_PATH_LIST_SEPARATOR))
|
729
|
-
/* find unescaped separator or end of string */;
|
730
|
-
|
731
|
-
len = next ? (size_t)(next++ - scan) : strlen(scan);
|
732
|
-
if (!len)
|
733
|
-
continue;
|
734
|
-
|
735
|
-
GITERR_CHECK_ERROR(git_buf_set(path, scan, len));
|
736
|
-
GITERR_CHECK_ERROR(git_buf_joinpath(path, path->ptr, name));
|
737
|
-
|
738
|
-
if (git_path_exists(path->ptr))
|
739
|
-
return 0;
|
740
|
-
}
|
741
|
-
|
742
|
-
git_buf_clear(path);
|
743
|
-
giterr_set(GITERR_OS, "The %s file '%s' doesn't exist", label, name);
|
744
|
-
return GIT_ENOTFOUND;
|
745
|
-
}
|
746
|
-
|
747
|
-
int git_futils_find_system_file(git_buf *path, const char *filename)
|
748
|
-
{
|
749
|
-
return git_futils_find_in_dirlist(
|
750
|
-
path, filename, GIT_FUTILS_DIR_SYSTEM, "system");
|
751
|
-
}
|
752
|
-
|
753
|
-
int git_futils_find_global_file(git_buf *path, const char *filename)
|
754
|
-
{
|
755
|
-
return git_futils_find_in_dirlist(
|
756
|
-
path, filename, GIT_FUTILS_DIR_GLOBAL, "global");
|
757
|
-
}
|
758
|
-
|
759
|
-
int git_futils_find_xdg_file(git_buf *path, const char *filename)
|
760
|
-
{
|
761
|
-
return git_futils_find_in_dirlist(
|
762
|
-
path, filename, GIT_FUTILS_DIR_XDG, "global/xdg");
|
763
|
-
}
|
764
|
-
|
765
562
|
int git_futils_fake_symlink(const char *old, const char *new)
|
766
563
|
{
|
767
564
|
int retcode = GIT_ERROR;
|
@@ -806,11 +603,8 @@ int git_futils_cp(const char *from, const char *to, mode_t filemode)
|
|
806
603
|
return ifd;
|
807
604
|
|
808
605
|
if ((ofd = p_open(to, O_WRONLY | O_CREAT | O_EXCL, filemode)) < 0) {
|
809
|
-
if (errno == ENOENT || errno == ENOTDIR)
|
810
|
-
ofd = GIT_ENOTFOUND;
|
811
|
-
giterr_set(GITERR_OS, "Failed to open '%s' for writing", to);
|
812
606
|
p_close(ifd);
|
813
|
-
return
|
607
|
+
return git_path_set_error(errno, to, "open for writing");
|
814
608
|
}
|
815
609
|
|
816
610
|
return cp_by_fd(ifd, ofd, true);
|
@@ -886,18 +680,18 @@ static int _cp_r_callback(void *ref, git_buf *from)
|
|
886
680
|
from->ptr[git_path_basename_offset(from)] == '.')
|
887
681
|
return 0;
|
888
682
|
|
889
|
-
if (git_buf_joinpath(
|
890
|
-
&info->to, info->to_root, from->ptr + info->from_prefix) < 0)
|
891
|
-
return
|
683
|
+
if ((error = git_buf_joinpath(
|
684
|
+
&info->to, info->to_root, from->ptr + info->from_prefix)) < 0)
|
685
|
+
return error;
|
892
686
|
|
893
|
-
if (
|
894
|
-
if (errno != ENOENT && errno != ENOTDIR) {
|
895
|
-
giterr_set(GITERR_OS,
|
896
|
-
"Could not access %s while copying files", info->to.ptr);
|
897
|
-
return -1;
|
898
|
-
}
|
899
|
-
} else
|
687
|
+
if (!(error = git_path_lstat(info->to.ptr, &to_st)))
|
900
688
|
exists = true;
|
689
|
+
else if (error != GIT_ENOTFOUND)
|
690
|
+
return error;
|
691
|
+
else {
|
692
|
+
giterr_clear();
|
693
|
+
error = 0;
|
694
|
+
}
|
901
695
|
|
902
696
|
if ((error = git_path_lstat(from->ptr, &from_st)) < 0)
|
903
697
|
return error;
|
@@ -915,7 +709,7 @@ static int _cp_r_callback(void *ref, git_buf *from)
|
|
915
709
|
|
916
710
|
/* recurse onto target directory */
|
917
711
|
if (!error && (!exists || S_ISDIR(to_st.st_mode)))
|
918
|
-
error = git_path_direach(from, _cp_r_callback, info);
|
712
|
+
error = git_path_direach(from, 0, _cp_r_callback, info);
|
919
713
|
|
920
714
|
if (oldmode != 0)
|
921
715
|
info->dirmode = oldmode;
|
@@ -930,7 +724,7 @@ static int _cp_r_callback(void *ref, git_buf *from)
|
|
930
724
|
if (p_unlink(info->to.ptr) < 0) {
|
931
725
|
giterr_set(GITERR_OS, "Cannot overwrite existing file '%s'",
|
932
726
|
info->to.ptr);
|
933
|
-
return
|
727
|
+
return GIT_EEXISTS;
|
934
728
|
}
|
935
729
|
}
|
936
730
|
|
@@ -946,13 +740,15 @@ static int _cp_r_callback(void *ref, git_buf *from)
|
|
946
740
|
return error;
|
947
741
|
|
948
742
|
/* make symlink or regular file */
|
949
|
-
if (
|
743
|
+
if (info->flags & GIT_CPDIR_LINK_FILES) {
|
744
|
+
error = p_link(from->ptr, info->to.ptr);
|
745
|
+
} else if (S_ISLNK(from_st.st_mode)) {
|
950
746
|
error = cp_link(from->ptr, info->to.ptr, (size_t)from_st.st_size);
|
951
|
-
else {
|
747
|
+
} else {
|
952
748
|
mode_t usemode = from_st.st_mode;
|
953
749
|
|
954
750
|
if ((info->flags & GIT_CPDIR_SIMPLE_TO_MODE) != 0)
|
955
|
-
usemode = (usemode
|
751
|
+
usemode = GIT_PERMS_FOR_WRITE(usemode);
|
956
752
|
|
957
753
|
error = git_futils_cp(from->ptr, info->to.ptr, usemode);
|
958
754
|
}
|
@@ -973,6 +769,7 @@ int git_futils_cp_r(
|
|
973
769
|
if (git_buf_joinpath(&path, from, "") < 0) /* ensure trailing slash */
|
974
770
|
return -1;
|
975
771
|
|
772
|
+
memset(&info, 0, sizeof(info));
|
976
773
|
info.to_root = to;
|
977
774
|
info.flags = flags;
|
978
775
|
info.dirmode = dirmode;
|
@@ -1010,10 +807,8 @@ int git_futils_filestamp_check(
|
|
1010
807
|
if (stamp == NULL)
|
1011
808
|
return 1;
|
1012
809
|
|
1013
|
-
if (p_stat(path, &st) < 0)
|
1014
|
-
giterr_set(GITERR_OS, "Could not stat '%s'", path);
|
810
|
+
if (p_stat(path, &st) < 0)
|
1015
811
|
return GIT_ENOTFOUND;
|
1016
|
-
}
|
1017
812
|
|
1018
813
|
if (stamp->mtime == (git_time_t)st.st_mtime &&
|
1019
814
|
stamp->size == (git_off_t)st.st_size &&
|
@@ -1037,3 +832,16 @@ void git_futils_filestamp_set(
|
|
1037
832
|
else
|
1038
833
|
memset(target, 0, sizeof(*target));
|
1039
834
|
}
|
835
|
+
|
836
|
+
|
837
|
+
void git_futils_filestamp_set_from_stat(
|
838
|
+
git_futils_filestamp *stamp, struct stat *st)
|
839
|
+
{
|
840
|
+
if (st) {
|
841
|
+
stamp->mtime = (git_time_t)st->st_mtime;
|
842
|
+
stamp->size = (git_off_t)st->st_size;
|
843
|
+
stamp->ino = (unsigned int)st->st_ino;
|
844
|
+
} else {
|
845
|
+
memset(stamp, 0, sizeof(*stamp));
|
846
|
+
}
|
847
|
+
}
|