rugged 0.17.0.b7 → 0.18.0.b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (310) hide show
  1. data/LICENSE +1 -1
  2. data/README.md +88 -32
  3. data/ext/rugged/extconf.rb +4 -2
  4. data/ext/rugged/rugged.c +72 -10
  5. data/ext/rugged/rugged.h +14 -10
  6. data/ext/rugged/rugged_blob.c +8 -10
  7. data/ext/rugged/rugged_branch.c +11 -14
  8. data/ext/rugged/rugged_commit.c +31 -24
  9. data/ext/rugged/rugged_config.c +2 -2
  10. data/ext/rugged/rugged_index.c +133 -198
  11. data/ext/rugged/rugged_note.c +372 -0
  12. data/ext/rugged/rugged_object.c +50 -22
  13. data/ext/rugged/rugged_reference.c +122 -130
  14. data/ext/rugged/rugged_remote.c +72 -29
  15. data/ext/rugged/rugged_repo.c +402 -20
  16. data/ext/rugged/rugged_revwalk.c +7 -3
  17. data/ext/rugged/rugged_settings.c +110 -0
  18. data/ext/rugged/rugged_signature.c +23 -7
  19. data/ext/rugged/rugged_tag.c +32 -16
  20. data/ext/rugged/rugged_tree.c +44 -15
  21. data/lib/rugged.rb +1 -0
  22. data/lib/rugged/index.rb +8 -0
  23. data/lib/rugged/remote.rb +13 -0
  24. data/lib/rugged/repository.rb +3 -3
  25. data/lib/rugged/version.rb +1 -1
  26. data/test/blob_test.rb +13 -15
  27. data/test/branch_test.rb +32 -67
  28. data/test/commit_test.rb +50 -12
  29. data/test/config_test.rb +12 -11
  30. data/test/coverage/HEAD.json +1 -1
  31. data/test/coverage/cover.rb +40 -21
  32. data/test/errors_test.rb +34 -0
  33. data/test/fixtures/alternate/objects/14/6ae76773c91e3b1d00cf7a338ec55ae58297e2 +0 -0
  34. data/test/fixtures/alternate/objects/14/9c32d47e99d0a3572ff1e70a2e0051bbf347a9 +0 -0
  35. data/test/fixtures/alternate/objects/14/fb3108588f9421bf764041e5e3ac305eb6277f +0 -0
  36. data/test/fixtures/testrepo.git/logs/refs/notes/commits +1 -0
  37. data/test/fixtures/testrepo.git/objects/44/1034f860c1d5d90e4188d11ae0d325176869a8 +1 -0
  38. data/test/fixtures/testrepo.git/objects/60/d415052a33de2150bf68757f6461df4f563ae4 +0 -0
  39. data/test/fixtures/testrepo.git/objects/68/8a8f4ef7496901d15322972f96e212a9e466cc +1 -0
  40. data/test/fixtures/testrepo.git/objects/94/eca2de348d5f672faf56b0decafa5937e3235e +0 -0
  41. data/test/fixtures/testrepo.git/objects/9b/7384fe1676186192842f5d3e129457b62db9e3 +0 -0
  42. data/test/fixtures/testrepo.git/objects/b7/4713326bc972cc15751ed504dca6f6f3b91f7a +3 -0
  43. data/test/fixtures/testrepo.git/refs/notes/commits +1 -0
  44. data/test/index_test.rb +65 -69
  45. data/test/lib_test.rb +76 -11
  46. data/test/note_test.rb +158 -0
  47. data/test/object_test.rb +8 -11
  48. data/test/reference_test.rb +77 -85
  49. data/test/remote_test.rb +86 -8
  50. data/test/repo_pack_test.rb +9 -7
  51. data/test/repo_reset_test.rb +80 -0
  52. data/test/repo_test.rb +176 -53
  53. data/test/tag_test.rb +44 -7
  54. data/test/test_helper.rb +63 -35
  55. data/test/tree_test.rb +34 -13
  56. data/test/walker_test.rb +14 -14
  57. data/vendor/libgit2/Makefile.embed +1 -1
  58. data/vendor/libgit2/deps/http-parser/http_parser.c +974 -578
  59. data/vendor/libgit2/deps/http-parser/http_parser.h +106 -70
  60. data/vendor/libgit2/deps/regex/regcomp.c +7 -6
  61. data/vendor/libgit2/deps/regex/regex_internal.c +1 -1
  62. data/vendor/libgit2/deps/regex/regex_internal.h +12 -3
  63. data/vendor/libgit2/deps/regex/regexec.c +5 -5
  64. data/vendor/libgit2/include/git2.h +5 -1
  65. data/vendor/libgit2/include/git2/attr.h +4 -2
  66. data/vendor/libgit2/include/git2/blob.h +39 -12
  67. data/vendor/libgit2/include/git2/branch.h +123 -35
  68. data/vendor/libgit2/include/git2/checkout.h +206 -48
  69. data/vendor/libgit2/include/git2/clone.h +72 -27
  70. data/vendor/libgit2/include/git2/commit.h +20 -17
  71. data/vendor/libgit2/include/git2/common.h +67 -1
  72. data/vendor/libgit2/include/git2/config.h +81 -60
  73. data/vendor/libgit2/include/git2/cred_helpers.h +53 -0
  74. data/vendor/libgit2/include/git2/diff.h +459 -150
  75. data/vendor/libgit2/include/git2/errors.h +9 -1
  76. data/vendor/libgit2/include/git2/graph.h +41 -0
  77. data/vendor/libgit2/include/git2/ignore.h +7 -6
  78. data/vendor/libgit2/include/git2/index.h +323 -97
  79. data/vendor/libgit2/include/git2/indexer.h +27 -59
  80. data/vendor/libgit2/include/git2/inttypes.h +4 -0
  81. data/vendor/libgit2/include/git2/merge.h +13 -3
  82. data/vendor/libgit2/include/git2/message.h +14 -8
  83. data/vendor/libgit2/include/git2/net.h +9 -7
  84. data/vendor/libgit2/include/git2/notes.h +88 -29
  85. data/vendor/libgit2/include/git2/object.h +16 -6
  86. data/vendor/libgit2/include/git2/odb.h +80 -17
  87. data/vendor/libgit2/include/git2/odb_backend.h +47 -11
  88. data/vendor/libgit2/include/git2/oid.h +26 -17
  89. data/vendor/libgit2/include/git2/pack.h +62 -8
  90. data/vendor/libgit2/include/git2/push.h +131 -0
  91. data/vendor/libgit2/include/git2/refdb.h +103 -0
  92. data/vendor/libgit2/include/git2/refdb_backend.h +109 -0
  93. data/vendor/libgit2/include/git2/reflog.h +30 -21
  94. data/vendor/libgit2/include/git2/refs.h +215 -193
  95. data/vendor/libgit2/include/git2/refspec.h +22 -2
  96. data/vendor/libgit2/include/git2/remote.h +158 -37
  97. data/vendor/libgit2/include/git2/repository.h +150 -31
  98. data/vendor/libgit2/include/git2/reset.h +43 -9
  99. data/vendor/libgit2/include/git2/revparse.h +48 -4
  100. data/vendor/libgit2/include/git2/revwalk.h +25 -10
  101. data/vendor/libgit2/include/git2/signature.h +20 -12
  102. data/vendor/libgit2/include/git2/stash.h +121 -0
  103. data/vendor/libgit2/include/git2/status.h +122 -53
  104. data/vendor/libgit2/include/git2/strarray.h +17 -11
  105. data/vendor/libgit2/include/git2/submodule.h +42 -7
  106. data/vendor/libgit2/include/git2/tag.h +72 -59
  107. data/vendor/libgit2/include/git2/threads.h +4 -2
  108. data/vendor/libgit2/include/git2/trace.h +68 -0
  109. data/vendor/libgit2/include/git2/transport.h +328 -0
  110. data/vendor/libgit2/include/git2/tree.h +149 -120
  111. data/vendor/libgit2/include/git2/types.h +13 -12
  112. data/vendor/libgit2/include/git2/version.h +3 -3
  113. data/vendor/libgit2/src/amiga/map.c +2 -2
  114. data/vendor/libgit2/src/attr.c +58 -48
  115. data/vendor/libgit2/src/attr.h +4 -18
  116. data/vendor/libgit2/src/attr_file.c +30 -6
  117. data/vendor/libgit2/src/attr_file.h +6 -8
  118. data/vendor/libgit2/src/attrcache.h +24 -0
  119. data/vendor/libgit2/src/blob.c +30 -7
  120. data/vendor/libgit2/src/blob.h +1 -1
  121. data/vendor/libgit2/src/branch.c +361 -68
  122. data/vendor/libgit2/src/branch.h +17 -0
  123. data/vendor/libgit2/src/bswap.h +1 -1
  124. data/vendor/libgit2/src/buf_text.c +291 -0
  125. data/vendor/libgit2/src/buf_text.h +122 -0
  126. data/vendor/libgit2/src/buffer.c +27 -101
  127. data/vendor/libgit2/src/buffer.h +54 -39
  128. data/vendor/libgit2/src/cache.c +15 -6
  129. data/vendor/libgit2/src/cache.h +1 -1
  130. data/vendor/libgit2/src/cc-compat.h +3 -1
  131. data/vendor/libgit2/src/checkout.c +1165 -222
  132. data/vendor/libgit2/src/checkout.h +24 -0
  133. data/vendor/libgit2/src/clone.c +171 -86
  134. data/vendor/libgit2/src/commit.c +44 -45
  135. data/vendor/libgit2/src/commit.h +3 -3
  136. data/vendor/libgit2/src/commit_list.c +194 -0
  137. data/vendor/libgit2/src/commit_list.h +49 -0
  138. data/vendor/libgit2/src/common.h +44 -10
  139. data/vendor/libgit2/src/compress.c +1 -1
  140. data/vendor/libgit2/src/compress.h +1 -1
  141. data/vendor/libgit2/src/config.c +211 -124
  142. data/vendor/libgit2/src/config.h +23 -4
  143. data/vendor/libgit2/src/config_cache.c +2 -2
  144. data/vendor/libgit2/src/config_file.c +129 -53
  145. data/vendor/libgit2/src/config_file.h +10 -8
  146. data/vendor/libgit2/src/crlf.c +66 -67
  147. data/vendor/libgit2/src/date.c +12 -12
  148. data/vendor/libgit2/src/delta-apply.c +14 -1
  149. data/vendor/libgit2/src/delta-apply.h +18 -1
  150. data/vendor/libgit2/src/delta.c +40 -107
  151. data/vendor/libgit2/src/delta.h +19 -17
  152. data/vendor/libgit2/src/diff.c +347 -496
  153. data/vendor/libgit2/src/diff.h +27 -1
  154. data/vendor/libgit2/src/diff_output.c +564 -249
  155. data/vendor/libgit2/src/diff_output.h +15 -8
  156. data/vendor/libgit2/src/diff_tform.c +687 -0
  157. data/vendor/libgit2/src/errors.c +27 -36
  158. data/vendor/libgit2/src/fetch.c +13 -351
  159. data/vendor/libgit2/src/fetch.h +13 -3
  160. data/vendor/libgit2/src/fetchhead.c +295 -0
  161. data/vendor/libgit2/src/fetchhead.h +34 -0
  162. data/vendor/libgit2/src/filebuf.c +42 -15
  163. data/vendor/libgit2/src/filebuf.h +4 -2
  164. data/vendor/libgit2/src/fileops.c +466 -113
  165. data/vendor/libgit2/src/fileops.h +154 -28
  166. data/vendor/libgit2/src/filter.c +3 -75
  167. data/vendor/libgit2/src/filter.h +1 -29
  168. data/vendor/libgit2/src/fnmatch.c +1 -1
  169. data/vendor/libgit2/src/fnmatch.h +1 -1
  170. data/vendor/libgit2/src/global.c +54 -10
  171. data/vendor/libgit2/src/global.h +10 -1
  172. data/vendor/libgit2/src/graph.c +178 -0
  173. data/vendor/libgit2/src/hash.c +25 -52
  174. data/vendor/libgit2/src/hash.h +21 -9
  175. data/vendor/libgit2/src/{sha1/sha1.c → hash/hash_generic.c} +20 -12
  176. data/vendor/libgit2/src/hash/hash_generic.h +24 -0
  177. data/vendor/libgit2/src/hash/hash_openssl.h +45 -0
  178. data/vendor/libgit2/src/hash/hash_win32.c +291 -0
  179. data/vendor/libgit2/src/hash/hash_win32.h +140 -0
  180. data/vendor/libgit2/src/hashsig.c +368 -0
  181. data/vendor/libgit2/src/hashsig.h +72 -0
  182. data/vendor/libgit2/src/ignore.c +22 -15
  183. data/vendor/libgit2/src/ignore.h +6 -1
  184. data/vendor/libgit2/src/index.c +770 -171
  185. data/vendor/libgit2/src/index.h +13 -5
  186. data/vendor/libgit2/src/indexer.c +286 -431
  187. data/vendor/libgit2/src/iterator.c +854 -466
  188. data/vendor/libgit2/src/iterator.h +134 -109
  189. data/vendor/libgit2/src/map.h +1 -1
  190. data/vendor/libgit2/src/merge.c +296 -0
  191. data/vendor/libgit2/src/merge.h +22 -0
  192. data/vendor/libgit2/src/message.c +1 -1
  193. data/vendor/libgit2/src/message.h +1 -1
  194. data/vendor/libgit2/src/mwindow.c +35 -30
  195. data/vendor/libgit2/src/mwindow.h +2 -2
  196. data/vendor/libgit2/src/netops.c +162 -98
  197. data/vendor/libgit2/src/netops.h +50 -15
  198. data/vendor/libgit2/src/notes.c +109 -58
  199. data/vendor/libgit2/src/notes.h +2 -1
  200. data/vendor/libgit2/src/object.c +46 -57
  201. data/vendor/libgit2/src/object.h +1 -8
  202. data/vendor/libgit2/src/odb.c +151 -40
  203. data/vendor/libgit2/src/odb.h +5 -1
  204. data/vendor/libgit2/src/odb_loose.c +4 -5
  205. data/vendor/libgit2/src/odb_pack.c +122 -80
  206. data/vendor/libgit2/src/offmap.h +65 -0
  207. data/vendor/libgit2/src/oid.c +12 -4
  208. data/vendor/libgit2/src/oidmap.h +1 -1
  209. data/vendor/libgit2/src/pack-objects.c +88 -61
  210. data/vendor/libgit2/src/pack-objects.h +8 -8
  211. data/vendor/libgit2/src/pack.c +293 -28
  212. data/vendor/libgit2/src/pack.h +49 -4
  213. data/vendor/libgit2/src/path.c +103 -14
  214. data/vendor/libgit2/src/path.h +23 -7
  215. data/vendor/libgit2/src/pathspec.c +168 -0
  216. data/vendor/libgit2/src/pathspec.h +40 -0
  217. data/vendor/libgit2/src/pool.c +29 -4
  218. data/vendor/libgit2/src/pool.h +8 -1
  219. data/vendor/libgit2/src/posix.c +26 -27
  220. data/vendor/libgit2/src/posix.h +2 -3
  221. data/vendor/libgit2/src/pqueue.c +23 -1
  222. data/vendor/libgit2/src/pqueue.h +23 -1
  223. data/vendor/libgit2/src/push.c +653 -0
  224. data/vendor/libgit2/src/push.h +51 -0
  225. data/vendor/libgit2/src/refdb.c +185 -0
  226. data/vendor/libgit2/src/refdb.h +46 -0
  227. data/vendor/libgit2/src/refdb_fs.c +1024 -0
  228. data/vendor/libgit2/src/refdb_fs.h +15 -0
  229. data/vendor/libgit2/src/reflog.c +77 -45
  230. data/vendor/libgit2/src/reflog.h +1 -3
  231. data/vendor/libgit2/src/refs.c +366 -1326
  232. data/vendor/libgit2/src/refs.h +22 -13
  233. data/vendor/libgit2/src/refspec.c +46 -7
  234. data/vendor/libgit2/src/refspec.h +11 -1
  235. data/vendor/libgit2/src/remote.c +758 -120
  236. data/vendor/libgit2/src/remote.h +10 -5
  237. data/vendor/libgit2/src/repo_template.h +6 -6
  238. data/vendor/libgit2/src/repository.c +315 -96
  239. data/vendor/libgit2/src/repository.h +5 -3
  240. data/vendor/libgit2/src/reset.c +99 -81
  241. data/vendor/libgit2/src/revparse.c +157 -84
  242. data/vendor/libgit2/src/revwalk.c +68 -470
  243. data/vendor/libgit2/src/revwalk.h +44 -0
  244. data/vendor/libgit2/src/sha1_lookup.c +1 -1
  245. data/vendor/libgit2/src/sha1_lookup.h +1 -1
  246. data/vendor/libgit2/src/signature.c +68 -200
  247. data/vendor/libgit2/src/signature.h +1 -1
  248. data/vendor/libgit2/src/stash.c +663 -0
  249. data/vendor/libgit2/src/status.c +101 -79
  250. data/vendor/libgit2/src/strmap.h +1 -1
  251. data/vendor/libgit2/src/submodule.c +67 -51
  252. data/vendor/libgit2/src/submodule.h +1 -1
  253. data/vendor/libgit2/src/tag.c +35 -29
  254. data/vendor/libgit2/src/tag.h +1 -1
  255. data/vendor/libgit2/src/thread-utils.c +1 -1
  256. data/vendor/libgit2/src/thread-utils.h +2 -2
  257. data/vendor/libgit2/src/trace.c +39 -0
  258. data/vendor/libgit2/src/trace.h +56 -0
  259. data/vendor/libgit2/src/transport.c +81 -34
  260. data/vendor/libgit2/src/transports/cred.c +60 -0
  261. data/vendor/libgit2/src/transports/cred_helpers.c +49 -0
  262. data/vendor/libgit2/src/transports/git.c +234 -127
  263. data/vendor/libgit2/src/transports/http.c +761 -433
  264. data/vendor/libgit2/src/transports/local.c +460 -64
  265. data/vendor/libgit2/src/transports/smart.c +345 -0
  266. data/vendor/libgit2/src/transports/smart.h +179 -0
  267. data/vendor/libgit2/src/{pkt.c → transports/smart_pkt.c} +131 -12
  268. data/vendor/libgit2/src/transports/smart_protocol.c +856 -0
  269. data/vendor/libgit2/src/transports/winhttp.c +1136 -0
  270. data/vendor/libgit2/src/tree-cache.c +2 -2
  271. data/vendor/libgit2/src/tree-cache.h +1 -1
  272. data/vendor/libgit2/src/tree.c +239 -166
  273. data/vendor/libgit2/src/tree.h +11 -2
  274. data/vendor/libgit2/src/tsort.c +39 -23
  275. data/vendor/libgit2/src/unix/map.c +1 -1
  276. data/vendor/libgit2/src/unix/posix.h +12 -2
  277. data/vendor/libgit2/src/unix/realpath.c +30 -0
  278. data/vendor/libgit2/src/util.c +250 -13
  279. data/vendor/libgit2/src/util.h +71 -14
  280. data/vendor/libgit2/src/vector.c +123 -60
  281. data/vendor/libgit2/src/vector.h +24 -22
  282. data/vendor/libgit2/src/win32/dir.c +1 -1
  283. data/vendor/libgit2/src/win32/dir.h +1 -1
  284. data/vendor/libgit2/src/win32/error.c +77 -0
  285. data/vendor/libgit2/src/win32/error.h +13 -0
  286. data/vendor/libgit2/src/win32/findfile.c +143 -54
  287. data/vendor/libgit2/src/win32/findfile.h +10 -6
  288. data/vendor/libgit2/src/win32/map.c +1 -1
  289. data/vendor/libgit2/src/win32/mingw-compat.h +1 -1
  290. data/vendor/libgit2/src/win32/msvc-compat.h +10 -1
  291. data/vendor/libgit2/src/win32/posix.h +10 -1
  292. data/vendor/libgit2/src/win32/posix_w32.c +132 -63
  293. data/vendor/libgit2/src/win32/precompiled.c +1 -1
  294. data/vendor/libgit2/src/win32/pthread.c +1 -1
  295. data/vendor/libgit2/src/win32/pthread.h +1 -1
  296. data/vendor/libgit2/src/win32/utf-conv.c +5 -5
  297. data/vendor/libgit2/src/win32/utf-conv.h +3 -3
  298. data/vendor/libgit2/src/win32/version.h +20 -0
  299. metadata +308 -252
  300. data/test/fixtures/testrepo.git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
  301. data/test/fixtures/testrepo.git/objects/7f/043268ea43ce18e3540acaabf9e090c91965b0 +0 -0
  302. data/test/fixtures/testrepo.git/objects/a3/e05719b428a2d0ed7a55c4ce53dcc5768c6d5e +0 -0
  303. data/test/index_test.rb~ +0 -218
  304. data/vendor/libgit2/src/pkt.h +0 -91
  305. data/vendor/libgit2/src/ppc/sha1.c +0 -70
  306. data/vendor/libgit2/src/ppc/sha1.h +0 -26
  307. data/vendor/libgit2/src/protocol.c +0 -110
  308. data/vendor/libgit2/src/protocol.h +0 -21
  309. data/vendor/libgit2/src/sha1.h +0 -33
  310. data/vendor/libgit2/src/transport.h +0 -148
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (C) 2009-2012 the libgit2 contributors
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
3
  *
