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.
@@ -45,6 +45,10 @@ struct git_odb {
45
45
  */
46
46
  int git_odb__hashobj(git_oid *id, git_rawobj *obj);
47
47
 
48
+ /*
49
+ * Format the object header such as it would appear in the on-disk object
50
+ */
51
+ int git_odb__format_object_header(char *hdr, size_t n, size_t obj_len, git_otype obj_type);
48
52
  /*
49
53
  * Hash an open file descriptor.
50
54
  * This is a performance call when the contents of a fd need to be hashed,
@@ -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.
@@ -678,7 +678,7 @@ static int loose_backend__exists(git_odb_backend *backend, const git_oid *oid)
678
678
 
679
679
  struct foreach_state {
680
680
  size_t dir_len;
681
- int (*cb)(git_oid *oid, void *data);
681
+ git_odb_foreach_cb cb;
682
682
  void *data;
683
683
  int cb_error;
684
684
  };
@@ -734,7 +734,7 @@ static int foreach_cb(void *_state, git_buf *path)
734
734
  return git_path_direach(path, foreach_object_dir_cb, state);
735
735
  }
736
736
 
737
- static int loose_backend__foreach(git_odb_backend *_backend, int (*cb)(git_oid *oid, void *data), void *data)
737
+ static int loose_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb cb, void *data)
738
738
  {
739
739
  char *objects_dir;
740
740
  int error;
@@ -870,7 +870,6 @@ static int loose_backend__write(git_oid *oid, git_odb_backend *_backend, const v
870
870
 
871
871
  if (git_buf_joinpath(&final_path, backend->objects_dir, "tmp_object") < 0 ||
872
872
  git_filebuf_open(&fbuf, final_path.ptr,
873
- GIT_FILEBUF_HASH_CONTENTS |
874
873
  GIT_FILEBUF_TEMPORARY |
875
874
  (backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT)) < 0)
876
875
  {
@@ -880,7 +879,6 @@ static int loose_backend__write(git_oid *oid, git_odb_backend *_backend, const v
880
879
 
881
880
  git_filebuf_write(&fbuf, header, header_len);
882
881
  git_filebuf_write(&fbuf, data, len);
883
- git_filebuf_hash(oid, &fbuf);
884
882
 
885
883
  if (object_file_name(&final_path, backend->objects_dir, oid) < 0 ||
886
884
  git_futils_mkpath2file(final_path.ptr, GIT_OBJECT_DIR_MODE) < 0 ||
@@ -915,6 +913,7 @@ int git_odb_backend_loose(
915
913
  backend = git__calloc(1, sizeof(loose_backend));
916
914
  GITERR_CHECK_ALLOC(backend);
917
915
 
916
+ backend->parent.version = GIT_ODB_BACKEND_VERSION;
918
917
  backend->objects_dir = git__strdup(objects_dir);
919
918
  GITERR_CHECK_ALLOC(backend->objects_dir);
920
919
 
@@ -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.
@@ -26,6 +26,11 @@ struct pack_backend {
26
26
  char *pack_folder;
27
27
  };
28
28
 
29
+ struct pack_writepack {
30
+ struct git_odb_writepack parent;
31
+ git_indexer_stream *indexer_stream;
32
+ };
33
+
29
34
  /**
30
35
  * The wonderful tale of a Packed Object lookup query
31
36
  * ===================================================
@@ -127,13 +132,9 @@ struct pack_backend {
127
132
  *
128
133
  ***********************************************************/
129
134
 
130
- static void pack_window_free_all(struct pack_backend *backend, struct git_pack_file *p);
131
- static int pack_window_contains(git_mwindow *win, off_t offset);
132
-
133
135
  static int packfile_sort__cb(const void *a_, const void *b_);
134
136
 
135
137
  static int packfile_load__cb(void *_data, git_buf *path);
136
- static int packfile_refresh_all(struct pack_backend *backend);
137
138
 
138
139
  static int pack_entry_find(struct git_pack_entry *e,
139
140
  struct pack_backend *backend, const git_oid *oid);
@@ -158,23 +159,6 @@ static int pack_entry_find_prefix(
158
159
  *
159
160
  ***********************************************************/
160
161
 
161
- GIT_INLINE(void) pack_window_free_all(struct pack_backend *backend, struct git_pack_file *p)
162
- {
163
- GIT_UNUSED(backend);
164
- git_mwindow_free_all(&p->mwf);
165
- }
166
-
167
- GIT_INLINE(int) pack_window_contains(git_mwindow *win, off_t offset)
168
- {
169
- /* We must promise at least 20 bytes (one hash) after the
170
- * offset is available from this window, otherwise the offset
171
- * is not actually in this window and a different window (which
172
- * has that one hash excess) must be used. This is to support
173
- * the object header and delta base parsing routines below.
174
- */
175
- return git_mwindow_contains(win, offset + 20);
176
- }
177
-
178
162
  static int packfile_sort__cb(const void *a_, const void *b_)
179
163
  {
180
164
  const struct git_pack_file *a = a_;
@@ -211,7 +195,7 @@ static int packfile_load__cb(void *_data, git_buf *path)
211
195
  struct pack_backend *backend = (struct pack_backend *)_data;
212
196
  struct git_pack_file *pack;
213
197
  int error;
214
- unsigned int i;
198
+ size_t i;
215
199
 
216
200
  if (git__suffixcmp(path->ptr, ".idx") != 0)
217
201
  return 0; /* not an index */
@@ -232,40 +216,13 @@ static int packfile_load__cb(void *_data, git_buf *path)
232
216
  return git_vector_insert(&backend->packs, pack);
233
217
  }
234
218
 
235
- static int packfile_refresh_all(struct pack_backend *backend)
236
- {
237
- int error;
238
- struct stat st;
239
- git_buf path = GIT_BUF_INIT;
240
-
241
- if (backend->pack_folder == NULL)
242
- return 0;
243
-
244
- if (p_stat(backend->pack_folder, &st) < 0 || !S_ISDIR(st.st_mode))
245
- return git_odb__error_notfound("failed to refresh packfiles", NULL);
246
-
247
- git_buf_sets(&path, backend->pack_folder);
248
-
249
- /* reload all packs */
250
- error = git_path_direach(&path, packfile_load__cb, (void *)backend);
251
-
252
- git_buf_free(&path);
253
-
254
- if (error < 0)
255
- return error;
256
-
257
- git_vector_sort(&backend->packs);
258
-
259
- return 0;
260
- }
261
-
262
219
  static int pack_entry_find_inner(
263
220
  struct git_pack_entry *e,
264
221
  struct pack_backend *backend,
265
222
  const git_oid *oid,
266
223
  struct git_pack_file *last_found)
267
224
  {
268
- unsigned int i;
225
+ size_t i;
269
226
 
270
227
  if (last_found &&
271
228
  git_pack_entry_find(e, last_found, oid, GIT_OID_HEXSZ) == 0)
@@ -289,17 +246,12 @@ static int pack_entry_find_inner(
289
246
 
290
247
  static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backend, const git_oid *oid)
291
248
  {
292
- int error;
293
249
  struct git_pack_file *last_found = backend->last_found;
294
250
 
295
251
  if (backend->last_found &&
296
252
  git_pack_entry_find(e, backend->last_found, oid, GIT_OID_HEXSZ) == 0)
297
253
  return 0;
298
254
 
299
- if (!pack_entry_find_inner(e, backend, oid, last_found))
300
- return 0;
301
- if ((error = packfile_refresh_all(backend)) < 0)
302
- return error;
303
255
  if (!pack_entry_find_inner(e, backend, oid, last_found))
304
256
  return 0;
305
257
 
@@ -314,7 +266,7 @@ static unsigned pack_entry_find_prefix_inner(
314
266
  struct git_pack_file *last_found)
315
267
  {
316
268
  int error;
317
- unsigned int i;
269
+ size_t i;
318
270
  unsigned found = 0;
319
271
 
320
272
  if (last_found) {
@@ -351,17 +303,9 @@ static int pack_entry_find_prefix(
351
303
  const git_oid *short_oid,
352
304
  size_t len)
353
305
  {
354
- unsigned found = 0;
355
- int error;
356
306
  struct git_pack_file *last_found = backend->last_found;
307
+ unsigned int found = pack_entry_find_prefix_inner(e, backend, short_oid, len, last_found);
357
308
 
358
- if ((found = pack_entry_find_prefix_inner(e, backend, short_oid, len, last_found)) > 0)
359
- goto cleanup;
360
- if ((error = packfile_refresh_all(backend)) < 0)
361
- return error;
362
- found = pack_entry_find_prefix_inner(e, backend, short_oid, len, last_found);
363
-
364
- cleanup:
365
309
  if (!found)
366
310
  return git_odb__error_notfound("no matching pack entry for prefix", short_oid);
367
311
  else if (found > 1)
@@ -378,20 +322,47 @@ cleanup:
378
322
  * Implement the git_odb_backend API calls
379
323
  *
380
324
  ***********************************************************/
325
+ static int pack_backend__refresh(git_odb_backend *_backend)
326
+ {
327
+ struct pack_backend *backend = (struct pack_backend *)_backend;
381
328
 
382
- /*
383
- int pack_backend__read_header(git_rawobj *obj, git_odb_backend *backend, const git_oid *oid)
329
+ int error;
330
+ struct stat st;
331
+ git_buf path = GIT_BUF_INIT;
332
+
333
+ if (backend->pack_folder == NULL)
334
+ return 0;
335
+
336
+ if (p_stat(backend->pack_folder, &st) < 0 || !S_ISDIR(st.st_mode))
337
+ return git_odb__error_notfound("failed to refresh packfiles", NULL);
338
+
339
+ git_buf_sets(&path, backend->pack_folder);
340
+
341
+ /* reload all packs */
342
+ error = git_path_direach(&path, packfile_load__cb, (void *)backend);
343
+
344
+ git_buf_free(&path);
345
+
346
+ if (error < 0)
347
+ return error;
348
+
349
+ git_vector_sort(&backend->packs);
350
+ return 0;
351
+ }
352
+
353
+
354
+ static int pack_backend__read_header(size_t *len_p, git_otype *type_p, struct git_odb_backend *backend, const git_oid *oid)
384
355
  {
385
- pack_location location;
356
+ struct git_pack_entry e;
357
+ int error;
386
358
 
387
- assert(obj && backend && oid);
359
+ assert(len_p && type_p && backend && oid);
388
360
 
389
- if (locate_packfile(&location, (struct pack_backend *)backend, oid) < 0)
390
- return GIT_ENOTFOUND;
361
+ if ((error = pack_entry_find(&e, (struct pack_backend *)backend, oid)) < 0)
362
+ return error;
391
363
 
392
- return read_header_packed(obj, &location);
364
+ return git_packfile_resolve_header(len_p, type_p, e.p, e.offset);
393
365
  }
394
- */
395
366
 
396
367
  static int pack_backend__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid)
397
368
  {
@@ -453,7 +424,7 @@ static int pack_backend__exists(git_odb_backend *backend, const git_oid *oid)
453
424
  return pack_entry_find(&e, (struct pack_backend *)backend, oid) == 0;
454
425
  }
455
426
 
456
- static int pack_backend__foreach(git_odb_backend *_backend, int (*cb)(git_oid *oid, void *data), void *data)
427
+ static int pack_backend__foreach(git_odb_backend *_backend, git_odb_foreach_cb cb, void *data)
457
428
  {
458
429
  int error;
459
430
  struct git_pack_file *p;
@@ -464,7 +435,7 @@ static int pack_backend__foreach(git_odb_backend *_backend, int (*cb)(git_oid *o
464
435
  backend = (struct pack_backend *)_backend;
465
436
 
466
437
  /* Make sure we know about the packfiles */
467
- if ((error = packfile_refresh_all(backend)) < 0)
438
+ if ((error = pack_backend__refresh(_backend)) < 0)
468
439
  return error;
469
440
 
470
441
  git_vector_foreach(&backend->packs, i, p) {
@@ -475,10 +446,71 @@ static int pack_backend__foreach(git_odb_backend *_backend, int (*cb)(git_oid *o
475
446
  return 0;
476
447
  }
477
448
 
449
+ static int pack_backend__writepack_add(struct git_odb_writepack *_writepack, const void *data, size_t size, git_transfer_progress *stats)
450
+ {
451
+ struct pack_writepack *writepack = (struct pack_writepack *)_writepack;
452
+
453
+ assert(writepack);
454
+
455
+ return git_indexer_stream_add(writepack->indexer_stream, data, size, stats);
456
+ }
457
+
458
+ static int pack_backend__writepack_commit(struct git_odb_writepack *_writepack, git_transfer_progress *stats)
459
+ {
460
+ struct pack_writepack *writepack = (struct pack_writepack *)_writepack;
461
+
462
+ assert(writepack);
463
+
464
+ return git_indexer_stream_finalize(writepack->indexer_stream, stats);
465
+ }
466
+
467
+ static void pack_backend__writepack_free(struct git_odb_writepack *_writepack)
468
+ {
469
+ struct pack_writepack *writepack = (struct pack_writepack *)_writepack;
470
+
471
+ assert(writepack);
472
+
473
+ git_indexer_stream_free(writepack->indexer_stream);
474
+ git__free(writepack);
475
+ }
476
+
477
+ static int pack_backend__writepack(struct git_odb_writepack **out,
478
+ git_odb_backend *_backend,
479
+ git_transfer_progress_callback progress_cb,
480
+ void *progress_payload)
481
+ {
482
+ struct pack_backend *backend;
483
+ struct pack_writepack *writepack;
484
+
485
+ assert(out && _backend);
486
+
487
+ *out = NULL;
488
+
489
+ backend = (struct pack_backend *)_backend;
490
+
491
+ writepack = git__calloc(1, sizeof(struct pack_writepack));
492
+ GITERR_CHECK_ALLOC(writepack);
493
+
494
+ if (git_indexer_stream_new(&writepack->indexer_stream,
495
+ backend->pack_folder, progress_cb, progress_payload) < 0) {
496
+ git__free(writepack);
497
+ return -1;
498
+ }
499
+
500
+ writepack->parent.backend = _backend;
501
+ writepack->parent.add = pack_backend__writepack_add;
502
+ writepack->parent.commit = pack_backend__writepack_commit;
503
+ writepack->parent.free = pack_backend__writepack_free;
504
+
505
+ *out = (git_odb_writepack *)writepack;
506
+
507
+ return 0;
508
+ }
509
+
478
510
  static void pack_backend__free(git_odb_backend *_backend)
479
511
  {
480
512
  struct pack_backend *backend;
481
- unsigned int i;
513
+ size_t i;
482
514
 
483
515
  assert(_backend);
484
516
 
@@ -486,7 +518,7 @@ static void pack_backend__free(git_odb_backend *_backend)
486
518
 
487
519
  for (i = 0; i < backend->packs.length; ++i) {
488
520
  struct git_pack_file *p = git_vector_get(&backend->packs, i);
489
- packfile_free(p);
521
+ git_packfile_free(p);
490
522
  }
491
523
 
492
524
  git_vector_free(&backend->packs);
@@ -504,6 +536,7 @@ int git_odb_backend_one_pack(git_odb_backend **backend_out, const char *idx)
504
536
 
505
537
  backend = git__calloc(1, sizeof(struct pack_backend));
506
538
  GITERR_CHECK_ALLOC(backend);
539
+ backend->parent.version = GIT_ODB_BACKEND_VERSION;
507
540
 
508
541
  if (git_vector_init(&backend->packs, 1, NULL) < 0)
509
542
  goto on_error;
@@ -513,8 +546,9 @@ int git_odb_backend_one_pack(git_odb_backend **backend_out, const char *idx)
513
546
 
514
547
  backend->parent.read = &pack_backend__read;
515
548
  backend->parent.read_prefix = &pack_backend__read_prefix;
516
- backend->parent.read_header = NULL;
549
+ backend->parent.read_header = &pack_backend__read_header;
517
550
  backend->parent.exists = &pack_backend__exists;
551
+ backend->parent.refresh = &pack_backend__refresh;
518
552
  backend->parent.foreach = &pack_backend__foreach;
519
553
  backend->parent.free = &pack_backend__free;
520
554
 
@@ -536,6 +570,7 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
536
570
 
537
571
  backend = git__calloc(1, sizeof(struct pack_backend));
538
572
  GITERR_CHECK_ALLOC(backend);
573
+ backend->parent.version = GIT_ODB_BACKEND_VERSION;
539
574
 
540
575
  if (git_vector_init(&backend->packs, 8, packfile_sort__cb) < 0 ||
541
576
  git_buf_joinpath(&path, objects_dir, "pack") < 0)
@@ -545,14 +580,21 @@ int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir)
545
580
  }
546
581
 
547
582
  if (git_path_isdir(git_buf_cstr(&path)) == true) {
583
+ int error;
584
+
548
585
  backend->pack_folder = git_buf_detach(&path);
586
+ error = pack_backend__refresh((git_odb_backend *)backend);
587
+ if (error < 0)
588
+ return error;
549
589
  }
550
590
 
551
591
  backend->parent.read = &pack_backend__read;
552
592
  backend->parent.read_prefix = &pack_backend__read_prefix;
553
- backend->parent.read_header = NULL;
593
+ backend->parent.read_header = &pack_backend__read_header;
554
594
  backend->parent.exists = &pack_backend__exists;
595
+ backend->parent.refresh = &pack_backend__refresh;
555
596
  backend->parent.foreach = &pack_backend__foreach;
597
+ backend->parent.writepack = &pack_backend__writepack;
556
598
  backend->parent.free = &pack_backend__free;
557
599
 
558
600
  *backend_out = (git_odb_backend *)backend;
@@ -0,0 +1,65 @@
1
+ /*
2
+ * Copyright (C) 2012 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_offmap_h__
8
+ #define INCLUDE_offmap_h__
9
+
10
+ #include "common.h"
11
+ #include "git2/types.h"
12
+
13
+ #define kmalloc git__malloc
14
+ #define kcalloc git__calloc
15
+ #define krealloc git__realloc
16
+ #define kfree git__free
17
+ #include "khash.h"
18
+
19
+ __KHASH_TYPE(off, git_off_t, void *);
20
+ typedef khash_t(off) git_offmap;
21
+
22
+ #define GIT__USE_OFFMAP \
23
+ __KHASH_IMPL(off, static kh_inline, git_off_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal);
24
+
25
+ #define git_offmap_alloc() kh_init(off)
26
+ #define git_offmap_free(h) kh_destroy(off, h), h = NULL
27
+ #define git_offmap_clear(h) kh_clear(off, h)
28
+
29
+ #define git_offmap_num_entries(h) kh_size(h)
30
+
31
+ #define git_offmap_lookup_index(h, k) kh_get(off, h, k)
32
+ #define git_offmap_valid_index(h, idx) (idx != kh_end(h))
33
+
34
+ #define git_offmap_exists(h, k) (kh_get(off, h, k) != kh_end(h))
35
+
36
+ #define git_offmap_value_at(h, idx) kh_val(h, idx)
37
+ #define git_offmap_set_value_at(h, idx, v) kh_val(h, idx) = v
38
+ #define git_offmap_delete_at(h, idx) kh_del(off, h, idx)
39
+
40
+ #define git_offmap_insert(h, key, val, rval) do { \
41
+ khiter_t __pos = kh_put(off, h, key, &rval); \
42
+ if (rval >= 0) { \
43
+ if (rval == 0) kh_key(h, __pos) = key; \
44
+ kh_val(h, __pos) = val; \
45
+ } } while (0)
46
+
47
+ #define git_offmap_insert2(h, key, val, oldv, rval) do { \
48
+ khiter_t __pos = kh_put(off, h, key, &rval); \
49
+ if (rval >= 0) { \
50
+ if (rval == 0) { \
51
+ oldv = kh_val(h, __pos); \
52
+ kh_key(h, __pos) = key; \
53
+ } else { oldv = NULL; } \
54
+ kh_val(h, __pos) = val; \
55
+ } } while (0)
56
+
57
+ #define git_offmap_delete(h, key) do { \
58
+ khiter_t __pos = git_offmap_lookup_index(h, key); \
59
+ if (git_offmap_valid_index(h, __pos)) \
60
+ git_offmap_delete_at(h, __pos); } while (0)
61
+
62
+ #define git_offmap_foreach kh_foreach
63
+ #define git_offmap_foreach_value kh_foreach_value
64
+
65
+ #endif