rugged 0.17.0.b7 → 0.18.0.b1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,372 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2013 GitHub, Inc
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+
25
+ #include "rugged.h"
26
+
27
+ extern VALUE rb_cRuggedRepo;
28
+ extern VALUE rb_cRuggedObject;
29
+
30
+ static VALUE rugged_git_note_message(const git_note *note)
31
+ {
32
+ const char *message;
33
+ message = git_note_message(note);
34
+
35
+ /*
36
+ * the note object is just a blob, normally it should be human readable
37
+ * and in unicode like annotated tag's message,
38
+ * since git allows attaching any blob as a note message
39
+ * we're just making sure this works for everyone and it doesn't
40
+ * reencode things it shouldn't.
41
+ *
42
+ * since we don't really ever know the encoding of a blob
43
+ * lets default to the binary encoding (ascii-8bit)
44
+ * If there is a way to tell, we should just pass 0/null here instead
45
+ *
46
+ * we're skipping the use of STR_NEW because we don't want our string to
47
+ * eventually end up converted to Encoding.default_internal because this
48
+ * string could very well be binary data
49
+ */
50
+ return rugged_str_ascii(message, strlen(message));
51
+ }
52
+
53
+ static VALUE rugged_git_note_oid(const git_note* note)
54
+ {
55
+ const git_oid *oid;
56
+ oid = git_note_oid(note);
57
+
58
+ return rugged_create_oid(oid);
59
+ }
60
+
61
+ /*
62
+ * call-seq:
63
+ * obj.notes(notes_ref = 'refs/notes/commits') -> hash
64
+ *
65
+ * Lookup a note for +obj+ from +notes_ref+:
66
+ * - +notes_ref+: (optional): cannonical name of the reference to use, defaults to "refs/notes/commits"
67
+ *
68
+ * Returns a new Hash object.
69
+ *
70
+ * obj.notes #=> {:message=>"note text\n", :oid=>"94eca2de348d5f672faf56b0decafa5937e3235e"}
71
+ */
72
+ static VALUE rb_git_note_lookup(int argc, VALUE *argv, VALUE self)
73
+ {
74
+ git_repository *repo;
75
+ const char *notes_ref = NULL;
76
+ VALUE rb_notes_ref;
77
+ VALUE rb_note_hash;
78
+ VALUE owner;
79
+ git_note *note;
80
+ git_object *object;
81
+ int error;
82
+
83
+ rb_scan_args(argc, argv, "01", &rb_notes_ref);
84
+
85
+ if (!NIL_P(rb_notes_ref)) {
86
+ Check_Type(rb_notes_ref, T_STRING);
87
+ notes_ref = StringValueCStr(rb_notes_ref);
88
+ }
89
+
90
+ Data_Get_Struct(self, git_object, object);
91
+
92
+ owner = rugged_owner(self);
93
+ Data_Get_Struct(owner, git_repository, repo);
94
+
95
+ error = git_note_read(&note, repo, notes_ref, git_object_id(object));
96
+
97
+ if (error == GIT_ENOTFOUND)
98
+ return Qnil;
99
+
100
+ rugged_exception_check(error);
101
+
102
+ rb_note_hash = rb_hash_new();
103
+ rb_hash_aset(rb_note_hash, CSTR2SYM("message"), rugged_git_note_message(note));
104
+ rb_hash_aset(rb_note_hash, CSTR2SYM("oid"), rugged_git_note_oid(note));
105
+
106
+ git_note_free(note);
107
+
108
+ return rb_note_hash;
109
+ }
110
+
111
+ /*
112
+ * call-seq:
113
+ * obj.create_note(data = {}) -> oid
114
+ *
115
+ * Write a new +note+ to +object+, with the given +data+
116
+ * arguments, passed as a +Hash+:
117
+ *
118
+ * - +:message+: the content of the note to add to the object
119
+ * - +:committer+: a hash with the signature for the committer
120
+ * - +:author+: a hash with the signature for the author
121
+ * - +:ref+: (optional): cannonical name of the reference to use, defaults to "refs/notes/commits"
122
+ * - +:force+: (optional): overwrite existing note (disabled by default)
123
+ *
124
+ * When the note is successfully written to disk, its +oid+ will be
125
+ * returned as a hex +String+.
126
+ *
127
+ * author = {:email=>"tanoku@gmail.com", :time=>Time.now, :name=>"Vicent Mart\303\255"}
128
+ *
129
+ * obj.create_note(
130
+ * :author => author,
131
+ * :committer => author,
132
+ * :message => "Hello world\n\n",
133
+ * :ref => 'refs/notes/builds'
134
+ * )
135
+ */
136
+ static VALUE rb_git_note_create(VALUE self, VALUE rb_data)
137
+ {
138
+ VALUE rb_ref, rb_message, rb_force;
139
+ git_repository *repo = NULL;
140
+ const char *notes_ref = NULL;
141
+
142
+ VALUE owner;
143
+
144
+ git_signature *author, *committer;
145
+ git_oid note_oid;
146
+
147
+ git_object *target = NULL;
148
+ int error = 0;
149
+ int force = 0;
150
+
151
+ Check_Type(rb_data, T_HASH);
152
+
153
+ Data_Get_Struct(self, git_object, target);
154
+
155
+ owner = rugged_owner(self);
156
+ Data_Get_Struct(owner, git_repository, repo);
157
+
158
+ rb_ref = rb_hash_aref(rb_data, CSTR2SYM("ref"));
159
+
160
+ rb_force = rb_hash_aref(rb_data, CSTR2SYM("force"));
161
+ if (!NIL_P(rb_force))
162
+ force = rugged_parse_bool(rb_force);
163
+
164
+ if (!NIL_P(rb_ref)) {
165
+ Check_Type(rb_ref, T_STRING);
166
+ notes_ref = StringValueCStr(rb_ref);
167
+ }
168
+
169
+ rb_message = rb_hash_aref(rb_data, CSTR2SYM("message"));
170
+ Check_Type(rb_message, T_STRING);
171
+
172
+ committer = rugged_signature_get(
173
+ rb_hash_aref(rb_data, CSTR2SYM("committer"))
174
+ );
175
+
176
+ author = rugged_signature_get(
177
+ rb_hash_aref(rb_data, CSTR2SYM("author"))
178
+ );
179
+
180
+ error = git_note_create(
181
+ &note_oid,
182
+ repo,
183
+ author,
184
+ committer,
185
+ notes_ref,
186
+ git_object_id(target),
187
+ StringValueCStr(rb_message),
188
+ force);
189
+
190
+
191
+ git_signature_free(author);
192
+ git_signature_free(committer);
193
+
194
+ rugged_exception_check(error);
195
+
196
+ return rugged_create_oid(&note_oid);
197
+ }
198
+
199
+ /*
200
+ * call-seq:
201
+ * obj.remove_note(data = {}) -> boolean
202
+ *
203
+ * Removes a +note+ from +object+, with the given +data+
204
+ * arguments, passed as a +Hash+:
205
+ *
206
+ * - +:committer+: a hash with the signature for the committer
207
+ * - +:author+: a hash with the signature for the author
208
+ * - +:ref+: (optional): cannonical name of the reference to use, defaults to "refs/notes/commits"
209
+ *
210
+ * When the note is successfully removed +true+ will be
211
+ * returned as a +Boolean+.
212
+ *
213
+ * author = {:email=>"tanoku@gmail.com", :time=>Time.now, :name=>"Vicent Mart\303\255"}
214
+ *
215
+ * obj.remove_note(
216
+ * :author => author,
217
+ * :committer => author,
218
+ * :ref => 'refs/notes/builds'
219
+ * )
220
+ */
221
+ static VALUE rb_git_note_remove(VALUE self, VALUE rb_data)
222
+ {
223
+ VALUE rb_ref;
224
+ git_repository *repo = NULL;
225
+ const char *notes_ref = NULL;
226
+
227
+ VALUE owner;
228
+
229
+ git_signature *author, *committer;
230
+
231
+ git_object *target = NULL;
232
+ int error = 0;
233
+
234
+ Check_Type(rb_data, T_HASH);
235
+
236
+ Data_Get_Struct(self, git_object, target);
237
+
238
+ owner = rugged_owner(self);
239
+ Data_Get_Struct(owner, git_repository, repo);
240
+
241
+ rb_ref = rb_hash_aref(rb_data, CSTR2SYM("ref"));
242
+
243
+ if (!NIL_P(rb_ref)) {
244
+ Check_Type(rb_ref, T_STRING);
245
+ notes_ref = StringValueCStr(rb_ref);
246
+ }
247
+
248
+ committer = rugged_signature_get(
249
+ rb_hash_aref(rb_data, CSTR2SYM("committer"))
250
+ );
251
+
252
+ author = rugged_signature_get(
253
+ rb_hash_aref(rb_data, CSTR2SYM("author"))
254
+ );
255
+
256
+ error = git_note_remove(
257
+ repo,
258
+ notes_ref,
259
+ author,
260
+ committer,
261
+ git_object_id(target));
262
+
263
+ git_signature_free(author);
264
+ git_signature_free(committer);
265
+
266
+ if (error == GIT_ENOTFOUND)
267
+ return Qfalse;
268
+
269
+ rugged_exception_check(error);
270
+
271
+ return Qtrue;
272
+ }
273
+
274
+ static int cb_note__each(const git_oid *blob_id, const git_oid *annotated_object_id, void *payload)
275
+ {
276
+ VALUE rb_repo = (VALUE)payload;
277
+
278
+ git_object *annotated_object;
279
+ git_object *note_blob;
280
+
281
+ git_repository *repo;
282
+
283
+ Data_Get_Struct(rb_repo, git_repository, repo);
284
+
285
+ rugged_exception_check(
286
+ git_object_lookup(&annotated_object, repo, annotated_object_id, GIT_OBJ_ANY)
287
+ );
288
+
289
+ rugged_exception_check(
290
+ git_object_lookup(&note_blob, repo, blob_id, GIT_OBJ_BLOB)
291
+ );
292
+
293
+ rb_yield_values(2,
294
+ rugged_object_new(rb_repo, note_blob),
295
+ rugged_object_new(rb_repo, annotated_object)
296
+ );
297
+ return GIT_OK;
298
+ }
299
+
300
+ /*
301
+ * call-seq:
302
+ * repo.each_note(notes_ref = "refs/notes/commits") { |note_blob, annotated_object| block }
303
+ * repo.each_note(notes_ref = "refs/notes/commits") -> an_enumerator
304
+ *
305
+ * Call the given block once for each note_blob/annotated_object pair in +repository+
306
+ * - +notes_ref+: (optional): cannonical name of the reference to use defaults to "refs/notes/commits"
307
+ *
308
+ * If no block is given, an +Enumerator+ is returned.
309
+ *
310
+ * @repo.each_note do |note_blob, annotated_object|
311
+ * puts "#{note_blob.oid} => #{annotated_object.oid}"
312
+ * end
313
+ */
314
+ static VALUE rb_git_note_each(int argc, VALUE *argv, VALUE self)
315
+ {
316
+ git_repository *repo;
317
+ const char *notes_ref = NULL;
318
+ int error;
319
+
320
+ VALUE rb_notes_ref;
321
+
322
+ rb_scan_args(argc, argv, "01", &rb_notes_ref);
323
+
324
+ if (!rb_block_given_p()) {
325
+ return rb_funcall(self, rb_intern("to_enum"), 3, CSTR2SYM("each_note"), self, rb_notes_ref);
326
+ }
327
+
328
+ if (!NIL_P(rb_notes_ref)) {
329
+ Check_Type(rb_notes_ref, T_STRING);
330
+ notes_ref = StringValueCStr(rb_notes_ref);
331
+ }
332
+
333
+ Data_Get_Struct(self, git_repository, repo);
334
+
335
+ error = git_note_foreach(repo, notes_ref, &cb_note__each, (void *)self);
336
+ rugged_exception_check(error);
337
+ return Qnil;
338
+ }
339
+
340
+ /*
341
+ * call-seq:
342
+ * repo.notes_default_ref() -> string
343
+ *
344
+ * Get the default notes reference for a +repository+:
345
+ *
346
+ * Returns a new String object.
347
+ *
348
+ * repo.default_notes_ref #=> "refs/notes/commits"
349
+ */
350
+ static VALUE rb_git_note_default_ref_GET(VALUE self)
351
+ {
352
+ git_repository *repo = NULL;
353
+ const char * ref_name;
354
+
355
+ Data_Get_Struct(self, git_repository, repo);
356
+
357
+ rugged_exception_check(
358
+ git_note_default_ref(&ref_name, repo)
359
+ );
360
+
361
+ return rugged_str_new2(ref_name, NULL);
362
+ }
363
+
364
+ void Init_rugged_notes()
365
+ {
366
+ rb_define_method(rb_cRuggedObject, "notes", rb_git_note_lookup, -1);
367
+ rb_define_method(rb_cRuggedObject, "create_note", rb_git_note_create, 1);
368
+ rb_define_method(rb_cRuggedObject, "remove_note", rb_git_note_remove, 1);
369
+
370
+ rb_define_method(rb_cRuggedRepo, "each_note", rb_git_note_each, -1);
371
+ rb_define_method(rb_cRuggedRepo, "default_notes_ref", rb_git_note_default_ref_GET, 0);
372
+ }
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * The MIT License
3
3
  *