4
4
  * This file is part of libgit2, distributed under the GNU GPL v2 with
5
5
  * a Linking Exception. For full terms see the included COPYING file.
@@ -179,13 +179,23 @@ GIT_EXTERN(size_t) git_object__size(git_otype type);
179
179
  *
180
180
  * @param peeled Pointer to the peeled git_object
181
181
  * @param object The object to be processed
182
- * @param target_type The type of the requested object
183
- * @return 0 or an error code
182
+ * @param target_type The type of the requested object (GIT_OBJ_COMMIT,
183
+ * GIT_OBJ_TAG, GIT_OBJ_TREE, GIT_OBJ_BLOB or GIT_OBJ_ANY).
184
+ * @return 0 on success, GIT_EAMBIGUOUS, GIT_ENOTFOUND or an error code
184
185
  */
185
186
  GIT_EXTERN(int) git_object_peel(
186
- git_object **peeled,
187
- git_object *object,
188
- git_otype target_type);
187
+ git_object **peeled,
188
+ const git_object *object,
189
+ git_otype target_type);
190
+
191
+ /**
192
+ * Create an in-memory copy of a Git object. The copy must be
193
+ * explicitly free'd or it will leak.
194
+ *
195
+ * @param dest Pointer to store the copy of the object
196
+ * @param source Original object to copy
197
+ */
198
+ GIT_EXTERN(int) git_object_dup(git_object **dest, git_object *source);
189
199
 
