rugged 0.18.0.gh.de28323 → 0.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (283) hide show
  1. data/README.md +9 -4
  2. data/Rakefile +1 -1
  3. data/ext/rugged/extconf.rb +10 -0
  4. data/ext/rugged/rugged.c +153 -86
  5. data/ext/rugged/rugged.h +44 -33
  6. data/ext/rugged/rugged_blob.c +288 -60
  7. data/ext/rugged/rugged_branch.c +82 -57
  8. data/ext/rugged/rugged_commit.c +83 -86
  9. data/ext/rugged/rugged_config.c +68 -68
  10. data/ext/rugged/rugged_diff.c +509 -0
  11. data/ext/rugged/rugged_diff_delta.c +94 -0
  12. data/ext/rugged/rugged_diff_hunk.c +100 -0
  13. data/ext/rugged/rugged_diff_line.c +79 -0
  14. data/ext/rugged/rugged_diff_patch.c +169 -0
  15. data/ext/rugged/rugged_index.c +539 -8
  16. data/ext/rugged/rugged_note.c +74 -80
  17. data/ext/rugged/rugged_object.c +63 -8
  18. data/ext/rugged/rugged_reference.c +231 -145
  19. data/ext/rugged/rugged_remote.c +509 -53
  20. data/ext/rugged/rugged_repo.c +572 -236
  21. data/ext/rugged/rugged_revwalk.c +59 -36
  22. data/ext/rugged/rugged_settings.c +7 -9
  23. data/ext/rugged/rugged_signature.c +7 -11
  24. data/ext/rugged/rugged_tag.c +93 -39
  25. data/ext/rugged/rugged_tree.c +321 -58
  26. data/lib/rugged.rb +1 -0
  27. data/lib/rugged/commit.rb +16 -1
  28. data/lib/rugged/console.rb +9 -0
  29. data/lib/rugged/diff.rb +19 -0
  30. data/lib/rugged/diff/delta.rb +54 -0
  31. data/lib/rugged/diff/hunk.rb +23 -0
  32. data/lib/rugged/diff/line.rb +29 -0
  33. data/lib/rugged/diff/patch.rb +28 -0
  34. data/lib/rugged/repository.rb +36 -39
  35. data/lib/rugged/version.rb +1 -1
  36. data/test/blob_test.rb +308 -1
  37. data/test/branch_test.rb +7 -0
  38. data/test/commit_test.rb +7 -10
  39. data/test/coverage/cover.rb +9 -1
  40. data/test/diff_test.rb +777 -0
  41. data/test/fixtures/archive.tar.gz +0 -0
  42. data/test/fixtures/attr/attr0 +1 -0
  43. data/test/fixtures/attr/attr1 +29 -0
  44. data/test/fixtures/attr/attr2 +21 -0
  45. data/test/fixtures/attr/attr3 +4 -0
  46. data/test/fixtures/attr/binfile +1 -0
  47. data/test/fixtures/attr/dir/file +0 -0
  48. data/test/fixtures/attr/file +1 -0
  49. data/test/fixtures/attr/gitattributes +29 -0
  50. data/test/fixtures/attr/gitignore +2 -0
  51. data/test/fixtures/attr/ign +1 -0
  52. data/test/fixtures/attr/macro_bad +1 -0
  53. data/test/fixtures/attr/macro_test +1 -0
  54. data/test/fixtures/attr/root_test1 +1 -0
  55. data/test/fixtures/attr/root_test2 +6 -0
  56. data/test/fixtures/attr/root_test3 +19 -0
  57. data/test/fixtures/attr/root_test4.txt +14 -0
  58. data/test/fixtures/attr/sub/abc +37 -0
  59. data/test/fixtures/attr/sub/dir/file +0 -0
  60. data/test/fixtures/attr/sub/file +1 -0
  61. data/test/fixtures/attr/sub/ign/file +1 -0
  62. data/test/fixtures/attr/sub/ign/sub/file +1 -0
  63. data/test/fixtures/attr/sub/sub/dir +0 -0
  64. data/test/fixtures/attr/sub/sub/file +1 -0
  65. data/test/fixtures/attr/sub/sub/subsub.txt +1 -0
  66. data/test/fixtures/attr/sub/subdir_test1 +2 -0
  67. data/test/fixtures/attr/sub/subdir_test2.txt +1 -0
  68. data/test/fixtures/diff/another.txt +38 -0
  69. data/test/fixtures/diff/readme.txt +36 -0
  70. data/test/fixtures/mergedrepo/conflicts-one.txt +5 -0
  71. data/test/fixtures/mergedrepo/conflicts-two.txt +5 -0
  72. data/test/fixtures/mergedrepo/one.txt +10 -0
  73. data/test/fixtures/mergedrepo/two.txt +12 -0
  74. data/test/fixtures/status/current_file +1 -0
  75. data/test/fixtures/status/ignored_file +1 -0
  76. data/test/fixtures/status/modified_file +2 -0
  77. data/test/fixtures/status/new_file +1 -0
  78. data/test/fixtures/status/staged_changes +2 -0
  79. data/test/fixtures/status/staged_changes_modified_file +3 -0
  80. data/test/fixtures/status/staged_delete_modified_file +1 -0
  81. data/test/fixtures/status/staged_new_file +1 -0
  82. data/test/fixtures/status/staged_new_file_modified_file +2 -0
  83. data/test/fixtures/status/subdir.txt +2 -0
  84. data/test/fixtures/status/subdir/current_file +1 -0
  85. data/test/fixtures/status/subdir/modified_file +2 -0
  86. data/test/fixtures/status/subdir/new_file +1 -0
  87. data/test/fixtures/status//350/277/231 +1 -0
  88. data/test/fixtures/testrepo.git/config +5 -0
  89. data/test/fixtures/testrepo.git/objects/77/71329dfa3002caf8c61a0ceb62a31d09023f37 +0 -0
  90. data/test/fixtures/text_file.md +464 -0
  91. data/test/fixtures/unsymlinked.git/HEAD +1 -0
  92. data/test/fixtures/unsymlinked.git/config +6 -0
  93. data/test/fixtures/unsymlinked.git/description +1 -0
  94. data/test/fixtures/unsymlinked.git/info/exclude +2 -0
  95. data/test/fixtures/unsymlinked.git/objects/08/8b64704e0d6b8bd061dea879418cb5442a3fbf +0 -0
  96. data/test/fixtures/unsymlinked.git/objects/13/a5e939bca25940c069fd2169d993dba328e30b +0 -0
  97. data/test/fixtures/unsymlinked.git/objects/19/bf568e59e3a0b363cafb4106226e62d4a4c41c +0 -0
  98. data/test/fixtures/unsymlinked.git/objects/58/1fadd35b4cf320d102a152f918729011604773 +0 -0
  99. data/test/fixtures/unsymlinked.git/objects/5c/87b6791e8b13da658a14d1ef7e09b5dc3bac8c +0 -0
  100. data/test/fixtures/unsymlinked.git/objects/6f/e5f5398af85fb3de8a6aba0339b6d3bfa26a27 +0 -0
  101. data/test/fixtures/unsymlinked.git/objects/7f/ccd75616ec188b8f1b23d67506a334cc34a49d +0 -0
  102. data/test/fixtures/unsymlinked.git/objects/80/6999882bf91d24241e4077906b9017605eb1f3 +0 -0
  103. data/test/fixtures/unsymlinked.git/objects/83/7d176303c5005505ec1e4a30231c40930c0230 +0 -0
  104. data/test/fixtures/unsymlinked.git/objects/a8/595ccca04f40818ae0155c8f9c77a230e597b6 +2 -0
  105. data/test/fixtures/unsymlinked.git/objects/cf/8f1cf5cce859c438d6cc067284cb5e161206e7 +0 -0
  106. data/test/fixtures/unsymlinked.git/objects/d5/278d05c8607ec420bfee4cf219fbc0eeebfd6a +0 -0
  107. data/test/fixtures/unsymlinked.git/objects/f4/e16fb76536591a41454194058d048d8e4dd2e9 +0 -0
  108. data/test/fixtures/unsymlinked.git/objects/f9/e65619d93fdf2673882e0a261c5e93b1a84006 +0 -0
  109. data/test/fixtures/unsymlinked.git/refs/heads/exe-file +1 -0
  110. data/test/fixtures/unsymlinked.git/refs/heads/master +1 -0
  111. data/test/fixtures/unsymlinked.git/refs/heads/reg-file +1 -0
  112. data/test/index_test.rb +120 -0
  113. data/test/reference_test.rb +38 -3
  114. data/test/remote_test.rb +224 -3
  115. data/test/repo_reset_test.rb +2 -0
  116. data/test/repo_test.rb +147 -10
  117. data/test/test_helper.rb +5 -2
  118. data/vendor/libgit2/include/git2/attr.h +3 -3
  119. data/vendor/libgit2/include/git2/blob.h +11 -17
  120. data/vendor/libgit2/include/git2/branch.h +3 -2
  121. data/vendor/libgit2/include/git2/checkout.h +7 -0
  122. data/vendor/libgit2/include/git2/clone.h +3 -0
  123. data/vendor/libgit2/include/git2/commit.h +61 -66
  124. data/vendor/libgit2/include/git2/common.h +73 -42
  125. data/vendor/libgit2/include/git2/config.h +57 -71
  126. data/vendor/libgit2/include/git2/cred_helpers.h +2 -2
  127. data/vendor/libgit2/include/git2/diff.h +179 -30
  128. data/vendor/libgit2/include/git2/errors.h +3 -3
  129. data/vendor/libgit2/include/git2/index.h +225 -146
  130. data/vendor/libgit2/include/git2/indexer.h +2 -22
  131. data/vendor/libgit2/include/git2/inttypes.h +9 -9
  132. data/vendor/libgit2/include/git2/merge.h +123 -5
  133. data/vendor/libgit2/include/git2/odb.h +59 -38
  134. data/vendor/libgit2/include/git2/odb_backend.h +45 -104
  135. data/vendor/libgit2/include/git2/oid.h +30 -19
  136. data/vendor/libgit2/include/git2/pack.h +21 -3
  137. data/vendor/libgit2/include/git2/refdb.h +0 -35
  138. data/vendor/libgit2/include/git2/refs.h +93 -31
  139. data/vendor/libgit2/include/git2/refspec.h +17 -0
  140. data/vendor/libgit2/include/git2/remote.h +60 -20
  141. data/vendor/libgit2/include/git2/repository.h +48 -70
  142. data/vendor/libgit2/include/git2/reset.h +3 -3
  143. data/vendor/libgit2/include/git2/revparse.h +22 -0
  144. data/vendor/libgit2/include/git2/stash.h +1 -1
  145. data/vendor/libgit2/include/git2/status.h +131 -56
  146. data/vendor/libgit2/include/git2/strarray.h +2 -2
  147. data/vendor/libgit2/include/git2/submodule.h +16 -16
  148. data/vendor/libgit2/include/git2/sys/commit.h +46 -0
  149. data/vendor/libgit2/include/git2/sys/config.h +71 -0
  150. data/vendor/libgit2/include/git2/sys/index.h +179 -0
  151. data/vendor/libgit2/include/git2/sys/odb_backend.h +86 -0
  152. data/vendor/libgit2/include/git2/sys/refdb_backend.h +158 -0
  153. data/vendor/libgit2/include/git2/sys/refs.h +38 -0
  154. data/vendor/libgit2/include/git2/sys/repository.h +106 -0
  155. data/vendor/libgit2/include/git2/tag.h +44 -18
  156. data/vendor/libgit2/include/git2/trace.h +1 -2
  157. data/vendor/libgit2/include/git2/transport.h +74 -0
  158. data/vendor/libgit2/include/git2/tree.h +12 -22
  159. data/vendor/libgit2/include/git2/types.h +33 -0
  160. data/vendor/libgit2/include/git2/version.h +2 -2
  161. data/vendor/libgit2/src/array.h +66 -0
  162. data/vendor/libgit2/src/attr.c +26 -13
  163. data/vendor/libgit2/src/attr_file.c +3 -2
  164. data/vendor/libgit2/src/attr_file.h +3 -3
  165. data/vendor/libgit2/src/attrcache.h +4 -4
  166. data/vendor/libgit2/src/blob.c +13 -9
  167. data/vendor/libgit2/src/blob.h +2 -2
  168. data/vendor/libgit2/src/branch.c +67 -49
  169. data/vendor/libgit2/src/cache.c +224 -54
  170. data/vendor/libgit2/src/cache.h +33 -20
  171. data/vendor/libgit2/src/checkout.c +145 -85
  172. data/vendor/libgit2/src/clone.c +62 -50
  173. data/vendor/libgit2/src/commit.c +74 -40
  174. data/vendor/libgit2/src/commit.h +2 -3
  175. data/vendor/libgit2/src/commit_list.c +14 -8
  176. data/vendor/libgit2/src/config.c +119 -36
  177. data/vendor/libgit2/src/config.h +3 -0
  178. data/vendor/libgit2/src/config_cache.c +24 -7
  179. data/vendor/libgit2/src/config_file.c +9 -6
  180. data/vendor/libgit2/src/crlf.c +4 -2
  181. data/vendor/libgit2/src/date.c +3 -3
  182. data/vendor/libgit2/src/delta.c +1 -1
  183. data/vendor/libgit2/src/diff.c +681 -303
  184. data/vendor/libgit2/src/diff.h +34 -2
  185. data/vendor/libgit2/src/diff_driver.c +405 -0
  186. data/vendor/libgit2/src/diff_driver.h +49 -0
  187. data/vendor/libgit2/src/diff_file.c +447 -0
  188. data/vendor/libgit2/src/diff_file.h +58 -0
  189. data/vendor/libgit2/src/diff_patch.c +995 -0
  190. data/vendor/libgit2/src/diff_patch.h +46 -0
  191. data/vendor/libgit2/src/diff_print.c +430 -0
  192. data/vendor/libgit2/src/diff_tform.c +464 -203
  193. data/vendor/libgit2/src/diff_xdiff.c +166 -0
  194. data/vendor/libgit2/src/diff_xdiff.h +28 -0
  195. data/vendor/libgit2/src/fetch.c +11 -4
  196. data/vendor/libgit2/src/fileops.c +85 -61
  197. data/vendor/libgit2/src/fileops.h +4 -0
  198. data/vendor/libgit2/src/global.c +10 -2
  199. data/vendor/libgit2/src/global.h +0 -8
  200. data/vendor/libgit2/src/hash/hash_generic.h +3 -3
  201. data/vendor/libgit2/src/hash/hash_win32.h +4 -4
  202. data/vendor/libgit2/src/hashsig.c +0 -1
  203. data/vendor/libgit2/src/ignore.c +68 -28
  204. data/vendor/libgit2/src/ignore.h +10 -1
  205. data/vendor/libgit2/src/index.c +666 -84
  206. data/vendor/libgit2/src/index.h +6 -0
  207. data/vendor/libgit2/src/indexer.c +10 -28
  208. data/vendor/libgit2/src/iterator.c +427 -283
  209. data/vendor/libgit2/src/iterator.h +58 -4
  210. data/vendor/libgit2/src/merge.c +1892 -32
  211. data/vendor/libgit2/src/merge.h +132 -5
  212. data/vendor/libgit2/src/merge_file.c +174 -0
  213. data/vendor/libgit2/src/merge_file.h +71 -0
  214. data/vendor/libgit2/src/mwindow.c +1 -1
  215. data/vendor/libgit2/src/notes.c +45 -48
  216. data/vendor/libgit2/src/object.c +89 -127
  217. data/vendor/libgit2/src/object.h +0 -1
  218. data/vendor/libgit2/src/object_api.c +129 -0
  219. data/vendor/libgit2/src/odb.c +156 -59
  220. data/vendor/libgit2/src/odb.h +5 -2
  221. data/vendor/libgit2/src/odb_loose.c +31 -17
  222. data/vendor/libgit2/src/odb_pack.c +39 -43
  223. data/vendor/libgit2/src/oid.c +62 -27
  224. data/vendor/libgit2/src/oid.h +33 -0
  225. data/vendor/libgit2/src/oidmap.h +4 -6
  226. data/vendor/libgit2/src/pack-objects.c +54 -22
  227. data/vendor/libgit2/src/pack.c +98 -56
  228. data/vendor/libgit2/src/pack.h +3 -1
  229. data/vendor/libgit2/src/pathspec.c +26 -1
  230. data/vendor/libgit2/src/pathspec.h +14 -0
  231. data/vendor/libgit2/src/pool.c +5 -0
  232. data/vendor/libgit2/src/posix.c +2 -2
  233. data/vendor/libgit2/src/posix.h +3 -0
  234. data/vendor/libgit2/src/push.c +13 -10
  235. data/vendor/libgit2/src/refdb.c +82 -62
  236. data/vendor/libgit2/src/refdb.h +16 -16
  237. data/vendor/libgit2/src/refdb_fs.c +386 -133
  238. data/vendor/libgit2/src/reflog.c +3 -1
  239. data/vendor/libgit2/src/refs.c +247 -221
  240. data/vendor/libgit2/src/refs.h +2 -1
  241. data/vendor/libgit2/src/refspec.c +18 -1
  242. data/vendor/libgit2/src/refspec.h +3 -1
  243. data/vendor/libgit2/src/remote.c +434 -253
  244. data/vendor/libgit2/src/remote.h +5 -3
  245. data/vendor/libgit2/src/repository.c +197 -111
  246. data/vendor/libgit2/src/repository.h +26 -5
  247. data/vendor/libgit2/src/reset.c +1 -1
  248. data/vendor/libgit2/src/revparse.c +84 -79
  249. data/vendor/libgit2/src/revwalk.c +1 -1
  250. data/vendor/libgit2/src/signature.c +22 -10
  251. data/vendor/libgit2/src/stash.c +5 -2
  252. data/vendor/libgit2/src/status.c +311 -107
  253. data/vendor/libgit2/src/status.h +23 -0
  254. data/vendor/libgit2/src/submodule.c +21 -13
  255. data/vendor/libgit2/src/tag.c +42 -31
  256. data/vendor/libgit2/src/tag.h +2 -3
  257. data/vendor/libgit2/src/thread-utils.h +105 -3
  258. data/vendor/libgit2/src/trace.c +1 -2
  259. data/vendor/libgit2/src/trace.h +3 -3
  260. data/vendor/libgit2/src/transport.c +18 -6
  261. data/vendor/libgit2/src/transports/cred.c +103 -1
  262. data/vendor/libgit2/src/transports/local.c +19 -9
  263. data/vendor/libgit2/src/transports/smart_protocol.c +32 -12
  264. data/vendor/libgit2/src/transports/ssh.c +519 -0
  265. data/vendor/libgit2/src/transports/winhttp.c +3 -1
  266. data/vendor/libgit2/src/tree.c +26 -28
  267. data/vendor/libgit2/src/tree.h +3 -3
  268. data/vendor/libgit2/src/unix/posix.h +2 -0
  269. data/vendor/libgit2/src/util.c +43 -6
  270. data/vendor/libgit2/src/util.h +40 -12
  271. data/vendor/libgit2/src/vector.c +3 -5
  272. data/vendor/libgit2/src/vector.h +9 -0
  273. data/vendor/libgit2/src/win32/dir.c +1 -1
  274. data/vendor/libgit2/src/win32/error.c +2 -0
  275. data/vendor/libgit2/src/win32/findfile.c +3 -6
  276. data/vendor/libgit2/src/win32/posix_w32.c +85 -59
  277. data/vendor/libgit2/src/win32/pthread.c +16 -8
  278. data/vendor/libgit2/src/win32/pthread.h +7 -4
  279. metadata +407 -306
  280. data/test/coverage/HEAD.json +0 -1
  281. data/vendor/libgit2/include/git2/refdb_backend.h +0 -109
  282. data/vendor/libgit2/src/diff_output.c +0 -1819
  283. data/vendor/libgit2/src/diff_output.h +0 -93
