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
@@ -172,8 +172,7 @@ static VALUE rb_git_blob_create(VALUE self, VALUE rb_repo, VALUE rb_buffer)
172
172
  git_repository *repo;
173
173
 
174
174
  Check_Type(rb_buffer, T_STRING);
175
- if (!rb_obj_is_instance_of(rb_repo, rb_cRuggedRepo))
176
- rb_raise(rb_eTypeError, "Expecting a Rugged Repository");
175
+ rugged_check_repo(rb_repo);
177
176
 
178
177
  Data_Get_Struct(rb_repo, git_repository, repo);
179
178
 
@@ -185,26 +184,25 @@ static VALUE rb_git_blob_create(VALUE self, VALUE rb_repo, VALUE rb_buffer)
185
184
 
186
185
  /*
187
186
  * call-seq:
188
- * Blob.write_file(repository, file_path) -> oid
187
+ * Blob.from_workdir(repository, file_path) -> oid
189
188
  *
190
189
  * Write the file specified in +file_path+ to a blob in +repository+.
191
190
  * +file_path+ must be relative to the repository's working folder.
192
191
  *
193
- * Blob.write_file(repo, 'src/blob.h') #=> '9d09060c850defbc7711d08b57def0d14e742f4e'
192
+ * Blob.from_workdir(repo, 'src/blob.h') #=> '9d09060c850defbc7711d08b57def0d14e742f4e'
194
193
  */
195
- static VALUE rb_git_blob_writefile(VALUE self, VALUE rb_repo, VALUE rb_path)
194
+ static VALUE rb_git_blob_from_workdir(VALUE self, VALUE rb_repo, VALUE rb_path)
196
195
  {
197
196
  int error;
198
197
  git_oid oid;
199
198
  git_repository *repo;
200
199
 
201
200
  Check_Type(rb_path, T_STRING);
202
- if (!rb_obj_is_instance_of(rb_repo, rb_cRuggedRepo))
203
- rb_raise(rb_eTypeError, "Expecting a Rugged Repository");
201
+ rugged_check_repo(rb_repo);
204
202
 
205
203
  Data_Get_Struct(rb_repo, git_repository, repo);
206
204
 
207
- error = git_blob_create_fromfile(&oid, repo, StringValueCStr(rb_path));
205
+ error = git_blob_create_fromworkdir(&oid, repo, StringValueCStr(rb_path));
208
206
  rugged_exception_check(error);
209
207
 
210
208
  return rugged_create_oid(&oid);
@@ -259,5 +257,5 @@ void Init_rugged_blob()
259
257
  rb_define_method(rb_cRuggedBlob, "sloc", rb_git_blob_sloc, 0);
260
258
 
261
259
  rb_define_singleton_method(rb_cRuggedBlob, "create", rb_git_blob_create, 2);
262
- rb_define_singleton_method(rb_cRuggedBlob, "write_file", rb_git_blob_writefile, 2);
260
+ rb_define_singleton_method(rb_cRuggedBlob, "from_workdir", rb_git_blob_from_workdir, 2);
263
261
  }
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * The MIT License
3
3
  *
4
- * Copyright (c) 2012 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
@@ -62,7 +62,7 @@ static int parse_branch_type(VALUE rb_filter)
62
62
  * +name+ needs to be a branch name, not an absolute reference path
63
63
  * (e.g. 'development' instead of '/refs/heads/development')
64
64
  *
65
- * +target+ needs to be an existing object (of any type) in the given +repository+.
65
+ * +target+ needs to be an existing commit in the given +repository+.
66
66
  *
67
67
  * If +force+ is +true+, any existing branches will be overwritten.
68
68
  *
@@ -71,7 +71,7 @@ static int parse_branch_type(VALUE rb_filter)
71
71
  static VALUE rb_git_branch_create(int argc, VALUE *argv, VALUE self)
72
72
  {
73
73
  git_reference *branch;
74
- git_object *target = NULL;
74
+ git_commit *target = NULL;
75
75
  git_repository *repo = NULL;
76
76
  int error, force = 0;
77
77
 
@@ -87,14 +87,14 @@ static VALUE rb_git_branch_create(int argc, VALUE *argv, VALUE self)
87
87
 
88
88
  Check_Type(rb_name, T_STRING);
89
89
 
90
- target = rugged_object_load(repo, rb_target, GIT_OBJ_ANY);
90
+ target = (git_commit *)rugged_object_get(repo, rb_target, GIT_OBJ_COMMIT);
91
91
 
92
92
  if (!NIL_P(rb_force)) {
93
93
  force = rugged_parse_bool(rb_force);
94
94
  }
95
95
 
96
96
  error = git_branch_create(&branch, repo, StringValueCStr(rb_name), target, force);
97
- git_object_free(target);
97
+ git_commit_free(target);
98
98
 
99
99
  rugged_exception_check(error);
100
100
 
@@ -142,7 +142,6 @@ static VALUE rb_git_branch_lookup(int argc, VALUE *argv, VALUE self)
142
142
  return Qnil;
143
143
 
144
144
  rugged_exception_check(error);
145
-
146
145
  return rugged_branch_new(rb_repo, branch);
147
146
  }