190
200
  /** @} */
191
201
  GIT_END_DECL
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (C) 2009-2012 the libgit2 contributors
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
3
  *
4
4
  * This file is part of libgit2, distributed under the GNU GPL v2 with
5
5
  * a Linking Exception. For full terms see the included COPYING file.
@@ -11,6 +11,7 @@
11
11
  #include "types.h"
12
12
  #include "oid.h"
13
13
  #include "odb_backend.h"
14
+ #include "indexer.h"
14
15
 
15
16
  /**
16
17
  * @file git2/odb.h
@@ -87,6 +88,23 @@ GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int
87
88
  */
88
89
  GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority);
89
90
 
91
+ /**
92
+ * Add an on-disk alternate to an existing Object DB.
93
+ *
94
+ * Note that the added path must point to an `objects`, not
95
+ * to a full repository, to use it as an alternate store.
96
+ *
97
+ * Alternate backends are always checked for objects *after*
98
+ * all the main backends have been exhausted.
99
+ *
100
+ * Writing is disabled on alternate backends.
101
+ *
102
+ * @param odb database to add the backend to
103
+ * @param path path to the objects folder for the alternate
104
+ * @return 0 on success; error code otherwise
105
+ */
106
+ GIT_EXTERN(int) git_odb_add_disk_alternate(git_odb *odb, const char *path);
107
+
90
108
  /**
91
109
  * Close an open object database.
92
110
  *
@@ -135,9 +153,10 @@ GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *i
135
153
  * @param db database to search for the object in.
136
154
  * @param short_id a prefix of the id of the object to read.
137
155
  * @param len the length of the prefix
138
- * @return 0 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)
156
+ * @return
157
+ * - 0 if the object was read;
158
+ * - GIT_ENOTFOUND if the object is not in the database.
159
+ * - GIT_EAMBIGUOUS if the prefix is ambiguous (several objects match the prefix)
141
160
  */