@@ -33,21 +33,10 @@ static VALUE rugged_git_note_message(const git_note *note)
33
33
  message = git_note_message(note);
34
34
 
35
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
36
+ * assume the note message is utf8 compatible, because that's
37
+ * the sensible thing to do.
49
38
  */
50
- return rugged_str_ascii(message, strlen(message));
39
+ return rb_str_new_utf8(message);
51
40
  }
52
41
 
53
42
  static VALUE rugged_git_note_oid(const git_note* note)
@@ -59,15 +48,15 @@ static VALUE rugged_git_note_oid(const git_note* note)
59
48
  }
60
49
 
61
50
  /*
62
- * call-seq:
63
- * obj.notes(notes_ref = 'refs/notes/commits') -> hash
51
+ * call-seq:
52
+ * obj.notes(notes_ref = 'refs/notes/commits') -> hash
64
53
  *
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"
54
+ * Lookup a note for +obj+ from +notes_ref+:
55
+ * - +notes_ref+: (optional): cannonical name of the reference to use, defaults to "refs/notes/commits"
67
56
  *
68
- * Returns a new Hash object.
57
+ * Returns a new Hash object.
69
58
  *
70
- * obj.notes #=> {:message=>"note text\n", :oid=>"94eca2de348d5f672faf56b0decafa5937e3235e"}
59
+ * obj.notes #=> {:message=>"note text\n", :oid=>"94eca2de348d5f672faf56b0decafa5937e3235e"}
71
60
  */
