rugged 0.1.2 → 0.16.0b1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +25 -36
- data/Rakefile +20 -98
- data/ext/rugged/extconf.rb +44 -4
- data/ext/rugged/remote.c +215 -0
- data/ext/rugged/rugged.c +171 -0
- data/ext/rugged/rugged.h +126 -0
- data/ext/rugged/rugged_blob.c +99 -0
- data/ext/rugged/rugged_commit.c +224 -0
- data/ext/rugged/rugged_config.c +238 -0
- data/ext/rugged/rugged_index.c +440 -0
- data/ext/rugged/rugged_object.c +203 -0
- data/ext/rugged/rugged_reference.c +401 -0
- data/ext/rugged/rugged_repo.c +482 -0
- data/ext/rugged/rugged_revwalk.c +138 -0
- data/ext/rugged/rugged_signature.c +80 -0
- data/ext/rugged/rugged_tag.c +216 -0
- data/ext/rugged/rugged_tree.c +322 -0
- data/ext/rugged/vendor/libgit2-dist.tar.gz +0 -0
- data/ext/rugged/vendor/libgit2-dist/deps/http-parser/http_parser.c +1778 -0
- data/ext/rugged/vendor/libgit2-dist/deps/http-parser/http_parser.h +267 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/adler32.c +169 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/crc32.c +442 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/crc32.h +441 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/deflate.c +1834 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/deflate.h +342 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffast.c +340 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffast.h +11 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inffixed.h +94 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inflate.c +1480 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inflate.h +122 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inftrees.c +330 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/inftrees.h +62 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/trees.c +1244 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/trees.h +128 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/zconf.h +54 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/zlib.h +1613 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/zutil.c +318 -0
- data/ext/rugged/vendor/libgit2-dist/deps/zlib/zutil.h +274 -0
- data/ext/rugged/vendor/libgit2-dist/examples/general.c +451 -0
- data/ext/rugged/vendor/libgit2-dist/examples/network/common.h +14 -0
- data/ext/rugged/vendor/libgit2-dist/examples/network/fetch.c +97 -0
- data/ext/rugged/vendor/libgit2-dist/examples/network/git2.c +58 -0
- data/ext/rugged/vendor/libgit2-dist/examples/network/index-pack.c +47 -0
- data/ext/rugged/vendor/libgit2-dist/examples/network/ls-remote.c +76 -0
- data/ext/rugged/vendor/libgit2-dist/examples/showindex.c +43 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2.h +44 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/blob.h +120 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/branch.h +15 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/commit.h +263 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/common.h +103 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/config.h +278 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/errors.h +144 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/index.h +306 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/indexer.h +76 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/inttypes.h +305 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/net.h +51 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/object.h +173 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/odb.h +331 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/odb_backend.h +100 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/oid.h +218 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/reflog.h +128 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/refs.h +309 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/refspec.h +60 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/remote.h +176 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/repository.h +290 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/revwalk.h +169 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/signature.h +65 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/status.h +63 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/stdint.h +247 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/tag.h +279 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/threads.h +48 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/tree.h +318 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/types.h +169 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/version.h +15 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/windows.h +59 -0
- data/ext/rugged/vendor/libgit2-dist/include/git2/zlib.h +40 -0
- data/ext/rugged/vendor/libgit2-dist/src/blob.c +135 -0
- data/ext/rugged/vendor/libgit2-dist/src/blob.h +23 -0
- data/ext/rugged/vendor/libgit2-dist/src/bswap.h +97 -0
- data/ext/rugged/vendor/libgit2-dist/src/buffer.c +113 -0
- data/ext/rugged/vendor/libgit2-dist/src/buffer.h +32 -0
- data/ext/rugged/vendor/libgit2-dist/src/cache.c +111 -0
- data/ext/rugged/vendor/libgit2-dist/src/cache.h +64 -0
- data/ext/rugged/vendor/libgit2-dist/src/cc-compat.h +67 -0
- data/ext/rugged/vendor/libgit2-dist/src/commit.c +299 -0
- data/ext/rugged/vendor/libgit2-dist/src/commit.h +34 -0
- data/ext/rugged/vendor/libgit2-dist/src/common.h +64 -0
- data/ext/rugged/vendor/libgit2-dist/src/config.c +418 -0
- data/ext/rugged/vendor/libgit2-dist/src/config.h +24 -0
- data/ext/rugged/vendor/libgit2-dist/src/config_file.c +1210 -0
- data/ext/rugged/vendor/libgit2-dist/src/delta-apply.c +115 -0
- data/ext/rugged/vendor/libgit2-dist/src/delta-apply.h +33 -0
- data/ext/rugged/vendor/libgit2-dist/src/dir.h +47 -0
- data/ext/rugged/vendor/libgit2-dist/src/errors.c +104 -0
- data/ext/rugged/vendor/libgit2-dist/src/fetch.c +172 -0
- data/ext/rugged/vendor/libgit2-dist/src/fetch.h +18 -0
- data/ext/rugged/vendor/libgit2-dist/src/filebuf.c +400 -0
- data/ext/rugged/vendor/libgit2-dist/src/filebuf.h +72 -0
- data/ext/rugged/vendor/libgit2-dist/src/fileops.c +358 -0
- data/ext/rugged/vendor/libgit2-dist/src/fileops.h +151 -0
- data/ext/rugged/vendor/libgit2-dist/src/global.c +134 -0
- data/ext/rugged/vendor/libgit2-dist/src/global.h +24 -0
- data/ext/rugged/vendor/libgit2-dist/src/hash.c +74 -0
- data/ext/rugged/vendor/libgit2-dist/src/hash.h +29 -0
- data/ext/rugged/vendor/libgit2-dist/src/hashtable.c +243 -0
- data/ext/rugged/vendor/libgit2-dist/src/hashtable.h +80 -0
- data/ext/rugged/vendor/libgit2-dist/src/index.c +918 -0
- data/ext/rugged/vendor/libgit2-dist/src/index.h +34 -0
- data/ext/rugged/vendor/libgit2-dist/src/indexer.c +401 -0
- data/ext/rugged/vendor/libgit2-dist/src/map.h +37 -0
- data/ext/rugged/vendor/libgit2-dist/src/mwindow.c +272 -0
- data/ext/rugged/vendor/libgit2-dist/src/mwindow.h +45 -0
- data/ext/rugged/vendor/libgit2-dist/src/netops.c +198 -0
- data/ext/rugged/vendor/libgit2-dist/src/netops.h +36 -0
- data/ext/rugged/vendor/libgit2-dist/src/object.c +295 -0
- data/ext/rugged/vendor/libgit2-dist/src/odb.c +672 -0
- data/ext/rugged/vendor/libgit2-dist/src/odb.h +43 -0
- data/ext/rugged/vendor/libgit2-dist/src/odb_loose.c +855 -0
- data/ext/rugged/vendor/libgit2-dist/src/odb_pack.c +485 -0
- data/ext/rugged/vendor/libgit2-dist/src/oid.c +388 -0
- data/ext/rugged/vendor/libgit2-dist/src/pack.c +788 -0
- data/ext/rugged/vendor/libgit2-dist/src/pack.h +99 -0
- data/ext/rugged/vendor/libgit2-dist/src/path.c +270 -0
- data/ext/rugged/vendor/libgit2-dist/src/path.h +84 -0
- data/ext/rugged/vendor/libgit2-dist/src/pkt.c +426 -0
- data/ext/rugged/vendor/libgit2-dist/src/pkt.h +77 -0
- data/ext/rugged/vendor/libgit2-dist/src/posix.c +94 -0
- data/ext/rugged/vendor/libgit2-dist/src/posix.h +69 -0
- data/ext/rugged/vendor/libgit2-dist/src/ppc/sha1.c +70 -0
- data/ext/rugged/vendor/libgit2-dist/src/ppc/sha1.h +26 -0
- data/ext/rugged/vendor/libgit2-dist/src/pqueue.c +141 -0
- data/ext/rugged/vendor/libgit2-dist/src/pqueue.h +81 -0
- data/ext/rugged/vendor/libgit2-dist/src/protocol.c +50 -0
- data/ext/rugged/vendor/libgit2-dist/src/protocol.h +23 -0
- data/ext/rugged/vendor/libgit2-dist/src/reflog.c +318 -0
- data/ext/rugged/vendor/libgit2-dist/src/reflog.h +34 -0
- data/ext/rugged/vendor/libgit2-dist/src/refs.c +1693 -0
- data/ext/rugged/vendor/libgit2-dist/src/refs.h +58 -0
- data/ext/rugged/vendor/libgit2-dist/src/refspec.c +95 -0
- data/ext/rugged/vendor/libgit2-dist/src/refspec.h +23 -0
- data/ext/rugged/vendor/libgit2-dist/src/remote.c +339 -0
- data/ext/rugged/vendor/libgit2-dist/src/remote.h +25 -0
- data/ext/rugged/vendor/libgit2-dist/src/repository.c +849 -0
- data/ext/rugged/vendor/libgit2-dist/src/repository.h +60 -0
- data/ext/rugged/vendor/libgit2-dist/src/revwalk.c +569 -0
- data/ext/rugged/vendor/libgit2-dist/src/sha1.c +280 -0
- data/ext/rugged/vendor/libgit2-dist/src/sha1.h +21 -0
- data/ext/rugged/vendor/libgit2-dist/src/sha1_lookup.c +177 -0
- data/ext/rugged/vendor/libgit2-dist/src/sha1_lookup.h +18 -0
- data/ext/rugged/vendor/libgit2-dist/src/signature.c +335 -0
- data/ext/rugged/vendor/libgit2-dist/src/signature.h +18 -0
- data/ext/rugged/vendor/libgit2-dist/src/status.c +696 -0
- data/ext/rugged/vendor/libgit2-dist/src/tag.c +446 -0
- data/ext/rugged/vendor/libgit2-dist/src/tag.h +28 -0
- data/ext/rugged/vendor/libgit2-dist/src/thread-utils.c +55 -0
- data/ext/rugged/vendor/libgit2-dist/src/thread-utils.h +108 -0
- data/ext/rugged/vendor/libgit2-dist/src/transport.c +85 -0
- data/ext/rugged/vendor/libgit2-dist/src/transport.h +110 -0
- data/ext/rugged/vendor/libgit2-dist/src/transports/git.c +502 -0
- data/ext/rugged/vendor/libgit2-dist/src/transports/http.c +756 -0
- data/ext/rugged/vendor/libgit2-dist/src/transports/local.c +235 -0
- data/ext/rugged/vendor/libgit2-dist/src/tree-cache.c +201 -0
- data/ext/rugged/vendor/libgit2-dist/src/tree-cache.h +31 -0
- data/ext/rugged/vendor/libgit2-dist/src/tree.c +758 -0
- data/ext/rugged/vendor/libgit2-dist/src/tree.h +37 -0
- data/ext/rugged/vendor/libgit2-dist/src/tsort.c +365 -0
- data/ext/rugged/vendor/libgit2-dist/src/unix/map.c +70 -0
- data/ext/rugged/vendor/libgit2-dist/src/unix/posix.h +25 -0
- data/ext/rugged/vendor/libgit2-dist/src/util.c +381 -0
- data/ext/rugged/vendor/libgit2-dist/src/util.h +137 -0
- data/ext/rugged/vendor/libgit2-dist/src/vector.c +174 -0
- data/ext/rugged/vendor/libgit2-dist/src/vector.h +45 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/dir.c +115 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/fnmatch.c +180 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/fnmatch.h +27 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/map.c +131 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/mingw-compat.h +24 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/msvc-compat.h +38 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/posix.h +53 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/posix_w32.c +404 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/pthread.c +65 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/pthread.h +40 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/utf-conv.c +88 -0
- data/ext/rugged/vendor/libgit2-dist/src/win32/utf-conv.h +17 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/buf/basic.c +29 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/clay.h +187 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/clay_libgit2.h +28 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/clay_main.c +1073 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/config/add.c +37 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/config/new.c +36 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/config/read.c +209 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/config/stress.c +39 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/config/write.c +77 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/dirent.c +222 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/filebuf.c +106 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/oid.c +18 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/path.c +139 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/rmdir.c +50 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/string.c +28 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/strtol.c +37 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/core/vector.c +66 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/index/rename.c +60 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/network/remotes.c +50 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/chars.c +52 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/compare.c +124 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/convert.c +75 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/data.h +323 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/fromstr.c +30 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/hash.c +162 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/short.c +94 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/size.c +13 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/raw/type2string.c +54 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/object/tree/frompath.c +75 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/loose.c +84 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/loose_data.h +522 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/pack_data.h +151 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/packed.c +78 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/odb/sorting.c +71 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/getters.c +68 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/init.c +104 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/repo/open.c +54 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/status/single.c +38 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/status/status_data.h +48 -0
- data/ext/rugged/vendor/libgit2-dist/tests-clay/status/worktree.c +124 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t00-core.c +628 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t01-data.h +322 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t01-rawobj.c +638 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t03-data.h +344 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t03-objwrite.c +255 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t04-commit.c +788 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t05-revwalk.c +140 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t06-index.c +219 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t07-hashtable.c +192 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t08-tag.c +357 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t09-tree.c +221 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t10-refs.c +1294 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t12-repo.c +174 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t13-threads.c +41 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t17-bufs.c +61 -0
- data/ext/rugged/vendor/libgit2-dist/tests/t18-status.c +448 -0
- data/ext/rugged/vendor/libgit2-dist/tests/test_helpers.c +310 -0
- data/ext/rugged/vendor/libgit2-dist/tests/test_helpers.h +83 -0
- data/ext/rugged/vendor/libgit2-dist/tests/test_lib.c +198 -0
- data/ext/rugged/vendor/libgit2-dist/tests/test_lib.h +54 -0
- data/ext/rugged/vendor/libgit2-dist/tests/test_main.c +89 -0
- data/lib/rugged.rb +4 -3
- data/lib/rugged/index.rb +0 -8
- data/lib/rugged/objects.rb +45 -0
- data/lib/rugged/repository.rb +29 -0
- data/lib/rugged/tree.rb +16 -6
- data/lib/rugged/version.rb +1 -1
- data/lib/rugged/walker.rb +5 -0
- data/test/blob_test.rb +18 -14
- data/test/commit_test.rb +28 -26
- data/test/coverage/HEAD.json +1 -0
- data/test/coverage/cover.rb +106 -0
- data/test/fixtures/testrepo.git/refs/heads/new_name +1 -0
- data/test/index_test.rb +101 -78
- data/test/lib_test.rb +4 -4
- data/test/object_test.rb +3 -3
- data/test/reference_test.rb +75 -0
- data/test/remote_test.rb +19 -0
- data/test/repo_pack_test.rb +4 -4
- data/test/repo_test.rb +44 -15
- data/test/tag_test.rb +7 -17
- data/test/test_helper.rb +24 -5
- data/test/tree_test.rb +30 -12
- data/test/walker_test.rb +40 -31
- metadata +273 -50
- data/lib/rugged/person.rb +0 -20
- data/lib/rugged/tree_entry.rb +0 -9
- data/test/fixtures/testrepo.git/objects/1d/83f106355e4309a293e42ad2a2c4b8bdbe77ae +0 -0
- data/test/fixtures/testrepo.git/objects/2f/3321418db5b2a841375b8b70880a8ab5a4148f +0 -0
- data/test/fixtures/testrepo.git/objects/36/9b00a7700cca3a506d79e301d6ad8bf735d9ee +0 -3
- data/test/fixtures/testrepo.git/objects/3d/b1b5ceace59ff65279757003763046fd4cbbe6 +0 -0
- data/test/fixtures/testrepo.git/objects/4c/d1604907792e2c43e03dcec1216f99d63e68c4 +0 -3
- data/test/fixtures/testrepo.git/objects/e0/f46d77041c149296549b01ed4a18b02c4b7400 +0 -0
@@ -0,0 +1,299 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2009-2011 the libgit2 contributors
|
3
|
+
*
|
4
|
+
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
|
+
* a Linking Exception. For full terms see the included COPYING file.
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include "git2/common.h"
|
9
|
+
#include "git2/object.h"
|
10
|
+
#include "git2/repository.h"
|
11
|
+
#include "git2/signature.h"
|
12
|
+
|
13
|
+
#include "common.h"
|
14
|
+
#include "odb.h"
|
15
|
+
#include "commit.h"
|
16
|
+
#include "signature.h"
|
17
|
+
|
18
|
+
#include <stdarg.h>
|
19
|
+
|
20
|
+
#define COMMIT_BASIC_PARSE 0x0
|
21
|
+
#define COMMIT_FULL_PARSE 0x1
|
22
|
+
|
23
|
+
#define COMMIT_PRINT(commit) {\
|
24
|
+
char oid[41]; oid[40] = 0;\
|
25
|
+
git_oid_fmt(oid, &commit->object.id);\
|
26
|
+
printf("Oid: %s | In degree: %d | Time: %u\n", oid, commit->in_degree, commit->commit_time);\
|
27
|
+
}
|
28
|
+
|
29
|
+
static void clear_parents(git_commit *commit)
|
30
|
+
{
|
31
|
+
unsigned int i;
|
32
|
+
|
33
|
+
for (i = 0; i < commit->parent_oids.length; ++i) {
|
34
|
+
git_oid *parent = git_vector_get(&commit->parent_oids, i);
|
35
|
+
git__free(parent);
|
36
|
+
}
|
37
|
+
|
38
|
+
git_vector_clear(&commit->parent_oids);
|
39
|
+
}
|
40
|
+
|
41
|
+
void git_commit__free(git_commit *commit)
|
42
|
+
{
|
43
|
+
clear_parents(commit);
|
44
|
+
git_vector_free(&commit->parent_oids);
|
45
|
+
|
46
|
+
git_signature_free(commit->author);
|
47
|
+
git_signature_free(commit->committer);
|
48
|
+
|
49
|
+
git__free(commit->message);
|
50
|
+
git__free(commit->message_encoding);
|
51
|
+
git__free(commit);
|
52
|
+
}
|
53
|
+
|
54
|
+
const git_oid *git_commit_id(git_commit *c)
|
55
|
+
{
|
56
|
+
return git_object_id((git_object *)c);
|
57
|
+
}
|
58
|
+
|
59
|
+
int git_commit_create_v(
|
60
|
+
git_oid *oid,
|
61
|
+
git_repository *repo,
|
62
|
+
const char *update_ref,
|
63
|
+
const git_signature *author,
|
64
|
+
const git_signature *committer,
|
65
|
+
const char *message_encoding,
|
66
|
+
const char *message,
|
67
|
+
const git_tree *tree,
|
68
|
+
int parent_count,
|
69
|
+
...)
|
70
|
+
{
|
71
|
+
va_list ap;
|
72
|
+
int i, error;
|
73
|
+
const git_commit **parents;
|
74
|
+
|
75
|
+
parents = git__malloc(parent_count * sizeof(git_commit *));
|
76
|
+
|
77
|
+
va_start(ap, parent_count);
|
78
|
+
for (i = 0; i < parent_count; ++i)
|
79
|
+
parents[i] = va_arg(ap, const git_commit *);
|
80
|
+
va_end(ap);
|
81
|
+
|
82
|
+
error = git_commit_create(
|
83
|
+
oid, repo, update_ref, author, committer,
|
84
|
+
message_encoding, message,
|
85
|
+
tree, parent_count, parents);
|
86
|
+
|
87
|
+
git__free((void *)parents);
|
88
|
+
|
89
|
+
return error;
|
90
|
+
}
|
91
|
+
|
92
|
+
int git_commit_create(
|
93
|
+
git_oid *oid,
|
94
|
+
git_repository *repo,
|
95
|
+
const char *update_ref,
|
96
|
+
const git_signature *author,
|
97
|
+
const git_signature *committer,
|
98
|
+
const char *message_encoding,
|
99
|
+
const char *message,
|
100
|
+
const git_tree *tree,
|
101
|
+
int parent_count,
|
102
|
+
const git_commit *parents[])
|
103
|
+
{
|
104
|
+
git_buf commit = GIT_BUF_INIT;
|
105
|
+
int error, i;
|
106
|
+
git_odb *odb;
|
107
|
+
|
108
|
+
if (git_object_owner((const git_object *)tree) != repo)
|
109
|
+
return git__throw(GIT_EINVALIDARGS, "The given tree does not belong to this repository");
|
110
|
+
|
111
|
+
git_oid__writebuf(&commit, "tree ", git_object_id((const git_object *)tree));
|
112
|
+
|
113
|
+
for (i = 0; i < parent_count; ++i) {
|
114
|
+
if (git_object_owner((const git_object *)parents[i]) != repo) {
|
115
|
+
error = git__throw(GIT_EINVALIDARGS, "The given parent does not belong to this repository");
|
116
|
+
goto cleanup;
|
117
|
+
}
|
118
|
+
|
119
|
+
git_oid__writebuf(&commit, "parent ", git_object_id((const git_object *)parents[i]));
|
120
|
+
}
|
121
|
+
|
122
|
+
git_signature__writebuf(&commit, "author ", author);
|
123
|
+
git_signature__writebuf(&commit, "committer ", committer);
|
124
|
+
|
125
|
+
if (message_encoding != NULL)
|
126
|
+
git_buf_printf(&commit, "encoding %s\n", message_encoding);
|
127
|
+
|
128
|
+
git_buf_putc(&commit, '\n');
|
129
|
+
git_buf_puts(&commit, message);
|
130
|
+
|
131
|
+
if (git_buf_oom(&commit)) {
|
132
|
+
error = git__throw(GIT_ENOMEM, "Not enough memory to build the commit data");
|
133
|
+
goto cleanup;
|
134
|
+
}
|
135
|
+
|
136
|
+
error = git_repository_odb__weakptr(&odb, repo);
|
137
|
+
if (error < GIT_SUCCESS)
|
138
|
+
goto cleanup;
|
139
|
+
|
140
|
+
error = git_odb_write(oid, odb, commit.ptr, commit.size, GIT_OBJ_COMMIT);
|
141
|
+
git_buf_free(&commit);
|
142
|
+
|
143
|
+
if (error == GIT_SUCCESS && update_ref != NULL) {
|
144
|
+
git_reference *head;
|
145
|
+
git_reference *target;
|
146
|
+
|
147
|
+
error = git_reference_lookup(&head, repo, update_ref);
|
148
|
+
if (error < GIT_SUCCESS)
|
149
|
+
return git__rethrow(error, "Failed to create commit");
|
150
|
+
|
151
|
+
error = git_reference_resolve(&target, head);
|
152
|
+
if (error < GIT_SUCCESS) {
|
153
|
+
if (error != GIT_ENOTFOUND) {
|
154
|
+
git_reference_free(head);
|
155
|
+
return git__rethrow(error, "Failed to create commit");
|
156
|
+
}
|
157
|
+
/*
|
158
|
+
* The target of the reference was not found. This can happen
|
159
|
+
* just after a repository has been initialized (the master
|
160
|
+
* branch doesn't exist yet, as it doesn't have anything to
|
161
|
+
* point to) or after an orphan checkout, so if the target
|
162
|
+
* branch doesn't exist yet, create it and return.
|
163
|
+
*/
|
164
|
+
error = git_reference_create_oid(&target, repo, git_reference_target(head), oid, 1);
|
165
|
+
|
166
|
+
git_reference_free(head);
|
167
|
+
if (error == GIT_SUCCESS)
|
168
|
+
git_reference_free(target);
|
169
|
+
|
170
|
+
return error;
|
171
|
+
}
|
172
|
+
|
173
|
+
error = git_reference_set_oid(target, oid);
|
174
|
+
|
175
|
+
git_reference_free(head);
|
176
|
+
git_reference_free(target);
|
177
|
+
}
|
178
|
+
|
179
|
+
if (error < GIT_SUCCESS)
|
180
|
+
return git__rethrow(error, "Failed to create commit");
|
181
|
+
|
182
|
+
return GIT_SUCCESS;
|
183
|
+
|
184
|
+
cleanup:
|
185
|
+
git_buf_free(&commit);
|
186
|
+
return error;
|
187
|
+
}
|
188
|
+
|
189
|
+
int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len)
|
190
|
+
{
|
191
|
+
const char *buffer = data;
|
192
|
+
const char *buffer_end = (const char *)data + len;
|
193
|
+
|
194
|
+
git_oid parent_oid;
|
195
|
+
int error;
|
196
|
+
|
197
|
+
git_vector_init(&commit->parent_oids, 4, NULL);
|
198
|
+
|
199
|
+
if ((error = git_oid__parse(&commit->tree_oid, &buffer, buffer_end, "tree ")) < GIT_SUCCESS)
|
200
|
+
return git__rethrow(error, "Failed to parse buffer");
|
201
|
+
|
202
|
+
/*
|
203
|
+
* TODO: commit grafts!
|
204
|
+
*/
|
205
|
+
|
206
|
+
while (git_oid__parse(&parent_oid, &buffer, buffer_end, "parent ") == GIT_SUCCESS) {
|
207
|
+
git_oid *new_oid;
|
208
|
+
|
209
|
+
new_oid = git__malloc(sizeof(git_oid));
|
210
|
+
git_oid_cpy(new_oid, &parent_oid);
|
211
|
+
|
212
|
+
if (git_vector_insert(&commit->parent_oids, new_oid) < GIT_SUCCESS)
|
213
|
+
return GIT_ENOMEM;
|
214
|
+
}
|
215
|
+
|
216
|
+
commit->author = git__malloc(sizeof(git_signature));
|
217
|
+
if ((error = git_signature__parse(commit->author, &buffer, buffer_end, "author ", '\n')) < GIT_SUCCESS)
|
218
|
+
return git__rethrow(error, "Failed to parse commit");
|
219
|
+
|
220
|
+
/* Always parse the committer; we need the commit time */
|
221
|
+
commit->committer = git__malloc(sizeof(git_signature));
|
222
|
+
if ((error = git_signature__parse(commit->committer, &buffer, buffer_end, "committer ", '\n')) < GIT_SUCCESS)
|
223
|
+
return git__rethrow(error, "Failed to parse commit");
|
224
|
+
|
225
|
+
if (git__prefixcmp(buffer, "encoding ") == 0) {
|
226
|
+
const char *encoding_end;
|
227
|
+
buffer += strlen("encoding ");
|
228
|
+
|
229
|
+
encoding_end = buffer;
|
230
|
+
while (encoding_end < buffer_end && *encoding_end != '\n')
|
231
|
+
encoding_end++;
|
232
|
+
|
233
|
+
commit->message_encoding = git__strndup(buffer, encoding_end - buffer);
|
234
|
+
if (!commit->message_encoding)
|
235
|
+
return GIT_ENOMEM;
|
236
|
+
|
237
|
+
buffer = encoding_end;
|
238
|
+
}
|
239
|
+
|
240
|
+
/* parse commit message */
|
241
|
+
while (buffer < buffer_end - 1 && *buffer == '\n')
|
242
|
+
buffer++;
|
243
|
+
|
244
|
+
if (buffer <= buffer_end) {
|
245
|
+
commit->message = git__strndup(buffer, buffer_end - buffer);
|
246
|
+
if (!commit->message)
|
247
|
+
return GIT_ENOMEM;
|
248
|
+
}
|
249
|
+
|
250
|
+
return GIT_SUCCESS;
|
251
|
+
}
|
252
|
+
|
253
|
+
int git_commit__parse(git_commit *commit, git_odb_object *obj)
|
254
|
+
{
|
255
|
+
assert(commit);
|
256
|
+
return git_commit__parse_buffer(commit, obj->raw.data, obj->raw.len);
|
257
|
+
}
|
258
|
+
|
259
|
+
#define GIT_COMMIT_GETTER(_rvalue, _name, _return) \
|
260
|
+
_rvalue git_commit_##_name(git_commit *commit) \
|
261
|
+
{\
|
262
|
+
assert(commit); \
|
263
|
+
return _return; \
|
264
|
+
}
|
265
|
+
|
266
|
+
GIT_COMMIT_GETTER(const git_signature *, author, commit->author)
|
267
|
+
GIT_COMMIT_GETTER(const git_signature *, committer, commit->committer)
|
268
|
+
GIT_COMMIT_GETTER(const char *, message, commit->message)
|
269
|
+
GIT_COMMIT_GETTER(const char *, message_encoding, commit->message_encoding)
|
270
|
+
GIT_COMMIT_GETTER(git_time_t, time, commit->committer->when.time)
|
271
|
+
GIT_COMMIT_GETTER(int, time_offset, commit->committer->when.offset)
|
272
|
+
GIT_COMMIT_GETTER(unsigned int, parentcount, commit->parent_oids.length)
|
273
|
+
GIT_COMMIT_GETTER(const git_oid *, tree_oid, &commit->tree_oid);
|
274
|
+
|
275
|
+
|
276
|
+
int git_commit_tree(git_tree **tree_out, git_commit *commit)
|
277
|
+
{
|
278
|
+
assert(commit);
|
279
|
+
return git_tree_lookup(tree_out, commit->object.repo, &commit->tree_oid);
|
280
|
+
}
|
281
|
+
|
282
|
+
int git_commit_parent(git_commit **parent, git_commit *commit, unsigned int n)
|
283
|
+
{
|
284
|
+
git_oid *parent_oid;
|
285
|
+
assert(commit);
|
286
|
+
|
287
|
+
parent_oid = git_vector_get(&commit->parent_oids, n);
|
288
|
+
if (parent_oid == NULL)
|
289
|
+
return git__throw(GIT_ENOTFOUND, "Parent %u does not exist", n);
|
290
|
+
|
291
|
+
return git_commit_lookup(parent, commit->object.repo, parent_oid);
|
292
|
+
}
|
293
|
+
|
294
|
+
const git_oid *git_commit_parent_oid(git_commit *commit, unsigned int n)
|
295
|
+
{
|
296
|
+
assert(commit);
|
297
|
+
|
298
|
+
return git_vector_get(&commit->parent_oids, n);
|
299
|
+
}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2009-2011 the libgit2 contributors
|
3
|
+
*
|
4
|
+
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
|
+
* a Linking Exception. For full terms see the included COPYING file.
|
6
|
+
*/
|
7
|
+
#ifndef INCLUDE_commit_h__
|
8
|
+
#define INCLUDE_commit_h__
|
9
|
+
|
10
|
+
#include "git2/commit.h"
|
11
|
+
#include "tree.h"
|
12
|
+
#include "repository.h"
|
13
|
+
#include "vector.h"
|
14
|
+
|
15
|
+
#include <time.h>
|
16
|
+
|
17
|
+
struct git_commit {
|
18
|
+
git_object object;
|
19
|
+
|
20
|
+
git_vector parent_oids;
|
21
|
+
git_oid tree_oid;
|
22
|
+
|
23
|
+
git_signature *author;
|
24
|
+
git_signature *committer;
|
25
|
+
|
26
|
+
char *message_encoding;
|
27
|
+
char *message;
|
28
|
+
};
|
29
|
+
|
30
|
+
void git_commit__free(git_commit *c);
|
31
|
+
int git_commit__parse(git_commit *commit, git_odb_object *obj);
|
32
|
+
|
33
|
+
int git_commit__parse_buffer(git_commit *commit, const void *data, size_t len);
|
34
|
+
#endif
|
@@ -0,0 +1,64 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2009-2011 the libgit2 contributors
|
3
|
+
*
|
4
|
+
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
|
+
* a Linking Exception. For full terms see the included COPYING file.
|
6
|
+
*/
|
7
|
+
#ifndef INCLUDE_common_h__
|
8
|
+
#define INCLUDE_common_h__
|
9
|
+
|
10
|
+
#include "git2/common.h"
|
11
|
+
#include "cc-compat.h"
|
12
|
+
|
13
|
+
#include <assert.h>
|
14
|
+
#include <errno.h>
|
15
|
+
#include <limits.h>
|
16
|
+
#include <stdlib.h>
|
17
|
+
#include <stdio.h>
|
18
|
+
#include <string.h>
|
19
|
+
|
20
|
+
#include <sys/types.h>
|
21
|
+
#include <sys/stat.h>
|
22
|
+
|
23
|
+
#ifdef GIT_WIN32
|
24
|
+
|
25
|
+
# include <io.h>
|
26
|
+
# include <direct.h>
|
27
|
+
# include <windows.h>
|
28
|
+
# include "win32/msvc-compat.h"
|
29
|
+
# include "win32/mingw-compat.h"
|
30
|
+
# ifdef GIT_THREADS
|
31
|
+
# include "win32/pthread.h"
|
32
|
+
#endif
|
33
|
+
|
34
|
+
# define snprintf _snprintf
|
35
|
+
|
36
|
+
#ifndef _SSIZE_T_DEFINED
|
37
|
+
typedef SSIZE_T ssize_t;
|
38
|
+
#endif
|
39
|
+
|
40
|
+
#else
|
41
|
+
# include <unistd.h>
|
42
|
+
|
43
|
+
# ifdef GIT_THREADS
|
44
|
+
# include <pthread.h>
|
45
|
+
# endif
|
46
|
+
#endif
|
47
|
+
|
48
|
+
#include "git2/types.h"
|
49
|
+
#include "git2/errors.h"
|
50
|
+
#include "thread-utils.h"
|
51
|
+
#include "bswap.h"
|
52
|
+
|
53
|
+
extern void git___throw(const char *, ...) GIT_FORMAT_PRINTF(1, 2);
|
54
|
+
#define git__throw(error, ...) \
|
55
|
+
(git___throw(__VA_ARGS__), error)
|
56
|
+
|
57
|
+
extern void git___rethrow(const char *, ...) GIT_FORMAT_PRINTF(1, 2);
|
58
|
+
#define git__rethrow(error, ...) \
|
59
|
+
(git___rethrow(__VA_ARGS__), error)
|
60
|
+
|
61
|
+
#include "util.h"
|
62
|
+
|
63
|
+
|
64
|
+
#endif /* INCLUDE_common_h__ */
|
@@ -0,0 +1,418 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2009-2011 the libgit2 contributors
|
3
|
+
*
|
4
|
+
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
5
|
+
* a Linking Exception. For full terms see the included COPYING file.
|
6
|
+
*/
|
7
|
+
|
8
|
+
#include "common.h"
|
9
|
+
#include "fileops.h"
|
10
|
+
#include "hashtable.h"
|
11
|
+
#include "config.h"
|
12
|
+
#include "git2/config.h"
|
13
|
+
#include "vector.h"
|
14
|
+
#if GIT_WIN32
|
15
|
+
# include <windows.h>
|
16
|
+
#endif
|
17
|
+
|
18
|
+
#include <ctype.h>
|
19
|
+
|
20
|
+
typedef struct {
|
21
|
+
git_config_file *file;
|
22
|
+
int priority;
|
23
|
+
} file_internal;
|
24
|
+
|
25
|
+
static void config_free(git_config *cfg)
|
26
|
+
{
|
27
|
+
unsigned int i;
|
28
|
+
git_config_file *file;
|
29
|
+
file_internal *internal;
|
30
|
+
|
31
|
+
for(i = 0; i < cfg->files.length; ++i){
|
32
|
+
internal = git_vector_get(&cfg->files, i);
|
33
|
+
file = internal->file;
|
34
|
+
file->free(file);
|
35
|
+
git__free(internal);
|
36
|
+
}
|
37
|
+
|
38
|
+
git_vector_free(&cfg->files);
|
39
|
+
git__free(cfg);
|
40
|
+
}
|
41
|
+
|
42
|
+
void git_config_free(git_config *cfg)
|
43
|
+
{
|
44
|
+
if (cfg == NULL)
|
45
|
+
return;
|
46
|
+
|
47
|
+
GIT_REFCOUNT_DEC(cfg, config_free);
|
48
|
+
}
|
49
|
+
|
50
|
+
static int config_backend_cmp(const void *a, const void *b)
|
51
|
+
{
|
52
|
+
const file_internal *bk_a = (const file_internal *)(a);
|
53
|
+
const file_internal *bk_b = (const file_internal *)(b);
|
54
|
+
|
55
|
+
return bk_b->priority - bk_a->priority;
|
56
|
+
}
|
57
|
+
|
58
|
+
int git_config_new(git_config **out)
|
59
|
+
{
|
60
|
+
git_config *cfg;
|
61
|
+
|
62
|
+
cfg = git__malloc(sizeof(git_config));
|
63
|
+
if (cfg == NULL)
|
64
|
+
return GIT_ENOMEM;
|
65
|
+
|
66
|
+
memset(cfg, 0x0, sizeof(git_config));
|
67
|
+
|
68
|
+
if (git_vector_init(&cfg->files, 3, config_backend_cmp) < 0) {
|
69
|
+
git__free(cfg);
|
70
|
+
return GIT_ENOMEM;
|
71
|
+
}
|
72
|
+
|
73
|
+
*out = cfg;
|
74
|
+
GIT_REFCOUNT_INC(cfg);
|
75
|
+
return GIT_SUCCESS;
|
76
|
+
}
|
77
|
+
|
78
|
+
int git_config_add_file_ondisk(git_config *cfg, const char *path, int priority)
|
79
|
+
{
|
80
|
+
git_config_file *file = NULL;
|
81
|
+
int error;
|
82
|
+
|
83
|
+
error = git_config_file__ondisk(&file, path);
|
84
|
+
if (error < GIT_SUCCESS)
|
85
|
+
return error;
|
86
|
+
|
87
|
+
error = git_config_add_file(cfg, file, priority);
|
88
|
+
if (error < GIT_SUCCESS) {
|
89
|
+
/*
|
90
|
+
* free manually; the file is not owned by the config
|
91
|
+
* instance yet and will not be freed on cleanup
|
92
|
+
*/
|
93
|
+
file->free(file);
|
94
|
+
return error;
|
95
|
+
}
|
96
|
+
|
97
|
+
return GIT_SUCCESS;
|
98
|
+
}
|
99
|
+
|
100
|
+
int git_config_open_ondisk(git_config **cfg, const char *path)
|
101
|
+
{
|
102
|
+
int error;
|
103
|
+
|
104
|
+
error = git_config_new(cfg);
|
105
|
+
if (error < GIT_SUCCESS)
|
106
|
+
return error;
|
107
|
+
|
108
|
+
error = git_config_add_file_ondisk(*cfg, path, 1);
|
109
|
+
if (error < GIT_SUCCESS)
|
110
|
+
git_config_free(*cfg);
|
111
|
+
|
112
|
+
return error;
|
113
|
+
}
|
114
|
+
|
115
|
+
int git_config_add_file(git_config *cfg, git_config_file *file, int priority)
|
116
|
+
{
|
117
|
+
file_internal *internal;
|
118
|
+
int error;
|
119
|
+
|
120
|
+
assert(cfg && file);
|
121
|
+
|
122
|
+
if ((error = file->open(file)) < GIT_SUCCESS)
|
123
|
+
return git__rethrow(error, "Failed to open config file");
|
124
|
+
|
125
|
+
internal = git__malloc(sizeof(file_internal));
|
126
|
+
if (internal == NULL)
|
127
|
+
return GIT_ENOMEM;
|
128
|
+
|
129
|
+
internal->file = file;
|
130
|
+
internal->priority = priority;
|
131
|
+
|
132
|
+
if (git_vector_insert(&cfg->files, internal) < 0) {
|
133
|
+
git__free(internal);
|
134
|
+
return GIT_ENOMEM;
|
135
|
+
}
|
136
|
+
|
137
|
+
git_vector_sort(&cfg->files);
|
138
|
+
internal->file->cfg = cfg;
|
139
|
+
|
140
|
+
return GIT_SUCCESS;
|
141
|
+
}
|
142
|
+
|
143
|
+
/*
|
144
|
+
* Loop over all the variables
|
145
|
+
*/
|
146
|
+
|
147
|
+
int git_config_foreach(git_config *cfg, int (*fn)(const char *, const char *, void *), void *data)
|
148
|
+
{
|
149
|
+
int ret = GIT_SUCCESS;
|
150
|
+
unsigned int i;
|
151
|
+
file_internal *internal;
|
152
|
+
git_config_file *file;
|
153
|
+
|
154
|
+
for(i = 0; i < cfg->files.length && ret == 0; ++i) {
|
155
|
+
internal = git_vector_get(&cfg->files, i);
|
156
|
+
file = internal->file;
|
157
|
+
ret = file->foreach(file, fn, data);
|
158
|
+
}
|
159
|
+
|
160
|
+
return ret;
|
161
|
+
}
|
162
|
+
|
163
|
+
int git_config_delete(git_config *cfg, const char *name)
|
164
|
+
{
|
165
|
+
return git_config_set_string(cfg, name, NULL);
|
166
|
+
}
|
167
|
+
|
168
|
+
/**************
|
169
|
+
* Setters
|
170
|
+
**************/
|
171
|
+
|
172
|
+
int git_config_set_int64(git_config *cfg, const char *name, int64_t value)
|
173
|
+
{
|
174
|
+
char str_value[32]; /* All numbers should fit in here */
|
175
|
+
p_snprintf(str_value, sizeof(str_value), "%" PRId64, value);
|
176
|
+
return git_config_set_string(cfg, name, str_value);
|
177
|
+
}
|
178
|
+
|
179
|
+
int git_config_set_int32(git_config *cfg, const char *name, int32_t value)
|
180
|
+
{
|
181
|
+
return git_config_set_int64(cfg, name, (int64_t)value);
|
182
|
+
}
|
183
|
+
|
184
|
+
int git_config_set_bool(git_config *cfg, const char *name, int value)
|
185
|
+
{
|
186
|
+
return git_config_set_string(cfg, name, value ? "true" : "false");
|
187
|
+
}
|
188
|
+
|
189
|
+
int git_config_set_string(git_config *cfg, const char *name, const char *value)
|
190
|
+
{
|
191
|
+
file_internal *internal;
|
192
|
+
git_config_file *file;
|
193
|
+
|
194
|
+
if (cfg->files.length == 0)
|
195
|
+
return git__throw(GIT_EINVALIDARGS, "Cannot set variable value; no files open in the `git_config` instance");
|
196
|
+
|
197
|
+
internal = git_vector_get(&cfg->files, 0);
|
198
|
+
file = internal->file;
|
199
|
+
|
200
|
+
return file->set(file, name, value);
|
201
|
+
}
|
202
|
+
|
203
|
+
/***********
|
204
|
+
* Getters
|
205
|
+
***********/
|
206
|
+
|
207
|
+
int git_config_get_int64(git_config *cfg, const char *name, int64_t *out)
|
208
|
+
{
|
209
|
+
const char *value, *num_end;
|
210
|
+
int ret;
|
211
|
+
int64_t num;
|
212
|
+
|
213
|
+
ret = git_config_get_string(cfg, name, &value);
|
214
|
+
if (ret < GIT_SUCCESS)
|
215
|
+
return git__rethrow(ret, "Failed to retrieve value for '%s'", name);
|
216
|
+
|
217
|
+
ret = git__strtol64(&num, value, &num_end, 0);
|
218
|
+
if (ret < GIT_SUCCESS)
|
219
|
+
return git__rethrow(ret, "Failed to convert value for '%s'", name);
|
220
|
+
|
221
|
+
switch (*num_end) {
|
222
|
+
case 'g':
|
223
|
+
case 'G':
|
224
|
+
num *= 1024;
|
225
|
+
/* fallthrough */
|
226
|
+
|
227
|
+
case 'm':
|
228
|
+
case 'M':
|
229
|
+
num *= 1024;
|
230
|
+
/* fallthrough */
|
231
|
+
|
232
|
+
case 'k':
|
233
|
+
case 'K':
|
234
|
+
num *= 1024;
|
235
|
+
|
236
|
+
/* check that that there are no more characters after the
|
237
|
+
* given modifier suffix */
|
238
|
+
if (num_end[1] != '\0')
|
239
|
+
return git__throw(GIT_EINVALIDTYPE,
|
240
|
+
"Failed to get value for '%s'. Invalid type suffix", name);
|
241
|
+
|
242
|
+
/* fallthrough */
|
243
|
+
|
244
|
+
case '\0':
|
245
|
+
*out = num;
|
246
|
+
return GIT_SUCCESS;
|
247
|
+
|
248
|
+
default:
|
249
|
+
return git__throw(GIT_EINVALIDTYPE,
|
250
|
+
"Failed to get value for '%s'. Value is of invalid type", name);
|
251
|
+
}
|
252
|
+
}
|
253
|
+
|
254
|
+
int git_config_get_int32(git_config *cfg, const char *name, int32_t *out)
|
255
|
+
{
|
256
|
+
int64_t tmp_long;
|
257
|
+
int32_t tmp_int;
|
258
|
+
int ret;
|
259
|
+
|
260
|
+
ret = git_config_get_int64(cfg, name, &tmp_long);
|
261
|
+
if (ret < GIT_SUCCESS)
|
262
|
+
return git__rethrow(ret, "Failed to convert value for '%s'", name);
|
263
|
+
|
264
|
+
tmp_int = tmp_long & 0xFFFFFFFF;
|
265
|
+
if (tmp_int != tmp_long)
|
266
|
+
return git__throw(GIT_EOVERFLOW, "Value for '%s' is too large", name);
|
267
|
+
|
268
|
+
*out = tmp_int;
|
269
|
+
|
270
|
+
return ret;
|
271
|
+
}
|
272
|
+
|
273
|
+
int git_config_get_bool(git_config *cfg, const char *name, int *out)
|
274
|
+
{
|
275
|
+
const char *value;
|
276
|
+
int error = GIT_SUCCESS;
|
277
|
+
|
278
|
+
error = git_config_get_string(cfg, name, &value);
|
279
|
+
if (error < GIT_SUCCESS)
|
280
|
+
return git__rethrow(error, "Failed to get value for %s", name);
|
281
|
+
|
282
|
+
/* A missing value means true */
|
283
|
+
if (value == NULL) {
|
284
|
+
*out = 1;
|
285
|
+
return GIT_SUCCESS;
|
286
|
+
}
|
287
|
+
|
288
|
+
if (!strcasecmp(value, "true") ||
|
289
|
+
!strcasecmp(value, "yes") ||
|
290
|
+
!strcasecmp(value, "on")) {
|
291
|
+
*out = 1;
|
292
|
+
return GIT_SUCCESS;
|
293
|
+
}
|
294
|
+
if (!strcasecmp(value, "false") ||
|
295
|
+
!strcasecmp(value, "no") ||
|
296
|
+
!strcasecmp(value, "off")) {
|
297
|
+
*out = 0;
|
298
|
+
return GIT_SUCCESS;
|
299
|
+
}
|
300
|
+
|
301
|
+
/* Try to parse it as an integer */
|
302
|
+
error = git_config_get_int32(cfg, name, out);
|
303
|
+
if (error == GIT_SUCCESS)
|
304
|
+
*out = !!(*out);
|
305
|
+
|
306
|
+
if (error < GIT_SUCCESS)
|
307
|
+
return git__rethrow(error, "Failed to get value for %s", name);
|
308
|
+
return error;
|
309
|
+
}
|
310
|
+
|
311
|
+
int git_config_get_string(git_config *cfg, const char *name, const char **out)
|
312
|
+
{
|
313
|
+
file_internal *internal;
|
314
|
+
git_config_file *file;
|
315
|
+
int error = GIT_ENOTFOUND;
|
316
|
+
unsigned int i;
|
317
|
+
|
318
|
+
if (cfg->files.length == 0)
|
319
|
+
return git__throw(GIT_EINVALIDARGS, "Cannot get variable value; no files open in the `git_config` instance");
|
320
|
+
|
321
|
+
for (i = 0; i < cfg->files.length; ++i) {
|
322
|
+
internal = git_vector_get(&cfg->files, i);
|
323
|
+
file = internal->file;
|
324
|
+
if ((error = file->get(file, name, out)) == GIT_SUCCESS)
|
325
|
+
return GIT_SUCCESS;
|
326
|
+
}
|
327
|
+
|
328
|
+
return git__throw(error, "Config value '%s' not found", name);
|
329
|
+
}
|
330
|
+
|
331
|
+
int git_config_find_global(char *global_config_path)
|
332
|
+
{
|
333
|
+
const char *home;
|
334
|
+
|
335
|
+
home = getenv("HOME");
|
336
|
+
|
337
|
+
#ifdef GIT_WIN32
|
338
|
+
if (home == NULL)
|
339
|
+
home = getenv("USERPROFILE");
|
340
|
+
#endif
|
341
|
+
|
342
|
+
if (home == NULL)
|
343
|
+
return git__throw(GIT_EOSERR, "Failed to open global config file. Cannot locate the user's home directory");
|
344
|
+
|
345
|
+
git_path_join(global_config_path, home, GIT_CONFIG_FILENAME);
|
346
|
+
|
347
|
+
if (git_futils_exists(global_config_path) < GIT_SUCCESS)
|
348
|
+
return git__throw(GIT_EOSERR, "Failed to open global config file. The file does not exist");
|
349
|
+
|
350
|
+
return GIT_SUCCESS;
|
351
|
+
}
|
352
|
+
|
353
|
+
|
354
|
+
|
355
|
+
#if GIT_WIN32
|
356
|
+
static int win32_find_system(char *system_config_path)
|
357
|
+
{
|
358
|
+
const wchar_t *query = L"%PROGRAMFILES%\\Git\\etc\\gitconfig";
|
359
|
+
wchar_t *apphome_utf16;
|
360
|
+
char *apphome_utf8;
|
361
|
+
DWORD size, ret;
|
362
|
+
|
363
|
+
size = ExpandEnvironmentStringsW(query, NULL, 0);
|
364
|
+
/* The function gave us the full size of the buffer in chars, including NUL */
|
365
|
+
apphome_utf16 = git__malloc(size * sizeof(wchar_t));
|
366
|
+
if (apphome_utf16 == NULL)
|
367
|
+
return GIT_ENOMEM;
|
368
|
+
|
369
|
+
ret = ExpandEnvironmentStringsW(query, apphome_utf16, size);
|
370
|
+
if (ret != size)
|
371
|
+
return git__throw(GIT_ERROR, "Failed to expand environment strings");
|
372
|
+
|
373
|
+
if (_waccess(apphome_utf16, F_OK) < 0) {
|
374
|
+
git__free(apphome_utf16);
|
375
|
+
return GIT_ENOTFOUND;
|
376
|
+
}
|
377
|
+
|
378
|
+
apphome_utf8 = gitwin_from_utf16(apphome_utf16);
|
379
|
+
git__free(apphome_utf16);
|
380
|
+
|
381
|
+
if (strlen(apphome_utf8) >= GIT_PATH_MAX) {
|
382
|
+
git__free(apphome_utf8);
|
383
|
+
return git__throw(GIT_ESHORTBUFFER, "Path is too long");
|
384
|
+
}
|
385
|
+
|
386
|
+
strcpy(system_config_path, apphome_utf8);
|
387
|
+
git__free(apphome_utf8);
|
388
|
+
return GIT_SUCCESS;
|
389
|
+
}
|
390
|
+
#endif
|
391
|
+
|
392
|
+
int git_config_find_system(char *system_config_path)
|
393
|
+
{
|
394
|
+
const char *etc = "/etc/gitconfig";
|
395
|
+
|
396
|
+
if (git_futils_exists(etc) == GIT_SUCCESS) {
|
397
|
+
memcpy(system_config_path, etc, strlen(etc) + 1);
|
398
|
+
return GIT_SUCCESS;
|
399
|
+
}
|
400
|
+
|
401
|
+
#if GIT_WIN32
|
402
|
+
return win32_find_system(system_config_path);
|
403
|
+
#else
|
404
|
+
return GIT_ENOTFOUND;
|
405
|
+
#endif
|
406
|
+
}
|
407
|
+
|
408
|
+
int git_config_open_global(git_config **out)
|
409
|
+
{
|
410
|
+
int error;
|
411
|
+
char global_path[GIT_PATH_MAX];
|
412
|
+
|
413
|
+
if ((error = git_config_find_global(global_path)) < GIT_SUCCESS)
|
414
|
+
return error;
|
415
|
+
|
416
|
+
return git_config_open_ondisk(out, global_path);
|
417
|
+
}
|
418
|
+
|