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
@@ -7,14 +7,15 @@
|
|
7
7
|
|
8
8
|
#include "common.h"
|
9
9
|
#include "config.h"
|
10
|
-
#include "fileops.h"
|
11
10
|
#include "filebuf.h"
|
11
|
+
#include "sysdir.h"
|
12
12
|
#include "buffer.h"
|
13
13
|
#include "buf_text.h"
|
14
14
|
#include "git2/config.h"
|
15
15
|
#include "git2/sys/config.h"
|
16
16
|
#include "git2/types.h"
|
17
17
|
#include "strmap.h"
|
18
|
+
#include "array.h"
|
18
19
|
|
19
20
|
#include <ctype.h>
|
20
21
|
#include <sys/types.h>
|
@@ -25,8 +26,18 @@ GIT__USE_STRMAP;
|
|
25
26
|
typedef struct cvar_t {
|
26
27
|
struct cvar_t *next;
|
27
28
|
git_config_entry *entry;
|
29
|
+
bool included; /* whether this is part of [include] */
|
28
30
|
} cvar_t;
|
29
31
|
|
32
|
+
typedef struct git_config_file_iter {
|
33
|
+
git_config_iterator parent;
|
34
|
+
git_strmap_iter iter;
|
35
|
+
cvar_t* next_var;
|
36
|
+
} git_config_file_iter;
|
37
|
+
|
38
|
+
/* Max depth for [include] directives */
|
39
|
+
#define MAX_INCLUDE_DEPTH 10
|
40
|
+
|
30
41
|
#define CVAR_LIST_HEAD(list) ((list)->head)
|
31
42
|
|
32
43
|
#define CVAR_LIST_TAIL(list) ((list)->tail)
|
@@ -65,34 +76,63 @@ typedef struct cvar_t {
|
|
65
76
|
(iter) && (((tmp) = CVAR_LIST_NEXT(iter) || 1));\
|
66
77
|
(iter) = (tmp))
|
67
78
|
|
68
|
-
|
69
|
-
|
79
|
+
struct reader {
|
80
|
+
time_t file_mtime;
|
81
|
+
size_t file_size;
|
82
|
+
char *file_path;
|
83
|
+
git_buf buffer;
|
84
|
+
char *read_ptr;
|
85
|
+
int line_number;
|
86
|
+
int eof;
|
87
|
+
};
|
70
88
|
|
89
|
+
typedef struct {
|
90
|
+
git_atomic refcount;
|
71
91
|
git_strmap *values;
|
92
|
+
} refcounted_strmap;
|
72
93
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
94
|
+
typedef struct {
|
95
|
+
git_config_backend parent;
|
96
|
+
/* mutex to coordinate accessing the values */
|
97
|
+
git_mutex values_mutex;
|
98
|
+
refcounted_strmap *values;
|
99
|
+
int readonly;
|
100
|
+
} diskfile_header;
|
79
101
|
|
80
|
-
|
81
|
-
|
82
|
-
size_t file_size;
|
102
|
+
typedef struct {
|
103
|
+
diskfile_header header;
|
83
104
|
|
84
105
|
git_config_level_t level;
|
106
|
+
|
107
|
+
git_array_t(struct reader) readers;
|
108
|
+
|
109
|
+
char *file_path;
|
85
110
|
} diskfile_backend;
|
86
111
|
|
87
|
-
|
88
|
-
|
112
|
+
typedef struct {
|
113
|
+
diskfile_header header;
|
114
|
+
|
115
|
+
diskfile_backend *snapshot_from;
|
116
|
+
} diskfile_readonly_backend;
|
117
|
+
|
118
|
+
static int config_parse(git_strmap *values, diskfile_backend *cfg_file, struct reader *reader, git_config_level_t level, int depth);
|
119
|
+
static int parse_variable(struct reader *reader, char **var_name, char **var_value);
|
89
120
|
static int config_write(diskfile_backend *cfg, const char *key, const regex_t *preg, const char *value);
|
90
121
|
static char *escape_value(const char *ptr);
|
91
122
|
|
92
|
-
|
123
|
+
int git_config_file__snapshot(git_config_backend **out, diskfile_backend *in);
|
124
|
+
static int config_snapshot(git_config_backend **out, git_config_backend *in);
|
125
|
+
|
126
|
+
static void set_parse_error(struct reader *reader, int col, const char *error_str)
|
93
127
|
{
|
94
128
|
giterr_set(GITERR_CONFIG, "Failed to parse config file: %s (in %s:%d, column %d)",
|
95
|
-
error_str,
|
129
|
+
error_str, reader->file_path, reader->line_number, col);
|
130
|
+
}
|
131
|
+
|
132
|
+
static int config_error_readonly(void)
|
133
|
+
{
|
134
|
+
giterr_set(GITERR_CONFIG, "this backend is read-only");
|
135
|
+
return -1;
|
96
136
|
}
|
97
137
|
|
98
138
|
static void cvar_free(cvar_t *var)
|
@@ -118,7 +158,7 @@ int git_config_file_normalize_section(char *start, char *end)
|
|
118
158
|
if (end && scan >= end)
|
119
159
|
break;
|
120
160
|
if (isalnum(*scan))
|
121
|
-
*scan = tolower(*scan);
|
161
|
+
*scan = (char)tolower(*scan);
|
122
162
|
else if (*scan != '-' || scan == start)
|
123
163
|
return GIT_EINVALIDSPEC;
|
124
164
|
}
|
@@ -129,39 +169,28 @@ int git_config_file_normalize_section(char *start, char *end)
|
|
129
169
|
return 0;
|
130
170
|
}
|
131
171
|
|
132
|
-
/*
|
133
|
-
static int
|
172
|
+
/* Add or append the new config option */
|
173
|
+
static int append_entry(git_strmap *values, cvar_t *var)
|
134
174
|
{
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
name = git__strdup(in);
|
140
|
-
GITERR_CHECK_ALLOC(name);
|
141
|
-
|
142
|
-
fdot = strchr(name, '.');
|
143
|
-
ldot = strrchr(name, '.');
|
144
|
-
|
145
|
-
if (fdot == NULL || fdot == name || ldot == NULL || !ldot[1])
|
146
|
-
goto invalid;
|
175
|
+
git_strmap_iter pos;
|
176
|
+
cvar_t *existing;
|
177
|
+
int error = 0;
|
147
178
|
|
148
|
-
|
149
|
-
if (
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
179
|
+
pos = git_strmap_lookup_index(values, var->entry->name);
|
180
|
+
if (!git_strmap_valid_index(values, pos)) {
|
181
|
+
git_strmap_insert(values, var->entry->name, var, error);
|
182
|
+
} else {
|
183
|
+
existing = git_strmap_value_at(values, pos);
|
184
|
+
while (existing->next != NULL) {
|
185
|
+
existing = existing->next;
|
186
|
+
}
|
187
|
+
existing->next = var;
|
188
|
+
}
|
157
189
|
|
158
|
-
|
159
|
-
|
190
|
+
if (error > 0)
|
191
|
+
error = 0;
|
160
192
|
|
161
|
-
|
162
|
-
git__free(name);
|
163
|
-
giterr_set(GITERR_CONFIG, "Invalid config item name '%s'", in);
|
164
|
-
return GIT_EINVALIDSPEC;
|
193
|
+
return error;
|
165
194
|
}
|
166
195
|
|
167
196
|
static void free_vars(git_strmap *values)
|
@@ -181,295 +210,341 @@ static void free_vars(git_strmap *values)
|
|
181
210
|
git_strmap_free(values);
|
182
211
|
}
|
183
212
|
|
213
|
+
static void refcounted_strmap_free(refcounted_strmap *map)
|
214
|
+
{
|
215
|
+
if (!map)
|
216
|
+
return;
|
217
|
+
|
218
|
+
if (git_atomic_dec(&map->refcount) != 0)
|
219
|
+
return;
|
220
|
+
|
221
|
+
free_vars(map->values);
|
222
|
+
git__free(map);
|
223
|
+
}
|
224
|
+
|
225
|
+
/**
|
226
|
+
* Take the current values map from the backend and increase its
|
227
|
+
* refcount. This is its own function to make sure we use the mutex to
|
228
|
+
* avoid the map pointer from changing under us.
|
229
|
+
*/
|
230
|
+
static refcounted_strmap *refcounted_strmap_take(diskfile_header *h)
|
231
|
+
{
|
232
|
+
refcounted_strmap *map;
|
233
|
+
|
234
|
+
git_mutex_lock(&h->values_mutex);
|
235
|
+
|
236
|
+
map = h->values;
|
237
|
+
git_atomic_inc(&map->refcount);
|
238
|
+
|
239
|
+
git_mutex_unlock(&h->values_mutex);
|
240
|
+
|
241
|
+
return map;
|
242
|
+
}
|
243
|
+
|
244
|
+
static int refcounted_strmap_alloc(refcounted_strmap **out)
|
245
|
+
{
|
246
|
+
refcounted_strmap *map;
|
247
|
+
int error;
|
248
|
+
|
249
|
+
map = git__calloc(1, sizeof(refcounted_strmap));
|
250
|
+
GITERR_CHECK_ALLOC(map);
|
251
|
+
|
252
|
+
git_atomic_set(&map->refcount, 1);
|
253
|
+
|
254
|
+
if ((error = git_strmap_alloc(&map->values)) < 0)
|
255
|
+
git__free(map);
|
256
|
+
else
|
257
|
+
*out = map;
|
258
|
+
|
259
|
+
return error;
|
260
|
+
}
|
261
|
+
|
184
262
|
static int config_open(git_config_backend *cfg, git_config_level_t level)
|
185
263
|
{
|
186
264
|
int res;
|
265
|
+
struct reader *reader;
|
187
266
|
diskfile_backend *b = (diskfile_backend *)cfg;
|
188
267
|
|
189
268
|
b->level = level;
|
190
269
|
|
191
|
-
b->values
|
192
|
-
|
270
|
+
if ((res = refcounted_strmap_alloc(&b->header.values)) < 0)
|
271
|
+
return res;
|
272
|
+
|
273
|
+
git_array_init(b->readers);
|
274
|
+
reader = git_array_alloc(b->readers);
|
275
|
+
if (!reader) {
|
276
|
+
refcounted_strmap_free(b->header.values);
|
277
|
+
return -1;
|
278
|
+
}
|
279
|
+
memset(reader, 0, sizeof(struct reader));
|
280
|
+
|
281
|
+
reader->file_path = git__strdup(b->file_path);
|
282
|
+
GITERR_CHECK_ALLOC(reader->file_path);
|
193
283
|
|
194
|
-
git_buf_init(&
|
284
|
+
git_buf_init(&reader->buffer, 0);
|
195
285
|
res = git_futils_readbuffer_updated(
|
196
|
-
&
|
286
|
+
&reader->buffer, b->file_path, &reader->file_mtime, &reader->file_size, NULL);
|
197
287
|
|
198
288
|
/* It's fine if the file doesn't exist */
|
199
289
|
if (res == GIT_ENOTFOUND)
|
200
290
|
return 0;
|
201
291
|
|
202
|
-
if (res < 0 || (res = config_parse(b, level)) < 0) {
|
203
|
-
|
204
|
-
b->values = NULL;
|
292
|
+
if (res < 0 || (res = config_parse(b->header.values->values, b, reader, level, 0)) < 0) {
|
293
|
+
refcounted_strmap_free(b->header.values);
|
294
|
+
b->header.values = NULL;
|
205
295
|
}
|
206
296
|
|
207
|
-
|
297
|
+
reader = git_array_get(b->readers, 0);
|
298
|
+
git_buf_free(&reader->buffer);
|
299
|
+
|
208
300
|
return res;
|
209
301
|
}
|
210
302
|
|
303
|
+
/* The meat of the refresh, as we want to use it in different places */
|
304
|
+
static int config__refresh(git_config_backend *cfg)
|
305
|
+
{
|
306
|
+
refcounted_strmap *values = NULL, *tmp;
|
307
|
+
diskfile_backend *b = (diskfile_backend *)cfg;
|
308
|
+
struct reader *reader = NULL;
|
309
|
+
int error = 0;
|
310
|
+
|
311
|
+
if ((error = refcounted_strmap_alloc(&values)) < 0)
|
312
|
+
goto out;
|
313
|
+
|
314
|
+
reader = git_array_get(b->readers, git_array_size(b->readers) - 1);
|
315
|
+
GITERR_CHECK_ALLOC(reader);
|
316
|
+
|
317
|
+
if ((error = config_parse(values->values, b, reader, b->level, 0)) < 0)
|
318
|
+
goto out;
|
319
|
+
|
320
|
+
git_mutex_lock(&b->header.values_mutex);
|
321
|
+
|
322
|
+
tmp = b->header.values;
|
323
|
+
b->header.values = values;
|
324
|
+
values = tmp;
|
325
|
+
|
326
|
+
git_mutex_unlock(&b->header.values_mutex);
|
327
|
+
|
328
|
+
out:
|
329
|
+
refcounted_strmap_free(values);
|
330
|
+
if (reader)
|
331
|
+
git_buf_free(&reader->buffer);
|
332
|
+
return error;
|
333
|
+
}
|
334
|
+
|
211
335
|
static int config_refresh(git_config_backend *cfg)
|
212
336
|
{
|
213
|
-
int
|
337
|
+
int error = 0, updated = 0, any_updated = 0;
|
214
338
|
diskfile_backend *b = (diskfile_backend *)cfg;
|
215
|
-
|
339
|
+
struct reader *reader = NULL;
|
340
|
+
uint32_t i;
|
216
341
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
free_vars(b->values);
|
229
|
-
b->values = old_values;
|
230
|
-
} else {
|
231
|
-
free_vars(old_values);
|
342
|
+
for (i = 0; i < git_array_size(b->readers); i++) {
|
343
|
+
reader = git_array_get(b->readers, i);
|
344
|
+
error = git_futils_readbuffer_updated(
|
345
|
+
&reader->buffer, reader->file_path,
|
346
|
+
&reader->file_mtime, &reader->file_size, &updated);
|
347
|
+
|
348
|
+
if (error < 0 && error != GIT_ENOTFOUND)
|
349
|
+
return error;
|
350
|
+
|
351
|
+
if (updated)
|
352
|
+
any_updated = 1;
|
232
353
|
}
|
233
354
|
|
234
|
-
|
235
|
-
|
355
|
+
if (!any_updated)
|
356
|
+
return (error == GIT_ENOTFOUND) ? 0 : error;
|
357
|
+
|
358
|
+
return config__refresh(cfg);
|
236
359
|
}
|
237
360
|
|
238
361
|
static void backend_free(git_config_backend *_backend)
|
239
362
|
{
|
240
363
|
diskfile_backend *backend = (diskfile_backend *)_backend;
|
364
|
+
uint32_t i;
|
241
365
|
|
242
366
|
if (backend == NULL)
|
243
367
|
return;
|
244
368
|
|
369
|
+
for (i = 0; i < git_array_size(backend->readers); i++) {
|
370
|
+
struct reader *r = git_array_get(backend->readers, i);
|
371
|
+
git__free(r->file_path);
|
372
|
+
}
|
373
|
+
git_array_clear(backend->readers);
|
374
|
+
|
245
375
|
git__free(backend->file_path);
|
246
|
-
|
376
|
+
refcounted_strmap_free(backend->header.values);
|
377
|
+
git_mutex_free(&backend->header.values_mutex);
|
247
378
|
git__free(backend);
|
248
379
|
}
|
249
380
|
|
250
|
-
static
|
251
|
-
|
252
|
-
const char *regexp,
|
253
|
-
int (*fn)(const git_config_entry *, void *),
|
254
|
-
void *data)
|
381
|
+
static void config_iterator_free(
|
382
|
+
git_config_iterator* iter)
|
255
383
|
{
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
regex_t regex;
|
260
|
-
int result = 0;
|
384
|
+
iter->backend->free(iter->backend);
|
385
|
+
git__free(iter);
|
386
|
+
}
|
261
387
|
|
262
|
-
|
263
|
-
|
388
|
+
static int config_iterator_next(
|
389
|
+
git_config_entry **entry,
|
390
|
+
git_config_iterator *iter)
|
391
|
+
{
|
392
|
+
git_config_file_iter *it = (git_config_file_iter *) iter;
|
393
|
+
diskfile_header *h = (diskfile_header *) it->parent.backend;
|
394
|
+
git_strmap *values = h->values->values;
|
395
|
+
int err = 0;
|
396
|
+
cvar_t * var;
|
397
|
+
|
398
|
+
if (it->next_var == NULL) {
|
399
|
+
err = git_strmap_next((void**) &var, &(it->iter), values);
|
400
|
+
} else {
|
401
|
+
var = it->next_var;
|
402
|
+
}
|
264
403
|
|
265
|
-
if (
|
266
|
-
|
267
|
-
|
268
|
-
regfree(®ex);
|
269
|
-
return -1;
|
270
|
-
}
|
404
|
+
if (err < 0) {
|
405
|
+
it->next_var = NULL;
|
406
|
+
return err;
|
271
407
|
}
|
272
408
|
|
273
|
-
|
274
|
-
|
275
|
-
next_var = CVAR_LIST_NEXT(var);
|
409
|
+
*entry = var->entry;
|
410
|
+
it->next_var = CVAR_LIST_NEXT(var);
|
276
411
|
|
277
|
-
|
278
|
-
|
279
|
-
continue;
|
412
|
+
return 0;
|
413
|
+
}
|
280
414
|
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
);
|
415
|
+
static int config_iterator_new(
|
416
|
+
git_config_iterator **iter,
|
417
|
+
struct git_config_backend* backend)
|
418
|
+
{
|
419
|
+
diskfile_header *h;
|
420
|
+
git_config_file_iter *it;
|
421
|
+
git_config_backend *snapshot;
|
422
|
+
diskfile_backend *b = (diskfile_backend *) backend;
|
423
|
+
int error;
|
289
424
|
|
290
|
-
|
291
|
-
|
292
|
-
regfree(®ex);
|
425
|
+
if ((error = config_snapshot(&snapshot, backend)) < 0)
|
426
|
+
return error;
|
293
427
|
|
294
|
-
|
428
|
+
if ((error = snapshot->open(snapshot, b->level)) < 0)
|
429
|
+
return error;
|
430
|
+
|
431
|
+
it = git__calloc(1, sizeof(git_config_file_iter));
|
432
|
+
GITERR_CHECK_ALLOC(it);
|
433
|
+
|
434
|
+
h = (diskfile_header *)snapshot;
|
435
|
+
|
436
|
+
/* strmap_begin() is currently a macro returning 0 */
|
437
|
+
GIT_UNUSED(h);
|
438
|
+
|
439
|
+
it->parent.backend = snapshot;
|
440
|
+
it->iter = git_strmap_begin(h->values);
|
441
|
+
it->next_var = NULL;
|
442
|
+
|
443
|
+
it->parent.next = config_iterator_next;
|
444
|
+
it->parent.free = config_iterator_free;
|
445
|
+
*iter = (git_config_iterator *) it;
|
446
|
+
|
447
|
+
return 0;
|
295
448
|
}
|
296
449
|
|
297
450
|
static int config_set(git_config_backend *cfg, const char *name, const char *value)
|
298
451
|
{
|
299
|
-
cvar_t *var = NULL, *old_var = NULL;
|
300
452
|
diskfile_backend *b = (diskfile_backend *)cfg;
|
453
|
+
refcounted_strmap *map;
|
454
|
+
git_strmap *values;
|
301
455
|
char *key, *esc_value = NULL;
|
302
456
|
khiter_t pos;
|
303
457
|
int rval, ret;
|
304
458
|
|
305
|
-
if ((rval =
|
459
|
+
if ((rval = git_config__normalize_name(name, &key)) < 0)
|
306
460
|
return rval;
|
307
461
|
|
462
|
+
map = refcounted_strmap_take(&b->header);
|
463
|
+
values = map->values;
|
464
|
+
|
308
465
|
/*
|
309
466
|
* Try to find it in the existing values and update it if it
|
310
467
|
* only has one value.
|
311
468
|
*/
|
312
|
-
pos = git_strmap_lookup_index(
|
313
|
-
if (git_strmap_valid_index(
|
314
|
-
cvar_t *existing = git_strmap_value_at(
|
315
|
-
char *tmp = NULL;
|
316
|
-
|
317
|
-
git__free(key);
|
469
|
+
pos = git_strmap_lookup_index(values, key);
|
470
|
+
if (git_strmap_valid_index(values, pos)) {
|
471
|
+
cvar_t *existing = git_strmap_value_at(values, pos);
|
318
472
|
|
319
473
|
if (existing->next != NULL) {
|
320
474
|
giterr_set(GITERR_CONFIG, "Multivar incompatible with simple set");
|
321
|
-
|
475
|
+
ret = -1;
|
476
|
+
goto out;
|
322
477
|
}
|
323
478
|
|
324
479
|
/* don't update if old and new values already match */
|
325
480
|
if ((!existing->entry->value && !value) ||
|
326
|
-
(existing->entry->value && value &&
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
tmp = git__strdup(value);
|
331
|
-
GITERR_CHECK_ALLOC(tmp);
|
332
|
-
esc_value = escape_value(value);
|
333
|
-
GITERR_CHECK_ALLOC(esc_value);
|
481
|
+
(existing->entry->value && value &&
|
482
|
+
!strcmp(existing->entry->value, value))) {
|
483
|
+
ret = 0;
|
484
|
+
goto out;
|
334
485
|
}
|
335
|
-
|
336
|
-
git__free((void *)existing->entry->value);
|
337
|
-
existing->entry->value = tmp;
|
338
|
-
|
339
|
-
ret = config_write(b, existing->entry->name, NULL, esc_value);
|
340
|
-
|
341
|
-
git__free(esc_value);
|
342
|
-
return ret;
|
343
486
|
}
|
344
487
|
|
345
|
-
|
346
|
-
GITERR_CHECK_ALLOC(var);
|
347
|
-
memset(var, 0x0, sizeof(cvar_t));
|
348
|
-
var->entry = git__malloc(sizeof(git_config_entry));
|
349
|
-
GITERR_CHECK_ALLOC(var->entry);
|
350
|
-
memset(var->entry, 0x0, sizeof(git_config_entry));
|
351
|
-
|
352
|
-
var->entry->name = key;
|
353
|
-
var->entry->value = NULL;
|
488
|
+
/* No early returns due to sanity checks, let's write it out and refresh */
|
354
489
|
|
355
490
|
if (value) {
|
356
|
-
var->entry->value = git__strdup(value);
|
357
|
-
GITERR_CHECK_ALLOC(var->entry->value);
|
358
491
|
esc_value = escape_value(value);
|
359
492
|
GITERR_CHECK_ALLOC(esc_value);
|
360
493
|
}
|
361
494
|
|
362
|
-
if (config_write(b, key, NULL, esc_value) < 0)
|
363
|
-
|
364
|
-
cvar_free(var);
|
365
|
-
return -1;
|
366
|
-
}
|
495
|
+
if ((ret = config_write(b, key, NULL, esc_value)) < 0)
|
496
|
+
goto out;
|
367
497
|
|
368
|
-
|
369
|
-
git_strmap_insert2(b->values, key, var, old_var, rval);
|
370
|
-
if (rval < 0)
|
371
|
-
return -1;
|
372
|
-
if (old_var != NULL)
|
373
|
-
cvar_free(old_var);
|
498
|
+
ret = config_refresh(cfg);
|
374
499
|
|
375
|
-
|
500
|
+
out:
|
501
|
+
refcounted_strmap_free(map);
|
502
|
+
git__free(esc_value);
|
503
|
+
git__free(key);
|
504
|
+
return ret;
|
376
505
|
}
|
377
506
|
|
378
507
|
/*
|
379
508
|
* Internal function that actually gets the value in string form
|
380
509
|
*/
|
381
|
-
static int config_get(
|
510
|
+
static int config_get(git_config_backend *cfg, const char *key, const git_config_entry **out)
|
382
511
|
{
|
383
|
-
|
384
|
-
|
512
|
+
diskfile_header *h = (diskfile_header *)cfg;
|
513
|
+
refcounted_strmap *map;
|
514
|
+
git_strmap *values;
|
385
515
|
khiter_t pos;
|
386
|
-
int error;
|
387
|
-
|
388
|
-
if ((error = normalize_name(name, &key)) < 0)
|
389
|
-
return error;
|
390
|
-
|
391
|
-
pos = git_strmap_lookup_index(b->values, key);
|
392
|
-
git__free(key);
|
393
|
-
|
394
|
-
/* no error message; the config system will write one */
|
395
|
-
if (!git_strmap_valid_index(b->values, pos))
|
396
|
-
return GIT_ENOTFOUND;
|
397
|
-
|
398
|
-
*out = ((cvar_t *)git_strmap_value_at(b->values, pos))->entry;
|
399
|
-
|
400
|
-
return 0;
|
401
|
-
}
|
402
|
-
|
403
|
-
static int config_get_multivar(
|
404
|
-
git_config_backend *cfg,
|
405
|
-
const char *name,
|
406
|
-
const char *regex_str,
|
407
|
-
int (*fn)(const git_config_entry *, void *),
|
408
|
-
void *data)
|
409
|
-
{
|
410
516
|
cvar_t *var;
|
411
|
-
diskfile_backend *b = (diskfile_backend *)cfg;
|
412
|
-
char *key;
|
413
|
-
khiter_t pos;
|
414
517
|
int error;
|
415
518
|
|
416
|
-
if ((error =
|
519
|
+
if (!h->readonly && ((error = config_refresh(cfg)) < 0))
|
417
520
|
return error;
|
418
521
|
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
if (!git_strmap_valid_index(b->values, pos))
|
423
|
-
return GIT_ENOTFOUND;
|
424
|
-
|
425
|
-
var = git_strmap_value_at(b->values, pos);
|
426
|
-
|
427
|
-
if (regex_str != NULL) {
|
428
|
-
regex_t regex;
|
429
|
-
int result;
|
522
|
+
map = refcounted_strmap_take(h);
|
523
|
+
values = map->values;
|
430
524
|
|
431
|
-
|
432
|
-
result = regcomp(®ex, regex_str, REG_EXTENDED);
|
433
|
-
if (result < 0) {
|
434
|
-
giterr_set_regex(®ex, result);
|
435
|
-
regfree(®ex);
|
436
|
-
return -1;
|
437
|
-
}
|
438
|
-
|
439
|
-
/* and throw the callback only on the variables that
|
440
|
-
* match the regex */
|
441
|
-
do {
|
442
|
-
if (regexec(®ex, var->entry->value, 0, NULL, 0) == 0) {
|
443
|
-
/* early termination by the user is not an error;
|
444
|
-
* just break and return successfully */
|
445
|
-
if (fn(var->entry, data) < 0)
|
446
|
-
break;
|
447
|
-
}
|
448
|
-
|
449
|
-
var = var->next;
|
450
|
-
} while (var != NULL);
|
451
|
-
regfree(®ex);
|
452
|
-
} else {
|
453
|
-
/* no regex; go through all the variables */
|
454
|
-
do {
|
455
|
-
/* early termination by the user is not an error;
|
456
|
-
* just break and return successfully */
|
457
|
-
if (fn(var->entry, data) < 0)
|
458
|
-
break;
|
525
|
+
pos = git_strmap_lookup_index(values, key);
|
459
526
|
|
460
|
-
|
461
|
-
|
527
|
+
/* no error message; the config system will write one */
|
528
|
+
if (!git_strmap_valid_index(values, pos)) {
|
529
|
+
refcounted_strmap_free(map);
|
530
|
+
return GIT_ENOTFOUND;
|
462
531
|
}
|
463
532
|
|
533
|
+
var = git_strmap_value_at(values, pos);
|
534
|
+
while (var->next)
|
535
|
+
var = var->next;
|
536
|
+
|
537
|
+
refcounted_strmap_free(map);
|
538
|
+
*out = var->entry;
|
464
539
|
return 0;
|
465
540
|
}
|
466
541
|
|
467
542
|
static int config_set_multivar(
|
468
543
|
git_config_backend *cfg, const char *name, const char *regexp, const char *value)
|
469
544
|
{
|
470
|
-
int replaced = 0;
|
471
|
-
cvar_t *var, *newvar;
|
472
545
|
diskfile_backend *b = (diskfile_backend *)cfg;
|
546
|
+
refcounted_strmap *map;
|
547
|
+
git_strmap *values;
|
473
548
|
char *key;
|
474
549
|
regex_t preg;
|
475
550
|
int result;
|
@@ -477,65 +552,36 @@ static int config_set_multivar(
|
|
477
552
|
|
478
553
|
assert(regexp);
|
479
554
|
|
480
|
-
if ((result =
|
555
|
+
if ((result = git_config__normalize_name(name, &key)) < 0)
|
481
556
|
return result;
|
482
557
|
|
483
|
-
|
484
|
-
|
558
|
+
map = refcounted_strmap_take(&b->header);
|
559
|
+
values = b->header.values->values;
|
560
|
+
|
561
|
+
pos = git_strmap_lookup_index(values, key);
|
562
|
+
if (!git_strmap_valid_index(values, pos)) {
|
485
563
|
/* If we don't have it, behave like a normal set */
|
486
564
|
result = config_set(cfg, name, value);
|
565
|
+
refcounted_strmap_free(map);
|
487
566
|
git__free(key);
|
488
567
|
return result;
|
489
568
|
}
|
490
569
|
|
491
|
-
var = git_strmap_value_at(b->values, pos);
|
492
|
-
|
493
570
|
result = regcomp(&preg, regexp, REG_EXTENDED);
|
494
571
|
if (result < 0) {
|
495
|
-
git__free(key);
|
496
572
|
giterr_set_regex(&preg, result);
|
497
|
-
|
498
|
-
|
573
|
+
result = -1;
|
574
|
+
goto out;
|
499
575
|
}
|
500
576
|
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
GITERR_CHECK_ALLOC(tmp);
|
505
|
-
|
506
|
-
git__free((void *)var->entry->value);
|
507
|
-
var->entry->value = tmp;
|
508
|
-
replaced = 1;
|
509
|
-
}
|
577
|
+
/* If we do have it, set call config_write() and reload */
|
578
|
+
if ((result = config_write(b, key, &preg, value)) < 0)
|
579
|
+
goto out;
|
510
580
|
|
511
|
-
|
512
|
-
break;
|
513
|
-
|
514
|
-
var = var->next;
|
515
|
-
}
|
516
|
-
|
517
|
-
/* If we've reached the end of the variables and we haven't found it yet, we need to append it */
|
518
|
-
if (!replaced) {
|
519
|
-
newvar = git__malloc(sizeof(cvar_t));
|
520
|
-
GITERR_CHECK_ALLOC(newvar);
|
521
|
-
memset(newvar, 0x0, sizeof(cvar_t));
|
522
|
-
newvar->entry = git__malloc(sizeof(git_config_entry));
|
523
|
-
GITERR_CHECK_ALLOC(newvar->entry);
|
524
|
-
memset(newvar->entry, 0x0, sizeof(git_config_entry));
|
525
|
-
|
526
|
-
newvar->entry->name = git__strdup(var->entry->name);
|
527
|
-
GITERR_CHECK_ALLOC(newvar->entry->name);
|
528
|
-
|
529
|
-
newvar->entry->value = git__strdup(value);
|
530
|
-
GITERR_CHECK_ALLOC(newvar->entry->value);
|
531
|
-
|
532
|
-
newvar->entry->level = var->entry->level;
|
533
|
-
|
534
|
-
var->next = newvar;
|
535
|
-
}
|
536
|
-
|
537
|
-
result = config_write(b, key, &preg, value);
|
581
|
+
result = config_refresh(cfg);
|
538
582
|
|
583
|
+
out:
|
584
|
+
refcounted_strmap_free(map);
|
539
585
|
git__free(key);
|
540
586
|
regfree(&preg);
|
541
587
|
|
@@ -546,36 +592,92 @@ static int config_delete(git_config_backend *cfg, const char *name)
|
|
546
592
|
{
|
547
593
|
cvar_t *var;
|
548
594
|
diskfile_backend *b = (diskfile_backend *)cfg;
|
595
|
+
refcounted_strmap *map; git_strmap *values;
|
549
596
|
char *key;
|
550
597
|
int result;
|
551
598
|
khiter_t pos;
|
552
599
|
|
553
|
-
if ((result =
|
600
|
+
if ((result = git_config__normalize_name(name, &key)) < 0)
|
554
601
|
return result;
|
555
602
|
|
556
|
-
|
603
|
+
map = refcounted_strmap_take(&b->header);
|
604
|
+
values = b->header.values->values;
|
605
|
+
|
606
|
+
pos = git_strmap_lookup_index(values, key);
|
557
607
|
git__free(key);
|
558
608
|
|
559
|
-
if (!git_strmap_valid_index(
|
609
|
+
if (!git_strmap_valid_index(values, pos)) {
|
610
|
+
refcounted_strmap_free(map);
|
560
611
|
giterr_set(GITERR_CONFIG, "Could not find key '%s' to delete", name);
|
561
612
|
return GIT_ENOTFOUND;
|
562
613
|
}
|
563
614
|
|
564
|
-
var = git_strmap_value_at(
|
615
|
+
var = git_strmap_value_at(values, pos);
|
616
|
+
refcounted_strmap_free(map);
|
565
617
|
|
566
618
|
if (var->next != NULL) {
|
567
619
|
giterr_set(GITERR_CONFIG, "Cannot delete multivar with a single delete");
|
568
620
|
return -1;
|
569
621
|
}
|
570
622
|
|
571
|
-
|
623
|
+
if ((result = config_write(b, var->entry->name, NULL, NULL)) < 0)
|
624
|
+
return result;
|
625
|
+
|
626
|
+
return config_refresh(cfg);
|
627
|
+
}
|
628
|
+
|
629
|
+
static int config_delete_multivar(git_config_backend *cfg, const char *name, const char *regexp)
|
630
|
+
{
|
631
|
+
diskfile_backend *b = (diskfile_backend *)cfg;
|
632
|
+
refcounted_strmap *map;
|
633
|
+
git_strmap *values;
|
634
|
+
char *key;
|
635
|
+
regex_t preg;
|
636
|
+
int result;
|
637
|
+
khiter_t pos;
|
638
|
+
|
639
|
+
if ((result = git_config__normalize_name(name, &key)) < 0)
|
640
|
+
return result;
|
641
|
+
|
642
|
+
map = refcounted_strmap_take(&b->header);
|
643
|
+
values = b->header.values->values;
|
572
644
|
|
573
|
-
|
645
|
+
pos = git_strmap_lookup_index(values, key);
|
574
646
|
|
575
|
-
|
647
|
+
if (!git_strmap_valid_index(values, pos)) {
|
648
|
+
refcounted_strmap_free(map);
|
649
|
+
git__free(key);
|
650
|
+
giterr_set(GITERR_CONFIG, "Could not find key '%s' to delete", name);
|
651
|
+
return GIT_ENOTFOUND;
|
652
|
+
}
|
653
|
+
|
654
|
+
refcounted_strmap_free(map);
|
655
|
+
|
656
|
+
result = regcomp(&preg, regexp, REG_EXTENDED);
|
657
|
+
if (result < 0) {
|
658
|
+
giterr_set_regex(&preg, result);
|
659
|
+
result = -1;
|
660
|
+
goto out;
|
661
|
+
}
|
662
|
+
|
663
|
+
if ((result = config_write(b, key, &preg, NULL)) < 0)
|
664
|
+
goto out;
|
665
|
+
|
666
|
+
result = config_refresh(cfg);
|
667
|
+
|
668
|
+
out:
|
669
|
+
git__free(key);
|
670
|
+
regfree(&preg);
|
576
671
|
return result;
|
577
672
|
}
|
578
673
|
|
674
|
+
static int config_snapshot(git_config_backend **out, git_config_backend *in)
|
675
|
+
{
|
676
|
+
diskfile_backend *b = (diskfile_backend *) in;
|
677
|
+
|
678
|
+
return git_config_file__snapshot(out, b);
|
679
|
+
}
|
680
|
+
|
579
681
|
int git_config_file__ondisk(git_config_backend **out, const char *path)
|
580
682
|
{
|
581
683
|
diskfile_backend *backend;
|
@@ -583,46 +685,148 @@ int git_config_file__ondisk(git_config_backend **out, const char *path)
|
|
583
685
|
backend = git__calloc(1, sizeof(diskfile_backend));
|
584
686
|
GITERR_CHECK_ALLOC(backend);
|
585
687
|
|
586
|
-
backend->parent.version = GIT_CONFIG_BACKEND_VERSION;
|
688
|
+
backend->header.parent.version = GIT_CONFIG_BACKEND_VERSION;
|
689
|
+
git_mutex_init(&backend->header.values_mutex);
|
587
690
|
|
588
691
|
backend->file_path = git__strdup(path);
|
589
692
|
GITERR_CHECK_ALLOC(backend->file_path);
|
590
693
|
|
591
|
-
backend->parent.open = config_open;
|
592
|
-
backend->parent.get = config_get;
|
593
|
-
backend->parent.
|
594
|
-
backend->parent.
|
595
|
-
backend->parent.
|
596
|
-
backend->parent.
|
597
|
-
backend->parent.
|
598
|
-
backend->parent.refresh = config_refresh;
|
599
|
-
backend->parent.
|
694
|
+
backend->header.parent.open = config_open;
|
695
|
+
backend->header.parent.get = config_get;
|
696
|
+
backend->header.parent.set = config_set;
|
697
|
+
backend->header.parent.set_multivar = config_set_multivar;
|
698
|
+
backend->header.parent.del = config_delete;
|
699
|
+
backend->header.parent.del_multivar = config_delete_multivar;
|
700
|
+
backend->header.parent.iterator = config_iterator_new;
|
701
|
+
backend->header.parent.refresh = config_refresh;
|
702
|
+
backend->header.parent.snapshot = config_snapshot;
|
703
|
+
backend->header.parent.free = backend_free;
|
704
|
+
|
705
|
+
*out = (git_config_backend *)backend;
|
706
|
+
|
707
|
+
return 0;
|
708
|
+
}
|
709
|
+
|
710
|
+
static int config_set_readonly(git_config_backend *cfg, const char *name, const char *value)
|
711
|
+
{
|
712
|
+
GIT_UNUSED(cfg);
|
713
|
+
GIT_UNUSED(name);
|
714
|
+
GIT_UNUSED(value);
|
715
|
+
|
716
|
+
return config_error_readonly();
|
717
|
+
}
|
718
|
+
|
719
|
+
static int config_set_multivar_readonly(
|
720
|
+
git_config_backend *cfg, const char *name, const char *regexp, const char *value)
|
721
|
+
{
|
722
|
+
GIT_UNUSED(cfg);
|
723
|
+
GIT_UNUSED(name);
|
724
|
+
GIT_UNUSED(regexp);
|
725
|
+
GIT_UNUSED(value);
|
726
|
+
|
727
|
+
return config_error_readonly();
|
728
|
+
}
|
729
|
+
|
730
|
+
static int config_delete_multivar_readonly(git_config_backend *cfg, const char *name, const char *regexp)
|
731
|
+
{
|
732
|
+
GIT_UNUSED(cfg);
|
733
|
+
GIT_UNUSED(name);
|
734
|
+
GIT_UNUSED(regexp);
|
735
|
+
|
736
|
+
return config_error_readonly();
|
737
|
+
}
|
738
|
+
|
739
|
+
static int config_delete_readonly(git_config_backend *cfg, const char *name)
|
740
|
+
{
|
741
|
+
GIT_UNUSED(cfg);
|
742
|
+
GIT_UNUSED(name);
|
743
|
+
|
744
|
+
return config_error_readonly();
|
745
|
+
}
|
746
|
+
|
747
|
+
static int config_refresh_readonly(git_config_backend *cfg)
|
748
|
+
{
|
749
|
+
GIT_UNUSED(cfg);
|
750
|
+
|
751
|
+
return config_error_readonly();
|
752
|
+
}
|
753
|
+
|
754
|
+
static void backend_readonly_free(git_config_backend *_backend)
|
755
|
+
{
|
756
|
+
diskfile_backend *backend = (diskfile_backend *)_backend;
|
757
|
+
|
758
|
+
if (backend == NULL)
|
759
|
+
return;
|
760
|
+
|
761
|
+
refcounted_strmap_free(backend->header.values);
|
762
|
+
git_mutex_free(&backend->header.values_mutex);
|
763
|
+
git__free(backend);
|
764
|
+
}
|
765
|
+
|
766
|
+
static int config_readonly_open(git_config_backend *cfg, git_config_level_t level)
|
767
|
+
{
|
768
|
+
diskfile_readonly_backend *b = (diskfile_readonly_backend *) cfg;
|
769
|
+
diskfile_backend *src = b->snapshot_from;
|
770
|
+
refcounted_strmap *src_map;
|
771
|
+
|
772
|
+
/* We're just copying data, don't care about the level */
|
773
|
+
GIT_UNUSED(level);
|
774
|
+
|
775
|
+
src_map = refcounted_strmap_take(&src->header);
|
776
|
+
b->header.values = src_map;
|
777
|
+
|
778
|
+
return 0;
|
779
|
+
}
|
780
|
+
|
781
|
+
int git_config_file__snapshot(git_config_backend **out, diskfile_backend *in)
|
782
|
+
{
|
783
|
+
diskfile_readonly_backend *backend;
|
784
|
+
|
785
|
+
backend = git__calloc(1, sizeof(diskfile_readonly_backend));
|
786
|
+
GITERR_CHECK_ALLOC(backend);
|
787
|
+
|
788
|
+
backend->header.parent.version = GIT_CONFIG_BACKEND_VERSION;
|
789
|
+
git_mutex_init(&backend->header.values_mutex);
|
790
|
+
|
791
|
+
backend->snapshot_from = in;
|
792
|
+
|
793
|
+
backend->header.readonly = 1;
|
794
|
+
backend->header.parent.version = GIT_CONFIG_BACKEND_VERSION;
|
795
|
+
backend->header.parent.open = config_readonly_open;
|
796
|
+
backend->header.parent.get = config_get;
|
797
|
+
backend->header.parent.set = config_set_readonly;
|
798
|
+
backend->header.parent.set_multivar = config_set_multivar_readonly;
|
799
|
+
backend->header.parent.del = config_delete_readonly;
|
800
|
+
backend->header.parent.del_multivar = config_delete_multivar_readonly;
|
801
|
+
backend->header.parent.iterator = config_iterator_new;
|
802
|
+
backend->header.parent.refresh = config_refresh_readonly;
|
803
|
+
backend->header.parent.free = backend_readonly_free;
|
600
804
|
|
601
805
|
*out = (git_config_backend *)backend;
|
602
806
|
|
603
807
|
return 0;
|
604
808
|
}
|
605
809
|
|
606
|
-
static int
|
810
|
+
static int reader_getchar_raw(struct reader *reader)
|
607
811
|
{
|
608
812
|
int c;
|
609
813
|
|
610
|
-
c = *
|
814
|
+
c = *reader->read_ptr++;
|
611
815
|
|
612
816
|
/*
|
613
817
|
Win 32 line breaks: if we find a \r\n sequence,
|
614
818
|
return only the \n as a newline
|
615
819
|
*/
|
616
|
-
if (c == '\r' && *
|
617
|
-
|
820
|
+
if (c == '\r' && *reader->read_ptr == '\n') {
|
821
|
+
reader->read_ptr++;
|
618
822
|
c = '\n';
|
619
823
|
}
|
620
824
|
|
621
825
|
if (c == '\n')
|
622
|
-
|
826
|
+
reader->line_number++;
|
623
827
|
|
624
828
|
if (c == 0) {
|
625
|
-
|
829
|
+
reader->eof = 1;
|
626
830
|
c = '\n';
|
627
831
|
}
|
628
832
|
|
@@ -632,21 +836,23 @@ static int cfg_getchar_raw(diskfile_backend *cfg)
|
|
632
836
|
#define SKIP_WHITESPACE (1 << 1)
|
633
837
|
#define SKIP_COMMENTS (1 << 2)
|
634
838
|
|
635
|
-
static int
|
839
|
+
static int reader_getchar(struct reader *reader, int flags)
|
636
840
|
{
|
637
841
|
const int skip_whitespace = (flags & SKIP_WHITESPACE);
|
638
842
|
const int skip_comments = (flags & SKIP_COMMENTS);
|
639
843
|
int c;
|
640
844
|
|
641
|
-
assert(
|
845
|
+
assert(reader->read_ptr);
|
642
846
|
|
643
|
-
do
|
644
|
-
|
645
|
-
|
847
|
+
do {
|
848
|
+
c = reader_getchar_raw(reader);
|
849
|
+
} while (skip_whitespace && git__isspace(c) &&
|
850
|
+
!reader->eof);
|
646
851
|
|
647
852
|
if (skip_comments && (c == '#' || c == ';')) {
|
648
|
-
do
|
649
|
-
|
853
|
+
do {
|
854
|
+
c = reader_getchar_raw(reader);
|
855
|
+
} while (c != '\n');
|
650
856
|
}
|
651
857
|
|
652
858
|
return c;
|
@@ -655,23 +861,23 @@ static int cfg_getchar(diskfile_backend *cfg_file, int flags)
|
|
655
861
|
/*
|
656
862
|
* Read the next char, but don't move the reading pointer.
|
657
863
|
*/
|
658
|
-
static int
|
864
|
+
static int reader_peek(struct reader *reader, int flags)
|
659
865
|
{
|
660
866
|
void *old_read_ptr;
|
661
867
|
int old_lineno, old_eof;
|
662
868
|
int ret;
|
663
869
|
|
664
|
-
assert(
|
870
|
+
assert(reader->read_ptr);
|
665
871
|
|
666
|
-
old_read_ptr =
|
667
|
-
old_lineno =
|
668
|
-
old_eof =
|
872
|
+
old_read_ptr = reader->read_ptr;
|
873
|
+
old_lineno = reader->line_number;
|
874
|
+
old_eof = reader->eof;
|
669
875
|
|
670
|
-
ret =
|
876
|
+
ret = reader_getchar(reader, flags);
|
671
877
|
|
672
|
-
|
673
|
-
|
674
|
-
|
878
|
+
reader->read_ptr = old_read_ptr;
|
879
|
+
reader->line_number = old_lineno;
|
880
|
+
reader->eof = old_eof;
|
675
881
|
|
676
882
|
return ret;
|
677
883
|
}
|
@@ -679,13 +885,13 @@ static int cfg_peek(diskfile_backend *cfg, int flags)
|
|
679
885
|
/*
|
680
886
|
* Read and consume a line, returning it in newly-allocated memory.
|
681
887
|
*/
|
682
|
-
static char *
|
888
|
+
static char *reader_readline(struct reader *reader, bool skip_whitespace)
|
683
889
|
{
|
684
890
|
char *line = NULL;
|
685
891
|
char *line_src, *line_end;
|
686
892
|
size_t line_len;
|
687
893
|
|
688
|
-
line_src =
|
894
|
+
line_src = reader->read_ptr;
|
689
895
|
|
690
896
|
if (skip_whitespace) {
|
691
897
|
/* Skip empty empty lines */
|
@@ -714,10 +920,10 @@ static char *cfg_readline(diskfile_backend *cfg, bool skip_whitespace)
|
|
714
920
|
line_end++;
|
715
921
|
|
716
922
|
if (*line_end == '\0')
|
717
|
-
|
923
|
+
reader->eof = 1;
|
718
924
|
|
719
|
-
|
720
|
-
|
925
|
+
reader->line_number++;
|
926
|
+
reader->read_ptr = line_end;
|
721
927
|
|
722
928
|
return line;
|
723
929
|
}
|
@@ -725,11 +931,11 @@ static char *cfg_readline(diskfile_backend *cfg, bool skip_whitespace)
|
|
725
931
|
/*
|
726
932
|
* Consume a line, without storing it anywhere
|
727
933
|
*/
|
728
|
-
static void
|
934
|
+
static void reader_consume_line(struct reader *reader)
|
729
935
|
{
|
730
936
|
char *line_start, *line_end;
|
731
937
|
|
732
|
-
line_start =
|
938
|
+
line_start = reader->read_ptr;
|
733
939
|
line_end = strchr(line_start, '\n');
|
734
940
|
/* No newline at EOF */
|
735
941
|
if(line_end == NULL){
|
@@ -740,10 +946,10 @@ static void cfg_consume_line(diskfile_backend *cfg)
|
|
740
946
|
line_end++;
|
741
947
|
|
742
948
|
if (*line_end == '\0')
|
743
|
-
|
949
|
+
reader->eof = 1;
|
744
950
|
|
745
|
-
|
746
|
-
|
951
|
+
reader->line_number++;
|
952
|
+
reader->read_ptr = line_end;
|
747
953
|
}
|
748
954
|
|
749
955
|
GIT_INLINE(int) config_keychar(int c)
|
@@ -751,12 +957,11 @@ GIT_INLINE(int) config_keychar(int c)
|
|
751
957
|
return isalnum(c) || c == '-';
|
752
958
|
}
|
753
959
|
|
754
|
-
static int parse_section_header_ext(
|
960
|
+
static int parse_section_header_ext(struct reader *reader, const char *line, const char *base_name, char **section_name)
|
755
961
|
{
|
756
962
|
int c, rpos;
|
757
963
|
char *first_quote, *last_quote;
|
758
964
|
git_buf buf = GIT_BUF_INIT;
|
759
|
-
int quote_marks;
|
760
965
|
/*
|
761
966
|
* base_name is what came before the space. We should be at the
|
762
967
|
* first quotation mark, except for now, line isn't being kept in
|
@@ -767,7 +972,7 @@ static int parse_section_header_ext(diskfile_backend *cfg, const char *line, con
|
|
767
972
|
last_quote = strrchr(line, '"');
|
768
973
|
|
769
974
|
if (last_quote - first_quote == 0) {
|
770
|
-
set_parse_error(
|
975
|
+
set_parse_error(reader, 0, "Missing closing quotation mark in section header");
|
771
976
|
return -1;
|
772
977
|
}
|
773
978
|
|
@@ -775,37 +980,30 @@ static int parse_section_header_ext(diskfile_backend *cfg, const char *line, con
|
|
775
980
|
git_buf_printf(&buf, "%s.", base_name);
|
776
981
|
|
777
982
|
rpos = 0;
|
778
|
-
quote_marks = 0;
|
779
983
|
|
780
984
|
line = first_quote;
|
781
|
-
c = line[rpos
|
985
|
+
c = line[++rpos];
|
782
986
|
|
783
987
|
/*
|
784
988
|
* At the end of each iteration, whatever is stored in c will be
|
785
989
|
* added to the string. In case of error, jump to out
|
786
990
|
*/
|
787
991
|
do {
|
788
|
-
|
789
|
-
|
992
|
+
|
993
|
+
switch (c) {
|
994
|
+
case 0:
|
995
|
+
set_parse_error(reader, 0, "Unexpected end-of-line in section header");
|
790
996
|
git_buf_free(&buf);
|
791
997
|
return -1;
|
792
|
-
}
|
793
998
|
|
794
|
-
switch (c) {
|
795
999
|
case '"':
|
796
|
-
|
797
|
-
continue;
|
1000
|
+
goto end_parse;
|
798
1001
|
|
799
1002
|
case '\\':
|
800
|
-
c = line[rpos
|
801
|
-
|
802
|
-
switch (c) {
|
803
|
-
case '"':
|
804
|
-
case '\\':
|
805
|
-
break;
|
1003
|
+
c = line[++rpos];
|
806
1004
|
|
807
|
-
|
808
|
-
set_parse_error(
|
1005
|
+
if (c == 0) {
|
1006
|
+
set_parse_error(reader, rpos, "Unexpected end-of-line in section header");
|
809
1007
|
git_buf_free(&buf);
|
810
1008
|
return -1;
|
811
1009
|
}
|
@@ -814,29 +1012,37 @@ static int parse_section_header_ext(diskfile_backend *cfg, const char *line, con
|
|
814
1012
|
break;
|
815
1013
|
}
|
816
1014
|
|
817
|
-
git_buf_putc(&buf, c);
|
818
|
-
|
1015
|
+
git_buf_putc(&buf, (char)c);
|
1016
|
+
c = line[++rpos];
|
1017
|
+
} while (line + rpos < last_quote);
|
1018
|
+
|
1019
|
+
end_parse:
|
1020
|
+
if (line[rpos] != '"' || line[rpos + 1] != ']') {
|
1021
|
+
set_parse_error(reader, rpos, "Unexpected text after closing quotes");
|
1022
|
+
git_buf_free(&buf);
|
1023
|
+
return -1;
|
1024
|
+
}
|
819
1025
|
|
820
1026
|
*section_name = git_buf_detach(&buf);
|
821
1027
|
return 0;
|
822
1028
|
}
|
823
1029
|
|
824
|
-
static int parse_section_header(
|
1030
|
+
static int parse_section_header(struct reader *reader, char **section_out)
|
825
1031
|
{
|
826
1032
|
char *name, *name_end;
|
827
1033
|
int name_length, c, pos;
|
828
1034
|
int result;
|
829
1035
|
char *line;
|
830
1036
|
|
831
|
-
line =
|
1037
|
+
line = reader_readline(reader, true);
|
832
1038
|
if (line == NULL)
|
833
1039
|
return -1;
|
834
1040
|
|
835
1041
|
/* find the end of the variable's name */
|
836
|
-
name_end =
|
1042
|
+
name_end = strrchr(line, ']');
|
837
1043
|
if (name_end == NULL) {
|
838
1044
|
git__free(line);
|
839
|
-
set_parse_error(
|
1045
|
+
set_parse_error(reader, 0, "Missing ']' in section header");
|
840
1046
|
return -1;
|
841
1047
|
}
|
842
1048
|
|
@@ -855,14 +1061,14 @@ static int parse_section_header(diskfile_backend *cfg, char **section_out)
|
|
855
1061
|
do {
|
856
1062
|
if (git__isspace(c)){
|
857
1063
|
name[name_length] = '\0';
|
858
|
-
result = parse_section_header_ext(
|
1064
|
+
result = parse_section_header_ext(reader, line, name, section_out);
|
859
1065
|
git__free(line);
|
860
1066
|
git__free(name);
|
861
1067
|
return result;
|
862
1068
|
}
|
863
1069
|
|
864
1070
|
if (!config_keychar(c) && c != '.') {
|
865
|
-
set_parse_error(
|
1071
|
+
set_parse_error(reader, pos, "Unexpected character in header");
|
866
1072
|
goto fail_parse;
|
867
1073
|
}
|
868
1074
|
|
@@ -871,7 +1077,7 @@ static int parse_section_header(diskfile_backend *cfg, char **section_out)
|
|
871
1077
|
} while ((c = line[pos++]) != ']');
|
872
1078
|
|
873
1079
|
if (line[pos - 1] != ']') {
|
874
|
-
set_parse_error(
|
1080
|
+
set_parse_error(reader, pos, "Unexpected end of file");
|
875
1081
|
goto fail_parse;
|
876
1082
|
}
|
877
1083
|
|
@@ -888,14 +1094,14 @@ fail_parse:
|
|
888
1094
|
return -1;
|
889
1095
|
}
|
890
1096
|
|
891
|
-
static int skip_bom(
|
1097
|
+
static int skip_bom(struct reader *reader)
|
892
1098
|
{
|
893
1099
|
git_bom_t bom;
|
894
1100
|
int bom_offset = git_buf_text_detect_bom(&bom,
|
895
|
-
&
|
1101
|
+
&reader->buffer, reader->read_ptr - reader->buffer.ptr);
|
896
1102
|
|
897
1103
|
if (bom == GIT_BOM_UTF8)
|
898
|
-
|
1104
|
+
reader->read_ptr += bom_offset;
|
899
1105
|
|
900
1106
|
/* TODO: reference implementation is pretty stupid with BoM */
|
901
1107
|
|
@@ -965,49 +1171,64 @@ static int strip_comments(char *line, int in_quotes)
|
|
965
1171
|
return quote_count;
|
966
1172
|
}
|
967
1173
|
|
968
|
-
static int
|
1174
|
+
static int included_path(git_buf *out, const char *dir, const char *path)
|
1175
|
+
{
|
1176
|
+
/* From the user's home */
|
1177
|
+
if (path[0] == '~' && path[1] == '/')
|
1178
|
+
return git_sysdir_find_global_file(out, &path[1]);
|
1179
|
+
|
1180
|
+
return git_path_join_unrooted(out, path, dir, NULL);
|
1181
|
+
}
|
1182
|
+
|
1183
|
+
static int config_parse(git_strmap *values, diskfile_backend *cfg_file, struct reader *reader, git_config_level_t level, int depth)
|
969
1184
|
{
|
970
1185
|
int c;
|
971
1186
|
char *current_section = NULL;
|
972
1187
|
char *var_name;
|
973
1188
|
char *var_value;
|
974
|
-
cvar_t *var
|
1189
|
+
cvar_t *var;
|
975
1190
|
git_buf buf = GIT_BUF_INIT;
|
976
1191
|
int result = 0;
|
977
|
-
|
1192
|
+
uint32_t reader_idx;
|
1193
|
+
|
1194
|
+
if (depth >= MAX_INCLUDE_DEPTH) {
|
1195
|
+
giterr_set(GITERR_CONFIG, "Maximum config include depth reached");
|
1196
|
+
return -1;
|
1197
|
+
}
|
978
1198
|
|
1199
|
+
reader_idx = git_array_size(cfg_file->readers) - 1;
|
979
1200
|
/* Initialize the reading position */
|
980
|
-
|
981
|
-
|
1201
|
+
reader->read_ptr = reader->buffer.ptr;
|
1202
|
+
reader->eof = 0;
|
982
1203
|
|
983
1204
|
/* If the file is empty, there's nothing for us to do */
|
984
|
-
if (*
|
1205
|
+
if (*reader->read_ptr == '\0')
|
985
1206
|
return 0;
|
986
1207
|
|
987
|
-
skip_bom(
|
1208
|
+
skip_bom(reader);
|
988
1209
|
|
989
|
-
while (result == 0 && !
|
1210
|
+
while (result == 0 && !reader->eof) {
|
990
1211
|
|
991
|
-
c =
|
1212
|
+
c = reader_peek(reader, SKIP_WHITESPACE);
|
992
1213
|
|
993
1214
|
switch (c) {
|
994
1215
|
case '\n': /* EOF when peeking, set EOF in the reader to exit the loop */
|
995
|
-
|
1216
|
+
reader->eof = 1;
|
996
1217
|
break;
|
997
1218
|
|
998
1219
|
case '[': /* section header, new section begins */
|
999
1220
|
git__free(current_section);
|
1000
1221
|
current_section = NULL;
|
1001
|
-
result = parse_section_header(
|
1222
|
+
result = parse_section_header(reader, ¤t_section);
|
1002
1223
|
break;
|
1003
1224
|
|
1004
1225
|
case ';':
|
1005
1226
|
case '#':
|
1006
|
-
|
1227
|
+
reader_consume_line(reader);
|
1007
1228
|
break;
|
1008
1229
|
|
1009
1230
|
default: /* assume variable declaration */
|
1010
|
-
result = parse_variable(
|
1231
|
+
result = parse_variable(reader, &var_name, &var_value);
|
1011
1232
|
if (result < 0)
|
1012
1233
|
break;
|
1013
1234
|
|
@@ -1022,26 +1243,57 @@ static int config_parse(diskfile_backend *cfg_file, git_config_level_t level)
|
|
1022
1243
|
git_buf_printf(&buf, "%s.%s", current_section, var_name);
|
1023
1244
|
git__free(var_name);
|
1024
1245
|
|
1025
|
-
if (git_buf_oom(&buf))
|
1246
|
+
if (git_buf_oom(&buf)) {
|
1247
|
+
git__free(var_value);
|
1026
1248
|
return -1;
|
1249
|
+
}
|
1027
1250
|
|
1028
1251
|
var->entry->name = git_buf_detach(&buf);
|
1029
1252
|
var->entry->value = var_value;
|
1030
1253
|
var->entry->level = level;
|
1254
|
+
var->included = !!depth;
|
1255
|
+
|
1256
|
+
|
1257
|
+
if ((result = append_entry(values, var)) < 0)
|
1258
|
+
break;
|
1259
|
+
else
|
1260
|
+
result = 0;
|
1031
1261
|
|
1032
1262
|
/* Add or append the new config option */
|
1033
|
-
|
1034
|
-
|
1035
|
-
|
1263
|
+
if (!git__strcmp(var->entry->name, "include.path")) {
|
1264
|
+
struct reader *r;
|
1265
|
+
git_buf path = GIT_BUF_INIT;
|
1266
|
+
char *dir;
|
1267
|
+
uint32_t index;
|
1268
|
+
|
1269
|
+
r = git_array_alloc(cfg_file->readers);
|
1270
|
+
/* The reader may have been reallocated */
|
1271
|
+
reader = git_array_get(cfg_file->readers, reader_idx);
|
1272
|
+
memset(r, 0, sizeof(struct reader));
|
1273
|
+
if ((result = git_path_dirname_r(&path, reader->file_path)) < 0)
|
1274
|
+
break;
|
1275
|
+
|
1276
|
+
/* We need to know out index in the array, as the next config_parse call may realloc */
|
1277
|
+
index = git_array_size(cfg_file->readers) - 1;
|
1278
|
+
dir = git_buf_detach(&path);
|
1279
|
+
result = included_path(&path, dir, var->entry->value);
|
1280
|
+
git__free(dir);
|
1281
|
+
|
1282
|
+
if (result < 0)
|
1283
|
+
break;
|
1284
|
+
|
1285
|
+
r->file_path = git_buf_detach(&path);
|
1286
|
+
git_buf_init(&r->buffer, 0);
|
1287
|
+
if ((result = git_futils_readbuffer_updated(&r->buffer, r->file_path, &r->file_mtime,
|
1288
|
+
&r->file_size, NULL)) < 0)
|
1289
|
+
break;
|
1290
|
+
|
1291
|
+
result = config_parse(values, cfg_file, r, level, depth+1);
|
1292
|
+
r = git_array_get(cfg_file->readers, index);
|
1293
|
+
git_buf_free(&r->buffer);
|
1294
|
+
|
1036
1295
|
if (result < 0)
|
1037
1296
|
break;
|
1038
|
-
result = 0;
|
1039
|
-
} else {
|
1040
|
-
existing = git_strmap_value_at(cfg_file->values, pos);
|
1041
|
-
while (existing->next != NULL) {
|
1042
|
-
existing = existing->next;
|
1043
|
-
}
|
1044
|
-
existing->next = var;
|
1045
1297
|
}
|
1046
1298
|
|
1047
1299
|
break;
|
@@ -1082,6 +1334,24 @@ static int write_section(git_filebuf *file, const char *key)
|
|
1082
1334
|
return result;
|
1083
1335
|
}
|
1084
1336
|
|
1337
|
+
static const char *quotes_for_value(const char *value)
|
1338
|
+
{
|
1339
|
+
const char *ptr;
|
1340
|
+
|
1341
|
+
if (value[0] == ' ' || value[0] == '\0')
|
1342
|
+
return "\"";
|
1343
|
+
|
1344
|
+
for (ptr = value; *ptr; ++ptr) {
|
1345
|
+
if (*ptr == ';' || *ptr == '#')
|
1346
|
+
return "\"";
|
1347
|
+
}
|
1348
|
+
|
1349
|
+
if (ptr[-1] == ' ')
|
1350
|
+
return "\"";
|
1351
|
+
|
1352
|
+
return "";
|
1353
|
+
}
|
1354
|
+
|
1085
1355
|
/*
|
1086
1356
|
* This is pretty much the parsing, except we write out anything we don't have
|
1087
1357
|
*/
|
@@ -1089,38 +1359,44 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
|
|
1089
1359
|
{
|
1090
1360
|
int result, c;
|
1091
1361
|
int section_matches = 0, last_section_matched = 0, preg_replaced = 0, write_trailer = 0;
|
1092
|
-
const char *pre_end = NULL, *post_start = NULL, *data_start;
|
1362
|
+
const char *pre_end = NULL, *post_start = NULL, *data_start, *write_start;
|
1093
1363
|
char *current_section = NULL, *section, *name, *ldot;
|
1094
1364
|
git_filebuf file = GIT_FILEBUF_INIT;
|
1365
|
+
struct reader *reader = git_array_get(cfg->readers, 0);
|
1095
1366
|
|
1096
1367
|
/* We need to read in our own config file */
|
1097
|
-
result = git_futils_readbuffer(&
|
1368
|
+
result = git_futils_readbuffer(&reader->buffer, cfg->file_path);
|
1098
1369
|
|
1099
1370
|
/* Initialise the reading position */
|
1100
1371
|
if (result == GIT_ENOTFOUND) {
|
1101
|
-
|
1102
|
-
|
1372
|
+
reader->read_ptr = NULL;
|
1373
|
+
reader->eof = 1;
|
1103
1374
|
data_start = NULL;
|
1104
|
-
git_buf_clear(&
|
1375
|
+
git_buf_clear(&reader->buffer);
|
1105
1376
|
} else if (result == 0) {
|
1106
|
-
|
1107
|
-
|
1108
|
-
data_start =
|
1377
|
+
reader->read_ptr = reader->buffer.ptr;
|
1378
|
+
reader->eof = 0;
|
1379
|
+
data_start = reader->read_ptr;
|
1109
1380
|
} else {
|
1110
1381
|
return -1; /* OS error when reading the file */
|
1111
1382
|
}
|
1112
1383
|
|
1384
|
+
write_start = data_start;
|
1385
|
+
|
1113
1386
|
/* Lock the file */
|
1114
|
-
if (
|
1115
|
-
|
1387
|
+
if ((result = git_filebuf_open(
|
1388
|
+
&file, cfg->file_path, 0, GIT_CONFIG_FILE_MODE)) < 0) {
|
1389
|
+
git_buf_free(&reader->buffer);
|
1390
|
+
return result;
|
1391
|
+
}
|
1116
1392
|
|
1117
|
-
skip_bom(
|
1393
|
+
skip_bom(reader);
|
1118
1394
|
ldot = strrchr(key, '.');
|
1119
1395
|
name = ldot + 1;
|
1120
1396
|
section = git__strndup(key, ldot - key);
|
1121
1397
|
|
1122
|
-
while (!
|
1123
|
-
c =
|
1398
|
+
while (!reader->eof) {
|
1399
|
+
c = reader_peek(reader, SKIP_WHITESPACE);
|
1124
1400
|
|
1125
1401
|
if (c == '\0') { /* We've arrived at the end of the file */
|
1126
1402
|
break;
|
@@ -1133,11 +1409,11 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
|
|
1133
1409
|
* new section. If we actually want to replace it, the
|
1134
1410
|
* default case will take care of updating them.
|
1135
1411
|
*/
|
1136
|
-
pre_end = post_start =
|
1412
|
+
pre_end = post_start = reader->read_ptr;
|
1137
1413
|
|
1138
1414
|
git__free(current_section);
|
1139
1415
|
current_section = NULL;
|
1140
|
-
if (parse_section_header(
|
1416
|
+
if (parse_section_header(reader, ¤t_section) < 0)
|
1141
1417
|
goto rewrite_fail;
|
1142
1418
|
|
1143
1419
|
/* Keep track of when it stops matching */
|
@@ -1146,7 +1422,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
|
|
1146
1422
|
}
|
1147
1423
|
|
1148
1424
|
else if (c == ';' || c == '#') {
|
1149
|
-
|
1425
|
+
reader_consume_line(reader);
|
1150
1426
|
}
|
1151
1427
|
|
1152
1428
|
else {
|
@@ -1162,15 +1438,15 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
|
|
1162
1438
|
*/
|
1163
1439
|
if (!section_matches) {
|
1164
1440
|
if (!last_section_matched) {
|
1165
|
-
|
1441
|
+
reader_consume_line(reader);
|
1166
1442
|
continue;
|
1167
1443
|
}
|
1168
1444
|
} else {
|
1169
1445
|
int has_matched = 0;
|
1170
1446
|
char *var_name, *var_value;
|
1171
1447
|
|
1172
|
-
pre_end =
|
1173
|
-
if (parse_variable(
|
1448
|
+
pre_end = reader->read_ptr;
|
1449
|
+
if (parse_variable(reader, &var_name, &var_value) < 0)
|
1174
1450
|
goto rewrite_fail;
|
1175
1451
|
|
1176
1452
|
/* First try to match the name of the variable */
|
@@ -1189,23 +1465,28 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
|
|
1189
1465
|
if (!has_matched)
|
1190
1466
|
continue;
|
1191
1467
|
|
1192
|
-
post_start =
|
1468
|
+
post_start = reader->read_ptr;
|
1193
1469
|
}
|
1194
1470
|
|
1195
1471
|
/* We've found the variable we wanted to change, so
|
1196
1472
|
* write anything up to it */
|
1197
|
-
git_filebuf_write(&file,
|
1473
|
+
git_filebuf_write(&file, write_start, pre_end - write_start);
|
1198
1474
|
preg_replaced = 1;
|
1199
1475
|
|
1200
1476
|
/* Then replace the variable. If the value is NULL, it
|
1201
1477
|
* means we want to delete it, so don't write anything. */
|
1202
1478
|
if (value != NULL) {
|
1203
|
-
|
1479
|
+
const char *q = quotes_for_value(value);
|
1480
|
+
git_filebuf_printf(&file, "\t%s = %s%s%s\n", name, q, value, q);
|
1204
1481
|
}
|
1205
1482
|
|
1206
|
-
/*
|
1207
|
-
|
1208
|
-
|
1483
|
+
/*
|
1484
|
+
* If we have a multivar, we should keep looking for entries,
|
1485
|
+
* but only if we're in the right section. Otherwise we'll end up
|
1486
|
+
* looping on the edge of a matching and a non-matching section.
|
1487
|
+
*/
|
1488
|
+
if (section_matches && preg != NULL) {
|
1489
|
+
write_start = post_start;
|
1209
1490
|
continue;
|
1210
1491
|
}
|
1211
1492
|
|
@@ -1232,12 +1513,14 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
|
|
1232
1513
|
*/
|
1233
1514
|
if (write_trailer) {
|
1234
1515
|
/* Write out rest of the file */
|
1235
|
-
git_filebuf_write(&file, post_start,
|
1516
|
+
git_filebuf_write(&file, post_start, reader->buffer.size - (post_start - data_start));
|
1236
1517
|
} else {
|
1237
1518
|
if (preg_replaced) {
|
1238
|
-
git_filebuf_printf(&file, "\n%s",
|
1519
|
+
git_filebuf_printf(&file, "\n%s", write_start);
|
1239
1520
|
} else {
|
1240
|
-
|
1521
|
+
const char *q;
|
1522
|
+
|
1523
|
+
git_filebuf_write(&file, reader->buffer.ptr, reader->buffer.size);
|
1241
1524
|
|
1242
1525
|
/* And now if we just need to add a variable */
|
1243
1526
|
if (!section_matches && write_section(&file, section) < 0)
|
@@ -1248,15 +1531,16 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
|
|
1248
1531
|
* this, but instead we'll handle it gracefully with an error. */
|
1249
1532
|
if (value == NULL) {
|
1250
1533
|
giterr_set(GITERR_CONFIG,
|
1251
|
-
"
|
1534
|
+
"race condition when writing a config file (a cvar has been removed)");
|
1252
1535
|
goto rewrite_fail;
|
1253
1536
|
}
|
1254
1537
|
|
1255
1538
|
/* If we are here, there is at least a section line */
|
1256
|
-
if (
|
1539
|
+
if (reader->buffer.size > 0 && *(reader->buffer.ptr + reader->buffer.size - 1) != '\n')
|
1257
1540
|
git_filebuf_write(&file, "\n", 1);
|
1258
1541
|
|
1259
|
-
|
1542
|
+
q = quotes_for_value(value);
|
1543
|
+
git_filebuf_printf(&file, "\t%s = %s%s%s\n", name, q, value, q);
|
1260
1544
|
}
|
1261
1545
|
}
|
1262
1546
|
|
@@ -1264,10 +1548,10 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
|
|
1264
1548
|
git__free(current_section);
|
1265
1549
|
|
1266
1550
|
/* refresh stats - if this errors, then commit will error too */
|
1267
|
-
(void)git_filebuf_stats(&
|
1551
|
+
(void)git_filebuf_stats(&reader->file_mtime, &reader->file_size, &file);
|
1268
1552
|
|
1269
|
-
result = git_filebuf_commit(&file
|
1270
|
-
git_buf_free(&
|
1553
|
+
result = git_filebuf_commit(&file);
|
1554
|
+
git_buf_free(&reader->buffer);
|
1271
1555
|
|
1272
1556
|
return result;
|
1273
1557
|
|
@@ -1276,7 +1560,7 @@ rewrite_fail:
|
|
1276
1560
|
git__free(current_section);
|
1277
1561
|
|
1278
1562
|
git_filebuf_cleanup(&file);
|
1279
|
-
git_buf_free(&
|
1563
|
+
git_buf_free(&reader->buffer);
|
1280
1564
|
return -1;
|
1281
1565
|
}
|
1282
1566
|
|
@@ -1293,6 +1577,9 @@ static char *escape_value(const char *ptr)
|
|
1293
1577
|
assert(ptr);
|
1294
1578
|
|
1295
1579
|
len = strlen(ptr);
|
1580
|
+
if (!len)
|
1581
|
+
return git__calloc(1, sizeof(char));
|
1582
|
+
|
1296
1583
|
git_buf_grow(&buf, len);
|
1297
1584
|
|
1298
1585
|
while (*ptr != '\0') {
|
@@ -1365,19 +1652,19 @@ static int is_multiline_var(const char *str)
|
|
1365
1652
|
return (end > str) && (count & 1);
|
1366
1653
|
}
|
1367
1654
|
|
1368
|
-
static int parse_multiline_variable(
|
1655
|
+
static int parse_multiline_variable(struct reader *reader, git_buf *value, int in_quotes)
|
1369
1656
|
{
|
1370
1657
|
char *line = NULL, *proc_line = NULL;
|
1371
1658
|
int quote_count;
|
1372
1659
|
|
1373
1660
|
/* Check that the next line exists */
|
1374
|
-
line =
|
1661
|
+
line = reader_readline(reader, false);
|
1375
1662
|
if (line == NULL)
|
1376
1663
|
return -1;
|
1377
1664
|
|
1378
1665
|
/* We've reached the end of the file, there is input missing */
|
1379
1666
|
if (line[0] == '\0') {
|
1380
|
-
set_parse_error(
|
1667
|
+
set_parse_error(reader, 0, "Unexpected end of file while parsing multine var");
|
1381
1668
|
git__free(line);
|
1382
1669
|
return -1;
|
1383
1670
|
}
|
@@ -1387,7 +1674,7 @@ static int parse_multiline_variable(diskfile_backend *cfg, git_buf *value, int i
|
|
1387
1674
|
/* If it was just a comment, pretend it didn't exist */
|
1388
1675
|
if (line[0] == '\0') {
|
1389
1676
|
git__free(line);
|
1390
|
-
return parse_multiline_variable(
|
1677
|
+
return parse_multiline_variable(reader, value, quote_count);
|
1391
1678
|
/* TODO: unbounded recursion. This **could** be exploitable */
|
1392
1679
|
}
|
1393
1680
|
|
@@ -1395,7 +1682,7 @@ static int parse_multiline_variable(diskfile_backend *cfg, git_buf *value, int i
|
|
1395
1682
|
* standard, this character **has** to be last one in the buf, with
|
1396
1683
|
* no whitespace after it */
|
1397
1684
|
assert(is_multiline_var(value->ptr));
|
1398
|
-
|
1685
|
+
git_buf_shorten(value, 1);
|
1399
1686
|
|
1400
1687
|
proc_line = fixup_line(line, in_quotes);
|
1401
1688
|
if (proc_line == NULL) {
|
@@ -1412,19 +1699,19 @@ static int parse_multiline_variable(diskfile_backend *cfg, git_buf *value, int i
|
|
1412
1699
|
* keep putting stuff in the buffer
|
1413
1700
|
*/
|
1414
1701
|
if (is_multiline_var(value->ptr))
|
1415
|
-
return parse_multiline_variable(
|
1702
|
+
return parse_multiline_variable(reader, value, quote_count);
|
1416
1703
|
|
1417
1704
|
return 0;
|
1418
1705
|
}
|
1419
1706
|
|
1420
|
-
static int parse_variable(
|
1707
|
+
static int parse_variable(struct reader *reader, char **var_name, char **var_value)
|
1421
1708
|
{
|
1422
1709
|
const char *var_end = NULL;
|
1423
1710
|
const char *value_start = NULL;
|
1424
1711
|
char *line;
|
1425
1712
|
int quote_count;
|
1426
1713
|
|
1427
|
-
line =
|
1714
|
+
line = reader_readline(reader, true);
|
1428
1715
|
if (line == NULL)
|
1429
1716
|
return -1;
|
1430
1717
|
|
@@ -1459,7 +1746,7 @@ static int parse_variable(diskfile_backend *cfg, char **var_name, char **var_val
|
|
1459
1746
|
GITERR_CHECK_ALLOC(proc_line);
|
1460
1747
|
git_buf_puts(&multi_value, proc_line);
|
1461
1748
|
git__free(proc_line);
|
1462
|
-
if (parse_multiline_variable(
|
1749
|
+
if (parse_multiline_variable(reader, &multi_value, quote_count) < 0 || git_buf_oom(&multi_value)) {
|
1463
1750
|
git__free(*var_name);
|
1464
1751
|
git__free(line);
|
1465
1752
|
git_buf_free(&multi_value);
|