72
61
  static VALUE rb_git_note_lookup(int argc, VALUE *argv, VALUE self)
73
62
  {
@@ -109,29 +98,29 @@ static VALUE rb_git_note_lookup(int argc, VALUE *argv, VALUE self)
109
98
  }
110
99
 
111
100
  /*
112
- * call-seq:
113
- * obj.create_note(data = {}) -> oid
101
+ * call-seq:
102
+ * obj.create_note(data = {}) -> oid
114
103
  *
115
- * Write a new +note+ to +object+, with the given +data+
116
- * arguments, passed as a +Hash+:
104
+ * Write a new +note+ to +object+, with the given +data+
105
+ * arguments, passed as a +Hash+:
117
106
  *
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)
107
+ * - +:message+: the content of the note to add to the object
108
+ * - +:committer+: a hash with the signature for the committer
109
+ * - +:author+: a hash with the signature for the author
110
+ * - +:ref+: (optional): cannonical name of the reference to use, defaults to "refs/notes/commits"
111
+ * - +:force+: (optional): overwrite existing note (disabled by default)
123
112
  *
124
- * When the note is successfully written to disk, its +oid+ will be
125
- * returned as a hex +String+.
113
+ * When the note is successfully written to disk, its +oid+ will be
114
+ * returned as a hex +String+.
126
115
  *
127
- * author = {:email=>"tanoku@gmail.com", :time=>Time.now, :name=>"Vicent Mart\303\255"}
116
+ * author = {:email=>"tanoku@gmail.com", :time=>Time.now, :name=>"Vicent Mart\303\255"}
128
117
  *
129
- * obj.create_note(
130
- * :author => author,
131
- * :committer => author,
132
- * :message => "Hello world\n\n",
133
- * :ref => 'refs/notes/builds'
134
- * )
118
+ * obj.create_note(
119
+ * :author => author,
120
+ * :committer => author,
121
+ * :message => "Hello world\n\n",
122
+ * :ref => 'refs/notes/builds'
123
+ * )
135
124
  */