142
161
  GIT_EXTERN(int) git_odb_read_prefix(git_odb_object **out, git_odb *db, const git_oid *short_id, size_t len);
143
162
 
@@ -151,15 +170,15 @@ GIT_EXTERN(int) git_odb_read_prefix(git_odb_object **out, git_odb *db, const git
151
170
  * of an object, so the whole object will be read and then the
152
171
  * header will be returned.
153
172
  *
154
- * @param len_p pointer where to store the length
155
- * @param type_p pointer where to store the type
173
+ * @param len_out pointer where to store the length
174
+ * @param type_out pointer where to store the type
156
175
  * @param db database to search for the object in.
157
176
  * @param id identity of the object to read.
158
177
  * @return
159
178
  * - 0 if the object was read;
160
179
  * - GIT_ENOTFOUND if the object is not in the database.
161
180
  */
162
- GIT_EXTERN(int) git_odb_read_header(size_t *len_p, git_otype *type_p, git_odb *db, const git_oid *id);
181
+ GIT_EXTERN(int) git_odb_read_header(size_t *len_out, git_otype *type_out, git_odb *db, const git_oid *id);
163
182
 
164
183
  /**
165
184
  * Determine if the given object can be found in the object database.
@@ -172,6 +191,26 @@ GIT_EXTERN(int) git_odb_read_header(size_t *len_p, git_otype *type_p, git_odb *d
172
191
  */
173
192
  GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id);