148
147
 
@@ -157,14 +156,12 @@ static VALUE rb_git_branch_delete(VALUE self)
157
156
  {
158
157
  git_reference *branch = NULL;
159
158
 
160
- RUGGED_UNPACK_REFERENCE(self, branch);
159
+ Data_Get_Struct(self, git_reference, branch);
161
160
 
162
161
  rugged_exception_check(
163
162
  git_branch_delete(branch)
164
163
  );
165
164
 
166
- DATA_PTR(self) = NULL; /* this reference has been free'd */
167
- rugged_set_owner(self, Qnil); /* and is no longer owned */
168
165
  return Qnil;
169
166
  }
170
167
 
@@ -188,7 +185,7 @@ static int cb_branch__each_obj(const char *branch_name, git_branch_t branch_type
188
185
  );
189
186
 
190
187
  rb_yield(rugged_branch_new(rb_repo, branch));
191
- return GIT_OK;
188
+ return 0;
192
189
  }
193
190
 
194
191
  static VALUE each_branch(int argc, VALUE *argv, VALUE self, int branch_names_only)
@@ -274,21 +271,21 @@ static VALUE rb_git_branch_each(int argc, VALUE *argv, VALUE self)
274
271
  static VALUE rb_git_branch_move(int argc, VALUE *argv, VALUE self)
275
272
  {
276
273
  VALUE rb_new_branch_name, rb_force;
277
- git_reference *old_branch = NULL;
274
+ git_reference *old_branch = NULL, *new_branch = NULL;
278
275
  int error, force = 0;
279
276
 
280
277
  rb_scan_args(argc, argv, "11", &rb_new_branch_name, &rb_force);
281
278
 
282
- RUGGED_UNPACK_REFERENCE(self, old_branch);
279
+ Data_Get_Struct(self, git_reference, old_branch);
283
280
  Check_Type(rb_new_branch_name, T_STRING);
284
281
 
285
282
  if (!NIL_P(rb_force))
286
283
  force = rugged_parse_bool(rb_force);
287
284
 
288
- error = git_branch_move(old_branch, StringValueCStr(rb_new_branch_name), force);
285
+ error = git_branch_move(&new_branch, old_branch, StringValueCStr(rb_new_branch_name), force);
289
286
  rugged_exception_check(error);
290
287
 
291
- return Qnil;
288
+ return rugged_branch_new(rugged_owner(self), new_branch);
292
289
  }
293
290
 
294
291
  void Init_rugged_branch()
@@ -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
@@ -159,23 +159,23 @@ static VALUE rb_git_commit_tree_GET(VALUE self)
159
159
 
160
160
  /*
161
161
  * call-seq:
162
- * commit.tree_oid -> oid
162
+ * commit.tree_id -> oid
163
163
  *
164
164
  * Return the tree oid pointed at by this +commit+. The tree is
165
165
  * returned as a String object.
166
166
  *
167
- * commit.tree #=> "f148106ca58764adc93ad4e2d6b1d168422b9796"
167
+ * commit.tree_id #=> "f148106ca58764adc93ad4e2d6b1d168422b9796"
168
168
  */
169
- static VALUE rb_git_commit_tree_oid_GET(VALUE self)
169
+ static VALUE rb_git_commit_tree_id_GET(VALUE self)
170
170
  {
171
171
  git_commit *commit;
172
- const git_oid *tree_oid;
172
+ const git_oid *tree_id;
173
173
 
174
174
  Data_Get_Struct(self, git_commit, commit);
175
175
 
176
- tree_oid = git_commit_tree_oid(commit);
176
+ tree_id = git_commit_tree_id(commit);
177
177
 
178
- return rugged_create_oid(tree_oid);
178
+ return rugged_create_oid(tree_id);
179
179
  }
180
180
 
181
181
  /*
@@ -214,19 +214,19 @@ static VALUE rb_git_commit_parents_GET(VALUE self)
214
214
 
215
215
  /*
216
216
  * call-seq:
217
- * commit.parent_oids -> [oid, ...]
217
+ * commit.parent_ids -> [oid, ...]
218
218
  *
219
219
  * Return the parent oid(s) of this commit as an array of oid String
220
220
  * objects. An array is always returned even when the commit has only
221
221
  * one or zero parents.
222
222
  *
223
- * commit.parent_oids #=> => ["2cb831a8aea28b2c1b9c63385585b864e4d3bad1", ...]
224
- * root.parent_oids #=> []
223
+ * commit.parent_ids #=> => ["2cb831a8aea28b2c1b9c63385585b864e4d3bad1", ...]
224
+ * root.parent_ids #=> []
225
225
  */