136
125
  static VALUE rb_git_note_create(VALUE self, VALUE rb_data)
137
126
  {
@@ -197,26 +186,26 @@ static VALUE rb_git_note_create(VALUE self, VALUE rb_data)
197
186
  }
198
187
 
199
188
  /*
200
- * call-seq:
201
- * obj.remove_note(data = {}) -> boolean
189
+ * call-seq:
190
+ * obj.remove_note(data = {}) -> boolean
202
191
  *
203
- * Removes a +note+ from +object+, with the given +data+
204
- * arguments, passed as a +Hash+:
192
+ * Removes a +note+ from +object+, with the given +data+
193
+ * arguments, passed as a +Hash+:
205
194
  *
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"
195
+ * - +:committer+: a hash with the signature for the committer
196
+ * - +:author+: a hash with the signature for the author
197
+ * - +:ref+: (optional): cannonical name of the reference to use, defaults to "refs/notes/commits"
209
198
  *
210
- * When the note is successfully removed +true+ will be
211
- * returned as a +Boolean+.
199
+ * When the note is successfully removed +true+ will be
200
+ * returned as a +Boolean+.
212
201
  *
213
- * author = {:email=>"tanoku@gmail.com", :time=>Time.now, :name=>"Vicent Mart\303\255"}
202
+ * author = {:email=>"tanoku@gmail.com", :time=>Time.now, :name=>"Vicent Mart\303\255"}
214
203
  *
215
- * obj.remove_note(
216
- * :author => author,
217
- * :committer => author,
218
- * :ref => 'refs/notes/builds'
219
- * )
204
+ * obj.remove_note(
205
+ * :author => author,
206
+ * :committer => author,
207
+ * :ref => 'refs/notes/builds'
208
+ * )
220
209
  */
221
210
  static VALUE rb_git_note_remove(VALUE self, VALUE rb_data)
222
211
  {
@@ -271,16 +260,16 @@ static VALUE rb_git_note_remove(VALUE self, VALUE rb_data)
271
260
  return Qtrue;
272
261
  }
273
262
 
274
- static int cb_note__each(const git_oid *blob_id, const git_oid *annotated_object_id, void *payload)
263
+ static int cb_note__each(const git_oid *blob_id, const git_oid *annotated_object_id, void *data)
275
264
  {
276
- VALUE rb_repo = (VALUE)payload;
277
-
265
+ VALUE rb_args = rb_ary_new2(2);
266
+ struct rugged_cb_payload *payload = data;
278
267
  git_object *annotated_object;
279
268
  git_object *note_blob;
280
269
 
281
270
  git_repository *repo;
282
271
 
283
- Data_Get_Struct(rb_repo, git_repository, repo);
272
+ Data_Get_Struct(payload->rb_data, git_repository, repo);
284
273
 
285
274
  rugged_exception_check(
286
275
  git_object_lookup(&annotated_object, repo, annotated_object_id, GIT_OBJ_ANY)
@@ -290,33 +279,34 @@ static int cb_note__each(const git_oid *blob_id, const git_oid *annotated_object
290
279
  git_object_lookup(&note_blob, repo, blob_id, GIT_OBJ_BLOB)
291
280
  );
292
281
 
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;
282
+ rb_ary_push(rb_args, rugged_object_new(payload->rb_data, note_blob));
283
+ rb_ary_push(rb_args, rugged_object_new(payload->rb_data, annotated_object));
284
+
285
+ rb_protect(rb_yield_splat, rb_args, &payload->exception);
286
+
287
+ return payload->exception ? GIT_ERROR : GIT_OK;
298
288
  }
299
289
 
300
290
  /*
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
291
+ * call-seq:
292
+ * repo.each_note(notes_ref = "refs/notes/commits") { |note_blob, annotated_object| block }
293
+ * repo.each_note(notes_ref = "refs/notes/commits") -> an_enumerator
304
294
  *
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"
295
+ * Call the given block once for each note_blob/annotated_object pair in +repository+
296
+ * - +notes_ref+: (optional): cannonical name of the reference to use defaults to "refs/notes/commits"
307
297
  *
308
- * If no block is given, an +Enumerator+ is returned.
298
+ * If no block is given, an +Enumerator+ is returned.
309
299
  *
310
- * @repo.each_note do |note_blob, annotated_object|
311
- * puts "#{note_blob.oid} => #{annotated_object.oid}"
312
- * end
300
+ * @repo.each_note do |note_blob, annotated_object|
301
+ * puts "#{note_blob.oid} => #{annotated_object.oid}"
302
+ * end
313
303
  */
314
304
  static VALUE rb_git_note_each(int argc, VALUE *argv, VALUE self)
315
305
  {
316
306
  git_repository *repo;
317
307
  const char *notes_ref = NULL;
318
308
  int error;
319
-
309
+ struct rugged_cb_payload payload = { self, 0 };
320
310
  VALUE rb_notes_ref;
321
311
 
322
312
  rb_scan_args(argc, argv, "01", &rb_notes_ref);
@@ -332,20 +322,24 @@ static VALUE rb_git_note_each(int argc, VALUE *argv, VALUE self)
332
322
 
333
323
  Data_Get_Struct(self, git_repository, repo);
334
324
 
335
- error = git_note_foreach(repo, notes_ref, &cb_note__each, (void *)self);
325
+ error = git_note_foreach(repo, notes_ref, &cb_note__each, &payload);
326
+
327
+ if (payload.exception)
328
+ rb_jump_tag(payload.exception);
336
329
  rugged_exception_check(error);
330
+
337
331
  return Qnil;
338
332
  }
339
333
 
340
334
  /*
341
- * call-seq:
342
- * repo.notes_default_ref() -> string
335
+ * call-seq:
336
+ * repo.notes_default_ref() -> string
343
337
  *
344
- * Get the default notes reference for a +repository+:
338
+ * Get the default notes reference for a +repository+:
345
339
  *
346
- * Returns a new String object.
340
+ * Returns a new String object.
347
341
  *
348
- * repo.default_notes_ref #=> "refs/notes/commits"
342
+ * repo.default_notes_ref #=> "refs/notes/commits"
349
343
  */
350
344
  static VALUE rb_git_note_default_ref_GET(VALUE self)
351
345
  {
@@ -358,10 +352,10 @@ static VALUE rb_git_note_default_ref_GET(VALUE self)
358
352
  git_note_default_ref(&ref_name, repo)
359
353
  );
360
354
 
361
- return rugged_str_new2(ref_name, NULL);
355
+ return rb_str_new_utf8(ref_name);
362
356
  }
363
357
 
364
- void Init_rugged_notes()
358
+ void Init_rugged_notes(void)
365
359
  {
366
360
  rb_define_method(rb_cRuggedObject, "notes", rb_git_note_lookup, -1);
367
361
  rb_define_method(rb_cRuggedObject, "create_note", rb_git_note_create, 1);
@@ -85,7 +85,7 @@ 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)
88
+ int rugged_oid_get(git_oid *oid, git_repository *repo, VALUE p)
89
89
  {
90
90
  git_object *object;
91
91
  int error;
@@ -99,14 +99,16 @@ void rugged_oid_get(git_oid *oid, git_repository *repo, VALUE p)
99
99
  /* Fast path: see if the 40-char string is an OID */
100
100
  if (RSTRING_LEN(p) == 40 &&
101
101
  git_oid_fromstr(oid, RSTRING_PTR(p)) == 0)
102
- return;
102
+ return GIT_OK;
103
103
 
104
- error = git_revparse_single(&object, repo, StringValueCStr(p));
105
- rugged_exception_check(error);
104
+ if ((error = git_revparse_single(&object, repo, StringValueCStr(p))))
105
+ return error;
106
106
 
107
107
  git_oid_cpy(oid, git_object_id(object));
108
108
  git_object_free(object);
109
109
  }
