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
@@ -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
@@ -40,29 +40,6 @@ VALUE rugged_ref_new(VALUE klass, VALUE owner, git_reference *ref)
40
40
  return rb_ref;
41
41
  }
42
42
 
43
- /*
44
- * call-seq:
45
- * Reference.pack_all(repository)
46
- *
47
- * Pack all the references in +repository+ into the +packed_refs+
48
- * file.
49
- */
50
- static VALUE rb_git_ref_packall(VALUE klass, VALUE rb_repo)
51
- {
52
- git_repository *repo;
53
- int error;
54
-
55
- if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo))
56
- rb_raise(rb_eTypeError, "Expecting a Rugged::Repository instance");
57
-
58
- Data_Get_Struct(rb_repo, git_repository, repo);
59
-
60
- error = git_reference_packall(repo);
61
- rugged_exception_check(error);
62
-
63
- return Qnil;
64
- }
65
-
66
43
  static int ref_foreach__block(const char *ref_name, void *opaque)
67
44
  {
68
45
  rb_funcall((VALUE)opaque, rb_intern("call"), 1, rugged_str_new2(ref_name, rb_utf8_encoding()));
@@ -71,11 +48,12 @@ static int ref_foreach__block(const char *ref_name, void *opaque)
71
48
 
72
49
  /*
73
50
  * call-seq:
74
- * Reference.each(repository, filter = :all) { |ref_name| block }
75
- * Reference.each(repository, filter = :all) -> Iterator
51
+ * Reference.each(repository, filter = :all, glob = nil) { |ref_name| block }
52
+ * Reference.each(repository, filter = :all, glob = nil) -> Iterator
76
53
  *
77
54
  * Iterate through all the references in +repository+. Iteration can be
78
- * optionally filtered to only +:direct+ or +:symbolic+ references.
55
+ * optionally filtered to only +:oid+ or +:symbolic+ references, or to
56
+ * the ones matching the given +glob+, a standard Unix filename glob.
79
57
  *
80
58
  * The given block will be called once with the name of each reference.
81
59
  * If no block is given, an iterator will be returned.
@@ -83,13 +61,13 @@ static int ref_foreach__block(const char *ref_name, void *opaque)
83
61
  static VALUE rb_git_ref_each(int argc, VALUE *argv, VALUE self)
84
62
  {
85
63
  git_repository *repo;
86
- int error, flags = 0;
87
- VALUE rb_repo, rb_list, rb_block;
64
+ int error, flags = GIT_REF_LISTALL;
65
+ VALUE rb_repo, rb_list, rb_glob, rb_block;
88
66
 
89
- rb_scan_args(argc, argv, "11&", &rb_repo, &rb_list, &rb_block);
67
+ rb_scan_args(argc, argv, "12&", &rb_repo, &rb_list, &rb_glob, &rb_block);
90
68
 
91
69
  if (!rb_block_given_p())
92
- return rb_funcall(self, rb_intern("to_enum"), 3, CSTR2SYM("each"), rb_repo, rb_list);
70
+ return rb_funcall(self, rb_intern("to_enum"), 4, CSTR2SYM("each"), rb_repo, rb_list, rb_glob);
93
71
 
94
72
  if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo))
95
73
  rb_raise(rb_eTypeError, "Expecting a Rugged::Repository instance");
@@ -104,15 +82,23 @@ static VALUE rb_git_ref_each(int argc, VALUE *argv, VALUE self)
104
82
 
105
83
  if (list == rb_intern("all"))
106
84
  flags = GIT_REF_LISTALL;
107
- else if (list == rb_intern("direct"))
108
- flags = GIT_REF_OID|GIT_REF_PACKED;
85
+ else if (list == rb_intern("oid"))
86
+ flags = GIT_REF_OID;
109
87
  else if (list == rb_intern("symbolic"))
110
- flags = GIT_REF_SYMBOLIC|GIT_REF_PACKED;
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
+ if (!NIL_P(rb_glob)) {
95
+ Check_Type(rb_glob, T_STRING);
96
+ error = git_reference_foreach_glob(repo,
97
+ StringValueCStr(rb_glob), flags, &ref_foreach__block, (void *)rb_block);
111
98
  } else {
112
- flags = GIT_REF_LISTALL;
99
+ error = git_reference_foreach(repo, flags, &ref_foreach__block, (void *)rb_block);
113
100
  }
114
101
 
115
- error = git_reference_foreach(repo, flags, &ref_foreach__block, (void *)rb_block);
116
102
  rugged_exception_check(error);
117
103
  return Qnil;
118
104
  }
@@ -159,12 +145,13 @@ static VALUE rb_git_ref_exist(VALUE klass, VALUE rb_repo, VALUE rb_name)
159
145
  Check_Type(rb_name, T_STRING);
160
146
 
161
147
  error = git_reference_lookup(&ref, repo, StringValueCStr(rb_name));
148
+ git_reference_free(ref);
149
+
162
150
  if (error == GIT_ENOTFOUND)
163
151
  return Qfalse;
164
152
  else
165
153
  rugged_exception_check(error);
166
154
 
167
- git_reference_free(ref);
168
155
  return Qtrue;
169
156
  }
170
157
 
@@ -198,15 +185,14 @@ static VALUE rb_git_ref_create(int argc, VALUE *argv, VALUE klass)
198
185
  force = rugged_parse_bool(rb_force);
199
186
 
200
187
  if (git_oid_fromstr(&oid, StringValueCStr(rb_target)) == GIT_OK) {
201
- error = git_reference_create_oid(
188
+ error = git_reference_create(
202
189
  &ref, repo, StringValueCStr(rb_name), &oid, force);
203
190
  } else {
204
- error = git_reference_create_symbolic(
205
- &ref, repo, StringValueCStr(rb_name), RSTRING_PTR(rb_target), force);
191
+ error = git_reference_symbolic_create(
192
+ &ref, repo, StringValueCStr(rb_name), StringValueCStr(rb_target), force);
206
193
  }
207
194
 
208
195
  rugged_exception_check(error);
209
-
210
196
  return rugged_ref_new(klass, rb_repo, ref);
211
197
  }
212
198
 
@@ -227,19 +213,18 @@ static VALUE rb_git_ref_create(int argc, VALUE *argv, VALUE klass)
227
213
  static VALUE rb_git_ref_target(VALUE self)
228
214
  {
229
215
  git_reference *ref;
230
-
231
- RUGGED_UNPACK_REFERENCE(self, ref);
216
+ Data_Get_Struct(self, git_reference, ref);
232
217
 
233
218
  if (git_reference_type(ref) == GIT_REF_OID) {
234
- return rugged_create_oid(git_reference_oid(ref));
219
+ return rugged_create_oid(git_reference_target(ref));
235
220
  } else {
236
- return rugged_str_new2(git_reference_target(ref), rb_utf8_encoding());
221
+ return rugged_str_new2(git_reference_symbolic_target(ref), rb_utf8_encoding());
237
222
  }
238
223
  }
239
224
 
240
225
  /*
241
226
  * call-seq:
242
- * reference.target = t
227
+ * reference.set_target(t) -> Reference
243
228
  *
244
229
  * Set the target of a reference. If +reference+ is a direct reference,
245
230
  * the new target must be a +String+ representing a SHA1 OID.
@@ -247,18 +232,22 @@ static VALUE rb_git_ref_target(VALUE self)
247
232
  * If +reference+ is symbolic, the new target must be a +String+ with
248
233
  * the name of another reference.
249
234
  *
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.
238
+ *
250
239
  * r1.type #=> :symbolic
251
- * r1.target = "refs/heads/master"
240
+ * r1.set_target("refs/heads/master") #=> <Reference>
252
241
  *
253
242
  * r2.type #=> :direct
254
- * r2.target = "de5ba987198bcf2518885f0fc1350e5172cded78"
243
+ * r2.set_target("de5ba987198bcf2518885f0fc1350e5172cded78") #=> <Reference>
255
244
  */
256
245
  static VALUE rb_git_ref_set_target(VALUE self, VALUE rb_target)
257
246
  {
258
- git_reference *ref;
247
+ git_reference *ref, *out;
259
248
  int error;
260
249
 
261
- RUGGED_UNPACK_REFERENCE(self, ref);
250
+ Data_Get_Struct(self, git_reference, ref);
262
251
  Check_Type(rb_target, T_STRING);
263
252
 
264
253
  if (git_reference_type(ref) == GIT_REF_OID) {
@@ -267,13 +256,13 @@ static VALUE rb_git_ref_set_target(VALUE self, VALUE rb_target)
267
256
  error = git_oid_fromstr(&target, StringValueCStr(rb_target));
268
257
  rugged_exception_check(error);
269
258
 
270
- error = git_reference_set_oid(ref, &target);
259
+ error = git_reference_set_target(&out, ref, &target);
271
260
  } else {
272
- error = git_reference_set_target(ref, StringValueCStr(rb_target));
261
+ error = git_reference_symbolic_set_target(&out, ref, StringValueCStr(rb_target));
273
262
  }
274
263
 
275
264
  rugged_exception_check(error);
276
- return Qnil;
265
+ return rugged_ref_new(rb_cRuggedReference, rugged_owner(self), out);
277
266
  }
278
267
 
279
268
  /*
@@ -285,7 +274,8 @@ static VALUE rb_git_ref_set_target(VALUE self, VALUE rb_target)
285
274
  static VALUE rb_git_ref_type(VALUE self)
286
275
  {
287
276
  git_reference *ref;
288
- RUGGED_UNPACK_REFERENCE(self, ref);
277
+ Data_Get_Struct(self, git_reference, ref);
278
+
289
279
  switch (git_reference_type(ref)) {
290
280
  case GIT_REF_OID:
291
281
  return CSTR2SYM("direct");
@@ -296,42 +286,6 @@ static VALUE rb_git_ref_type(VALUE self)
296
286
  }
297
287
  }
298
288
 
299
- /*
300
- * call-seq:
301
- * reference.packed? -> true or false
302
- *
303
- * Return whether the reference is packed or not
304
- */
305
- static VALUE rb_git_ref_packed(VALUE self)
306
- {
307
- git_reference *ref;
308
- RUGGED_UNPACK_REFERENCE(self, ref);
309
-
310
- return git_reference_is_packed(ref) ? Qtrue : Qfalse;
311
- }
312
-
313
- /*
314
- * call-seq:
315
- * reference.reload!
316
- *
317
- * Reload the reference from disk
318
- */
319
- static VALUE rb_git_ref_reload(VALUE self)
320
- {
321
- int error;
322
- git_reference *ref;
323
- RUGGED_UNPACK_REFERENCE(self, ref);
324
-
325
- error = git_reference_reload(ref);
326
-
327
- /* If reload fails, the reference is invalidated */
328
- if (error < GIT_OK)
329
- ref = NULL;
330
-
331
- rugged_exception_check(error);
332
- return Qnil;
333
- }
334
-
335
289
  /*
336
290
  * call-seq:
337
291
  * reference.name -> name
@@ -343,7 +297,7 @@ static VALUE rb_git_ref_reload(VALUE self)
343
297
  static VALUE rb_git_ref_name(VALUE self)
344
298
  {
345
299
  git_reference *ref;
346
- RUGGED_UNPACK_REFERENCE(self, ref);
300
+ Data_Get_Struct(self, git_reference, ref);
347
301
  return rugged_str_new2(git_reference_name(ref), rb_utf8_encoding());
348
302
  }
349
303
 
@@ -366,7 +320,7 @@ static VALUE rb_git_ref_resolve(VALUE self)
366
320
  git_reference *resolved;
367
321
  int error;
368
322
 
369
- RUGGED_UNPACK_REFERENCE(self, ref);
323
+ Data_Get_Struct(self, git_reference, ref);
370
324
 
371
325
  error = git_reference_resolve(&resolved, ref);
372
326
  rugged_exception_check(error);
@@ -381,67 +335,67 @@ static VALUE rb_git_ref_resolve(VALUE self)
381
335
  * Change the name of a reference. If +force+ is +true+, any previously
382
336
  * existing references will be overwritten when renaming.
383
337
  *
338
+ * Return a new reference object with the new object
339
+ *
384
340
  * reference.name #=> 'refs/heads/master'
385
- * reference.rename('refs/heads/development') #=> nil
386
- * reference.name #=> 'refs/heads/development'
341
+ * new_ref = reference.rename('refs/heads/development') #=> <Reference>
342
+ * new_ref.name #=> 'refs/heads/development'
387
343
  */
388
344
  static VALUE rb_git_ref_rename(int argc, VALUE *argv, VALUE self)
389
345
  {
390
- git_reference *ref;
346
+ git_reference *ref, *out;
391
347
  VALUE rb_name, rb_force;
392
348
  int error, force = 0;
393
349
 
394
- RUGGED_UNPACK_REFERENCE(self, ref);
350
+ Data_Get_Struct(self, git_reference, ref);
395
351
  rb_scan_args(argc, argv, "11", &rb_name, &rb_force);
396
352
 
397
353
  Check_Type(rb_name, T_STRING);
398
354
  if (!NIL_P(rb_force))
399
355
  force = rugged_parse_bool(rb_force);
400
356
 
401
- error = git_reference_rename(ref, StringValueCStr(rb_name), force);
357
+ error = git_reference_rename(&out, ref, StringValueCStr(rb_name), force);
402
358
  rugged_exception_check(error);
403
359
 
404
- return Qnil;
360
+ return rugged_ref_new(rb_cRuggedReference, rugged_owner(self), out);
405
361
  }
406
362
 
407
363
  /*
408
364
  * call-seq:
409
365
  * reference.delete!
410
366
  *
411
- * Delete this reference from disk. The +reference+ object will
412
- * become invalidated.
367
+ * Delete this reference from disk.
413
368
  *
414
369
  * reference.name #=> 'HEAD'
415
370
  * reference.delete!
416
- * reference.name # Exception raised
371
+ * # Reference no longer exists on disk
417
372
  */
418
373
  static VALUE rb_git_ref_delete(VALUE self)
419
374
  {
420
375
  git_reference *ref;
421
376
  int error;
422
377
 
423
- RUGGED_UNPACK_REFERENCE(self, ref);
378
+ Data_Get_Struct(self, git_reference, ref);
424
379
 
425
380
  error = git_reference_delete(ref);
426
381
  rugged_exception_check(error);
427
382
 
428
- DATA_PTR(self) = NULL; /* this reference has been free'd */
429
- rugged_set_owner(self, Qnil); /* and is no longer owned */
430
383
  return Qnil;
431
384
  }
432
385
 
433
386
  static VALUE reflog_entry_new(const git_reflog_entry *entry)
434
387
  {
435
388
  VALUE rb_entry = rb_hash_new();
389
+ const char *message;
436
390
 
437
391
  rb_hash_aset(rb_entry,
438
- CSTR2SYM("oid_old"),
439
- rugged_create_oid(git_reflog_entry_oidold(entry))
392
+ CSTR2SYM("id_old"),
393
+ rugged_create_oid(git_reflog_entry_id_old(entry))
440
394
  );
441
395
 
442
396
  rb_hash_aset(rb_entry,
443
- CSTR2SYM("oid_new"),
444
- rugged_create_oid(git_reflog_entry_oidnew(entry))
397
+ CSTR2SYM("id_new"),
398
+ rugged_create_oid(git_reflog_entry_id_new(entry))
445
399
  );
446
400
 
447
401
  rb_hash_aset(rb_entry,
@@ -449,10 +403,10 @@ static VALUE reflog_entry_new(const git_reflog_entry *entry)
449
403
  rugged_signature_new(git_reflog_entry_committer(entry), NULL)
450
404
  );
451
405
 
452
- if (git_reflog_entry_msg(entry) != NULL) {
406
+ if ((message = git_reflog_entry_message(entry)) != NULL) {
453
407
  rb_hash_aset(rb_entry,
454
408
  CSTR2SYM("message"),
455
- rugged_str_new2(git_reflog_entry_msg(entry), NULL)
409
+ rugged_str_new2(message, NULL)
456
410
  );
457
411
  }
458
412
 
@@ -467,15 +421,15 @@ static VALUE reflog_entry_new(const git_reflog_entry *entry)
467
421
  *
468
422
  * Each +reflog_entry+ is a hash with the following keys:
469
423
  *
470
- * - +:oid_old+: previous OID before the change
471
- * - +:oid_new+: OID after the change
424
+ * - +:id_old+: previous OID before the change
425
+ * - +:id_new+: OID after the change
472
426
  * - +:committer+: author of the change
473
427
  * - +:message+: message for the change
474
428
  *
475
429
  * reference.log #=> [
476
430
  * # {
477
- * # :oid_old => nil,
478
- * # :oid_new => '9d09060c850defbc7711d08b57def0d14e742f4e',
431
+ * # :id_old => nil,
432
+ * # :id_new => '9d09060c850defbc7711d08b57def0d14e742f4e',
479
433
  * # :committer => {:name => 'Vicent Marti', :email => {'vicent@github.com'}},
480
434
  * # :message => 'created reference'
481
435
  * # }, ... ]
@@ -486,9 +440,9 @@ static VALUE rb_git_reflog(VALUE self)
486
440
  git_reference *ref;
487
441
  int error;
488
442
  VALUE rb_log;
489
- unsigned int i, ref_count;
443
+ size_t i, ref_count;
490
444
 
491
- RUGGED_UNPACK_REFERENCE(self, ref);
445
+ Data_Get_Struct(self, git_reference, ref);
492
446
 
493
447
  error = git_reflog_read(&reflog, ref);
494
448
  rugged_exception_check(error);
@@ -498,7 +452,7 @@ static VALUE rb_git_reflog(VALUE self)
498
452
 
499
453
  for (i = 0; i < ref_count; ++i) {
500
454
  const git_reflog_entry *entry =
501
- git_reflog_entry_byindex(reflog, i);
455
+ git_reflog_entry_byindex(reflog, ref_count - i - 1);
502
456
 
503
457
  rb_ary_push(rb_log, reflog_entry_new(entry));
504
458
  }
@@ -507,6 +461,19 @@ static VALUE rb_git_reflog(VALUE self)
507
461
  return rb_log;
508
462
  }
509
463
 
464
+ /*
465
+ * call-seq:
466
+ * reference.log? -> Boolean
467
+ *
468
+ * Return whether a given reference has a reflog.
469
+ */
470
+ static VALUE rb_git_has_reflog(VALUE self)
471
+ {
472
+ git_reference *ref;
473
+ Data_Get_Struct(self, git_reference, ref);
474
+ return git_reference_has_log(ref) ? Qtrue : Qfalse;
475
+ }
476
+
510
477
  /*
511
478
  * call-seq:
512
479
  * reference.log!(committer, message = nil)
@@ -523,10 +490,8 @@ static VALUE rb_git_reflog_write(int argc, VALUE *argv, VALUE self)
523
490
 
524
491
  git_signature *committer;
525
492
  const char *message = NULL;
526
-
527
- git_oid oid;
528
493
 
529
- RUGGED_UNPACK_REFERENCE(self, ref);
494
+ Data_Get_Struct(self, git_reference, ref);
530
495
 
531
496
  rb_scan_args(argc, argv, "11", &rb_committer, &rb_message);
532
497
 
@@ -540,19 +505,45 @@ static VALUE rb_git_reflog_write(int argc, VALUE *argv, VALUE self)
540
505
 
541
506
  committer = rugged_signature_get(rb_committer);
542
507
 
543
- error = git_reflog_append(reflog, git_reference_oid(ref), committer, message);
544
- rugged_exception_check(error);
545
-
546
- error = git_reflog_write(reflog);
547
- rugged_exception_check(error);
508
+ if (!(error = git_reflog_append(reflog,
509
+ git_reference_target(ref),
510
+ committer,
511
+ message)))
512
+ error = git_reflog_write(reflog);
548
513
 
549
514
  git_reflog_free(reflog);
550
-
551
515
  git_signature_free(committer);
552
516
 
517
+ rugged_exception_check(error);
518
+
553
519
  return Qnil;
554
520
  }
555
521
 
522
+ /*
523
+ * call-seq:
524
+ * reference.branch? -> Boolean
525
+ *
526
+ * Return whether a given reference is a branch
527
+ */
528
+ static VALUE rb_git_ref_is_branch(VALUE self)
529
+ {
530
+ git_reference *ref;
531
+ Data_Get_Struct(self, git_reference, ref);
532
+ return git_reference_is_branch(ref) ? Qtrue : Qfalse;
533
+ }
534
+
535
+ /*
536
+ * call-seq:
537
+ * reference.remote? -> Boolean
538
+ *
539
+ * Return whether a given reference is a remote
540
+ */
541
+ static VALUE rb_git_ref_is_remote(VALUE self)
542
+ {
543
+ git_reference *ref;
544
+ Data_Get_Struct(self, git_reference, ref);
545
+ return git_reference_is_remote(ref) ? Qtrue : Qfalse;
546
+ }
556
547
 
557
548
  void Init_rugged_reference()
558
549
  {
@@ -562,22 +553,23 @@ void Init_rugged_reference()
562
553
  rb_define_singleton_method(rb_cRuggedReference, "exist?", rb_git_ref_exist, 2);
563
554
  rb_define_singleton_method(rb_cRuggedReference, "exists?", rb_git_ref_exist, 2);
564
555
  rb_define_singleton_method(rb_cRuggedReference, "create", rb_git_ref_create, -1);
565
- rb_define_singleton_method(rb_cRuggedReference, "pack_all", rb_git_ref_packall, 1);
566
556
  rb_define_singleton_method(rb_cRuggedReference, "each", rb_git_ref_each, -1);
567
557
 
568
558
  rb_define_method(rb_cRuggedReference, "target", rb_git_ref_target, 0);
569
- rb_define_method(rb_cRuggedReference, "target=", rb_git_ref_set_target, 1);
559
+ rb_define_method(rb_cRuggedReference, "set_target", rb_git_ref_set_target, 1);
570
560
 
571
561
  rb_define_method(rb_cRuggedReference, "type", rb_git_ref_type, 0);
572
562
 
573
563
  rb_define_method(rb_cRuggedReference, "name", rb_git_ref_name, 0);
574
564
  rb_define_method(rb_cRuggedReference, "rename", rb_git_ref_rename, -1);
575
565
 
576
- rb_define_method(rb_cRuggedReference, "reload!", rb_git_ref_reload, 0);
577
566
  rb_define_method(rb_cRuggedReference, "resolve", rb_git_ref_resolve, 0);
578
567
  rb_define_method(rb_cRuggedReference, "delete!", rb_git_ref_delete, 0);
579
568
 
580
- rb_define_method(rb_cRuggedReference, "packed?", rb_git_ref_packed, 0);
569
+ rb_define_method(rb_cRuggedReference, "branch?", rb_git_ref_is_branch, 0);
570
+ rb_define_method(rb_cRuggedReference, "remote?", rb_git_ref_is_remote, 0);
571
+
581
572
  rb_define_method(rb_cRuggedReference, "log", rb_git_reflog, 0);
573
+ rb_define_method(rb_cRuggedReference, "log?", rb_git_has_reflog, 0);
582
574
  rb_define_method(rb_cRuggedReference, "log!", rb_git_reflog_write, -1);
583
575
  }