226
- static VALUE rb_git_commit_parent_oids_GET(VALUE self)
226
+ static VALUE rb_git_commit_parent_ids_GET(VALUE self)
227
227
  {
228
228
  git_commit *commit;
229
- const git_oid *parent_oid;
229
+ const git_oid *parent_id;
230
230
  unsigned int n, parent_count;
231
231
  VALUE ret_arr;
232
232
 
@@ -236,9 +236,9 @@ static VALUE rb_git_commit_parent_oids_GET(VALUE self)
236
236
  ret_arr = rb_ary_new2((long)parent_count);
237
237
 
238
238
  for (n = 0; n < parent_count; n++) {
239
- parent_oid = git_commit_parent_oid(commit, n);
240
- if (parent_oid) {
241
- rb_ary_push(ret_arr, rugged_create_oid(parent_oid));
239
+ parent_id = git_commit_parent_id(commit, n);
240
+ if (parent_id) {
241
+ rb_ary_push(ret_arr, rugged_create_oid(parent_id));
242
242
  }
243
243
  }
244
244
 
@@ -277,7 +277,8 @@ static VALUE rb_git_commit_parent_oids_GET(VALUE self)
277
277
  static VALUE rb_git_commit_create(VALUE self, VALUE rb_repo, VALUE rb_data)
278
278
  {
279
279
  VALUE rb_message, rb_tree, rb_parents, rb_ref;
280
- int parent_count, i, error;
280
+ VALUE rb_err_obj = Qnil;
281
+ int parent_count, i, error = 0;
281
282
  const git_commit **parents = NULL;
282
283
  git_commit **free_list = NULL;
283
284
  git_tree *tree;
@@ -313,10 +314,10 @@ static VALUE rb_git_commit_create(VALUE self, VALUE rb_repo, VALUE rb_data)
313
314
  Check_Type(rb_parents, T_ARRAY);
314
315
 
315
316
  rb_tree = rb_hash_aref(rb_data, CSTR2SYM("tree"));
316
- tree = (git_tree *)rugged_object_load(repo, rb_tree, GIT_OBJ_TREE);
317
+ tree = (git_tree *)rugged_object_get(repo, rb_tree, GIT_OBJ_TREE);
317
318
 
318
- parents = xmalloc(RARRAY_LEN(rb_parents) * sizeof(void *));
319
- free_list = xmalloc(RARRAY_LEN(rb_parents) * sizeof(void *));
319
+ parents = alloca(RARRAY_LEN(rb_parents) * sizeof(void *));
320
+ free_list = alloca(RARRAY_LEN(rb_parents) * sizeof(void *));
320
321
  parent_count = 0;
321
322
 
322
323
  for (i = 0; i < (int)RARRAY_LEN(rb_parents); ++i) {
@@ -343,7 +344,8 @@ static VALUE rb_git_commit_create(VALUE self, VALUE rb_repo, VALUE rb_data)
343
344
  } else if (rb_obj_is_kind_of(p, rb_cRuggedCommit)) {
344
345
  Data_Get_Struct(p, git_commit, parent);
345
346
  } else {
346
- rb_raise(rb_eTypeError, "Invalid type for parent object");
347
+ rb_err_obj = rb_exc_new2(rb_eTypeError, "Invalid type for parent object");
348
+ goto cleanup;
347
349
  }
348
350
 
349
351
  parents[parent_count] = parent;
@@ -372,8 +374,9 @@ cleanup:
372
374
  for (i = 0; i < parent_count; ++i)
373
375
  git_object_free((git_object *)free_list[i]);
374
376
 
375
- xfree(parents);
376
- xfree(free_list);
377
+ if (!NIL_P(rb_err_obj))
378
+ rb_exc_raise(rb_err_obj);
379
+
377
380
  rugged_exception_check(error);
378
381
 
379
382
  return rugged_create_oid(&commit_oid);
@@ -390,8 +393,12 @@ void Init_rugged_commit()
390
393
  rb_define_method(rb_cRuggedCommit, "committer", rb_git_commit_committer_GET, 0);
391
394
  rb_define_method(rb_cRuggedCommit, "author", rb_git_commit_author_GET, 0);
392
395
  rb_define_method(rb_cRuggedCommit, "tree", rb_git_commit_tree_GET, 0);
393
- rb_define_method(rb_cRuggedCommit, "tree_oid", rb_git_commit_tree_oid_GET, 0);
396
+
397
+ rb_define_method(rb_cRuggedCommit, "tree_id", rb_git_commit_tree_id_GET, 0);
398
+ rb_define_method(rb_cRuggedCommit, "tree_oid", rb_git_commit_tree_id_GET, 0);
399
+
394
400
  rb_define_method(rb_cRuggedCommit, "parents", rb_git_commit_parents_GET, 0);
395
- rb_define_method(rb_cRuggedCommit, "parent_oids", rb_git_commit_parent_oids_GET, 0);
401
+ rb_define_method(rb_cRuggedCommit, "parent_ids", rb_git_commit_parent_ids_GET, 0);
402
+ rb_define_method(rb_cRuggedCommit, "parent_oids", rb_git_commit_parent_ids_GET, 0);
396
403
  }
397
404
 
@@ -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
@@ -170,7 +170,7 @@ static VALUE rb_git_config_delete(VALUE self, VALUE rb_key)
170
170
  Data_Get_Struct(self, git_config, config);
171
171
  Check_Type(rb_key, T_STRING);
172
172
 
173
- error = git_config_delete(config, StringValueCStr(rb_key));
173
+ error = git_config_delete_entry(config, StringValueCStr(rb_key));
174
174
  if (error == GIT_ENOTFOUND)
175
175
  return Qfalse;
176
176
 
@@ -1,18 +1,18 @@
1
1
  /*
2
2
  * The MIT License
3
3
  *
4
- * Copyright (c) 2011 GitHub, Inc
5
- *
4
+ * Copyright (c) 2013 GitHub, Inc
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
8
8
  * in the Software without restriction, including without limitation the rights
9
9
  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
10
  * copies of the Software, and to permit persons to whom the Software is
11
11
  * furnished to do so, subject to the following conditions:
12
- *
12
+ *
13
13
  * The above copyright notice and this permission notice shall be included in
14
14
  * all copies or substantial portions of the Software.
15
- *
15
+ *
16
16
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
17
  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
18
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -28,14 +28,13 @@ extern VALUE rb_mRugged;
28
28
  VALUE rb_cRuggedIndex;
29
29
 
30
30
  static void rb_git_indexentry_toC(git_index_entry *entry, VALUE rb_entry);
31
- static VALUE rb_git_indexentry_fromC(git_index_entry *entry);
32
- static VALUE rb_git_unmerged_fromC(const git_index_entry_unmerged *entry);
31
+ static VALUE rb_git_indexentry_fromC(const git_index_entry *entry);
33
32
 
34
33
  /*
35
34
  * Index
36
35
  */
37
36
 
38
- void rb_git_index__free(git_index *index)
37
+ static void rb_git_index__free(git_index *index)
39
38
  {
40
39
  git_index_free(index);
41
40
  }
@@ -47,14 +46,20 @@ VALUE rugged_index_new(VALUE klass, VALUE owner, git_index *index)
47
46
  return rb_index;
48
47
  }
49
48
 
50
- static VALUE rb_git_index_new(VALUE klass, VALUE path)
49
+ static VALUE rb_git_index_new(int argc, VALUE *argv, VALUE klass)
51
50
  {
52
51
  git_index *index;
53
52
  int error;
54
53
 
55
- Check_Type(path, T_STRING);
54
+ VALUE rb_path;
55
+ const char *path = NULL;
56
+
57
+ if (rb_scan_args(argc, argv, "01", &rb_path) == 1) {
58
+ Check_Type(rb_path, T_STRING);
59
+ path = StringValueCStr(rb_path);
60
+ }
56
61
 
57
- error = git_index_open(&index, StringValueCStr(path));
62
+ error = git_index_open(&index, path);
58
63
  rugged_exception_check(error);
59
64
 
60
65
  return rugged_index_new(klass, Qnil, index);
@@ -90,15 +95,7 @@ static VALUE rb_git_index_write(VALUE self)
90
95
 
91
96
  error = git_index_write(index);
92
97
  rugged_exception_check(error);
93
-
94
- return Qnil;
95
- }
96
98
 
97
- static VALUE rb_git_index_uniq(VALUE self)
98
- {
99
- git_index *index;
100
- Data_Get_Struct(self, git_index, index);
101
- git_index_uniq(index);
102
99
  return Qnil;
103
100
  }
104
101
 
@@ -109,23 +106,41 @@ static VALUE rb_git_index_count(VALUE self)
109
106
  return INT2FIX(git_index_entrycount(index));
110
107
  }