110
+
111
+ return GIT_OK;
110
112
  }
111
113
 
112
114
  git_object *rugged_object_get(git_repository *repo, VALUE object_value, git_otype type)
@@ -202,6 +204,16 @@ static git_otype class2otype(VALUE klass)
202
204
  return GIT_OBJ_BAD;
203
205
  }
204
206
 
207
+ /*
208
+ * call-seq:
209
+ * Object.new(repo, oid) -> object
210
+ * Object.lookup(repo, oid) -> object
211
+ *
212
+ * Find and return the git object inside +repo+ with the given +oid+.
213
+ *
214
+ * +oid+ can either have be the complete, 40 character string or any
215
+ * unique prefix.
216
+ */
205
217
  VALUE rb_git_object_lookup(VALUE klass, VALUE rb_repo, VALUE rb_hex)
206
218
  {
207
219
  git_object *object;
@@ -240,7 +252,7 @@ VALUE rb_git_object_lookup(VALUE klass, VALUE rb_repo, VALUE rb_hex)
240
252
  return rugged_object_new(rb_repo, object);
241
253
  }
242
254
 
243
- static VALUE rugged_object_rev_parse(VALUE klass, VALUE rb_repo, VALUE rb_spec, int as_obj)
255
+ VALUE rugged_object_rev_parse(VALUE rb_repo, VALUE rb_spec, int as_obj)
244
256
  {
245
257
  git_object *object;
246
258
  const char *spec;
@@ -267,16 +279,44 @@ static VALUE rugged_object_rev_parse(VALUE klass, VALUE rb_repo, VALUE rb_spec,
267
279
  return ret;
268
280
  }
269
281
 
282
+ /*
283
+ * call-seq: Object.rev_parse(repo, str) -> object
284
+ *
285
+ * Find and return a single object inside +repo+ as specified by the
286
+ * git revision string +str+.
287
+ *
288
+ * See http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions or
289
+ * <code>man gitrevisions</code> for information on the accepted syntax.
290
+ *
291
+ * Raises a Rugged::InvalidError if +str+ does not contain a valid revision string.
292
+ */
270
293
  VALUE rb_git_object_rev_parse(VALUE klass, VALUE rb_repo, VALUE rb_spec)
271
294
  {
272
- return rugged_object_rev_parse(klass, rb_repo, rb_spec, 1);
295
+ return rugged_object_rev_parse(rb_repo, rb_spec, 1);
273
296
  }
274
297
 
298
+ /*
299
+ * call-seq: Object.rev_parse_oid(repo, str) -> oid
300
+ *
301
+ * Find and return the id of the object inside +repo+ as specified by the
302
+ * git revision string +str+.
303
+ *
304
+ * See http://git-scm.com/docs/git-rev-parse.html#_specifying_revisions or
305
+ * <code>man gitrevisions</code> for information on the accepted syntax.
306
+ *
307
+ * Raises a Rugged::InvalidError if +str+ does not contain a valid revision string.
308
+ */
275
309
  VALUE rb_git_object_rev_parse_oid(VALUE klass, VALUE rb_repo, VALUE rb_spec)
276
310
  {
277
- return rugged_object_rev_parse(klass, rb_repo, rb_spec, 0);
311
+ return rugged_object_rev_parse(rb_repo, rb_spec, 0);
278
312
  }
279
313
 
314
+ /*
315
+ * call-seq: object == other
316
+ *
317
+ * Returns true only if +object+ and other are both instances or subclasses of
318
+ * Rugged::Object and have the same object id, false otherwise.
319
+ */
280
320
  static VALUE rb_git_object_equal(VALUE self, VALUE other)
281
321
  {
282
322
  git_object *a, *b;
@@ -290,6 +330,11 @@ static VALUE rb_git_object_equal(VALUE self, VALUE other)
290
330
  return git_oid_cmp(git_object_id(a), git_object_id(b)) == 0 ? Qtrue : Qfalse;
291
331
  }
292
332
 
333
+ /*
334
+ * call-seq: object.oid -> oid
335
+ *
336
+ * Return the Object ID (a 40 character SHA1 hash) for +object+.
337
+ */
293
338
  static VALUE rb_git_object_oid_GET(VALUE self)
294
339
  {
295
340
  git_object *object;
@@ -297,6 +342,11 @@ static VALUE rb_git_object_oid_GET(VALUE self)
297
342
  return rugged_create_oid(git_object_id(object));
298
343
  }
299
344
 
345
+ /*
346
+ * call-seq: object.type -> type
347
+ *
348
+ * Returns the object's type. Can be one of +:commit+, +:tag+, +:tree+ or +:blob+.
349
+ */
300
350
  static VALUE rb_git_object_type_GET(VALUE self)
301
351
  {
302
352
  git_object *object;
@@ -305,6 +355,11 @@ static VALUE rb_git_object_type_GET(VALUE self)
305
355
  return rugged_otype_new(git_object_type(object));
306
356
  }
307
357
 
358
+ /*
359
+ * call-seq: object.read_raw -> raw_object
360
+ *
361
+ * Returns the git object as a Rugged::OdbObject instance.
362
+ */
308
363
  static VALUE rb_git_object_read_raw(VALUE self)
309
364
  {
310
365
  git_object *object;
@@ -313,7 +368,7 @@ static VALUE rb_git_object_read_raw(VALUE self)
313
368
  return rugged_raw_read(git_object_owner(object), git_object_id(object));
314
369
  }
315
370
 
316
- void Init_rugged_object()
371
+ void Init_rugged_object(void)
317
372
  {
318
373
  rb_cRuggedObject = rb_define_class_under(rb_mRugged, "Object", rb_cObject);
319
374
  rb_define_singleton_method(rb_cRuggedObject, "lookup", rb_git_object_lookup, 2);
@@ -40,75 +40,102 @@ VALUE rugged_ref_new(VALUE klass, VALUE owner, git_reference *ref)
40
40
  return rb_ref;
41
41
  }
42
42
 
43
- static int ref_foreach__block(const char *ref_name, void *opaque)
44
- {
45
- rb_funcall((VALUE)opaque, rb_intern("call"), 1, rugged_str_new2(ref_name, rb_utf8_encoding()));
46
- return GIT_OK;
47
- }
48
-
49
- /*
50
- * call-seq:
51
- * Reference.each(repository, filter = :all, glob = nil) { |ref_name| block }
52
- * Reference.each(repository, filter = :all, glob = nil) -> Iterator
53
- *
54
- * Iterate through all the references in +repository+. Iteration can be
55
- * optionally filtered to only +:oid+ or +:symbolic+ references, or to
56
- * the ones matching the given +glob+, a standard Unix filename glob.
57
- *
58
- * The given block will be called once with the name of each reference.
59
- * If no block is given, an iterator will be returned.
60
- */
61
- static VALUE rb_git_ref_each(int argc, VALUE *argv, VALUE self)
43
+ static VALUE rb_git_ref__each(int argc, VALUE *argv, VALUE self, int only_names)
62
44
  {
63
45
  git_repository *repo;
64
- int error, flags = GIT_REF_LISTALL;
65
- VALUE rb_repo, rb_list, rb_glob, rb_block;
46
+ git_reference_iterator *iter;
47
+ int error, exception = 0;
48
+ VALUE rb_repo, rb_glob;
66
49
 
67
- rb_scan_args(argc, argv, "12&", &rb_repo, &rb_list, &rb_glob, &rb_block);
50
+ rb_scan_args(argc, argv, "11", &rb_repo, &rb_glob);
68
51
 
69
- if (!rb_block_given_p())
70
- return rb_funcall(self, rb_intern("to_enum"), 4, CSTR2SYM("each"), rb_repo, rb_list, rb_glob);
52
+ if (!rb_block_given_p()) {
53
+ return rb_funcall(self,
54
+ rb_intern("to_enum"), 3,
55
+ only_names ? CSTR2SYM("each_name") : CSTR2SYM("each"),
56
+ rb_repo, rb_glob);
57
+ }
71
58
 
72
59
  if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo))
