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,280 @@
|
|
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 "sha1.h"
|
10
|
+
|
11
|
+
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
12
|
+
|
13
|
+
/*
|
14
|
+
* Force usage of rol or ror by selecting the one with the smaller constant.
|
15
|
+
* It _can_ generate slightly smaller code (a constant of 1 is special), but
|
16
|
+
* perhaps more importantly it's possibly faster on any uarch that does a
|
17
|
+
* rotate with a loop.
|
18
|
+
*/
|
19
|
+
|
20
|
+
#define SHA_ASM(op, x, n) ({ unsigned int __res; __asm__(op " %1,%0":"=r" (__res):"i" (n), "0" (x)); __res; })
|
21
|
+
#define SHA_ROL(x,n) SHA_ASM("rol", x, n)
|
22
|
+
#define SHA_ROR(x,n) SHA_ASM("ror", x, n)
|
23
|
+
|
24
|
+
#else
|
25
|
+
|
26
|
+
#define SHA_ROT(X,l,r) (((X) << (l)) | ((X) >> (r)))
|
27
|
+
#define SHA_ROL(X,n) SHA_ROT(X,n,32-(n))
|
28
|
+
#define SHA_ROR(X,n) SHA_ROT(X,32-(n),n)
|
29
|
+
|
30
|
+
#endif
|
31
|
+
|
32
|
+
/*
|
33
|
+
* If you have 32 registers or more, the compiler can (and should)
|
34
|
+
* try to change the array[] accesses into registers. However, on
|
35
|
+
* machines with less than ~25 registers, that won't really work,
|
36
|
+
* and at least gcc will make an unholy mess of it.
|
37
|
+
*
|
38
|
+
* So to avoid that mess which just slows things down, we force
|
39
|
+
* the stores to memory to actually happen (we might be better off
|
40
|
+
* with a 'W(t)=(val);asm("":"+m" (W(t))' there instead, as
|
41
|
+
* suggested by Artur Skawina - that will also make gcc unable to
|
42
|
+
* try to do the silly "optimize away loads" part because it won't
|
43
|
+
* see what the value will be).
|
44
|
+
*
|
45
|
+
* Ben Herrenschmidt reports that on PPC, the C version comes close
|
46
|
+
* to the optimized asm with this (ie on PPC you don't want that
|
47
|
+
* 'volatile', since there are lots of registers).
|
48
|
+
*
|
49
|
+
* On ARM we get the best code generation by forcing a full memory barrier
|
50
|
+
* between each SHA_ROUND, otherwise gcc happily get wild with spilling and
|
51
|
+
* the stack frame size simply explode and performance goes down the drain.
|
52
|
+
*/
|
53
|
+
|
54
|
+
#if defined(__i386__) || defined(__x86_64__)
|
55
|
+
#define setW(x, val) (*(volatile unsigned int *)&W(x) = (val))
|
56
|
+
#elif defined(__GNUC__) && defined(__arm__)
|
57
|
+
#define setW(x, val) do { W(x) = (val); __asm__("":::"memory"); } while (0)
|
58
|
+
#else
|
59
|
+
#define setW(x, val) (W(x) = (val))
|
60
|
+
#endif
|
61
|
+
|
62
|
+
/*
|
63
|
+
* Performance might be improved if the CPU architecture is OK with
|
64
|
+
* unaligned 32-bit loads and a fast ntohl() is available.
|
65
|
+
* Otherwise fall back to byte loads and shifts which is portable,
|
66
|
+
* and is faster on architectures with memory alignment issues.
|
67
|
+
*/
|
68
|
+
|
69
|
+
#if defined(__i386__) || defined(__x86_64__) || \
|
70
|
+
defined(_M_IX86) || defined(_M_X64) || \
|
71
|
+
defined(__ppc__) || defined(__ppc64__) || \
|
72
|
+
defined(__powerpc__) || defined(__powerpc64__) || \
|
73
|
+
defined(__s390__) || defined(__s390x__)
|
74
|
+
|
75
|
+
#define get_be32(p) ntohl(*(const unsigned int *)(p))
|
76
|
+
#define put_be32(p, v) do { *(unsigned int *)(p) = htonl(v); } while (0)
|
77
|
+
|
78
|
+
#else
|
79
|
+
|
80
|
+
#define get_be32(p) ( \
|
81
|
+
(*((const unsigned char *)(p) + 0) << 24) | \
|
82
|
+
(*((const unsigned char *)(p) + 1) << 16) | \
|
83
|
+
(*((const unsigned char *)(p) + 2) << 8) | \
|
84
|
+
(*((const unsigned char *)(p) + 3) << 0) )
|
85
|
+
#define put_be32(p, v) do { \
|
86
|
+
unsigned int __v = (v); \
|
87
|
+
*((unsigned char *)(p) + 0) = __v >> 24; \
|
88
|
+
*((unsigned char *)(p) + 1) = __v >> 16; \
|
89
|
+
*((unsigned char *)(p) + 2) = __v >> 8; \
|
90
|
+
*((unsigned char *)(p) + 3) = __v >> 0; } while (0)
|
91
|
+
|
92
|
+
#endif
|
93
|
+
|
94
|
+
/* This "rolls" over the 512-bit array */
|
95
|
+
#define W(x) (array[(x)&15])
|
96
|
+
|
97
|
+
/*
|
98
|
+
* Where do we get the source from? The first 16 iterations get it from
|
99
|
+
* the input data, the next mix it from the 512-bit array.
|
100
|
+
*/
|
101
|
+
#define SHA_SRC(t) get_be32(data + t)
|
102
|
+
#define SHA_MIX(t) SHA_ROL(W(t+13) ^ W(t+8) ^ W(t+2) ^ W(t), 1)
|
103
|
+
|
104
|
+
#define SHA_ROUND(t, input, fn, constant, A, B, C, D, E) do { \
|
105
|
+
unsigned int TEMP = input(t); setW(t, TEMP); \
|
106
|
+
E += TEMP + SHA_ROL(A,5) + (fn) + (constant); \
|
107
|
+
B = SHA_ROR(B, 2); } while (0)
|
108
|
+
|
109
|
+
#define T_0_15(t, A, B, C, D, E) SHA_ROUND(t, SHA_SRC, (((C^D)&B)^D) , 0x5a827999, A, B, C, D, E )
|
110
|
+
#define T_16_19(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (((C^D)&B)^D) , 0x5a827999, A, B, C, D, E )
|
111
|
+
#define T_20_39(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0x6ed9eba1, A, B, C, D, E )
|
112
|
+
#define T_40_59(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, ((B&C)+(D&(B^C))) , 0x8f1bbcdc, A, B, C, D, E )
|
113
|
+
#define T_60_79(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0xca62c1d6, A, B, C, D, E )
|
114
|
+
|
115
|
+
static void blk_SHA1_Block(blk_SHA_CTX *ctx, const unsigned int *data)
|
116
|
+
{
|
117
|
+
unsigned int A,B,C,D,E;
|
118
|
+
unsigned int array[16];
|
119
|
+
|
120
|
+
A = ctx->H[0];
|
121
|
+
B = ctx->H[1];
|
122
|
+
C = ctx->H[2];
|
123
|
+
D = ctx->H[3];
|
124
|
+
E = ctx->H[4];
|
125
|
+
|
126
|
+
/* Round 1 - iterations 0-16 take their input from 'data' */
|
127
|
+
T_0_15( 0, A, B, C, D, E);
|
128
|
+
T_0_15( 1, E, A, B, C, D);
|
129
|
+
T_0_15( 2, D, E, A, B, C);
|
130
|
+
T_0_15( 3, C, D, E, A, B);
|
131
|
+
T_0_15( 4, B, C, D, E, A);
|
132
|
+
T_0_15( 5, A, B, C, D, E);
|
133
|
+
T_0_15( 6, E, A, B, C, D);
|
134
|
+
T_0_15( 7, D, E, A, B, C);
|
135
|
+
T_0_15( 8, C, D, E, A, B);
|
136
|
+
T_0_15( 9, B, C, D, E, A);
|
137
|
+
T_0_15(10, A, B, C, D, E);
|
138
|
+
T_0_15(11, E, A, B, C, D);
|
139
|
+
T_0_15(12, D, E, A, B, C);
|
140
|
+
T_0_15(13, C, D, E, A, B);
|
141
|
+
T_0_15(14, B, C, D, E, A);
|
142
|
+
T_0_15(15, A, B, C, D, E);
|
143
|
+
|
144
|
+
/* Round 1 - tail. Input from 512-bit mixing array */
|
145
|
+
T_16_19(16, E, A, B, C, D);
|
146
|
+
T_16_19(17, D, E, A, B, C);
|
147
|
+
T_16_19(18, C, D, E, A, B);
|
148
|
+
T_16_19(19, B, C, D, E, A);
|
149
|
+
|
150
|
+
/* Round 2 */
|
151
|
+
T_20_39(20, A, B, C, D, E);
|
152
|
+
T_20_39(21, E, A, B, C, D);
|
153
|
+
T_20_39(22, D, E, A, B, C);
|
154
|
+
T_20_39(23, C, D, E, A, B);
|
155
|
+
T_20_39(24, B, C, D, E, A);
|
156
|
+
T_20_39(25, A, B, C, D, E);
|
157
|
+
T_20_39(26, E, A, B, C, D);
|
158
|
+
T_20_39(27, D, E, A, B, C);
|
159
|
+
T_20_39(28, C, D, E, A, B);
|
160
|
+
T_20_39(29, B, C, D, E, A);
|
161
|
+
T_20_39(30, A, B, C, D, E);
|
162
|
+
T_20_39(31, E, A, B, C, D);
|
163
|
+
T_20_39(32, D, E, A, B, C);
|
164
|
+
T_20_39(33, C, D, E, A, B);
|
165
|
+
T_20_39(34, B, C, D, E, A);
|
166
|
+
T_20_39(35, A, B, C, D, E);
|
167
|
+
T_20_39(36, E, A, B, C, D);
|
168
|
+
T_20_39(37, D, E, A, B, C);
|
169
|
+
T_20_39(38, C, D, E, A, B);
|
170
|
+
T_20_39(39, B, C, D, E, A);
|
171
|
+
|
172
|
+
/* Round 3 */
|
173
|
+
T_40_59(40, A, B, C, D, E);
|
174
|
+
T_40_59(41, E, A, B, C, D);
|
175
|
+
T_40_59(42, D, E, A, B, C);
|
176
|
+
T_40_59(43, C, D, E, A, B);
|
177
|
+
T_40_59(44, B, C, D, E, A);
|
178
|
+
T_40_59(45, A, B, C, D, E);
|
179
|
+
T_40_59(46, E, A, B, C, D);
|
180
|
+
T_40_59(47, D, E, A, B, C);
|
181
|
+
T_40_59(48, C, D, E, A, B);
|
182
|
+
T_40_59(49, B, C, D, E, A);
|
183
|
+
T_40_59(50, A, B, C, D, E);
|
184
|
+
T_40_59(51, E, A, B, C, D);
|
185
|
+
T_40_59(52, D, E, A, B, C);
|
186
|
+
T_40_59(53, C, D, E, A, B);
|
187
|
+
T_40_59(54, B, C, D, E, A);
|
188
|
+
T_40_59(55, A, B, C, D, E);
|
189
|
+
T_40_59(56, E, A, B, C, D);
|
190
|
+
T_40_59(57, D, E, A, B, C);
|
191
|
+
T_40_59(58, C, D, E, A, B);
|
192
|
+
T_40_59(59, B, C, D, E, A);
|
193
|
+
|
194
|
+
/* Round 4 */
|
195
|
+
T_60_79(60, A, B, C, D, E);
|
196
|
+
T_60_79(61, E, A, B, C, D);
|
197
|
+
T_60_79(62, D, E, A, B, C);
|
198
|
+
T_60_79(63, C, D, E, A, B);
|
199
|
+
T_60_79(64, B, C, D, E, A);
|
200
|
+
T_60_79(65, A, B, C, D, E);
|
201
|
+
T_60_79(66, E, A, B, C, D);
|
202
|
+
T_60_79(67, D, E, A, B, C);
|
203
|
+
T_60_79(68, C, D, E, A, B);
|
204
|
+
T_60_79(69, B, C, D, E, A);
|
205
|
+
T_60_79(70, A, B, C, D, E);
|
206
|
+
T_60_79(71, E, A, B, C, D);
|
207
|
+
T_60_79(72, D, E, A, B, C);
|
208
|
+
T_60_79(73, C, D, E, A, B);
|
209
|
+
T_60_79(74, B, C, D, E, A);
|
210
|
+
T_60_79(75, A, B, C, D, E);
|
211
|
+
T_60_79(76, E, A, B, C, D);
|
212
|
+
T_60_79(77, D, E, A, B, C);
|
213
|
+
T_60_79(78, C, D, E, A, B);
|
214
|
+
T_60_79(79, B, C, D, E, A);
|
215
|
+
|
216
|
+
ctx->H[0] += A;
|
217
|
+
ctx->H[1] += B;
|
218
|
+
ctx->H[2] += C;
|
219
|
+
ctx->H[3] += D;
|
220
|
+
ctx->H[4] += E;
|
221
|
+
}
|
222
|
+
|
223
|
+
void git__blk_SHA1_Init(blk_SHA_CTX *ctx)
|
224
|
+
{
|
225
|
+
ctx->size = 0;
|
226
|
+
|
227
|
+
/* Initialize H with the magic constants (see FIPS180 for constants) */
|
228
|
+
ctx->H[0] = 0x67452301;
|
229
|
+
ctx->H[1] = 0xefcdab89;
|
230
|
+
ctx->H[2] = 0x98badcfe;
|
231
|
+
ctx->H[3] = 0x10325476;
|
232
|
+
ctx->H[4] = 0xc3d2e1f0;
|
233
|
+
}
|
234
|
+
|
235
|
+
void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len)
|
236
|
+
{
|
237
|
+
unsigned int lenW = ctx->size & 63;
|
238
|
+
|
239
|
+
ctx->size += len;
|
240
|
+
|
241
|
+
/* Read the data into W and process blocks as they get full */
|
242
|
+
if (lenW) {
|
243
|
+
unsigned int left = 64 - lenW;
|
244
|
+
if (len < left)
|
245
|
+
left = len;
|
246
|
+
memcpy(lenW + (char *)ctx->W, data, left);
|
247
|
+
lenW = (lenW + left) & 63;
|
248
|
+
len -= left;
|
249
|
+
data = ((const char *)data + left);
|
250
|
+
if (lenW)
|
251
|
+
return;
|
252
|
+
blk_SHA1_Block(ctx, ctx->W);
|
253
|
+
}
|
254
|
+
while (len >= 64) {
|
255
|
+
blk_SHA1_Block(ctx, data);
|
256
|
+
data = ((const char *)data + 64);
|
257
|
+
len -= 64;
|
258
|
+
}
|
259
|
+
if (len)
|
260
|
+
memcpy(ctx->W, data, len);
|
261
|
+
}
|
262
|
+
|
263
|
+
void git__blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx)
|
264
|
+
{
|
265
|
+
static const unsigned char pad[64] = { 0x80 };
|
266
|
+
unsigned int padlen[2];
|
267
|
+
int i;
|
268
|
+
|
269
|
+
/* Pad with a binary 1 (ie 0x80), then zeroes, then length */
|
270
|
+
padlen[0] = htonl((uint32_t)(ctx->size >> 29));
|
271
|
+
padlen[1] = htonl((uint32_t)(ctx->size << 3));
|
272
|
+
|
273
|
+
i = ctx->size & 63;
|
274
|
+
git__blk_SHA1_Update(ctx, pad, 1+ (63 & (55 - i)));
|
275
|
+
git__blk_SHA1_Update(ctx, padlen, 8);
|
276
|
+
|
277
|
+
/* Output hash */
|
278
|
+
for (i = 0; i < 5; i++)
|
279
|
+
put_be32(hashout + i*4, ctx->H[i]);
|
280
|
+
}
|
@@ -0,0 +1,21 @@
|
|
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
|
+
typedef struct {
|
9
|
+
unsigned long long size;
|
10
|
+
unsigned int H[5];
|
11
|
+
unsigned int W[16];
|
12
|
+
} blk_SHA_CTX;
|
13
|
+
|
14
|
+
void git__blk_SHA1_Init(blk_SHA_CTX *ctx);
|
15
|
+
void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, unsigned long len);
|
16
|
+
void git__blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx);
|
17
|
+
|
18
|
+
#define SHA_CTX blk_SHA_CTX
|
19
|
+
#define SHA1_Init git__blk_SHA1_Init
|
20
|
+
#define SHA1_Update git__blk_SHA1_Update
|
21
|
+
#define SHA1_Final git__blk_SHA1_Final
|
@@ -0,0 +1,177 @@
|
|
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 <stdio.h>
|
9
|
+
|
10
|
+
#include "sha1_lookup.h"
|
11
|
+
#include "common.h"
|
12
|
+
|
13
|
+
/*
|
14
|
+
* Conventional binary search loop looks like this:
|
15
|
+
*
|
16
|
+
* unsigned lo, hi;
|
17
|
+
* do {
|
18
|
+
* unsigned mi = (lo + hi) / 2;
|
19
|
+
* int cmp = "entry pointed at by mi" minus "target";
|
20
|
+
* if (!cmp)
|
21
|
+
* return (mi is the wanted one)
|
22
|
+
* if (cmp > 0)
|
23
|
+
* hi = mi; "mi is larger than target"
|
24
|
+
* else
|
25
|
+
* lo = mi+1; "mi is smaller than target"
|
26
|
+
* } while (lo < hi);
|
27
|
+
*
|
28
|
+
* The invariants are:
|
29
|
+
*
|
30
|
+
* - When entering the loop, lo points at a slot that is never
|
31
|
+
* above the target (it could be at the target), hi points at a
|
32
|
+
* slot that is guaranteed to be above the target (it can never
|
33
|
+
* be at the target).
|
34
|
+
*
|
35
|
+
* - We find a point 'mi' between lo and hi (mi could be the same
|
36
|
+
* as lo, but never can be as same as hi), and check if it hits
|
37
|
+
* the target. There are three cases:
|
38
|
+
*
|
39
|
+
* - if it is a hit, we are happy.
|
40
|
+
*
|
41
|
+
* - if it is strictly higher than the target, we set it to hi,
|
42
|
+
* and repeat the search.
|
43
|
+
*
|
44
|
+
* - if it is strictly lower than the target, we update lo to
|
45
|
+
* one slot after it, because we allow lo to be at the target.
|
46
|
+
*
|
47
|
+
* If the loop exits, there is no matching entry.
|
48
|
+
*
|
49
|
+
* When choosing 'mi', we do not have to take the "middle" but
|
50
|
+
* anywhere in between lo and hi, as long as lo <= mi < hi is
|
51
|
+
* satisfied. When we somehow know that the distance between the
|
52
|
+
* target and lo is much shorter than the target and hi, we could
|
53
|
+
* pick mi that is much closer to lo than the midway.
|
54
|
+
*
|
55
|
+
* Now, we can take advantage of the fact that SHA-1 is a good hash
|
56
|
+
* function, and as long as there are enough entries in the table, we
|
57
|
+
* can expect uniform distribution. An entry that begins with for
|
58
|
+
* example "deadbeef..." is much likely to appear much later than in
|
59
|
+
* the midway of the table. It can reasonably be expected to be near
|
60
|
+
* 87% (222/256) from the top of the table.
|
61
|
+
*
|
62
|
+
* However, we do not want to pick "mi" too precisely. If the entry at
|
63
|
+
* the 87% in the above example turns out to be higher than the target
|
64
|
+
* we are looking for, we would end up narrowing the search space down
|
65
|
+
* only by 13%, instead of 50% we would get if we did a simple binary
|
66
|
+
* search. So we would want to hedge our bets by being less aggressive.
|
67
|
+
*
|
68
|
+
* The table at "table" holds at least "nr" entries of "elem_size"
|
69
|
+
* bytes each. Each entry has the SHA-1 key at "key_offset". The
|
70
|
+
* table is sorted by the SHA-1 key of the entries. The caller wants
|
71
|
+
* to find the entry with "key", and knows that the entry at "lo" is
|
72
|
+
* not higher than the entry it is looking for, and that the entry at
|
73
|
+
* "hi" is higher than the entry it is looking for.
|
74
|
+
*/
|
75
|
+
int sha1_entry_pos(const void *table,
|
76
|
+
size_t elem_size,
|
77
|
+
size_t key_offset,
|
78
|
+
unsigned lo, unsigned hi, unsigned nr,
|
79
|
+
const unsigned char *key)
|
80
|
+
{
|
81
|
+
const unsigned char *base = (const unsigned char*)table;
|
82
|
+
const unsigned char *hi_key, *lo_key;
|
83
|
+
unsigned ofs_0;
|
84
|
+
|
85
|
+
if (!nr || lo >= hi)
|
86
|
+
return -1;
|
87
|
+
|
88
|
+
if (nr == hi)
|
89
|
+
hi_key = NULL;
|
90
|
+
else
|
91
|
+
hi_key = base + elem_size * hi + key_offset;
|
92
|
+
lo_key = base + elem_size * lo + key_offset;
|
93
|
+
|
94
|
+
ofs_0 = 0;
|
95
|
+
do {
|
96
|
+
int cmp;
|
97
|
+
unsigned ofs, mi, range;
|
98
|
+
unsigned lov, hiv, kyv;
|
99
|
+
const unsigned char *mi_key;
|
100
|
+
|
101
|
+
range = hi - lo;
|
102
|
+
if (hi_key) {
|
103
|
+
for (ofs = ofs_0; ofs < 20; ofs++)
|
104
|
+
if (lo_key[ofs] != hi_key[ofs])
|
105
|
+
break;
|
106
|
+
ofs_0 = ofs;
|
107
|
+
/*
|
108
|
+
* byte 0 thru (ofs-1) are the same between
|
109
|
+
* lo and hi; ofs is the first byte that is
|
110
|
+
* different.
|
111
|
+
*/
|
112
|
+
hiv = hi_key[ofs_0];
|
113
|
+
if (ofs_0 < 19)
|
114
|
+
hiv = (hiv << 8) | hi_key[ofs_0+1];
|
115
|
+
} else {
|
116
|
+
hiv = 256;
|
117
|
+
if (ofs_0 < 19)
|
118
|
+
hiv <<= 8;
|
119
|
+
}
|
120
|
+
lov = lo_key[ofs_0];
|
121
|
+
kyv = key[ofs_0];
|
122
|
+
if (ofs_0 < 19) {
|
123
|
+
lov = (lov << 8) | lo_key[ofs_0+1];
|
124
|
+
kyv = (kyv << 8) | key[ofs_0+1];
|
125
|
+
}
|
126
|
+
assert(lov < hiv);
|
127
|
+
|
128
|
+
if (kyv < lov)
|
129
|
+
return -1 - lo;
|
130
|
+
if (hiv < kyv)
|
131
|
+
return -1 - hi;
|
132
|
+
|
133
|
+
/*
|
134
|
+
* Even if we know the target is much closer to 'hi'
|
135
|
+
* than 'lo', if we pick too precisely and overshoot
|
136
|
+
* (e.g. when we know 'mi' is closer to 'hi' than to
|
137
|
+
* 'lo', pick 'mi' that is higher than the target), we
|
138
|
+
* end up narrowing the search space by a smaller
|
139
|
+
* amount (i.e. the distance between 'mi' and 'hi')
|
140
|
+
* than what we would have (i.e. about half of 'lo'
|
141
|
+
* and 'hi'). Hedge our bets to pick 'mi' less
|
142
|
+
* aggressively, i.e. make 'mi' a bit closer to the
|
143
|
+
* middle than we would otherwise pick.
|
144
|
+
*/
|
145
|
+
kyv = (kyv * 6 + lov + hiv) / 8;
|
146
|
+
if (lov < hiv - 1) {
|
147
|
+
if (kyv == lov)
|
148
|
+
kyv++;
|
149
|
+
else if (kyv == hiv)
|
150
|
+
kyv--;
|
151
|
+
}
|
152
|
+
mi = (range - 1) * (kyv - lov) / (hiv - lov) + lo;
|
153
|
+
|
154
|
+
#ifdef INDEX_DEBUG_LOOKUP
|
155
|
+
printf("lo %u hi %u rg %u mi %u ", lo, hi, range, mi);
|
156
|
+
printf("ofs %u lov %x, hiv %x, kyv %x\n",
|
157
|
+
ofs_0, lov, hiv, kyv);
|
158
|
+
#endif
|
159
|
+
|
160
|
+
if (!(lo <= mi && mi < hi)) {
|
161
|
+
return git__throw(GIT_ERROR, "Assertion failure. Binary search invariant is false");
|
162
|
+
}
|
163
|
+
|
164
|
+
mi_key = base + elem_size * mi + key_offset;
|
165
|
+
cmp = memcmp(mi_key + ofs_0, key + ofs_0, 20 - ofs_0);
|
166
|
+
if (!cmp)
|
167
|
+
return mi;
|
168
|
+
if (cmp > 0) {
|
169
|
+
hi = mi;
|
170
|
+
hi_key = mi_key;
|
171
|
+
} else {
|
172
|
+
lo = mi + 1;
|
173
|
+
lo_key = mi_key + elem_size;
|
174
|
+
}
|
175
|
+
} while (lo < hi);
|
176
|
+
return -((int)lo)-1;
|
177
|
+
}
|