174
193
 
194
+ /**
195
+ * Refresh the object database to load newly added files.
196
+ *
197
+ * If the object databases have changed on disk while the library
198
+ * is running, this function will force a reload of the underlying
199
+ * indexes.
200
+ *
201
+ * Use this function when you're confident that an external
202
+ * application has tampered with the ODB.
203
+ *
204
+ * NOTE that it is not necessary to call this function at all. The
205
+ * library will automatically attempt to refresh the ODB
206
+ * when a lookup fails, to see if the looked up object exists
207
+ * on disk but hasn't been loaded yet.
208
+ *
209
+ * @param db database to refresh
210
+ * @return 0 on success, error code otherwise
211
+ */
212
+ GIT_EXTERN(int) git_odb_refresh(struct git_odb *db);
213
+
175
214
  /**
176
215
  * List all objects available in the database
177
216
  *
@@ -182,10 +221,10 @@ GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id);
182
221
  *
183
222
  * @param db database to use
184
223
  * @param cb the callback to call for each object
185
- * @param data data to pass to the callback
224
+ * @param payload data to pass to the callback
186
225
  * @return 0 on success, GIT_EUSER on non-zero callback, or error code
187
226
  */
188
- GIT_EXTERN(int) git_odb_foreach(git_odb *db, int (*cb)(git_oid *oid, void *data), void *data);
227
+ GIT_EXTERN(int) git_odb_foreach(git_odb *db, git_odb_foreach_cb cb, void *payload);
189
228
 