73
60
  rb_raise(rb_eTypeError, "Expecting a Rugged::Repository instance");
74
61
 
75
62
  Data_Get_Struct(rb_repo, git_repository, repo);
76
63
 
77
- if (!NIL_P(rb_list)) {
78
- ID list;
79
-
80
- Check_Type(rb_list, T_SYMBOL);
81
- list = SYM2ID(rb_list);
82
-
83
- if (list == rb_intern("all"))
84
- flags = GIT_REF_LISTALL;
85
- else if (list == rb_intern("oid"))
86
- flags = GIT_REF_OID;
87
- else if (list == rb_intern("symbolic"))
88
- flags = GIT_REF_SYMBOLIC;
89
- else {
90
- rb_raise(rb_eArgError, "Invalid list value (must be `all`, `oid` or `symbolic`)");
91
- }
92
- }
93
-
94
64
  if (!NIL_P(rb_glob)) {
95
65
  Check_Type(rb_glob, T_STRING);
96
- error = git_reference_foreach_glob(repo,
97
- StringValueCStr(rb_glob), flags, &ref_foreach__block, (void *)rb_block);
66
+ error = git_reference_iterator_glob_new(&iter, repo, StringValueCStr(rb_glob));
98
67
  } else {
99
- error = git_reference_foreach(repo, flags, &ref_foreach__block, (void *)rb_block);
68
+ error = git_reference_iterator_new(&iter, repo);
100
69
  }
101
70
 
102
71
  rugged_exception_check(error);
72
+
73
+ if (only_names) {
74
+ const char *ref_name;
75
+ while (!exception && (error = git_reference_next_name(&ref_name, iter)) == GIT_OK) {
76
+ rb_protect(rb_yield, rb_str_new_utf8(ref_name), &exception);
77
+ }
78
+ } else {
79
+ git_reference *ref;
80
+ while (!exception && (error = git_reference_next(&ref, iter)) == GIT_OK) {
81
+ rb_protect(rb_yield, rugged_ref_new(rb_cRuggedReference, rb_repo, ref), &exception);
82
+ }
83
+ }
84
+
85
+ git_reference_iterator_free(iter);
86
+
87
+ if (exception)
88
+ rb_jump_tag(exception);
89
+
90
+ if (error != GIT_ITEROVER)
91
+ rugged_exception_check(error);
92
+
103
93
  return Qnil;
104
94
  }
105
95
 
106
96
  /*
107
- * call-seq:
108
- * Reference.lookup(repository, ref_name) -> new_ref
97
+ * call-seq:
98
+ * Reference.each(repository, glob = nil) { |ref| block } -> nil
99
+ * Reference.each(repository, glob = nil) -> enumerator
100
+ *
101
+ * Iterate through all the references in +repository+. Iteration
102
+ * can be optionally filtered to the ones matching the given
103
+ * +glob+, a standard Unix filename glob.
104
+ *
105
+ * The given block will be called once with a Rugged::Reference
106
+ * instance for each reference.
107
+ *
108
+ * If no block is given, an enumerator will be returned.
109
+ */
110
+ static VALUE rb_git_ref_each(int argc, VALUE *argv, VALUE self)
111
+ {
112
+ return rb_git_ref__each(argc, argv, self, 0);
113
+ }
114
+
115
+ /*
116
+ * call-seq:
117
+ * Reference.each_name(repository, glob = nil) { |ref_name| block } -> nil
118
+ * Reference.each_name(repository, glob = nil) -> enumerator
119
+ *
120
+ * Iterate through all the reference names in +repository+. Iteration
121
+ * can be optionally filtered to the ones matching the given
122
+ * +glob+, a standard Unix filename glob.
109
123
  *
110
- * Lookup a reference from the +repository+.
111
- * Returns a new +Rugged::Reference+ object.
124
+ * The given block will be called once with the name of each reference.
125
+ *
126
+ * If no block is given, an enumerator will be returned.
127
+ */
128
+ static VALUE rb_git_ref_each_name(int argc, VALUE *argv, VALUE self)
129
+ {
130
+ return rb_git_ref__each(argc, argv, self, 1);
131
+ }
132
+
133
+ /*
134
+ * call-seq:
135
+ * Reference.lookup(repository, ref_name) -> new_ref
136
+ *
137
+ * Lookup a reference from the +repository+.
138
+ * Returns a new Rugged::Reference object.
112
139
  */
113
140
  static VALUE rb_git_ref_lookup(VALUE klass, VALUE rb_repo, VALUE rb_name)
114
141
  {
@@ -129,11 +156,67 @@ static VALUE rb_git_ref_lookup(VALUE klass, VALUE rb_repo, VALUE rb_name)
129
156
  }
130
157
 
131
158
  /*
132
- * call-seq:
133
- * Reference.exist?(repository, ref_name) -> true or false
134
- * Reference.exists?(repository, ref_name) -> true or false
159
+ * call-seq:
160
+ * Reference.valid_name?(ref_name) -> true or false
161
+ *
162
+ * Check if a reference name is well-formed.
163
+ *
164
+ * Valid reference names must follow one of two patterns:
165
+ *
166
+ * 1. Top-level names must contain only capital letters and underscores,
167
+ * and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
168
+ * 2. Names prefixed with "refs/" can be almost anything. You must avoid
169
+ * the characters '~', '^', ':', '\\', '?', '[', and '*', and the
170
+ * sequences ".." and "@{" which have special meaning to revparse.
171
+ *
172
+ * Returns true if the reference name is valid, false if not.
173
+ */
174
+ static VALUE rb_git_ref_valid_name(VALUE klass, VALUE rb_name)
175
+ {
176
+ Check_Type(rb_name, T_STRING);
177
+ return git_reference_is_valid_name(StringValueCStr(rb_name)) == 1 ? Qtrue : Qfalse;
178
+ }
179
+
180
+ /*
181
+ * call-seq:
182
+ * ref.peel -> oid
135
183
  *
136
- * Check if a given reference exists on +repository+.
184
+ * Peels tag objects to the sha that they point at. Replicates
185
+ * +git show-ref --dereference+.
186
+ */
187
+ static VALUE rb_git_ref_peel(VALUE self)
188
+ {
189
+ /* Leave room for \0 */
190
+ git_reference *ref;
191
+ git_object *object;
192
+ char oid[GIT_OID_HEXSZ + 1];
193
+ int error;
194
+
195
+ Data_Get_Struct(self, git_reference, ref);
196
+
197
+ error = git_reference_peel(&object, ref, GIT_OBJ_ANY);
198
+ if (error == GIT_ENOTFOUND)
199
+ return Qnil;
200
+ else
201
+ rugged_exception_check(error);
202
+
203
+ if (git_reference_type(ref) == GIT_REF_OID &&
204
+ !git_oid_cmp(git_object_id(object), git_reference_target(ref))) {
205
+ git_object_free(object);
206
+ return Qnil;
207
+ } else {
208
+ git_oid_tostr(oid, sizeof(oid), git_object_id(object));
209
+ git_object_free(object);
210
+ return rb_str_new_utf8(oid);
211
+ }
212
+ }
213
+
214
+ /*
215
+ * call-seq:
216
+ * Reference.exist?(repository, ref_name) -> true or false
217
+ * Reference.exists?(repository, ref_name) -> true or false
218
+ *
219
+ * Check if a given reference exists on +repository+.
137
220
  */