111
108
 
112
- static VALUE rb_git_index_count_unmerged(VALUE self)
109
+ static VALUE rb_git_index_get(int argc, VALUE *argv, VALUE self)
113
110
  {
114
111
  git_index *index;
115
- Data_Get_Struct(self, git_index, index);
116
- return INT2FIX(git_index_entrycount_unmerged(index));
117
- }
112
+ const git_index_entry *entry = NULL;
113
+
114
+ VALUE rb_entry, rb_stage;
118
115
 
119
- static VALUE rb_git_index_get(VALUE self, VALUE entry)
120
- {
121
- git_index *index;
122
116
  Data_Get_Struct(self, git_index, index);
123
117
 
124
- if (TYPE(entry) == T_STRING)
125
- entry = INT2FIX(git_index_find(index, StringValueCStr(entry)));
118
+ rb_scan_args(argc, argv, "11", &rb_entry, &rb_stage);
119
+
120
+ if (TYPE(rb_entry) == T_STRING) {
121
+ int stage = 0;
122
+
123
+ if (!NIL_P(rb_stage)) {
124
+ Check_Type(rb_stage, T_FIXNUM);
125
+ stage = FIX2INT(rb_stage);
126
+ }
127
+
128
+ entry = git_index_get_bypath(index, StringValueCStr(rb_entry), stage);
129
+ }
130
+
131
+ else if (TYPE(rb_entry) == T_FIXNUM) {
132
+ if (argc > 1) {
133
+ rb_raise(rb_eArgError,
134
+ "Too many arguments when trying to lookup entry by index");
135
+ }
136
+
137
+ entry = git_index_get_byindex(index, FIX2INT(rb_entry));
138
+ } else {
139
+ rb_raise(rb_eArgError,
140
+ "Invalid type for `entry`: expected String or Fixnum");
141
+ }
126
142
 
127
- Check_Type(entry, T_FIXNUM);
128
- return rb_git_indexentry_fromC(git_index_get(index, FIX2INT(entry)));
143
+ return entry ? rb_git_indexentry_fromC(entry) : Qnil;
129
144
  }
