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,331 @@
|
|
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_git_odb_h__
|
8
|
+
#define INCLUDE_git_odb_h__
|
9
|
+
|
10
|
+
#include "common.h"
|
11
|
+
#include "types.h"
|
12
|
+
#include "oid.h"
|
13
|
+
#include "odb_backend.h"
|
14
|
+
|
15
|
+
/**
|
16
|
+
* @file git2/odb.h
|
17
|
+
* @brief Git object database routines
|
18
|
+
* @defgroup git_odb Git object database routines
|
19
|
+
* @ingroup Git
|
20
|
+
* @{
|
21
|
+
*/
|
22
|
+
GIT_BEGIN_DECL
|
23
|
+
|
24
|
+
/**
|
25
|
+
* Create a new object database with no backends.
|
26
|
+
*
|
27
|
+
* Before the ODB can be used for read/writing, a custom database
|
28
|
+
* backend must be manually added using `git_odb_add_backend()`
|
29
|
+
*
|
30
|
+
* @param out location to store the database pointer, if opened.
|
31
|
+
* Set to NULL if the open failed.
|
32
|
+
* @return GIT_SUCCESS or an error code
|
33
|
+
*/
|
34
|
+
GIT_EXTERN(int) git_odb_new(git_odb **out);
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Create a new object database and automatically add
|
38
|
+
* the two default backends:
|
39
|
+
*
|
40
|
+
* - git_odb_backend_loose: read and write loose object files
|
41
|
+
* from disk, assuming `objects_dir` as the Objects folder
|
42
|
+
*
|
43
|
+
* - git_odb_backend_pack: read objects from packfiles,
|
44
|
+
* assuming `objects_dir` as the Objects folder which
|
45
|
+
* contains a 'pack/' folder with the corresponding data
|
46
|
+
*
|
47
|
+
* @param out location to store the database pointer, if opened.
|
48
|
+
* Set to NULL if the open failed.
|
49
|
+
* @param objects_dir path of the backends' "objects" directory.
|
50
|
+
* @return GIT_SUCCESS or an error code
|
51
|
+
*/
|
52
|
+
GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir);
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Add a custom backend to an existing Object DB
|
56
|
+
*
|
57
|
+
* The backends are checked in relative ordering, based on the
|
58
|
+
* value of the `priority` parameter.
|
59
|
+
*
|
60
|
+
* Read <odb_backends.h> for more information.
|
61
|
+
*
|
62
|
+
* @param odb database to add the backend to
|
63
|
+
* @param backend pointer to a git_odb_backend instance
|
64
|
+
* @param priority Value for ordering the backends queue
|
65
|
+
* @return 0 on sucess; error code otherwise
|
66
|
+
*/
|
67
|
+
GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority);
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Add a custom backend to an existing Object DB; this
|
71
|
+
* backend will work as an alternate.
|
72
|
+
*
|
73
|
+
* Alternate backends are always checked for objects *after*
|
74
|
+
* all the main backends have been exhausted.
|
75
|
+
*
|
76
|
+
* The backends are checked in relative ordering, based on the
|
77
|
+
* value of the `priority` parameter.
|
78
|
+
*
|
79
|
+
* Writing is disabled on alternate backends.
|
80
|
+
*
|
81
|
+
* Read <odb_backends.h> for more information.
|
82
|
+
*
|
83
|
+
* @param odb database to add the backend to
|
84
|
+
* @param backend pointer to a git_odb_backend instance
|
85
|
+
* @param priority Value for ordering the backends queue
|
86
|
+
* @return 0 on sucess; error code otherwise
|
87
|
+
*/
|
88
|
+
GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority);
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Close an open object database.
|
92
|
+
*
|
93
|
+
* @param db database pointer to close. If NULL no action is taken.
|
94
|
+
*/
|
95
|
+
GIT_EXTERN(void) git_odb_free(git_odb *db);
|
96
|
+
|
97
|
+
/**
|
98
|
+
* Read an object from the database.
|
99
|
+
*
|
100
|
+
* This method queries all available ODB backends
|
101
|
+
* trying to read the given OID.
|
102
|
+
*
|
103
|
+
* The returned object is reference counted and
|
104
|
+
* internally cached, so it should be closed
|
105
|
+
* by the user once it's no longer in use.
|
106
|
+
*
|
107
|
+
* @param out pointer where to store the read object
|
108
|
+
* @param db database to search for the object in.
|
109
|
+
* @param id identity of the object to read.
|
110
|
+
* @return
|
111
|
+
* - GIT_SUCCESS if the object was read;
|
112
|
+
* - GIT_ENOTFOUND if the object is not in the database.
|
113
|
+
*/
|
114
|
+
GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id);
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Read an object from the database, given a prefix
|
118
|
+
* of its identifier.
|
119
|
+
*
|
120
|
+
* This method queries all available ODB backends
|
121
|
+
* trying to match the 'len' first hexadecimal
|
122
|
+
* characters of the 'short_id'.
|
123
|
+
* The remaining (GIT_OID_HEXSZ-len)*4 bits of
|
124
|
+
* 'short_id' must be 0s.
|
125
|
+
* 'len' must be at least GIT_OID_MINPREFIXLEN,
|
126
|
+
* and the prefix must be long enough to identify
|
127
|
+
* a unique object in all the backends; the
|
128
|
+
* method will fail otherwise.
|
129
|
+
*
|
130
|
+
* The returned object is reference counted and
|
131
|
+
* internally cached, so it should be closed
|
132
|
+
* by the user once it's no longer in use.
|
133
|
+
*
|
134
|
+
* @param out pointer where to store the read object
|
135
|
+
* @param db database to search for the object in.
|
136
|
+
* @param short_id a prefix of the id of the object to read.
|
137
|
+
* @param len the length of the prefix
|
138
|
+
* @return GIT_SUCCESS if the object was read;
|
139
|
+
* GIT_ENOTFOUND if the object is not in the database.
|
140
|
+
* GIT_EAMBIGUOUS if the prefix is ambiguous (several objects match the prefix)
|
141
|
+
*/
|
142
|
+
GIT_EXTERN(int) git_odb_read_prefix(git_odb_object **out, git_odb *db, const git_oid *short_id, unsigned int len);
|
143
|
+
|
144
|
+
/**
|
145
|
+
* Read the header of an object from the database, without
|
146
|
+
* reading its full contents.
|
147
|
+
*
|
148
|
+
* The header includes the length and the type of an object.
|
149
|
+
*
|
150
|
+
* Note that most backends do not support reading only the header
|
151
|
+
* of an object, so the whole object will be read and then the
|
152
|
+
* header will be returned.
|
153
|
+
*
|
154
|
+
* @param len_p pointer where to store the length
|
155
|
+
* @param type_p pointer where to store the type
|
156
|
+
* @param db database to search for the object in.
|
157
|
+
* @param id identity of the object to read.
|
158
|
+
* @return
|
159
|
+
* - GIT_SUCCESS if the object was read;
|
160
|
+
* - GIT_ENOTFOUND if the object is not in the database.
|
161
|
+
*/
|
162
|
+
GIT_EXTERN(int) git_odb_read_header(size_t *len_p, git_otype *type_p, git_odb *db, const git_oid *id);
|
163
|
+
|
164
|
+
/**
|
165
|
+
* Determine if the given object can be found in the object database.
|
166
|
+
*
|
167
|
+
* @param db database to be searched for the given object.
|
168
|
+
* @param id the object to search for.
|
169
|
+
* @return
|
170
|
+
* - 1, if the object was found
|
171
|
+
* - 0, otherwise
|
172
|
+
*/
|
173
|
+
GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id);
|
174
|
+
|
175
|
+
/**
|
176
|
+
* Write an object directly into the ODB
|
177
|
+
*
|
178
|
+
* This method writes a full object straight into the ODB.
|
179
|
+
* For most cases, it is preferred to write objects through a write
|
180
|
+
* stream, which is both faster and less memory intensive, specially
|
181
|
+
* for big objects.
|
182
|
+
*
|
183
|
+
* This method is provided for compatibility with custom backends
|
184
|
+
* which are not able to support streaming writes
|
185
|
+
*
|
186
|
+
* @param oid pointer to store the OID result of the write
|
187
|
+
* @param odb object database where to store the object
|
188
|
+
* @param data buffer with the data to storr
|
189
|
+
* @param len size of the buffer
|
190
|
+
* @param type type of the data to store
|
191
|
+
* @return GIT_SUCCESS or an error code
|
192
|
+
*/
|
193
|
+
GIT_EXTERN(int) git_odb_write(git_oid *oid, git_odb *odb, const void *data, size_t len, git_otype type);
|
194
|
+
|
195
|
+
/**
|
196
|
+
* Open a stream to write an object into the ODB
|
197
|
+
*
|
198
|
+
* The type and final length of the object must be specified
|
199
|
+
* when opening the stream.
|
200
|
+
*
|
201
|
+
* The returned stream will be of type `GIT_STREAM_WRONLY` and
|
202
|
+
* will have the following methods:
|
203
|
+
*
|
204
|
+
* - stream->write: write `n` bytes into the stream
|
205
|
+
* - stream->finalize_write: close the stream and store the object in
|
206
|
+
* the odb
|
207
|
+
* - stream->free: free the stream
|
208
|
+
*
|
209
|
+
* The streaming write won't be effective until `stream->finalize_write`
|
210
|
+
* is called and returns without an error
|
211
|
+
*
|
212
|
+
* The stream must always be free'd or will leak memory.
|
213
|
+
*
|
214
|
+
* @see git_odb_stream
|
215
|
+
*
|
216
|
+
* @param stream pointer where to store the stream
|
217
|
+
* @param db object database where the stream will write
|
218
|
+
* @param size final size of the object that will be written
|
219
|
+
* @param type type of the object that will be written
|
220
|
+
* @return 0 if the stream was created; error code otherwise
|
221
|
+
*/
|
222
|
+
GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **stream, git_odb *db, size_t size, git_otype type);
|
223
|
+
|
224
|
+
/**
|
225
|
+
* Open a stream to read an object from the ODB
|
226
|
+
*
|
227
|
+
* Note that most backends do *not* support streaming reads
|
228
|
+
* because they store their objects as compressed/delta'ed blobs.
|
229
|
+
*
|
230
|
+
* It's recommended to use `git_odb_read` instead, which is
|
231
|
+
* assured to work on all backends.
|
232
|
+
*
|
233
|
+
* The returned stream will be of type `GIT_STREAM_RDONLY` and
|
234
|
+
* will have the following methods:
|
235
|
+
*
|
236
|
+
* - stream->read: read `n` bytes from the stream
|
237
|
+
* - stream->free: free the stream
|
238
|
+
*
|
239
|
+
* The stream must always be free'd or will leak memory.
|
240
|
+
*
|
241
|
+
* @see git_odb_stream
|
242
|
+
*
|
243
|
+
* @param stream pointer where to store the stream
|
244
|
+
* @param db object database where the stream will read from
|
245
|
+
* @param oid oid of the object the stream will read from
|
246
|
+
* @return 0 if the stream was created; error code otherwise
|
247
|
+
*/
|
248
|
+
GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const git_oid *oid);
|
249
|
+
|
250
|
+
/**
|
251
|
+
* Determine the object-ID (sha1 hash) of a data buffer
|
252
|
+
*
|
253
|
+
* The resulting SHA-1 OID will the itentifier for the data
|
254
|
+
* buffer as if the data buffer it were to written to the ODB.
|
255
|
+
*
|
256
|
+
* @param id the resulting object-ID.
|
257
|
+
* @param data data to hash
|
258
|
+
* @param len size of the data
|
259
|
+
* @param type of the data to hash
|
260
|
+
* @return GIT_SUCCESS or an error code
|
261
|
+
*/
|
262
|
+
GIT_EXTERN(int) git_odb_hash(git_oid *id, const void *data, size_t len, git_otype type);
|
263
|
+
|
264
|
+
/**
|
265
|
+
* Read a file from disk and fill a git_oid with the object id
|
266
|
+
* that the file would have if it were written to the Object
|
267
|
+
* Database as an object of the given type. Similar functionality
|
268
|
+
* to git.git's `git hash-object` without the `-w` flag.
|
269
|
+
*
|
270
|
+
* @param out oid structure the result is written into.
|
271
|
+
* @param path file to read and determine object id for
|
272
|
+
* @param type the type of the object that will be hashed
|
273
|
+
* @return GIT_SUCCESS or an error code
|
274
|
+
*/
|
275
|
+
GIT_EXTERN(int) git_odb_hashfile(git_oid *out, const char *path, git_otype type);
|
276
|
+
|
277
|
+
/**
|
278
|
+
* Close an ODB object
|
279
|
+
*
|
280
|
+
* This method must always be called once a `git_odb_object` is no
|
281
|
+
* longer needed, otherwise memory will leak.
|
282
|
+
*
|
283
|
+
* @param object object to close
|
284
|
+
*/
|
285
|
+
GIT_EXTERN(void) git_odb_object_free(git_odb_object *object);
|
286
|
+
|
287
|
+
/**
|
288
|
+
* Return the OID of an ODB object
|
289
|
+
*
|
290
|
+
* This is the OID from which the object was read from
|
291
|
+
*
|
292
|
+
* @param object the object
|
293
|
+
* @return a pointer to the OID
|
294
|
+
*/
|
295
|
+
GIT_EXTERN(const git_oid *) git_odb_object_id(git_odb_object *object);
|
296
|
+
|
297
|
+
/**
|
298
|
+
* Return the data of an ODB object
|
299
|
+
*
|
300
|
+
* This is the uncompressed, raw data as read from the ODB,
|
301
|
+
* without the leading header.
|
302
|
+
*
|
303
|
+
* This pointer is owned by the object and shall not be free'd.
|
304
|
+
*
|
305
|
+
* @param object the object
|
306
|
+
* @return a pointer to the data
|
307
|
+
*/
|
308
|
+
GIT_EXTERN(const void *) git_odb_object_data(git_odb_object *object);
|
309
|
+
|
310
|
+
/**
|
311
|
+
* Return the size of an ODB object
|
312
|
+
*
|
313
|
+
* This is the real size of the `data` buffer, not the
|
314
|
+
* actual size of the object.
|
315
|
+
*
|
316
|
+
* @param object the object
|
317
|
+
* @return the size
|
318
|
+
*/
|
319
|
+
GIT_EXTERN(size_t) git_odb_object_size(git_odb_object *object);
|
320
|
+
|
321
|
+
/**
|
322
|
+
* Return the type of an ODB object
|
323
|
+
*
|
324
|
+
* @param object the object
|
325
|
+
* @return the type
|
326
|
+
*/
|
327
|
+
GIT_EXTERN(git_otype) git_odb_object_type(git_odb_object *object);
|
328
|
+
|
329
|
+
/** @} */
|
330
|
+
GIT_END_DECL
|
331
|
+
#endif
|
@@ -0,0 +1,100 @@
|
|
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_git_odb_backend_h__
|
8
|
+
#define INCLUDE_git_odb_backend_h__
|
9
|
+
|
10
|
+
#include "common.h"
|
11
|
+
#include "types.h"
|
12
|
+
#include "oid.h"
|
13
|
+
|
14
|
+
/**
|
15
|
+
* @file git2/backend.h
|
16
|
+
* @brief Git custom backend functions
|
17
|
+
* @defgroup git_backend Git custom backend API
|
18
|
+
* @ingroup Git
|
19
|
+
* @{
|
20
|
+
*/
|
21
|
+
GIT_BEGIN_DECL
|
22
|
+
|
23
|
+
struct git_odb_stream;
|
24
|
+
|
25
|
+
/** An instance for a custom backend */
|
26
|
+
struct git_odb_backend {
|
27
|
+
git_odb *odb;
|
28
|
+
|
29
|
+
int (* read)(
|
30
|
+
void **, size_t *, git_otype *,
|
31
|
+
struct git_odb_backend *,
|
32
|
+
const git_oid *);
|
33
|
+
|
34
|
+
/* To find a unique object given a prefix
|
35
|
+
* of its oid.
|
36
|
+
* The oid given must be so that the
|
37
|
+
* remaining (GIT_OID_HEXSZ - len)*4 bits
|
38
|
+
* are 0s.
|
39
|
+
*/
|
40
|
+
int (* read_prefix)(
|
41
|
+
git_oid *,
|
42
|
+
void **, size_t *, git_otype *,
|
43
|
+
struct git_odb_backend *,
|
44
|
+
const git_oid *,
|
45
|
+
unsigned int);
|
46
|
+
|
47
|
+
int (* read_header)(
|
48
|
+
size_t *, git_otype *,
|
49
|
+
struct git_odb_backend *,
|
50
|
+
const git_oid *);
|
51
|
+
|
52
|
+
int (* write)(
|
53
|
+
git_oid *,
|
54
|
+
struct git_odb_backend *,
|
55
|
+
const void *,
|
56
|
+
size_t,
|
57
|
+
git_otype);
|
58
|
+
|
59
|
+
int (* writestream)(
|
60
|
+
struct git_odb_stream **,
|
61
|
+
struct git_odb_backend *,
|
62
|
+
size_t,
|
63
|
+
git_otype);
|
64
|
+
|
65
|
+
int (* readstream)(
|
66
|
+
struct git_odb_stream **,
|
67
|
+
struct git_odb_backend *,
|
68
|
+
const git_oid *);
|
69
|
+
|
70
|
+
int (* exists)(
|
71
|
+
struct git_odb_backend *,
|
72
|
+
const git_oid *);
|
73
|
+
|
74
|
+
void (* free)(struct git_odb_backend *);
|
75
|
+
};
|
76
|
+
|
77
|
+
/** A stream to read/write from a backend */
|
78
|
+
struct git_odb_stream {
|
79
|
+
struct git_odb_backend *backend;
|
80
|
+
int mode;
|
81
|
+
|
82
|
+
int (*read)(struct git_odb_stream *stream, char *buffer, size_t len);
|
83
|
+
int (*write)(struct git_odb_stream *stream, const char *buffer, size_t len);
|
84
|
+
int (*finalize_write)(git_oid *oid_p, struct git_odb_stream *stream);
|
85
|
+
void (*free)(struct git_odb_stream *stream);
|
86
|
+
};
|
87
|
+
|
88
|
+
/** Streaming mode */
|
89
|
+
typedef enum {
|
90
|
+
GIT_STREAM_RDONLY = (1 << 1),
|
91
|
+
GIT_STREAM_WRONLY = (1 << 2),
|
92
|
+
GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY),
|
93
|
+
} git_odb_streammode;
|
94
|
+
|
95
|
+
GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir);
|
96
|
+
GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir, int compression_level, int do_fsync);
|
97
|
+
|
98
|
+
GIT_END_DECL
|
99
|
+
|
100
|
+
#endif
|
@@ -0,0 +1,218 @@
|
|
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_git_oid_h__
|
8
|
+
#define INCLUDE_git_oid_h__
|
9
|
+
|
10
|
+
#include "common.h"
|
11
|
+
#include "types.h"
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @file git2/oid.h
|
15
|
+
* @brief Git object id routines
|
16
|
+
* @defgroup git_oid Git object id routines
|
17
|
+
* @ingroup Git
|
18
|
+
* @{
|
19
|
+
*/
|
20
|
+
GIT_BEGIN_DECL
|
21
|
+
|
22
|
+
/** Size (in bytes) of a raw/binary oid */
|
23
|
+
#define GIT_OID_RAWSZ 20
|
24
|
+
|
25
|
+
/** Size (in bytes) of a hex formatted oid */
|
26
|
+
#define GIT_OID_HEXSZ (GIT_OID_RAWSZ * 2)
|
27
|
+
|
28
|
+
/** Minimum length (in number of hex characters,
|
29
|
+
* i.e. packets of 4 bits) of an oid prefix */
|
30
|
+
#define GIT_OID_MINPREFIXLEN 4
|
31
|
+
|
32
|
+
/** Unique identity of any object (commit, tree, blob, tag). */
|
33
|
+
typedef struct _git_oid git_oid;
|
34
|
+
struct _git_oid {
|
35
|
+
/** raw binary formatted id */
|
36
|
+
unsigned char id[GIT_OID_RAWSZ];
|
37
|
+
};
|
38
|
+
|
39
|
+
/**
|
40
|
+
* Parse a hex formatted object id into a git_oid.
|
41
|
+
*
|
42
|
+
* @param out oid structure the result is written into.
|
43
|
+
* @param str input hex string; must be pointing at the start of
|
44
|
+
* the hex sequence and have at least the number of bytes
|
45
|
+
* needed for an oid encoded in hex (40 bytes).
|
46
|
+
* @return GIT_SUCCESS or an error code
|
47
|
+
*/
|
48
|
+
GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str);
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Parse N characters of a hex formatted object id into a git_oid
|
52
|
+
*
|
53
|
+
* If N is odd, N-1 characters will be parsed instead.
|
54
|
+
* The remaining space in the git_oid will be set to zero.
|
55
|
+
*
|
56
|
+
* @param out oid structure the result is written into.
|
57
|
+
* @param str input hex string of at least size `length`
|
58
|
+
* @param length length of the input string
|
59
|
+
* @return GIT_SUCCESS or an error code
|
60
|
+
*/
|
61
|
+
GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length);
|
62
|
+
|
63
|
+
/**
|
64
|
+
* Copy an already raw oid into a git_oid structure.
|
65
|
+
*
|
66
|
+
* @param out oid structure the result is written into.
|
67
|
+
* @param raw the raw input bytes to be copied.
|
68
|
+
*/
|
69
|
+
GIT_EXTERN(void) git_oid_fromraw(git_oid *out, const unsigned char *raw);
|
70
|
+
|
71
|
+
/**
|
72
|
+
* Format a git_oid into a hex string.
|
73
|
+
*
|
74
|
+
* @param str output hex string; must be pointing at the start of
|
75
|
+
* the hex sequence and have at least the number of bytes
|
76
|
+
* needed for an oid encoded in hex (40 bytes). Only the
|
77
|
+
* oid digits are written; a '\\0' terminator must be added
|
78
|
+
* by the caller if it is required.
|
79
|
+
* @param oid oid structure to format.
|
80
|
+
*/
|
81
|
+
GIT_EXTERN(void) git_oid_fmt(char *str, const git_oid *oid);
|
82
|
+
|
83
|
+
/**
|
84
|
+
* Format a git_oid into a loose-object path string.
|
85
|
+
*
|
86
|
+
* The resulting string is "aa/...", where "aa" is the first two
|
87
|
+
* hex digitis of the oid and "..." is the remaining 38 digits.
|
88
|
+
*
|
89
|
+
* @param str output hex string; must be pointing at the start of
|
90
|
+
* the hex sequence and have at least the number of bytes
|
91
|
+
* needed for an oid encoded in hex (41 bytes). Only the
|
92
|
+
* oid digits are written; a '\\0' terminator must be added
|
93
|
+
* by the caller if it is required.
|
94
|
+
* @param oid oid structure to format.
|
95
|
+
*/
|
96
|
+
GIT_EXTERN(void) git_oid_pathfmt(char *str, const git_oid *oid);
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Format a git_oid into a newly allocated c-string.
|
100
|
+
*
|
101
|
+
* @param oid the oid structure to format
|
102
|
+
* @return the c-string; NULL if memory is exhausted. Caller must
|
103
|
+
* deallocate the string with git__free().
|
104
|
+
*/
|
105
|
+
GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *oid);
|
106
|
+
|
107
|
+
/**
|
108
|
+
* Format a git_oid into a buffer as a hex format c-string.
|
109
|
+
*
|
110
|
+
* If the buffer is smaller than GIT_OID_HEXSZ+1, then the resulting
|
111
|
+
* oid c-string will be truncated to n-1 characters. If there are
|
112
|
+
* any input parameter errors (out == NULL, n == 0, oid == NULL),
|
113
|
+
* then a pointer to an empty string is returned, so that the return
|
114
|
+
* value can always be printed.
|
115
|
+
*
|
116
|
+
* @param out the buffer into which the oid string is output.
|
117
|
+
* @param n the size of the out buffer.
|
118
|
+
* @param oid the oid structure to format.
|
119
|
+
* @return the out buffer pointer, assuming no input parameter
|
120
|
+
* errors, otherwise a pointer to an empty string.
|
121
|
+
*/
|
122
|
+
GIT_EXTERN(char *) git_oid_to_string(char *out, size_t n, const git_oid *oid);
|
123
|
+
|
124
|
+
/**
|
125
|
+
* Copy an oid from one structure to another.
|
126
|
+
*
|
127
|
+
* @param out oid structure the result is written into.
|
128
|
+
* @param src oid structure to copy from.
|
129
|
+
*/
|
130
|
+
GIT_EXTERN(void) git_oid_cpy(git_oid *out, const git_oid *src);
|
131
|
+
|
132
|
+
/**
|
133
|
+
* Compare two oid structures.
|
134
|
+
*
|
135
|
+
* @param a first oid structure.
|
136
|
+
* @param b second oid structure.
|
137
|
+
* @return <0, 0, >0 if a < b, a == b, a > b.
|
138
|
+
*/
|
139
|
+
GIT_EXTERN(int) git_oid_cmp(const git_oid *a, const git_oid *b);
|
140
|
+
|
141
|
+
/**
|
142
|
+
* Compare the first 'len' hexadecimal characters (packets of 4 bits)
|
143
|
+
* of two oid structures.
|
144
|
+
*
|
145
|
+
* @param a first oid structure.
|
146
|
+
* @param b second oid structure.
|
147
|
+
* @param len the number of hex chars to compare
|
148
|
+
* @return 0 in case of a match
|
149
|
+
*/
|
150
|
+
GIT_EXTERN(int) git_oid_ncmp(const git_oid *a, const git_oid *b, unsigned int len);
|
151
|
+
|
152
|
+
/**
|
153
|
+
* Check if an oid equals an hex formatted object id.
|
154
|
+
*
|
155
|
+
* @param a oid structure.
|
156
|
+
* @param str input hex string of an object id.
|
157
|
+
* @return GIT_ENOTOID if str is not a valid hex string,
|
158
|
+
* GIT_SUCCESS in case of a match, GIT_ERROR otherwise.
|
159
|
+
*/
|
160
|
+
GIT_EXTERN(int) git_oid_streq(const git_oid *a, const char *str);
|
161
|
+
|
162
|
+
/**
|
163
|
+
* OID Shortener object
|
164
|
+
*/
|
165
|
+
typedef struct git_oid_shorten git_oid_shorten;
|
166
|
+
|
167
|
+
/**
|
168
|
+
* Create a new OID shortener.
|
169
|
+
*
|
170
|
+
* The OID shortener is used to process a list of OIDs
|
171
|
+
* in text form and return the shortest length that would
|
172
|
+
* uniquely identify all of them.
|
173
|
+
*
|
174
|
+
* E.g. look at the result of `git log --abbrev`.
|
175
|
+
*
|
176
|
+
* @param min_length The minimal length for all identifiers,
|
177
|
+
* which will be used even if shorter OIDs would still
|
178
|
+
* be unique.
|
179
|
+
* @return a `git_oid_shorten` instance, NULL if OOM
|
180
|
+
*/
|
181
|
+
git_oid_shorten *git_oid_shorten_new(size_t min_length);
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Add a new OID to set of shortened OIDs and calculate
|
185
|
+
* the minimal length to uniquely identify all the OIDs in
|
186
|
+
* the set.
|
187
|
+
*
|
188
|
+
* The OID is expected to be a 40-char hexadecimal string.
|
189
|
+
* The OID is owned by the user and will not be modified
|
190
|
+
* or freed.
|
191
|
+
*
|
192
|
+
* For performance reasons, there is a hard-limit of how many
|
193
|
+
* OIDs can be added to a single set (around ~22000, assuming
|
194
|
+
* a mostly randomized distribution), which should be enough
|
195
|
+
* for any kind of program, and keeps the algorithm fast and
|
196
|
+
* memory-efficient.
|
197
|
+
*
|
198
|
+
* Attempting to add more than those OIDs will result in a
|
199
|
+
* GIT_ENOMEM error
|
200
|
+
*
|
201
|
+
* @param os a `git_oid_shorten` instance
|
202
|
+
* @param text_oid an OID in text form
|
203
|
+
* @return the minimal length to uniquely identify all OIDs
|
204
|
+
* added so far to the set; or an error code (<0) if an
|
205
|
+
* error occurs.
|
206
|
+
*/
|
207
|
+
int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid);
|
208
|
+
|
209
|
+
/**
|
210
|
+
* Free an OID shortener instance
|
211
|
+
*
|
212
|
+
* @param os a `git_oid_shorten` instance
|
213
|
+
*/
|
214
|
+
void git_oid_shorten_free(git_oid_shorten *os);
|
215
|
+
|
216
|
+
/** @} */
|
217
|
+
GIT_END_DECL
|
218
|
+
#endif
|