138
221
  static VALUE rb_git_ref_exist(VALUE klass, VALUE rb_repo, VALUE rb_name)
139
222
  {
@@ -156,16 +239,16 @@ static VALUE rb_git_ref_exist(VALUE klass, VALUE rb_repo, VALUE rb_name)
156
239
  }
157
240
 
158
241
  /*
159
- * call-seq:
160
- * Reference.create(repository, name, oid, force = false) -> new_ref
161
- * Reference.create(repository, name, target, force = false) -> new_ref
242
+ * call-seq:
243
+ * Reference.create(repository, name, oid, force = false) -> new_ref
244
+ * Reference.create(repository, name, target, force = false) -> new_ref
162
245
  *
163
- * Create a symbolic or direct reference on +repository+ with the given +name+.
164
- * If the third argument is a valid OID, the reference will be created as direct.
165
- * Otherwise, it will be assumed the target is the name of another reference.
246
+ * Create a symbolic or direct reference on +repository+ with the given +name+.
247
+ * If the third argument is a valid OID, the reference will be created as direct.
248
+ * Otherwise, it will be assumed the target is the name of another reference.
166
249
  *
167
- * If a reference with the given +name+ already exists and +force+ is +true+,
168
- * it will be overwritten. Otherwise, an exception will be raised.
250
+ * If a reference with the given +name+ already exists and +force+ is +true+,
251
+ * it will be overwritten. Otherwise, an exception will be raised.
169
252
  */
170
253
  static VALUE rb_git_ref_create(int argc, VALUE *argv, VALUE klass)
171
254
  {
@@ -197,18 +280,18 @@ static VALUE rb_git_ref_create(int argc, VALUE *argv, VALUE klass)
197
280
  }
198
281
 
199
282
  /*
200
- * call-seq:
201
- * reference.target -> oid
202
- * reference.target -> ref_name
283
+ * call-seq:
284
+ * reference.target -> oid
285
+ * reference.target -> ref_name
203
286
  *
204
- * Return the target of the reference, which is an OID for +:direct+
205
- * references, and the name of another reference for +:symbolic+ ones.
287
+ * Return the target of the reference, which is an OID for +:direct+
288
+ * references, and the name of another reference for +:symbolic+ ones.
206
289
  *
207
- * r1.type #=> :symbolic
208
- * r1.target #=> "refs/heads/master"
290
+ * r1.type #=> :symbolic
291
+ * r1.target #=> "refs/heads/master"
209
292
  *
210
- * r2.type #=> :direct
211
- * r2.target #=> "de5ba987198bcf2518885f0fc1350e5172cded78"
293
+ * r2.type #=> :direct
294
+ * r2.target #=> "de5ba987198bcf2518885f0fc1350e5172cded78"
212
295
  */
213
296
  static VALUE rb_git_ref_target(VALUE self)
214
297
  {
@@ -218,29 +301,30 @@ static VALUE rb_git_ref_target(VALUE self)
218
301
  if (git_reference_type(ref) == GIT_REF_OID) {
219
302
  return rugged_create_oid(git_reference_target(ref));
220
303
  } else {
221
- return rugged_str_new2(git_reference_symbolic_target(ref), rb_utf8_encoding());
304
+ return rb_str_new_utf8(git_reference_symbolic_target(ref));
222
305
  }
223
306
  }
224
307
 
225
308
  /*
226
- * call-seq:
227
- * reference.set_target(t) -> Reference
309
+ * call-seq:
310
+ * reference.set_target(oid) -> new_ref
311
+ * reference.set_target(ref_name) -> new_ref
228
312
  *
229
- * Set the target of a reference. If +reference+ is a direct reference,
230
- * the new target must be a +String+ representing a SHA1 OID.
313
+ * Set the target of a reference. If +reference+ is a direct reference,
314
+ * the new target must be a +String+ representing a SHA1 OID.
231
315
  *
232
- * If +reference+ is symbolic, the new target must be a +String+ with
233
- * the name of another reference.
316
+ * If +reference+ is symbolic, the new target must be a +String+ with
317
+ * the name of another reference.
234
318
  *
235
- * The original reference is unaltered; a new reference object is
236
- * returned with the new target, and the changes are persisted to
237
- * disk.
319
+ * The original reference is unaltered; a new reference object is
320
+ * returned with the new target, and the changes are persisted to
321
+ * disk.
238
322
  *
239
- * r1.type #=> :symbolic
240
- * r1.set_target("refs/heads/master") #=> <Reference>
323
+ * r1.type #=> :symbolic
324
+ * r1.set_target("refs/heads/master") #=> <Reference>
241
325
  *
242
- * r2.type #=> :direct
243
- * r2.set_target("de5ba987198bcf2518885f0fc1350e5172cded78") #=> <Reference>
326
+ * r2.type #=> :direct
327
+ * r2.set_target("de5ba987198bcf2518885f0fc1350e5172cded78") #=> <Reference>
244
328
  */
245
329
  static VALUE rb_git_ref_set_target(VALUE self, VALUE rb_target)
246
330
  {
@@ -266,10 +350,10 @@ static VALUE rb_git_ref_set_target(VALUE self, VALUE rb_target)
266
350
  }
267
351
 
268
352
  /*
269
- * call-seq:
270
- * reference.type -> :symbolic or :direct
353
+ * call-seq:
354
+ * reference.type -> :symbolic or :direct
271
355
  *
272
- * Return whether the reference is +:symbolic+ or +:direct+
356
+ * Return whether the reference is +:symbolic+ or +:direct+
273
357
  */
274
358
  static VALUE rb_git_ref_type(VALUE self)
275
359
  {
@@ -287,32 +371,32 @@ static VALUE rb_git_ref_type(VALUE self)
287
371
  }
288
372
 
289
373
  /*
290
- * call-seq:
291
- * reference.name -> name
374
+ * call-seq:
375
+ * reference.name -> name
292
376
  *
293
- * Returns the name of the reference
377
+ * Returns the name of the reference
294
378
  *
295
- * reference.name #=> 'HEAD'
379
+ * reference.name #=> 'HEAD'
296
380
  */
297
381
  static VALUE rb_git_ref_name(VALUE self)
298
382
  {
299
383
  git_reference *ref;
300
384
  Data_Get_Struct(self, git_reference, ref);
301
- return rugged_str_new2(git_reference_name(ref), rb_utf8_encoding());
385
+ return rb_str_new_utf8(git_reference_name(ref));
302
386
  }
303
387
 
304
388
  /*
305
- * call-seq:
306
- * reference.resolve -> peeled_ref
389
+ * call-seq:
390
+ * reference.resolve -> peeled_ref
307
391
  *
308
- * Peel a symbolic reference to its target reference.
392
+ * Peel a symbolic reference to its target reference.
309
393
  *
310
- * r1.type #=> :symbolic
311
- * r1.name #=> 'HEAD'
312
- * r1.target #=> 'refs/heads/master'
394
+ * r1.type #=> :symbolic
395
+ * r1.name #=> 'HEAD'
396
+ * r1.target #=> 'refs/heads/master'
313
397
  *
314
- * r2 = r1.resolve #=> #<Rugged::Reference:0x401b3948>
315
- * r2.target #=> '9d09060c850defbc7711d08b57def0d14e742f4e'
398
+ * r2 = r1.resolve #=> #<Rugged::Reference:0x401b3948>
399
+ * r2.target #=> '9d09060c850defbc7711d08b57def0d14e742f4e'
316
400
  */
317
401
  static VALUE rb_git_ref_resolve(VALUE self)
318
402
  {
@@ -329,17 +413,17 @@ static VALUE rb_git_ref_resolve(VALUE self)
329
413
  }