130
145
 
131
146
  static VALUE rb_git_index_each(VALUE self)
@@ -138,9 +153,9 @@ static VALUE rb_git_index_each(VALUE self)
138
153
  if (!rb_block_given_p())
139
154
  return rb_funcall(self, rb_intern("to_enum"), 0);
140
155
 
141
- count = git_index_entrycount(index);
156
+ count = (unsigned int)git_index_entrycount(index);
142
157
  for (i = 0; i < count; ++i) {
143
- git_index_entry *entry = git_index_get(index, i);
158
+ const git_index_entry *entry = git_index_get_byindex(index, i);
144
159
  if (entry)
145
160
  rb_yield(rb_git_indexentry_fromC(entry));
146
161
  }
@@ -148,87 +163,47 @@ static VALUE rb_git_index_each(VALUE self)
148
163
  return Qnil;
149
164
  }
150
165
 
151
- static VALUE rb_git_index_get_unmerged(VALUE self, VALUE entry)
166
+ static VALUE rb_git_index_remove(int argc, VALUE *argv, VALUE self)
152
167
  {
153
168
  git_index *index;
154
- Data_Get_Struct(self, git_index, index);
155
-
156
- if (TYPE(entry) == T_STRING)
157
- return rb_git_unmerged_fromC(git_index_get_unmerged_bypath(index, StringValueCStr(entry)));
158
-
159
- if (TYPE(entry) == T_FIXNUM)
160
- return rb_git_unmerged_fromC(git_index_get_unmerged_byindex(index, FIX2INT(entry)));
169
+ int error, stage = 0;
161
170
 
162
- rb_raise(rb_eTypeError, "Expecting a path name or index for unmerged entries");
163
- }
171
+ VALUE rb_entry, rb_stage;
164
172
 
165
- static VALUE rb_git_index_remove(VALUE self, VALUE entry)
166
- {
167
- git_index *index;
168
- int error;
169
173
  Data_Get_Struct(self, git_index, index);
170
174
 
171
- if (TYPE(entry) == T_STRING)
172
- entry = INT2FIX(git_index_find(index, StringValueCStr(entry)));
175
+ if (rb_scan_args(argc, argv, "11", &rb_entry, &rb_stage) > 1) {
176
+ Check_Type(rb_stage, T_FIXNUM);
177
+ stage = FIX2INT(rb_stage);
178
+ }
179
+
180
+ Check_Type(rb_entry, T_STRING);
173
181
 
174
- Check_Type(entry, T_FIXNUM);
175
-
176
- error = git_index_remove(index, FIX2INT(entry));
182
+ error = git_index_remove(index, StringValueCStr(rb_entry), stage);
177
183
  rugged_exception_check(error);
178
184
 
179
185
  return Qnil;
180
186
  }
181
187
 
