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,25 @@
|
|
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_remote_h__
|
8
|
+
#define INCLUDE_remote_h__
|
9
|
+
|
10
|
+
#include "refspec.h"
|
11
|
+
#include "transport.h"
|
12
|
+
#include "repository.h"
|
13
|
+
|
14
|
+
struct git_remote {
|
15
|
+
char *name;
|
16
|
+
char *url;
|
17
|
+
git_vector refs;
|
18
|
+
struct git_refspec fetch;
|
19
|
+
struct git_refspec push;
|
20
|
+
git_transport *transport;
|
21
|
+
git_repository *repo;
|
22
|
+
unsigned int need_pack:1;
|
23
|
+
};
|
24
|
+
|
25
|
+
#endif
|
@@ -0,0 +1,849 @@
|
|
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
|
+
#include <stdarg.h>
|
8
|
+
|
9
|
+
#include "git2/object.h"
|
10
|
+
|
11
|
+
#include "common.h"
|
12
|
+
#include "repository.h"
|
13
|
+
#include "commit.h"
|
14
|
+
#include "tag.h"
|
15
|
+
#include "blob.h"
|
16
|
+
#include "fileops.h"
|
17
|
+
#include "config.h"
|
18
|
+
#include "refs.h"
|
19
|
+
|
20
|
+
#define GIT_OBJECTS_INFO_DIR GIT_OBJECTS_DIR "info/"
|
21
|
+
#define GIT_OBJECTS_PACK_DIR GIT_OBJECTS_DIR "pack/"
|
22
|
+
|
23
|
+
#define GIT_FILE_CONTENT_PREFIX "gitdir: "
|
24
|
+
|
25
|
+
#define GIT_BRANCH_MASTER "master"
|
26
|
+
|
27
|
+
|
28
|
+
static void drop_odb(git_repository *repo)
|
29
|
+
{
|
30
|
+
if (repo->_odb != NULL) {
|
31
|
+
GIT_REFCOUNT_OWN(repo->_odb, NULL);
|
32
|
+
git_odb_free(repo->_odb);
|
33
|
+
repo->_odb = NULL;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
|
37
|
+
static void drop_config(git_repository *repo)
|
38
|
+
{
|
39
|
+
if (repo->_config != NULL) {
|
40
|
+
GIT_REFCOUNT_OWN(repo->_config, NULL);
|
41
|
+
git_config_free(repo->_config);
|
42
|
+
repo->_config = NULL;
|
43
|
+
}
|
44
|
+
}
|
45
|
+
|
46
|
+
static void drop_index(git_repository *repo)
|
47
|
+
{
|
48
|
+
if (repo->_index != NULL) {
|
49
|
+
GIT_REFCOUNT_OWN(repo->_index, NULL);
|
50
|
+
git_index_free(repo->_index);
|
51
|
+
repo->_index = NULL;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
void git_repository_free(git_repository *repo)
|
56
|
+
{
|
57
|
+
if (repo == NULL)
|
58
|
+
return;
|
59
|
+
|
60
|
+
git_cache_free(&repo->objects);
|
61
|
+
git_repository__refcache_free(&repo->references);
|
62
|
+
|
63
|
+
git__free(repo->path_repository);
|
64
|
+
git__free(repo->workdir);
|
65
|
+
|
66
|
+
drop_config(repo);
|
67
|
+
drop_index(repo);
|
68
|
+
drop_odb(repo);
|
69
|
+
|
70
|
+
git__free(repo);
|
71
|
+
}
|
72
|
+
|
73
|
+
/*
|
74
|
+
* Git repository open methods
|
75
|
+
*
|
76
|
+
* Open a repository object from its path
|
77
|
+
*/
|
78
|
+
static int quickcheck_repository_dir(const char *repository_path)
|
79
|
+
{
|
80
|
+
char path_aux[GIT_PATH_MAX];
|
81
|
+
|
82
|
+
/* Ensure HEAD file exists */
|
83
|
+
git_path_join(path_aux, repository_path, GIT_HEAD_FILE);
|
84
|
+
if (git_futils_isfile(path_aux) < 0)
|
85
|
+
return GIT_ERROR;
|
86
|
+
|
87
|
+
git_path_join(path_aux, repository_path, GIT_OBJECTS_DIR);
|
88
|
+
if (git_futils_isdir(path_aux) < 0)
|
89
|
+
return GIT_ERROR;
|
90
|
+
|
91
|
+
git_path_join(path_aux, repository_path, GIT_REFS_DIR);
|
92
|
+
if (git_futils_isdir(path_aux) < 0)
|
93
|
+
return GIT_ERROR;
|
94
|
+
|
95
|
+
return GIT_SUCCESS;
|
96
|
+
}
|
97
|
+
|
98
|
+
|
99
|
+
static git_repository *repository_alloc(void)
|
100
|
+
{
|
101
|
+
int error;
|
102
|
+
|
103
|
+
git_repository *repo = git__malloc(sizeof(git_repository));
|
104
|
+
if (!repo)
|
105
|
+
return NULL;
|
106
|
+
|
107
|
+
memset(repo, 0x0, sizeof(git_repository));
|
108
|
+
|
109
|
+
error = git_cache_init(&repo->objects, GIT_DEFAULT_CACHE_SIZE, &git_object__free);
|
110
|
+
if (error < GIT_SUCCESS) {
|
111
|
+
git__free(repo);
|
112
|
+
return NULL;
|
113
|
+
}
|
114
|
+
|
115
|
+
return repo;
|
116
|
+
}
|
117
|
+
|
118
|
+
static int load_config_data(git_repository *repo)
|
119
|
+
{
|
120
|
+
int error, is_bare;
|
121
|
+
git_config *config;
|
122
|
+
|
123
|
+
error = git_repository_config__weakptr(&config, repo);
|
124
|
+
if (error < GIT_SUCCESS)
|
125
|
+
return error;
|
126
|
+
|
127
|
+
error = git_config_get_bool(config, "core.bare", &is_bare);
|
128
|
+
if (error == GIT_SUCCESS)
|
129
|
+
repo->is_bare = is_bare;
|
130
|
+
|
131
|
+
/* TODO: what else can we load/cache here? */
|
132
|
+
|
133
|
+
return GIT_SUCCESS;
|
134
|
+
}
|
135
|
+
|
136
|
+
static int load_workdir(git_repository *repo)
|
137
|
+
{
|
138
|
+
if (!repo->is_bare) {
|
139
|
+
char workdir_buf[GIT_PATH_MAX];
|
140
|
+
|
141
|
+
if (git_path_dirname_r(workdir_buf, sizeof(workdir_buf), repo->path_repository) < 0)
|
142
|
+
return git__throw(GIT_EOSERR,
|
143
|
+
"Failed to resolved working directory");
|
144
|
+
|
145
|
+
git_path_join(workdir_buf, workdir_buf, "");
|
146
|
+
|
147
|
+
repo->workdir = git__strdup(workdir_buf);
|
148
|
+
if (repo->workdir == NULL)
|
149
|
+
return GIT_ENOMEM;
|
150
|
+
}
|
151
|
+
|
152
|
+
return GIT_SUCCESS;
|
153
|
+
}
|
154
|
+
|
155
|
+
int git_repository_open(git_repository **repo_out, const char *path)
|
156
|
+
{
|
157
|
+
int error = GIT_SUCCESS;
|
158
|
+
char path_buf[GIT_PATH_MAX];
|
159
|
+
size_t path_len;
|
160
|
+
git_repository *repo = NULL;
|
161
|
+
|
162
|
+
error = git_path_prettify_dir(path_buf, path, NULL);
|
163
|
+
if (error < GIT_SUCCESS)
|
164
|
+
return git__rethrow(error, "Failed to open repository");
|
165
|
+
|
166
|
+
path_len = strlen(path_buf);
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Check if the path we've been given is actually the path
|
170
|
+
* of the working dir, by testing if it contains a `.git`
|
171
|
+
* folder inside of it.
|
172
|
+
*/
|
173
|
+
git_path_join(path_buf, path_buf, DOT_GIT);
|
174
|
+
if (git_futils_isdir(path_buf) < GIT_SUCCESS) {
|
175
|
+
path_buf[path_len] = 0;
|
176
|
+
}
|
177
|
+
|
178
|
+
if (quickcheck_repository_dir(path_buf) < GIT_SUCCESS)
|
179
|
+
return git__throw(GIT_ENOTAREPO,
|
180
|
+
"The given path is not a valid Git repository");
|
181
|
+
|
182
|
+
repo = repository_alloc();
|
183
|
+
if (repo == NULL)
|
184
|
+
return GIT_ENOMEM;
|
185
|
+
|
186
|
+
repo->path_repository = git__strdup(path_buf);
|
187
|
+
if (repo->path_repository == NULL) {
|
188
|
+
git_repository_free(repo);
|
189
|
+
return GIT_ENOMEM;
|
190
|
+
}
|
191
|
+
|
192
|
+
error = load_config_data(repo);
|
193
|
+
if (error < GIT_SUCCESS) {
|
194
|
+
git_repository_free(repo);
|
195
|
+
return error;
|
196
|
+
}
|
197
|
+
|
198
|
+
error = load_workdir(repo);
|
199
|
+
if (error < GIT_SUCCESS) {
|
200
|
+
git_repository_free(repo);
|
201
|
+
return error;
|
202
|
+
}
|
203
|
+
|
204
|
+
*repo_out = repo;
|
205
|
+
return GIT_SUCCESS;
|
206
|
+
}
|
207
|
+
|
208
|
+
static int load_config(
|
209
|
+
git_config **out,
|
210
|
+
git_repository *repo,
|
211
|
+
const char *global_config_path,
|
212
|
+
const char *system_config_path)
|
213
|
+
{
|
214
|
+
char config_path[GIT_PATH_MAX];
|
215
|
+
int error;
|
216
|
+
git_config *cfg = NULL;
|
217
|
+
|
218
|
+
assert(repo && out);
|
219
|
+
|
220
|
+
error = git_config_new(&cfg);
|
221
|
+
if (error < GIT_SUCCESS)
|
222
|
+
return error;
|
223
|
+
|
224
|
+
git_path_join(config_path, repo->path_repository, GIT_CONFIG_FILENAME_INREPO);
|
225
|
+
error = git_config_add_file_ondisk(cfg, config_path, 3);
|
226
|
+
if (error < GIT_SUCCESS)
|
227
|
+
goto cleanup;
|
228
|
+
|
229
|
+
if (global_config_path != NULL) {
|
230
|
+
error = git_config_add_file_ondisk(cfg, global_config_path, 2);
|
231
|
+
if (error < GIT_SUCCESS)
|
232
|
+
goto cleanup;
|
233
|
+
}
|
234
|
+
|
235
|
+
if (system_config_path != NULL) {
|
236
|
+
error = git_config_add_file_ondisk(cfg, system_config_path, 1);
|
237
|
+
if (error < GIT_SUCCESS)
|
238
|
+
goto cleanup;
|
239
|
+
}
|
240
|
+
|
241
|
+
*out = cfg;
|
242
|
+
return GIT_SUCCESS;
|
243
|
+
|
244
|
+
cleanup:
|
245
|
+
git_config_free(cfg);
|
246
|
+
*out = NULL;
|
247
|
+
return error;
|
248
|
+
}
|
249
|
+
|
250
|
+
int git_repository_config__weakptr(git_config **out, git_repository *repo)
|
251
|
+
{
|
252
|
+
if (repo->_config == NULL) {
|
253
|
+
int error;
|
254
|
+
|
255
|
+
char buf_global[GIT_PATH_MAX], buf_system[GIT_PATH_MAX];
|
256
|
+
|
257
|
+
const char *global_config_path = NULL;
|
258
|
+
const char *system_config_path = NULL;
|
259
|
+
|
260
|
+
if (git_config_find_global(buf_global) == GIT_SUCCESS)
|
261
|
+
global_config_path = buf_global;
|
262
|
+
|
263
|
+
if (git_config_find_system(buf_system) == GIT_SUCCESS)
|
264
|
+
system_config_path = buf_system;
|
265
|
+
|
266
|
+
error = load_config(&repo->_config, repo, global_config_path, system_config_path);
|
267
|
+
if (error < GIT_SUCCESS)
|
268
|
+
return error;
|
269
|
+
|
270
|
+
GIT_REFCOUNT_OWN(repo->_config, repo);
|
271
|
+
}
|
272
|
+
|
273
|
+
*out = repo->_config;
|
274
|
+
return GIT_SUCCESS;
|
275
|
+
}
|
276
|
+
|
277
|
+
int git_repository_config(git_config **out, git_repository *repo)
|
278
|
+
{
|
279
|
+
int error = git_repository_config__weakptr(out, repo);
|
280
|
+
|
281
|
+
if (error == GIT_SUCCESS) {
|
282
|
+
GIT_REFCOUNT_INC(*out);
|
283
|
+
}
|
284
|
+
|
285
|
+
return error;
|
286
|
+
}
|
287
|
+
|
288
|
+
void git_repository_set_config(git_repository *repo, git_config *config)
|
289
|
+
{
|
290
|
+
assert(repo && config);
|
291
|
+
|
292
|
+
drop_config(repo);
|
293
|
+
|
294
|
+
repo->_config = config;
|
295
|
+
GIT_REFCOUNT_OWN(repo->_config, repo);
|
296
|
+
}
|
297
|
+
|
298
|
+
int git_repository_odb__weakptr(git_odb **out, git_repository *repo)
|
299
|
+
{
|
300
|
+
assert(repo && out);
|
301
|
+
|
302
|
+
if (repo->_odb == NULL) {
|
303
|
+
int error;
|
304
|
+
char odb_path[GIT_PATH_MAX];
|
305
|
+
|
306
|
+
git_path_join(odb_path, repo->path_repository, GIT_OBJECTS_DIR);
|
307
|
+
|
308
|
+
error = git_odb_open(&repo->_odb, odb_path);
|
309
|
+
if (error < GIT_SUCCESS)
|
310
|
+
return error;
|
311
|
+
|
312
|
+
GIT_REFCOUNT_OWN(repo->_odb, repo);
|
313
|
+
}
|
314
|
+
|
315
|
+
*out = repo->_odb;
|
316
|
+
return GIT_SUCCESS;
|
317
|
+
}
|
318
|
+
|
319
|
+
int git_repository_odb(git_odb **out, git_repository *repo)
|
320
|
+
{
|
321
|
+
int error = git_repository_odb__weakptr(out, repo);
|
322
|
+
|
323
|
+
if (error == GIT_SUCCESS) {
|
324
|
+
GIT_REFCOUNT_INC(*out);
|
325
|
+
}
|
326
|
+
|
327
|
+
return error;
|
328
|
+
}
|
329
|
+
|
330
|
+
void git_repository_set_odb(git_repository *repo, git_odb *odb)
|
331
|
+
{
|
332
|
+
assert(repo && odb);
|
333
|
+
|
334
|
+
drop_odb(repo);
|
335
|
+
|
336
|
+
repo->_odb = odb;
|
337
|
+
GIT_REFCOUNT_OWN(repo->_odb, repo);
|
338
|
+
}
|
339
|
+
|
340
|
+
int git_repository_index__weakptr(git_index **out, git_repository *repo)
|
341
|
+
{
|
342
|
+
assert(out && repo);
|
343
|
+
|
344
|
+
if (repo->is_bare)
|
345
|
+
return git__throw(GIT_EBAREINDEX, "Cannot open index in bare repository");
|
346
|
+
|
347
|
+
if (repo->_index == NULL) {
|
348
|
+
int error;
|
349
|
+
char index_path[GIT_PATH_MAX];
|
350
|
+
|
351
|
+
git_path_join(index_path, repo->path_repository, GIT_INDEX_FILE);
|
352
|
+
|
353
|
+
error = git_index_open(&repo->_index, index_path);
|
354
|
+
if (error < GIT_SUCCESS)
|
355
|
+
return error;
|
356
|
+
|
357
|
+
GIT_REFCOUNT_OWN(repo->_index, repo);
|
358
|
+
}
|
359
|
+
|
360
|
+
*out = repo->_index;
|
361
|
+
return GIT_SUCCESS;
|
362
|
+
}
|
363
|
+
|
364
|
+
int git_repository_index(git_index **out, git_repository *repo)
|
365
|
+
{
|
366
|
+
int error = git_repository_index__weakptr(out, repo);
|
367
|
+
|
368
|
+
if (error == GIT_SUCCESS) {
|
369
|
+
GIT_REFCOUNT_INC(*out);
|
370
|
+
}
|
371
|
+
|
372
|
+
return error;
|
373
|
+
}
|
374
|
+
|
375
|
+
void git_repository_set_index(git_repository *repo, git_index *index)
|
376
|
+
{
|
377
|
+
assert(repo && index);
|
378
|
+
|
379
|
+
drop_index(repo);
|
380
|
+
|
381
|
+
repo->_index = index;
|
382
|
+
GIT_REFCOUNT_OWN(repo->_index, repo);
|
383
|
+
}
|
384
|
+
|
385
|
+
|
386
|
+
static int retrieve_device(dev_t *device_out, const char *path)
|
387
|
+
{
|
388
|
+
struct stat path_info;
|
389
|
+
|
390
|
+
assert(device_out);
|
391
|
+
|
392
|
+
if (p_lstat(path, &path_info))
|
393
|
+
return git__throw(GIT_EOSERR, "Failed to get file informations: %s", path);
|
394
|
+
|
395
|
+
*device_out = path_info.st_dev;
|
396
|
+
|
397
|
+
return GIT_SUCCESS;
|
398
|
+
}
|
399
|
+
|
400
|
+
static int retrieve_ceiling_directories_offset(const char *path, const char *ceiling_directories)
|
401
|
+
{
|
402
|
+
char buf[GIT_PATH_MAX + 1];
|
403
|
+
char buf2[GIT_PATH_MAX + 1];
|
404
|
+
const char *ceil, *sep;
|
405
|
+
int len, max_len = -1;
|
406
|
+
int min_len;
|
407
|
+
|
408
|
+
assert(path);
|
409
|
+
|
410
|
+
min_len = git_path_root(path) + 1;
|
411
|
+
|
412
|
+
if (ceiling_directories == NULL || min_len == 0)
|
413
|
+
return min_len;
|
414
|
+
|
415
|
+
for (sep = ceil = ceiling_directories; *sep; ceil = sep + 1) {
|
416
|
+
for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++);
|
417
|
+
len = sep - ceil;
|
418
|
+
|
419
|
+
if (len == 0 || len > GIT_PATH_MAX || git_path_root(ceil) == -1)
|
420
|
+
continue;
|
421
|
+
|
422
|
+
strncpy(buf, ceil, len);
|
423
|
+
buf[len] = '\0';
|
424
|
+
|
425
|
+
if (p_realpath(buf, buf2) == NULL)
|
426
|
+
continue;
|
427
|
+
|
428
|
+
len = strlen(buf2);
|
429
|
+
if (len > 0 && buf2[len-1] == '/')
|
430
|
+
buf[--len] = '\0';
|
431
|
+
|
432
|
+
if (!strncmp(path, buf2, len) &&
|
433
|
+
path[len] == '/' &&
|
434
|
+
len > max_len)
|
435
|
+
{
|
436
|
+
max_len = len;
|
437
|
+
}
|
438
|
+
}
|
439
|
+
|
440
|
+
return max_len <= min_len ? min_len : max_len;
|
441
|
+
}
|
442
|
+
|
443
|
+
static int read_gitfile(char *path_out, const char *file_path, const char *base_path)
|
444
|
+
{
|
445
|
+
git_fbuffer file;
|
446
|
+
int error;
|
447
|
+
size_t end_offset;
|
448
|
+
char *data;
|
449
|
+
|
450
|
+
assert(path_out && file_path && base_path);
|
451
|
+
|
452
|
+
error = git_futils_readbuffer(&file, file_path);
|
453
|
+
|
454
|
+
if (error < GIT_SUCCESS)
|
455
|
+
return error;
|
456
|
+
|
457
|
+
data = (char*)(file.data);
|
458
|
+
|
459
|
+
if (git__prefixcmp(data, GIT_FILE_CONTENT_PREFIX)) {
|
460
|
+
git_futils_freebuffer(&file);
|
461
|
+
return git__throw(GIT_ENOTFOUND, "Invalid gitfile format `%s`", file_path);
|
462
|
+
}
|
463
|
+
|
464
|
+
end_offset = strlen(data) - 1;
|
465
|
+
|
466
|
+
for (;data[end_offset] == '\r' || data[end_offset] == '\n'; --end_offset);
|
467
|
+
data[end_offset + 1] = '\0';
|
468
|
+
|
469
|
+
if (strlen(GIT_FILE_CONTENT_PREFIX) == end_offset + 1) {
|
470
|
+
git_futils_freebuffer(&file);
|
471
|
+
return git__throw(GIT_ENOTFOUND, "No path in git file `%s`", file_path);
|
472
|
+
}
|
473
|
+
|
474
|
+
data = data + strlen(GIT_FILE_CONTENT_PREFIX);
|
475
|
+
error = git_path_prettify_dir(path_out, data, base_path);
|
476
|
+
git_futils_freebuffer(&file);
|
477
|
+
|
478
|
+
if (error == 0 && git_futils_exists(path_out) == 0)
|
479
|
+
return GIT_SUCCESS;
|
480
|
+
|
481
|
+
return git__throw(GIT_EOBJCORRUPTED, "The `.git` file points to an inexisting path");
|
482
|
+
}
|
483
|
+
|
484
|
+
int git_repository_discover(
|
485
|
+
char *repository_path,
|
486
|
+
size_t size,
|
487
|
+
const char *start_path,
|
488
|
+
int across_fs,
|
489
|
+
const char *ceiling_dirs)
|
490
|
+
{
|
491
|
+
int error, ceiling_offset;
|
492
|
+
char bare_path[GIT_PATH_MAX];
|
493
|
+
char normal_path[GIT_PATH_MAX];
|
494
|
+
char *found_path;
|
495
|
+
dev_t current_device = 0;
|
496
|
+
|
497
|
+
assert(start_path && repository_path);
|
498
|
+
|
499
|
+
error = git_path_prettify_dir(bare_path, start_path, NULL);
|
500
|
+
if (error < GIT_SUCCESS)
|
501
|
+
return error;
|
502
|
+
|
503
|
+
if (!across_fs) {
|
504
|
+
error = retrieve_device(¤t_device, bare_path);
|
505
|
+
if (error < GIT_SUCCESS)
|
506
|
+
return error;
|
507
|
+
}
|
508
|
+
|
509
|
+
ceiling_offset = retrieve_ceiling_directories_offset(bare_path, ceiling_dirs);
|
510
|
+
git_path_join(normal_path, bare_path, DOT_GIT);
|
511
|
+
|
512
|
+
while(1) {
|
513
|
+
/**
|
514
|
+
* If the `.git` file is regular instead of
|
515
|
+
* a directory, it should contain the path of the actual git repository
|
516
|
+
*/
|
517
|
+
if (git_futils_isfile(normal_path) == GIT_SUCCESS) {
|
518
|
+
error = read_gitfile(repository_path, normal_path, bare_path);
|
519
|
+
|
520
|
+
if (error < GIT_SUCCESS)
|
521
|
+
return git__rethrow(error,
|
522
|
+
"Unable to read git file `%s`", normal_path);
|
523
|
+
|
524
|
+
error = quickcheck_repository_dir(repository_path);
|
525
|
+
if (error < GIT_SUCCESS)
|
526
|
+
return git__throw(GIT_ENOTFOUND,
|
527
|
+
"The `.git` file found at '%s' points"
|
528
|
+
"to an inexisting Git folder", normal_path);
|
529
|
+
|
530
|
+
return GIT_SUCCESS;
|
531
|
+
}
|
532
|
+
|
533
|
+
/**
|
534
|
+
* If the `.git` file is a folder, we check inside of it
|
535
|
+
*/
|
536
|
+
if (git_futils_isdir(normal_path) == GIT_SUCCESS) {
|
537
|
+
error = quickcheck_repository_dir(normal_path);
|
538
|
+
if (error == GIT_SUCCESS) {
|
539
|
+
found_path = normal_path;
|
540
|
+
break;
|
541
|
+
}
|
542
|
+
}
|
543
|
+
|
544
|
+
/**
|
545
|
+
* Otherwise, the repository may be bare, let's check
|
546
|
+
* the root anyway
|
547
|
+
*/
|
548
|
+
error = quickcheck_repository_dir(bare_path);
|
549
|
+
if (error == GIT_SUCCESS) {
|
550
|
+
found_path = bare_path;
|
551
|
+
break;
|
552
|
+
}
|
553
|
+
|
554
|
+
if (git_path_dirname_r(normal_path, sizeof(normal_path), bare_path) < GIT_SUCCESS)
|
555
|
+
return git__throw(GIT_EOSERR, "Failed to dirname '%s'", bare_path);
|
556
|
+
|
557
|
+
if (!across_fs) {
|
558
|
+
dev_t new_device;
|
559
|
+
error = retrieve_device(&new_device, normal_path);
|
560
|
+
|
561
|
+
if (error < GIT_SUCCESS || current_device != new_device) {
|
562
|
+
return git__throw(GIT_ENOTAREPO,
|
563
|
+
"Not a git repository (or any parent up to mount parent %s)\n"
|
564
|
+
"Stopping at filesystem boundary.", bare_path);
|
565
|
+
}
|
566
|
+
current_device = new_device;
|
567
|
+
}
|
568
|
+
|
569
|
+
strcpy(bare_path, normal_path);
|
570
|
+
git_path_join(normal_path, bare_path, DOT_GIT);
|
571
|
+
|
572
|
+
// nothing has been found, lets try the parent directory
|
573
|
+
if (bare_path[ceiling_offset] == '\0') {
|
574
|
+
return git__throw(GIT_ENOTAREPO,
|
575
|
+
"Not a git repository (or any of the parent directories): %s", start_path);
|
576
|
+
}
|
577
|
+
}
|
578
|
+
|
579
|
+
if (size < strlen(found_path) + 2) {
|
580
|
+
return git__throw(GIT_ESHORTBUFFER,
|
581
|
+
"The repository buffer is not long enough to handle the repository path `%s`", found_path);
|
582
|
+
}
|
583
|
+
|
584
|
+
git_path_join(repository_path, found_path, "");
|
585
|
+
return GIT_SUCCESS;
|
586
|
+
}
|
587
|
+
|
588
|
+
static int repo_init_reinit(const char *repository_path, int is_bare)
|
589
|
+
{
|
590
|
+
/* TODO: reinit the repository */
|
591
|
+
return git__throw(GIT_ENOTIMPLEMENTED,
|
592
|
+
"Failed to reinitialize the %srepository at '%s'. "
|
593
|
+
"This feature is not yet implemented",
|
594
|
+
is_bare ? "bare " : "", repository_path);
|
595
|
+
}
|
596
|
+
|
597
|
+
static int repo_init_createhead(const char *git_dir)
|
598
|
+
{
|
599
|
+
char ref_path[GIT_PATH_MAX];
|
600
|
+
git_filebuf ref = GIT_FILEBUF_INIT;
|
601
|
+
|
602
|
+
git_path_join(ref_path, git_dir, GIT_HEAD_FILE);
|
603
|
+
|
604
|
+
git_filebuf_open(&ref, ref_path, 0);
|
605
|
+
git_filebuf_printf(&ref, "ref: refs/heads/master\n");
|
606
|
+
|
607
|
+
return git_filebuf_commit(&ref, GIT_REFS_FILE_MODE);
|
608
|
+
}
|
609
|
+
|
610
|
+
static int repo_init_config(const char *git_dir, int is_bare)
|
611
|
+
{
|
612
|
+
char cfg_path[GIT_PATH_MAX];
|
613
|
+
git_config *config;
|
614
|
+
int error = GIT_SUCCESS;
|
615
|
+
|
616
|
+
#define SET_REPO_CONFIG(type, name, val) {\
|
617
|
+
error = git_config_set_##type(config, name, val);\
|
618
|
+
if (error < GIT_SUCCESS)\
|
619
|
+
goto cleanup;\
|
620
|
+
}
|
621
|
+
|
622
|
+
git_path_join(cfg_path, git_dir, GIT_CONFIG_FILENAME_INREPO);
|
623
|
+
|
624
|
+
error = git_config_open_ondisk(&config, cfg_path);
|
625
|
+
if (error < GIT_SUCCESS)
|
626
|
+
return error;
|
627
|
+
|
628
|
+
SET_REPO_CONFIG(bool, "core.bare", is_bare);
|
629
|
+
SET_REPO_CONFIG(int32, "core.repositoryformatversion", 0);
|
630
|
+
/* TODO: what other defaults? */
|
631
|
+
|
632
|
+
cleanup:
|
633
|
+
git_config_free(config);
|
634
|
+
return error;
|
635
|
+
}
|
636
|
+
|
637
|
+
static int repo_init_structure(const char *git_dir, int is_bare)
|
638
|
+
{
|
639
|
+
int error;
|
640
|
+
|
641
|
+
char temp_path[GIT_PATH_MAX];
|
642
|
+
|
643
|
+
if (git_futils_mkdir_r(git_dir, is_bare ? GIT_BARE_DIR_MODE : GIT_DIR_MODE))
|
644
|
+
return git__throw(GIT_ERROR, "Failed to initialize repository structure. Could not mkdir");
|
645
|
+
|
646
|
+
/* Hides the ".git" directory */
|
647
|
+
if (!is_bare) {
|
648
|
+
#ifdef GIT_WIN32
|
649
|
+
error = p_hide_directory__w32(git_dir);
|
650
|
+
if (error < GIT_SUCCESS)
|
651
|
+
return git__rethrow(error, "Failed to initialize repository structure");
|
652
|
+
#endif
|
653
|
+
}
|
654
|
+
|
655
|
+
/* Creates the '/objects/info/' directory */
|
656
|
+
git_path_join(temp_path, git_dir, GIT_OBJECTS_INFO_DIR);
|
657
|
+
error = git_futils_mkdir_r(temp_path, GIT_OBJECT_DIR_MODE);
|
658
|
+
if (error < GIT_SUCCESS)
|
659
|
+
return git__rethrow(error, "Failed to initialize repository structure");
|
660
|
+
|
661
|
+
/* Creates the '/objects/pack/' directory */
|
662
|
+
git_path_join(temp_path, git_dir, GIT_OBJECTS_PACK_DIR);
|
663
|
+
error = p_mkdir(temp_path, GIT_OBJECT_DIR_MODE);
|
664
|
+
if (error < GIT_SUCCESS)
|
665
|
+
return git__throw(error, "Unable to create `%s` folder", temp_path);
|
666
|
+
|
667
|
+
/* Creates the '/refs/heads/' directory */
|
668
|
+
git_path_join(temp_path, git_dir, GIT_REFS_HEADS_DIR);
|
669
|
+
error = git_futils_mkdir_r(temp_path, GIT_REFS_DIR_MODE);
|
670
|
+
if (error < GIT_SUCCESS)
|
671
|
+
return git__rethrow(error, "Failed to initialize repository structure");
|
672
|
+
|
673
|
+
/* Creates the '/refs/tags/' directory */
|
674
|
+
git_path_join(temp_path, git_dir, GIT_REFS_TAGS_DIR);
|
675
|
+
error = p_mkdir(temp_path, GIT_REFS_DIR_MODE);
|
676
|
+
if (error < GIT_SUCCESS)
|
677
|
+
return git__throw(error, "Unable to create `%s` folder", temp_path);
|
678
|
+
|
679
|
+
/* TODO: what's left? templates? */
|
680
|
+
|
681
|
+
return GIT_SUCCESS;
|
682
|
+
}
|
683
|
+
|
684
|
+
int git_repository_init(git_repository **repo_out, const char *path, unsigned is_bare)
|
685
|
+
{
|
686
|
+
int error = GIT_SUCCESS;
|
687
|
+
git_repository *repo = NULL;
|
688
|
+
char repository_path[GIT_PATH_MAX];
|
689
|
+
|
690
|
+
assert(repo_out && path);
|
691
|
+
|
692
|
+
git_path_join(repository_path, path, is_bare ? "" : GIT_DIR);
|
693
|
+
|
694
|
+
if (git_futils_isdir(repository_path)) {
|
695
|
+
if (quickcheck_repository_dir(repository_path) == GIT_SUCCESS)
|
696
|
+
return repo_init_reinit(repository_path, is_bare);
|
697
|
+
}
|
698
|
+
|
699
|
+
error = repo_init_structure(repository_path, is_bare);
|
700
|
+
if (error < GIT_SUCCESS)
|
701
|
+
goto cleanup;
|
702
|
+
|
703
|
+
error = repo_init_config(repository_path, is_bare);
|
704
|
+
if (error < GIT_SUCCESS)
|
705
|
+
goto cleanup;
|
706
|
+
|
707
|
+
error = repo_init_createhead(repository_path);
|
708
|
+
if (error < GIT_SUCCESS)
|
709
|
+
goto cleanup;
|
710
|
+
|
711
|
+
return git_repository_open(repo_out, repository_path);
|
712
|
+
|
713
|
+
cleanup:
|
714
|
+
git_repository_free(repo);
|
715
|
+
return git__rethrow(error, "Failed to (re)init the repository `%s`", path);
|
716
|
+
}
|
717
|
+
|
718
|
+
int git_repository_head_detached(git_repository *repo)
|
719
|
+
{
|
720
|
+
git_reference *ref;
|
721
|
+
int error;
|
722
|
+
size_t _size;
|
723
|
+
git_otype type;
|
724
|
+
git_odb *odb = NULL;
|
725
|
+
|
726
|
+
error = git_repository_odb__weakptr(&odb, repo);
|
727
|
+
if (error < GIT_SUCCESS)
|
728
|
+
return error;
|
729
|
+
|
730
|
+
error = git_reference_lookup(&ref, repo, GIT_HEAD_FILE);
|
731
|
+
if (error < GIT_SUCCESS)
|
732
|
+
return error;
|
733
|
+
|
734
|
+
if (git_reference_type(ref) == GIT_REF_SYMBOLIC) {
|
735
|
+
git_reference_free(ref);
|
736
|
+
return 0;
|
737
|
+
}
|
738
|
+
|
739
|
+
error = git_odb_read_header(&_size, &type, odb, git_reference_oid(ref));
|
740
|
+
|
741
|
+
git_reference_free(ref);
|
742
|
+
|
743
|
+
if (error < GIT_SUCCESS)
|
744
|
+
return error;
|
745
|
+
|
746
|
+
if (type != GIT_OBJ_COMMIT)
|
747
|
+
return git__throw(GIT_EOBJCORRUPTED, "HEAD is not a commit");
|
748
|
+
|
749
|
+
return 1;
|
750
|
+
}
|
751
|
+
|
752
|
+
int git_repository_head(git_reference **head_out, git_repository *repo)
|
753
|
+
{
|
754
|
+
git_reference *ref, *resolved_ref;
|
755
|
+
int error;
|
756
|
+
|
757
|
+
*head_out = NULL;
|
758
|
+
|
759
|
+
error = git_reference_lookup(&ref, repo, GIT_HEAD_FILE);
|
760
|
+
if (error < GIT_SUCCESS)
|
761
|
+
return git__rethrow(GIT_ENOTAREPO, "Failed to locate the HEAD");
|
762
|
+
|
763
|
+
error = git_reference_resolve(&resolved_ref, ref);
|
764
|
+
if (error < GIT_SUCCESS) {
|
765
|
+
git_reference_free(ref);
|
766
|
+
return git__rethrow(error, "Failed to resolve the HEAD");
|
767
|
+
}
|
768
|
+
|
769
|
+
git_reference_free(ref);
|
770
|
+
|
771
|
+
*head_out = resolved_ref;
|
772
|
+
return GIT_SUCCESS;
|
773
|
+
}
|
774
|
+
|
775
|
+
int git_repository_head_orphan(git_repository *repo)
|
776
|
+
{
|
777
|
+
git_reference *ref;
|
778
|
+
int error;
|
779
|
+
|
780
|
+
error = git_repository_head(&ref, repo);
|
781
|
+
|
782
|
+
if (error == GIT_SUCCESS)
|
783
|
+
git_reference_free(ref);
|
784
|
+
|
785
|
+
return error == GIT_ENOTFOUND ? 1 : error;
|
786
|
+
}
|
787
|
+
|
788
|
+
int git_repository_is_empty(git_repository *repo)
|
789
|
+
{
|
790
|
+
git_reference *head = NULL, *branch = NULL;
|
791
|
+
int error;
|
792
|
+
|
793
|
+
error = git_reference_lookup(&head, repo, "HEAD");
|
794
|
+
if (error < GIT_SUCCESS)
|
795
|
+
return git__throw(error, "Corrupted repository. HEAD does not exist");
|
796
|
+
|
797
|
+
if (git_reference_type(head) != GIT_REF_SYMBOLIC) {
|
798
|
+
git_reference_free(head);
|
799
|
+
return 0;
|
800
|
+
}
|
801
|
+
|
802
|
+
if (strcmp(git_reference_target(head), "refs/heads/master") != 0) {
|
803
|
+
git_reference_free(head);
|
804
|
+
return 0;
|
805
|
+
}
|
806
|
+
|
807
|
+
error = git_reference_resolve(&branch, head);
|
808
|
+
|
809
|
+
git_reference_free(head);
|
810
|
+
git_reference_free(branch);
|
811
|
+
|
812
|
+
return error == GIT_ENOTFOUND ? 1 : error;
|
813
|
+
}
|
814
|
+
|
815
|
+
const char *git_repository_path(git_repository *repo)
|
816
|
+
{
|
817
|
+
assert(repo);
|
818
|
+
return repo->path_repository;
|
819
|
+
}
|
820
|
+
|
821
|
+
const char *git_repository_workdir(git_repository *repo)
|
822
|
+
{
|
823
|
+
assert(repo);
|
824
|
+
|
825
|
+
if (repo->is_bare)
|
826
|
+
return NULL;
|
827
|
+
|
828
|
+
return repo->workdir;
|
829
|
+
}
|
830
|
+
|
831
|
+
int git_repository_set_workdir(git_repository *repo, const char *workdir)
|
832
|
+
{
|
833
|
+
assert(repo && workdir);
|
834
|
+
|
835
|
+
free(repo->workdir);
|
836
|
+
|
837
|
+
repo->workdir = git__strdup(workdir);
|
838
|
+
if (repo->workdir == NULL)
|
839
|
+
return GIT_ENOMEM;
|
840
|
+
|
841
|
+
repo->is_bare = 0;
|
842
|
+
return GIT_SUCCESS;
|
843
|
+
}
|
844
|
+
|
845
|
+
int git_repository_is_bare(git_repository *repo)
|
846
|
+
{
|
847
|
+
assert(repo);
|
848
|
+
return repo->is_bare;
|
849
|
+
}
|