190
229
  /**
191
230
  * Write an object directly into the ODB
@@ -198,14 +237,14 @@ GIT_EXTERN(int) git_odb_foreach(git_odb *db, int (*cb)(git_oid *oid, void *data)
198
237
  * This method is provided for compatibility with custom backends
199
238
  * which are not able to support streaming writes
200
239
  *
201
- * @param oid pointer to store the OID result of the write
240
+ * @param out pointer to store the OID result of the write
202
241
  * @param odb object database where to store the object
203
242
  * @param data buffer with the data to store
204
243
  * @param len size of the buffer
205
244
  * @param type type of the data to store
206
245
  * @return 0 or an error code
207
246
  */
208
- GIT_EXTERN(int) git_odb_write(git_oid *oid, git_odb *odb, const void *data, size_t len, git_otype type);
247
+ GIT_EXTERN(int) git_odb_write(git_oid *out, git_odb *odb, const void *data, size_t len, git_otype type);
209
248
 
210
249
  /**
211
250
  * Open a stream to write an object into the ODB
@@ -228,13 +267,13 @@ GIT_EXTERN(int) git_odb_write(git_oid *oid, git_odb *odb, const void *data, size
228
267
  *
229
268
  * @see git_odb_stream
230
269
  *
231
- * @param stream pointer where to store the stream
270
+ * @param out pointer where to store the stream
232
271
  * @param db object database where the stream will write
233
272
  * @param size final size of the object that will be written
234
273
  * @param type type of the object that will be written
235
274
  * @return 0 if the stream was created; error code otherwise
236
275
  */
237
- GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **stream, git_odb *db, size_t size, git_otype type);
276
+ GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **out, git_odb *db, size_t size, git_otype type);
238
277
 
239
278
  /**
240
279
  * Open a stream to read an object from the ODB
@@ -255,12 +294,36 @@ GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **stream, git_odb *db, size_
255
294
  *
256
295
  * @see git_odb_stream
257
296
  *
258
- * @param stream pointer where to store the stream
297
+ * @param out pointer where to store the stream
259
298
  * @param db object database where the stream will read from
260
299
  * @param oid oid of the object the stream will read from
261
300
  * @return 0 if the stream was created; error code otherwise
262
301
  */
263
- GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const git_oid *oid);
302
+ GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **out, git_odb *db, const git_oid *oid);
303
+
304
+ /**
305
+ * Open a stream for writing a pack file to the ODB.
306
+ *
307
+ * If the ODB layer understands pack files, then the given
308
+ * packfile will likely be streamed directly to disk (and a
309
+ * corresponding index created). If the ODB layer does not
310
+ * understand pack files, the objects will be stored in whatever
311
+ * format the ODB layer uses.
312
+ *
313
+ * @see git_odb_writepack
314
+ *
315
+ * @param out pointer to the writepack functions
316
+ * @param db object database where the stream will read from
317
+ * @param progress_cb function to call with progress information.
318
+ * Be aware that this is called inline with network and indexing operations,
319
+ * so performance may be affected.
320
+ * @param progress_payload payload for the progress callback
321
+ */
322
+ GIT_EXTERN(int) git_odb_write_pack(
323
+ git_odb_writepack **out,
324
+ git_odb *db,
325
+ git_transfer_progress_callback progress_cb,
326
+ void *progress_payload);
264
327
 
265
328
  /**
266
329
  * Determine the object-ID (sha1 hash) of a data buffer
@@ -268,13 +331,13 @@ GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const
268
331
  * The resulting SHA-1 OID will be the identifier for the data
269
332
  * buffer as if the data buffer it were to written to the ODB.
270
333
  *
271
- * @param id the resulting object-ID.
334
+ * @param out the resulting object-ID.
272
335
  * @param data data to hash
273
336
  * @param len size of the data
274
337
  * @param type of the data to hash
275
338
  * @return 0 or an error code
276
339
  */
277
- GIT_EXTERN(int) git_odb_hash(git_oid *id, const void *data, size_t len, git_otype type);
340
+ GIT_EXTERN(int) git_odb_hash(git_oid *out, const void *data, size_t len, git_otype type);
278
341
 