182
- static VALUE rb_git_index_add(int argc, VALUE *argv, VALUE self)
188
+ static VALUE rb_git_index_add(VALUE self, VALUE rb_entry)
183
189
  {
184
190
  git_index *index;
185
- int error;
186
- VALUE rb_entry, rb_stage;
187
-
188
- rb_scan_args(argc, argv, "11", &rb_entry, &rb_stage);
191
+ int error = 0;
189
192
 
190
193
  Data_Get_Struct(self, git_index, index);
191
194
 
192
195
  if (TYPE(rb_entry) == T_HASH) {
193
196
  git_index_entry entry;
194
- if (argc > 1)
195
- rb_raise(rb_eTypeError,
196
- "Wrong number or arguments (only an Index Entry is expected");
197
197
 
198
198
  rb_git_indexentry_toC(&entry, rb_entry);
199
- error = git_index_add2(index, &entry);
200
- } else if (TYPE(rb_entry) == T_STRING) {
201
- int stage = 0;
202
- if (!NIL_P(rb_stage))
203
- stage = NUM2INT(rb_stage);
204
- error = git_index_add(index, StringValueCStr(rb_entry), stage);
205
- } else {
206
- rb_raise(rb_eTypeError,
207
- "Expecting a hash defining an Index Entry or a path to a file in the repository");
199
+ error = git_index_add(index, &entry);
208
200
  }
209
201
 
210
- rugged_exception_check(error);
211
- return Qnil;
212
- }
213
-
214
- static VALUE rb_git_index_append(int argc, VALUE *argv, VALUE self)
215
- {
216
- git_index *index;
217
- int error;
218
- VALUE rb_entry, rb_stage;
219
-
220
- rb_scan_args(argc, argv, "11", &rb_entry, &rb_stage);
221
-
222
- Data_Get_Struct(self, git_index, index);
202
+ else if (TYPE(rb_entry) == T_STRING) {
203
+ error = git_index_add_bypath(index, StringValueCStr(rb_entry));
204
+ }
223
205
 
224
- if (TYPE(rb_entry) == T_HASH) {
225
- git_index_entry entry;
226
- rb_git_indexentry_toC(&entry, rb_entry);
227
- error = git_index_append2(index, &entry);
228
- } else if (TYPE(rb_entry) == T_STRING) {
229
- Check_Type(rb_stage, T_FIXNUM);
230
- error = git_index_append(index, StringValueCStr(rb_entry), FIX2INT(rb_stage));
231
- } else {
206
+ else {
232
207
  rb_raise(rb_eTypeError,
233
208
  "Expecting a hash defining an Index Entry or a path to a file in the repository");
234
209
  }
@@ -238,35 +213,7 @@ static VALUE rb_git_index_append(int argc, VALUE *argv, VALUE self)
238
213
  }
239
214
 
240
215
 
241
- /*
242
- * Index Entry
243
- */
244
- static VALUE rb_git_unmerged_fromC(const git_index_entry_unmerged *entry)
245
- {
246
- int i;
247
- VALUE rb_entry, rb_modes, rb_oids;
248
-
249
- if (!entry)
250
- return Qnil;
251
-
252
- rb_modes = rb_ary_new2(3);
253
- rb_oids = rb_ary_new2(3);
254
- for (i = 0; i < 3; ++i) {
255
- rb_ary_push(rb_modes, INT2FIX(entry->mode[i]));
256
- rb_ary_push(rb_oids, rugged_create_oid(&entry->oid[i]));
257
- }
258
-
259
- rb_entry = rb_hash_new();
260
- rb_hash_aset(rb_entry, CSTR2SYM("path"), rugged_str_new2(entry->path, NULL));
261
- rb_hash_aset(rb_entry, CSTR2SYM("oids"), rb_oids);
262
- rb_hash_aset(rb_entry, CSTR2SYM("modes"), rb_modes);
263
-
264
- return rb_entry;
265
- }
266
-
267
-
268
-
269
- static VALUE rb_git_indexentry_fromC(git_index_entry *entry)
216
+ static VALUE rb_git_indexentry_fromC(const git_index_entry *entry)
270
217
  {
271
218
  VALUE rb_entry, rb_mtime, rb_ctime;
272
219
  unsigned int valid, stage;
@@ -301,39 +248,59 @@ static VALUE rb_git_indexentry_fromC(git_index_entry *entry)
301
248
  return rb_entry;
302
249
  }
303
250
 
251
+ static inline unsigned int
252
+ default_entry_value(VALUE rb_entry, const char *key)
253
+ {
254
+ VALUE val = rb_hash_aref(rb_entry, CSTR2SYM(key));
255
+ if (NIL_P(val))
256
+ return 0;
257
+
258
+ Check_Type(val, T_FIXNUM);
259
+ return FIX2INT(val);
260
+ }
261
+
304
262
  static void rb_git_indexentry_toC(git_index_entry *entry, VALUE rb_entry)
305
263
  {
306
264
  VALUE val;
307
265
 
308
266
  Check_Type(rb_entry, T_HASH);
309
267
 
310
- #define GET_ENTRY_VAL(v, t) \
311
- rb_hash_aref(rb_entry, CSTR2SYM(v)); \
312
- Check_Type(val, t);
313
-
314
- val = GET_ENTRY_VAL("path", T_STRING);
268
+ val = rb_hash_aref(rb_entry, CSTR2SYM("path"));
269
+ Check_Type(val, T_STRING);
315
270
  entry->path = StringValueCStr(val);
316
271
 
317
- val = GET_ENTRY_VAL("oid", T_STRING);
318
- rugged_exception_check(git_oid_fromstr(&entry->oid, StringValueCStr(val)));
319
-
320
- val = GET_ENTRY_VAL("dev", T_FIXNUM);
321
- entry->dev = FIX2INT(val);
322
-
323
- val = GET_ENTRY_VAL("ino", T_FIXNUM);
324
- entry->ino = FIX2INT(val);
325
-
326
- val = GET_ENTRY_VAL("mode", T_FIXNUM);
327
- entry->mode = FIX2INT(val);
328
-
329
- val = GET_ENTRY_VAL("gid", T_FIXNUM);
330
- entry->gid = FIX2INT(val);
272
+ val = rb_hash_aref(rb_entry, CSTR2SYM("oid"));
273
+ Check_Type(val, T_STRING);
274
+ rugged_exception_check(
275
+ git_oid_fromstr(&entry->oid, StringValueCStr(val))
276
+ );
277
+
278
+ entry->dev = default_entry_value(rb_entry, "dev");
279
+ entry->ino = default_entry_value(rb_entry, "ino");
280
+ entry->mode = default_entry_value(rb_entry, "mode");
281
+ entry->gid = default_entry_value(rb_entry, "gid");
282
+ entry->uid = default_entry_value(rb_entry, "uid");
283
+ entry->file_size = (git_off_t)default_entry_value(rb_entry, "file_size");
284
+
285
+ if ((val = rb_hash_aref(rb_entry, CSTR2SYM("mtime"))) != Qnil) {
286
+ if (!rb_obj_is_kind_of(val, rb_cTime))
287
+ rb_raise(rb_eTypeError, ":mtime must be a Time instance");
288
+
289
+ entry->mtime.seconds = NUM2INT(rb_funcall(val, rb_intern("to_i"), 0));
290
+ entry->mtime.nanoseconds = NUM2INT(rb_funcall(val, rb_intern("usec"), 0)) * 1000;
291
+ } else {
292
+ entry->mtime.seconds = entry->mtime.nanoseconds = 0;
293
+ }
331
294
 
332
- val = GET_ENTRY_VAL("uid", T_FIXNUM);
333
- entry->uid = FIX2INT(val);
295
+ if ((val = rb_hash_aref(rb_entry, CSTR2SYM("ctime"))) != Qnil) {
296
+ if (!rb_obj_is_kind_of(val, rb_cTime))
297
+ rb_raise(rb_eTypeError, ":ctime must be a Time instance");
334
298
 
335
- val = GET_ENTRY_VAL("file_size", T_FIXNUM);
336
- entry->file_size = FIX2INT(val);
299
+ entry->ctime.seconds = NUM2INT(rb_funcall(val, rb_intern("to_i"), 0));
300
+ entry->ctime.nanoseconds = NUM2INT(rb_funcall(val, rb_intern("usec"), 0)) * 1000;
301
+ } else {
302
+ entry->ctime.seconds = entry->ctime.nanoseconds = 0;
303
+ }
337
304
 
338
305
  entry->flags = 0x0;
339
306
  entry->flags_extended = 0x0;
@@ -350,57 +317,31 @@ static void rb_git_indexentry_toC(git_index_entry *entry, VALUE rb_entry)
350
317
  entry->flags &= ~GIT_IDXENTRY_VALID;
351
318
  if (rugged_parse_bool(val))
352
319
  entry->flags |= GIT_IDXENTRY_VALID;
353
- } /* TODO: always valid by default? */
354
-
355
- val = rb_hash_aref(rb_entry, CSTR2SYM("mtime"));
356
- if (!rb_obj_is_kind_of(val, rb_cTime))
357
- rb_raise(rb_eTypeError, ":mtime must be a Time instance");
358
- entry->mtime.seconds = NUM2INT(rb_funcall(val, rb_intern("to_i"), 0));
359
- entry->mtime.nanoseconds = NUM2INT(rb_funcall(val, rb_intern("usec"), 0)) * 1000;
360
-
361
- val = rb_hash_aref(rb_entry, CSTR2SYM("ctime"));
362
- if (!rb_obj_is_kind_of(val, rb_cTime))
363
- rb_raise(rb_eTypeError, ":ctime must be a Time instance");
364
- entry->ctime.seconds = NUM2INT(rb_funcall(val, rb_intern("to_i"), 0));
365
- entry->ctime.nanoseconds = NUM2INT(rb_funcall(val, rb_intern("usec"), 0)) * 1000;
366
-
367
- #undef GET_ENTRY_VAL
368
- }
369
-
370
- VALUE rb_git_indexer(VALUE self, VALUE rb_packfile_path)
371
- {
372
- int error;
373
- git_indexer *indexer;
374
- VALUE rb_oid;
375
-
376
- Check_Type(rb_packfile_path, T_STRING);
377
-
378
- error = git_indexer_new(&indexer, StringValueCStr(rb_packfile_path));
379
- rugged_exception_check(error);
380
-
381
- error = git_indexer_run(indexer, NULL);
382
- rugged_exception_check(error);
383
-
384
- error = git_indexer_write(indexer);
385
- rugged_exception_check(error);
386
-
387
- rb_oid = rugged_create_oid(git_indexer_hash(indexer));
388
-
389
- git_indexer_free(indexer);
390
- return rb_oid;
320
+ } else {
321
+ entry->flags |= GIT_IDXENTRY_VALID;
322
+ }
391
323
  }