330
414
 
331
415
  /*
332
- * call-seq:
333
- * reference.rename(new_name, force = false)
416
+ * call-seq:
417
+ * reference.rename(new_name, force = false)
334
418
  *
335
- * Change the name of a reference. If +force+ is +true+, any previously
336
- * existing references will be overwritten when renaming.
419
+ * Change the name of a reference. If +force+ is +true+, any previously
420
+ * existing references will be overwritten when renaming.
337
421
  *
338
- * Return a new reference object with the new object
422
+ * Return a new reference object with the new object
339
423
  *
340
- * reference.name #=> 'refs/heads/master'
341
- * new_ref = reference.rename('refs/heads/development') #=> <Reference>
342
- * new_ref.name #=> 'refs/heads/development'
424
+ * reference.name #=> 'refs/heads/master'
425
+ * new_ref = reference.rename('refs/heads/development') #=> <Reference>
426
+ * new_ref.name #=> 'refs/heads/development'
343
427
  */
344
428
  static VALUE rb_git_ref_rename(int argc, VALUE *argv, VALUE self)
345
429
  {
@@ -361,14 +445,14 @@ static VALUE rb_git_ref_rename(int argc, VALUE *argv, VALUE self)
361
445
  }
362
446
 
363
447
  /*
364
- * call-seq:
365
- * reference.delete!
448
+ * call-seq:
449
+ * reference.delete! -> nil
366
450
  *
367
- * Delete this reference from disk.
451
+ * Delete this reference from disk.
368
452
  *
369
- * reference.name #=> 'HEAD'
370
- * reference.delete!
371
- * # Reference no longer exists on disk
453
+ * reference.name #=> 'HEAD'
454
+ * reference.delete!
455
+ * # Reference no longer exists on disk
372
456
  */
373
457
  static VALUE rb_git_ref_delete(VALUE self)
374
458
  {
@@ -404,35 +488,34 @@ static VALUE reflog_entry_new(const git_reflog_entry *entry)
404
488
  );
405
489
 
406
490
  if ((message = git_reflog_entry_message(entry)) != NULL) {
407
- rb_hash_aset(rb_entry,
408
- CSTR2SYM("message"),
409
- rugged_str_new2(message, NULL)
410
- );
491
+ rb_hash_aset(rb_entry, CSTR2SYM("message"), rb_str_new_utf8(message));
411
492
  }
412
493
 
413
494
  return rb_entry;
414
495
  }
415
496
 
416
497
  /*
417
- * call-seq:
418
- * reference.log -> [reflog_entry, ...]
498
+ * call-seq:
499
+ * reference.log -> [reflog_entry, ...]
500
+ *
501
+ * Return an array with the log of all modifications to this reference
419
502
  *
420
- * Return an array with the log of all modifications to this reference
503
+ * Each +reflog_entry+ is a hash with the following keys:
421
504
  *
422
- * Each +reflog_entry+ is a hash with the following keys:
505
+ * - +:id_old+: previous OID before the change
506
+ * - +:id_new+: OID after the change
507
+ * - +:committer+: author of the change
508
+ * - +:message+: message for the change
423
509
  *
424
- * - +:id_old+: previous OID before the change
425
- * - +:id_new+: OID after the change
426
- * - +:committer+: author of the change
427
- * - +:message+: message for the change
510
+ * Example:
428
511
  *
429
- * reference.log #=> [
430
- * # {
431
- * # :id_old => nil,
432
- * # :id_new => '9d09060c850defbc7711d08b57def0d14e742f4e',
433
- * # :committer => {:name => 'Vicent Marti', :email => {'vicent@github.com'}},
434
- * # :message => 'created reference'
435
- * # }, ... ]
512
+ * reference.log #=> [
513
+ * # {
514
+ * # :id_old => nil,
515
+ * # :id_new => '9d09060c850defbc7711d08b57def0d14e742f4e',
516
+ * # :committer => {:name => 'Vicent Marti', :email => {'vicent@github.com'}},
517
+ * # :message => 'created reference'
518
+ * # }, ... ]
436
519
  */
437
520
  static VALUE rb_git_reflog(VALUE self)
438
521
  {
@@ -462,10 +545,10 @@ static VALUE rb_git_reflog(VALUE self)
462
545
  }
463
546
 
464
547
  /*
465
- * call-seq:
466
- * reference.log? -> Boolean
548
+ * call-seq:
549
+ * reference.log? -> true or false
467
550
  *
468
- * Return whether a given reference has a reflog.
551
+ * Return +true+ if the reference has a reflog, +false+ otherwise.
469
552
  */
470
553
  static VALUE rb_git_has_reflog(VALUE self)
471
554
  {
@@ -475,10 +558,10 @@ static VALUE rb_git_has_reflog(VALUE self)
475
558
  }
476
559
 
477
560
  /*
478
- * call-seq:
479
- * reference.log!(committer, message = nil)
561
+ * call-seq:
562
+ * reference.log!(committer, message = nil) -> nil
480
563
  *
481
- * Log a modification for this reference to the reflog.
564
+ * Log a modification for this reference to the reflog.
482
565
  */
483
566
  static VALUE rb_git_reflog_write(int argc, VALUE *argv, VALUE self)
484
567
  {
@@ -520,10 +603,10 @@ static VALUE rb_git_reflog_write(int argc, VALUE *argv, VALUE self)
520
603
  }
521
604
 
522
605
  /*
523
- * call-seq:
524
- * reference.branch? -> Boolean
606
+ * call-seq:
607
+ * reference.branch? -> true or false
525
608
  *
526
- * Return whether a given reference is a branch
609
+ * Return whether a given reference is a branch
527
610
  */
528
611
  static VALUE rb_git_ref_is_branch(VALUE self)
529
612
  {
@@ -533,10 +616,10 @@ static VALUE rb_git_ref_is_branch(VALUE self)
533
616
  }
534
617
 
535
618
  /*
536
- * call-seq:
537
- * reference.remote? -> Boolean
619
+ * call-seq:
620
+ * reference.remote? -> true or false
538
621
  *
539
- * Return whether a given reference is a remote
622
+ * Return whether a given reference is a remote
540
623
  */
541
624
  static VALUE rb_git_ref_is_remote(VALUE self)
542
625
  {
@@ -545,7 +628,7 @@ static VALUE rb_git_ref_is_remote(VALUE self)
545
628
  return git_reference_is_remote(ref) ? Qtrue : Qfalse;
546
629
  }
547
630
 
548
- void Init_rugged_reference()
631
+ void Init_rugged_reference(void)
549
632
  {
550
633
  rb_cRuggedReference = rb_define_class_under(rb_mRugged, "Reference", rb_cObject);
551
634
 
@@ -554,8 +637,11 @@ void Init_rugged_reference()
554
637
  rb_define_singleton_method(rb_cRuggedReference, "exists?", rb_git_ref_exist, 2);
555
638
  rb_define_singleton_method(rb_cRuggedReference, "create", rb_git_ref_create, -1);
556
639
  rb_define_singleton_method(rb_cRuggedReference, "each", rb_git_ref_each, -1);
640
+ rb_define_singleton_method(rb_cRuggedReference, "each_name", rb_git_ref_each_name, -1);
641
+ rb_define_singleton_method(rb_cRuggedReference, "valid_name?", rb_git_ref_valid_name, 1);
557
642
 
558
643
  rb_define_method(rb_cRuggedReference, "target", rb_git_ref_target, 0);
644
+ rb_define_method(rb_cRuggedReference, "peel", rb_git_ref_peel, 0);
559
645
  rb_define_method(rb_cRuggedReference, "set_target", rb_git_ref_set_target, 1);
560
646
 
561
647
  rb_define_method(rb_cRuggedReference, "type", rb_git_ref_type, 0);