4
- * Copyright (c) 2011 GitHub, Inc
4
+ * Copyright (c) 2013 GitHub, Inc
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -85,35 +85,65 @@ VALUE rugged_otype_new(git_otype t)
85
85
  }
86
86
  }
87
87
 
88
+ void rugged_oid_get(git_oid *oid, git_repository *repo, VALUE p)
89
+ {
90
+ git_object *object;
91
+ int error;
92
+
93
+ if (rb_obj_is_kind_of(p, rb_cRuggedObject)) {
94
+ Data_Get_Struct(p, git_object, object);
95
+ git_oid_cpy(oid, git_object_id(object));
96
+ } else {
97
+ Check_Type(p, T_STRING);
98
+
99
+ /* Fast path: see if the 40-char string is an OID */
100
+ if (RSTRING_LEN(p) == 40 &&
101
+ git_oid_fromstr(oid, RSTRING_PTR(p)) == 0)
102
+ return;
103
+
104
+ error = git_revparse_single(&object, repo, StringValueCStr(p));
105
+ rugged_exception_check(error);
106
+
107
+ git_oid_cpy(oid, git_object_id(object));
108
+ git_object_free(object);
109
+ }
110
+ }
88
111
 
89
- git_object *rugged_object_load(git_repository *repo, VALUE object_value, git_otype type)
112
+ git_object *rugged_object_get(git_repository *repo, VALUE object_value, git_otype type)
90
113
  {
91
114
  git_object *object = NULL;
92
115
 
93
- if (TYPE(object_value) == T_STRING) {
94
- git_oid oid;
95
- int oid_length = (int)RSTRING_LEN(object_value);
116
+ if (rb_obj_is_kind_of(object_value, rb_cRuggedObject)) {
117
+ git_object *owned_obj = NULL;
118
+ Data_Get_Struct(object_value, git_object, owned_obj);
119
+ git_object_dup(&object, owned_obj);
120
+ } else {
96
121
  int error;
97
122
 
98
- error = git_oid_fromstrn(&oid, RSTRING_PTR(object_value), oid_length);
99
- rugged_exception_check(error);
123
+ Check_Type(object_value, T_STRING);
100
124
 
101
- if (oid_length < GIT_OID_HEXSZ)
102
- error = git_object_lookup_prefix(&object, repo, &oid, oid_length, type);
103
- else
104
- error = git_object_lookup(&object, repo, &oid, type);
105
- rugged_exception_check(error);
125
+ /* Fast path: if we have a 40-char string, just perform the lookup directly */
126
+ if (RSTRING_LEN(object_value) == 40) {
127
+ git_oid oid;
106
128
 
107
- } else if (rb_obj_is_kind_of(object_value, rb_cRuggedObject)) {
108
- Data_Get_Struct(object_value, git_object, object);
129
+ /* If it's not an OID, we can still try the revparse */
130
+ if (git_oid_fromstr(&oid, RSTRING_PTR(object_value)) == 0) {
131
+ error = git_object_lookup(&object, repo, &oid, type);
132
+ rugged_exception_check(error);
133
+ return object;
134
+ }
135
+ }
109
136
 
110
- if (type != GIT_OBJ_ANY && git_object_type(object) != type)
111
- rb_raise(rb_eTypeError, "Object is not of the required type");
112
- } else {
113
- rb_raise(rb_eTypeError, "Invalid GIT object; an object reference must be a SHA1 id or an object itself");
137
+ /* Otherwise, assume the string is a revlist and try to parse it */
138
+ error = git_revparse_single(&object, repo, StringValueCStr(object_value));
139
+ rugged_exception_check(error);
114
140
  }
115
141
 
116
142
  assert(object);
143
+
144
+ if (type != GIT_OBJ_ANY && git_object_type(object) != type)
145
+ rb_raise(rb_eArgError, "Object is not of the required type");
146
+
117
147
  return object;
118
148
  }
119
149
 
@@ -190,8 +220,7 @@ VALUE rb_git_object_lookup(VALUE klass, VALUE rb_repo, VALUE rb_hex)
190
220
  Check_Type(rb_hex, T_STRING);
191
221
  oid_length = (int)RSTRING_LEN(rb_hex);
192
222
 
193
- if (!rb_obj_is_instance_of(rb_repo, rb_cRuggedRepo))
194
- rb_raise(rb_eTypeError, "Expecting a Rugged Repository");
223
+ rugged_check_repo(rb_repo);
195
224
 
196
225
  if (oid_length > GIT_OID_HEXSZ)
197
226
  rb_raise(rb_eTypeError, "The given OID is too long");
@@ -222,8 +251,7 @@ static VALUE rugged_object_rev_parse(VALUE klass, VALUE rb_repo, VALUE rb_spec,
222
251
  Check_Type(rb_spec, T_STRING);
223
252
  spec = RSTRING_PTR(rb_spec);
224
253
 
225
- if (!rb_obj_is_instance_of(rb_repo, rb_cRuggedRepo))
226
- rb_raise(rb_eTypeError, "Expecting a Rugged Repository");
254
+ rugged_check_repo(rb_repo);
227
255
 
228
256
  Data_Get_Struct(rb_repo, git_repository, repo);
229
257