392
324
 
393
- VALUE rb_git_index_writetree(VALUE self)
325
+ static VALUE rb_git_index_writetree(int argc, VALUE *argv, VALUE self)
394
326
  {
395
327
  git_index *index;
396
328
  git_oid tree_oid;
397
329
  int error;
330
+ VALUE rb_repo;
398
331
 
399
332
  Data_Get_Struct(self, git_index, index);
400
333
 
401
- error = git_tree_create_fromindex(&tree_oid, index);
402
- rugged_exception_check(error);
334
+ if (rb_scan_args(argc, argv, "01", &rb_repo) == 1) {
335
+ git_repository *repo = NULL;
336
+ rugged_check_repo(rb_repo);
337
+ Data_Get_Struct(rb_repo, git_repository, repo);
338
+ error = git_index_write_tree_to(&tree_oid, index, repo);
339
+ }
340
+ else {
341
+ error = git_index_write_tree(&tree_oid, index);
342
+ }
403
343
 
344
+ rugged_exception_check(error);
404
345
  return rugged_create_oid(&tree_oid);
405
346
  }
406
347
 
@@ -413,7 +354,7 @@ VALUE rb_git_index_writetree(VALUE self)
413
354
  * Further index operations (+add+, +update+, +remove+, etc) will
414
355
  * be considered changes on top of +tree+.