279
342
  /**
280
343
  * Read a file from disk and fill a git_oid with the object id
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (C) 2009-2012 the libgit2 contributors
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
3
  *
4
4
  * This file is part of libgit2, distributed under the GNU GPL v2 with
5
5
  * a Linking Exception. For full terms see the included COPYING file.
@@ -10,6 +10,7 @@
10
10
  #include "common.h"
11
11
  #include "types.h"
12
12
  #include "oid.h"
13
+ #include "indexer.h"
13
14
 
14
15
  /**
15
16
  * @file git2/backend.h
@@ -21,9 +22,18 @@
21
22
  GIT_BEGIN_DECL
22
23
 
23
24
  struct git_odb_stream;
25
+ struct git_odb_writepack;
24
26
 
25
- /** An instance for a custom backend */
27
+ /**
28
+ * Function type for callbacks from git_odb_foreach.
29
+ */
30
+ typedef int (*git_odb_foreach_cb)(const git_oid *id, void *payload);
31
+
32
+ /**
33
+ * An instance for a custom backend
34
+ */
26
35
  struct git_odb_backend {
36
+ unsigned int version;
27
37
  git_odb *odb;
28
38
 
29
39
  /* read and read_prefix each return to libgit2 a buffer which
@@ -53,6 +63,10 @@ struct git_odb_backend {
53
63
  struct git_odb_backend *,
54
64
  const git_oid *);
55
65
 
66
+ /* The writer may assume that the object
67
+ * has already been hashed and is passed
68
+ * in the first parameter.
69
+ */
56
70
  int (* write)(
57
71
  git_oid *,
58
72
  struct git_odb_backend *,
@@ -75,15 +89,25 @@ struct git_odb_backend {
75
89
  struct git_odb_backend *,
76
90
  const git_oid *);
77
91
 
78
- int (*foreach)(
79
- struct git_odb_backend *,
80
- int (*cb)(git_oid *oid, void *data),
81
- void *data
82
- );
92
+ int (* refresh)(struct git_odb_backend *);
93
+
94
+ int (* foreach)(
95
+ struct git_odb_backend *,
96
+ git_odb_foreach_cb cb,
97
+ void *payload);
98
+
99
+ int (* writepack)(
100
+ struct git_odb_writepack **,
101
+ struct git_odb_backend *,
102
+ git_transfer_progress_callback progress_cb,
103
+ void *progress_payload);
83
104
 
84
105
  void (* free)(struct git_odb_backend *);
85
106
  };
86
107
 
108
+ #define GIT_ODB_BACKEND_VERSION 1
109
+ #define GIT_ODB_BACKEND_INIT {GIT_ODB_BACKEND_VERSION}
110
+
87
111
  /** Streaming mode */
88
112
  enum {
89
113
  GIT_STREAM_RDONLY = (1 << 1),
@@ -94,7 +118,7 @@ enum {
94
118
  /** A stream to read/write from a backend */
95
119
  struct git_odb_stream {
96
120
  struct git_odb_backend *backend;
97
- int mode;
121
+ unsigned int mode;
98
122
 
99
123
  int (*read)(struct git_odb_stream *stream, char *buffer, size_t len);
100
124
  int (*write)(struct git_odb_stream *stream, const char *buffer, size_t len);
@@ -102,12 +126,24 @@ struct git_odb_stream {
102
126
  void (*free)(struct git_odb_stream *stream);
103
127
  };
104
128
 
105
- GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir);
106
- GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir, int compression_level, int do_fsync);
107
- GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **backend_out, const char *index_file);
129
+ /** A stream to write a pack file to the ODB */
130
+ struct git_odb_writepack {
131
+ struct git_odb_backend *backend;
132
+
133
+ int (*add)(struct git_odb_writepack *writepack, const void *data, size_t size, git_transfer_progress *stats);
134
+ int (*commit)(struct git_odb_writepack *writepack, git_transfer_progress *stats);
135
+ void (*free)(struct git_odb_writepack *writepack);
136
+ };
108
137
 
109
138
  GIT_EXTERN(void *) git_odb_backend_malloc(git_odb_backend *backend, size_t len);
110
139
 
140
+ /**
141
+ * Constructors for in-box ODB backends.
142
+ */
143
+ GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **out, const char *objects_dir);
144
+ GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **out, const char *objects_dir, int compression_level, int do_fsync);
145
+ GIT_EXTERN(int) git_odb_backend_one_pack(git_odb_backend **out, const char *index_file);
146
+
111
147
  GIT_END_DECL
112
148
 
113
149
  #endif
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (C) 2009-2012 the libgit2 contributors
2
+ * Copyright (C) the libgit2 contributors. All rights reserved.
3
3
  *
4
4
  * This file is part of libgit2, distributed under the GNU GPL v2 with
5
5
  * a Linking Exception. For full terms see the included COPYING file.
@@ -30,11 +30,10 @@ GIT_BEGIN_DECL
30
30
  #define GIT_OID_MINPREFIXLEN 4
31
31
 
32
32
  /** Unique identity of any object (commit, tree, blob, tag). */
33
- typedef struct _git_oid git_oid;
34
- struct _git_oid {
33
+ typedef struct git_oid {
35
34
  /** raw binary formatted id */
36
35
  unsigned char id[GIT_OID_RAWSZ];
37
- };
36
+ } git_oid;
38
37
 
39
38
  /**
40
39
  * Parse a hex formatted object id into a git_oid.
@@ -47,6 +46,16 @@ struct _git_oid {
47
46
  */
48
47
  GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str);
49
48
 
49
+ /**
50
+ * Parse a hex formatted null-terminated string into a git_oid.
51
+ *
52
+ * @param out oid structure the result is written into.
53
+ * @param str input hex string; must be at least 4 characters
54
+ * long and null-terminated.
55
+ * @return 0 or an error code
56
+ */
57
+ GIT_EXTERN(int) git_oid_fromstrp(git_oid *out, const char *str);
58
+
50
59
  /**
51
60
  * Parse N characters of a hex formatted object id into a git_oid
52
61
  *
@@ -71,14 +80,14 @@ GIT_EXTERN(void) git_oid_fromraw(git_oid *out, const unsigned char *raw);
71
80
  /**
72
81
  * Format a git_oid into a hex string.
73
82
  *
74
- * @param str output hex string; must be pointing at the start of
83
+ * @param out output hex string; must be pointing at the start of
75
84
  * the hex sequence and have at least the number of bytes
76
85
  * needed for an oid encoded in hex (40 bytes). Only the
77
86
  * oid digits are written; a '\\0' terminator must be added
78
87
  * by the caller if it is required.
79
88
  * @param oid oid structure to format.
80
89
  */
81
- GIT_EXTERN(void) git_oid_fmt(char *str, const git_oid *oid);
90
+ GIT_EXTERN(void) git_oid_fmt(char *out, const git_oid *id);
82
91
 
83
92
  /**
84
93
  * Format a git_oid into a loose-object path string.
@@ -86,14 +95,14 @@ GIT_EXTERN(void) git_oid_fmt(char *str, const git_oid *oid);
86
95
  * The resulting string is "aa/...", where "aa" is the first two
87
96
  * hex digits of the oid and "..." is the remaining 38 digits.
88
97
  *
89
- * @param str output hex string; must be pointing at the start of
98
+ * @param out output hex string; must be pointing at the start of
90
99
  * the hex sequence and have at least the number of bytes
91
100
  * needed for an oid encoded in hex (41 bytes). Only the
92
101
  * oid digits are written; a '\\0' terminator must be added
93
102
  * by the caller if it is required.
94
- * @param oid oid structure to format.
103
+ * @param id oid structure to format.
95
104
  */
96
- GIT_EXTERN(void) git_oid_pathfmt(char *str, const git_oid *oid);
105
+ GIT_EXTERN(void) git_oid_pathfmt(char *out, const git_oid *id);
97
106
 
98
107
  /**
99
108
  * Format a git_oid into a newly allocated c-string.
@@ -102,7 +111,7 @@ GIT_EXTERN(void) git_oid_pathfmt(char *str, const git_oid *oid);
102
111
  * @return the c-string; NULL if memory is exhausted. Caller must
103
112
  * deallocate the string with git__free().
104
113
  */
105
- GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *oid);
114
+ GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *id);
106
115
 
107
116
  /**
108
117
  * Format a git_oid into a buffer as a hex format c-string.
@@ -115,11 +124,11 @@ GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *oid);
115
124
  *
116
125
  * @param out the buffer into which the oid string is output.
117
126
  * @param n the size of the out buffer.
118
- * @param oid the oid structure to format.
127
+ * @param id the oid structure to format.
119
128
  * @return the out buffer pointer, assuming no input parameter
120
129
  * errors, otherwise a pointer to an empty string.
121
130
  */
122
- GIT_EXTERN(char *) git_oid_tostr(char *out, size_t n, const git_oid *oid);
131
+ GIT_EXTERN(char *) git_oid_tostr(char *out, size_t n, const git_oid *id);
123
132
 
124
133
  /**
125
134
  * Copy an oid from one structure to another.
@@ -176,19 +185,19 @@ GIT_EXTERN(int) git_oid_ncmp(const git_oid *a, const git_oid *b, size_t len);
176
185
  /**
177
186
  * Check if an oid equals an hex formatted object id.
178
187
  *
179
- * @param a oid structure.
188
+ * @param id oid structure.
180
189
  * @param str input hex string of an object id.
181
190
  * @return GIT_ENOTOID if str is not a valid hex string,
182
191
  * 0 in case of a match, GIT_ERROR otherwise.
183
192
  */
184
- GIT_EXTERN(int) git_oid_streq(const git_oid *a, const char *str);
193
+ GIT_EXTERN(int) git_oid_streq(const git_oid *id, const char *str);
185
194
 
186
195
  /**
187
196
  * Check is an oid is all zeros.
188
197
  *
189
198
  * @return 1 if all zeros, 0 otherwise.
190
199
  */
191
- GIT_EXTERN(int) git_oid_iszero(const git_oid *a);
200
+ GIT_EXTERN(int) git_oid_iszero(const git_oid *id);
192
201
 
193
202
  /**
194
203
  * OID Shortener object
@@ -230,12 +239,12 @@ GIT_EXTERN(git_oid_shorten *) git_oid_shorten_new(size_t min_length);
230
239
  * GIT_ENOMEM error
231
240
  *
232
241
  * @param os a `git_oid_shorten` instance
233
- * @param text_oid an OID in text form
242
+ * @param text_id an OID in text form
234
243
  * @return the minimal length to uniquely identify all OIDs
235
244
  * added so far to the set; or an error code (<0) if an
236
245
  * error occurs.
237
246
  */
238
- GIT_EXTERN(int) git_oid_shorten_add(git_oid_shorten *os, const char *text_oid);
247
+ GIT_EXTERN(int) git_oid_shorten_add(git_oid_shorten *os, const char *text_id);
239
248
 
240
249
  /**
241
250
  * Free an OID shortener instance