415
356
  */
416
- VALUE rb_git_index_readtree(VALUE self, VALUE rb_tree)
357
+ static VALUE rb_git_index_readtree(VALUE self, VALUE rb_tree)
417
358
  {
418
359
  git_index *index;
419
360
  git_tree *tree;
@@ -422,7 +363,7 @@ VALUE rb_git_index_readtree(VALUE self, VALUE rb_tree)
422
363
  Data_Get_Struct(self, git_index, index);
423
364
  Data_Get_Struct(rb_tree, git_tree, tree);
424
365
 
425
- error = git_index_read_tree(index, tree, NULL);
366
+ error = git_index_read_tree(index, tree);
426
367
  rugged_exception_check(error);
427
368
 
428
369
  return Qnil;
@@ -431,34 +372,28 @@ VALUE rb_git_index_readtree(VALUE self, VALUE rb_tree)
431
372
  void Init_rugged_index()
432
373
  {
433
374
  /*
434
- * Index
375
+ * Index
435
376
  */
436
377
  rb_cRuggedIndex = rb_define_class_under(rb_mRugged, "Index", rb_cObject);
437
- rb_define_singleton_method(rb_cRuggedIndex, "new", rb_git_index_new, 1);
378
+ rb_define_singleton_method(rb_cRuggedIndex, "new", rb_git_index_new, -1);
438
379
 
439
380
  rb_define_method(rb_cRuggedIndex, "count", rb_git_index_count, 0);
440
- rb_define_method(rb_cRuggedIndex, "count_unmerged", rb_git_index_count_unmerged, 0);
441
381
  rb_define_method(rb_cRuggedIndex, "reload", rb_git_index_read, 0);
442
382
  rb_define_method(rb_cRuggedIndex, "clear", rb_git_index_clear, 0);
443
383
  rb_define_method(rb_cRuggedIndex, "write", rb_git_index_write, 0);
444
- rb_define_method(rb_cRuggedIndex, "uniq!", rb_git_index_uniq, 0);
445
- rb_define_method(rb_cRuggedIndex, "get_entry", rb_git_index_get, 1);
446
- rb_define_method(rb_cRuggedIndex, "get_unmerged", rb_git_index_get_unmerged, 1);
447
- rb_define_method(rb_cRuggedIndex, "[]", rb_git_index_get, 1);
384
+ rb_define_method(rb_cRuggedIndex, "get", rb_git_index_get, -1);
385
+ rb_define_method(rb_cRuggedIndex, "[]", rb_git_index_get, -1);
448
386
  rb_define_method(rb_cRuggedIndex, "each", rb_git_index_each, 0);
449
387
 
450
- rb_define_method(rb_cRuggedIndex, "add", rb_git_index_add, -1);
451
- rb_define_method(rb_cRuggedIndex, "update", rb_git_index_add, -1);
388
+ rb_define_method(rb_cRuggedIndex, "add", rb_git_index_add, 1);
389
+ rb_define_method(rb_cRuggedIndex, "update", rb_git_index_add, 1);
390
+ rb_define_method(rb_cRuggedIndex, "<<", rb_git_index_add, 1);
452
391
 
453
- rb_define_method(rb_cRuggedIndex, "append", rb_git_index_append, -1);
454
- rb_define_method(rb_cRuggedIndex, "<<", rb_git_index_append, -1);
392
+ rb_define_method(rb_cRuggedIndex, "remove", rb_git_index_remove, -1);
455
393
 
456
- rb_define_method(rb_cRuggedIndex, "remove", rb_git_index_remove, 1);
457
- rb_define_method(rb_cRuggedIndex, "write_tree", rb_git_index_writetree, 0);
394
+ rb_define_method(rb_cRuggedIndex, "write_tree", rb_git_index_writetree, -1);
458
395
  rb_define_method(rb_cRuggedIndex, "read_tree", rb_git_index_readtree, 1);
459
396
 
460
- rb_define_singleton_method(rb_cRuggedIndex, "index_pack", rb_git_indexer, 1);
461
-
462
397
  rb_const_set(rb_cRuggedIndex, rb_intern("ENTRY_FLAGS_STAGE"), INT2FIX(GIT_IDXENTRY_STAGEMASK));
463
398
  rb_const_set(rb_cRuggedIndex, rb_intern("ENTRY_FLAGS_STAGE_SHIFT"), INT2FIX(GIT_IDXENTRY_STAGESHIFT));
464
399
  rb_const_set(rb_cRuggedIndex, rb_intern("ENTRY_FLAGS_VALID"), INT2FIX(GIT_IDXENTRY_VALID));