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
data/README.md CHANGED
@@ -17,6 +17,12 @@ Rugged is a self-contained gem. You can install it by running:
17
17
 
18
18
  $ gem install rugged
19
19
 
20
+ If you're using bundler and want to bundle libgit2 with rugged, you can use the `:submodules` option:
21
+
22
+ ```ruby
23
+ gem 'rugged', git: 'git://github.com/libgit2/rugged.git', branch: 'development', submodules: true
24
+ ```
25
+
20
26
  To load Rugged, you'll usually want to add something like this:
21
27
 
22
28
  ```ruby
@@ -34,17 +40,16 @@ at each area individually.
34
40
  #### Instantiation
35
41
 
36
42
  The repository is naturally central to Git. Rugged has a `Repository` class that
37
- you can instantiate with a path:
43
+ you can instantiate with a path to open an existing repository :
38
44
 
39
45
  ```ruby
40
46
  repo = Rugged::Repository.new('path/to/my/repository')
41
47
  # => #<Rugged::Repository:2228536260 {path: "path/to/my/repository/.git/"}>
42
48
  ```
43
49
 
44
- If you're working against a bare repository, you'll need to indicate that:
50
+ You can create a new repository with `init_at`. Add a second parameter `:bare` to make a bare repository:
45
51
 
46
52
  ```ruby
47
- # Second parameter indicates whether the repo is a bare repository
48
53
  Rugged::Repository.init_at('.', :bare)
49
54
  ```
50
55
 
@@ -171,7 +176,7 @@ commit.tree
171
176
  # => #<Rugged::Tree:2245269740>
172
177
 
173
178
  commit.parents
174
- => [#<Rugged::Commit:2245264600 {message: "Merge pull request #47 from isaac/remotes\n\nAdd Rugged::Repository#remotes", tree: #<Rugged::Tree:2245264240 {oid: 6a2aee58a41fa007d07aa55565e2231f9b39b4a9}>
179
+ # => [#<Rugged::Commit:2245264600 {message: "Merge pull request #47 from isaac/remotes\n\nAdd Rugged::Repository#remotes", tree: #<Rugged::Tree:2245264240 {oid: 6a2aee58a41fa007d07aa55565e2231f9b39b4a9}>]
175
180
  ```
176
181
 
177
182
  You can also write new objects to the database this way:
data/Rakefile CHANGED
@@ -30,7 +30,7 @@ Rake::Task[:clean].prerequisites << :embedded_clean
30
30
 
31
31
  desc "Open an irb session preloaded with Rugged"
32
32
  task :console do
33
- sh "irb -rubygems -I lib -r ./lib/rugged"
33
+ exec "script/console"
34
34
  end
35
35
 
36
36
  #
@@ -1,5 +1,15 @@
1
1
  require 'mkmf'
2
2
 
3
+ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
4
+
5
+ $CFLAGS << " #{ENV["CFLAGS"]}"
6
+ $CFLAGS << " -g"
7
+
8
+ if RbConfig::MAKEFILE_CONFIG['CC'] =~ /gcc|clang/
9
+ $CFLAGS << " -O3" unless $CFLAGS[/-O\d/]
10
+ $CFLAGS << " -Wall"
11
+ end
12
+
3
13
  def sys(cmd)
4
14
  puts " -- #{cmd}"
5
15
  unless ret = xsystem(cmd)
data/ext/rugged/rugged.c CHANGED
@@ -25,21 +25,28 @@
25
25
  #include "rugged.h"
26
26
 
27
27
  const char *RUGGED_ERROR_NAMES[] = {
28
- "NoMemError", /* GITERR_NOMEMORY, */
29
- "OSError", /* GITERR_OS, */
30
- "InvalidError", /* GITERR_INVALID, */
31
- "ReferenceError", /* GITERR_REFERENCE, */
32
- "ZlibError", /* GITERR_ZLIB, */
28
+ "NoMemError", /* GITERR_NOMEMORY, */
29
+ "OSError", /* GITERR_OS, */
30
+ "InvalidError", /* GITERR_INVALID, */
31
+ "ReferenceError", /* GITERR_REFERENCE, */
32
+ "ZlibError", /* GITERR_ZLIB, */
33
33
  "RepositoryError", /* GITERR_REPOSITORY, */
34
- "ConfigError", /* GITERR_CONFIG, */
35
- "RegexError", /* GITERR_REGEX, */
36
- "OdbError", /* GITERR_ODB, */
37
- "IndexError", /* GITERR_INDEX, */
38
- "ObjectError", /* GITERR_OBJECT, */
39
- "NetworkError", /* GITERR_NET, */
40
- "TagError", /* GITERR_TAG, */
41
- "TreeError", /* GITERR_TREE, */
42
- "IndexerError", /* GITERR_INDEXER, */
34
+ "ConfigError", /* GITERR_CONFIG, */
35
+ "RegexError", /* GITERR_REGEX, */
36
+ "OdbError", /* GITERR_ODB, */
37
+ "IndexError", /* GITERR_INDEX, */
38
+ "ObjectError", /* GITERR_OBJECT, */
39
+ "NetworkError", /* GITERR_NET, */
40
+ "TagError", /* GITERR_TAG, */
41
+ "TreeError", /* GITERR_TREE, */
42
+ "IndexerError", /* GITERR_INDEXER, */
43
+ "SslError", /* GITERR_SSL, */
44
+ "SubmoduleError", /* GITERR_SUBMODULE, */
45
+ "ThreadError", /* GITERR_THREAD, */
46
+ "StashError", /* GITERR_STASH, */
47
+ "CheckoutError", /* GITERR_CHECKOUT, */
48
+ "FetchheadError", /* GITERR_FETCHHEAD, */
49
+ "MergeError", /* GITERR_MERGE, */
43
50
  };
44
51
 
45
52
  #define RUGGED_ERROR_COUNT (int)((sizeof(RUGGED_ERROR_NAMES)/sizeof(RUGGED_ERROR_NAMES[0])))
@@ -51,15 +58,14 @@ VALUE rb_eRuggedErrors[RUGGED_ERROR_COUNT];
51
58
  static VALUE rb_mShutdownHook;
52
59
 
53
60
  /*
54
- * call-seq:
55
- * Rugged.libgit2_version -> version
61
+ * call-seq:
62
+ * Rugged.libgit2_version -> version
56
63
  *
57
- * Returns an array representing the current libgit2 version in use. Using
58
- * the array makes it easier for the end-user to take conditional actions
59
- * based on each respective version attribute: major, minor, rev.
64
+ * Returns an array representing the current libgit2 version in use. Using
65
+ * the array makes it easier for the end-user to take conditional actions
66
+ * based on each respective version attribute: major, minor, rev.
60
67
  *
61
- * Rugged.libgit2_version
62
- * #=> [0, 17, 0]
68
+ * Rugged.libgit2_version #=> [0, 17, 0]
63
69
  */
64
70
  static VALUE rb_git_libgit2_version(VALUE self)
65
71
  {
@@ -70,22 +76,21 @@ static VALUE rb_git_libgit2_version(VALUE self)
70
76
  git_libgit2_version(&major, &minor, &rev);
71
77
 
72
78
  // We return an array of three elements to represent the version components
73
- return rb_ary_new3(3, INT2NUM(major), INT2NUM(minor), INT2NUM(rev));
79
+ return rb_ary_new3(3, INT2NUM(major), INT2NUM(minor), INT2NUM(rev));
74
80
  }
75
81
 
76
82
  /*
77
- * call-seq:
78
- * Rugged.capabilities-> capabilities
83
+ * call-seq:
84
+ * Rugged.capabilities -> capabilities
79
85
  *
80
- * Returns an array representing the 'capabilities' that libgit2 was compiled
81
- * with — this includes GIT_CAP_THREADS (thread support) and GIT_CAP_HTTPS (https).
82
- * This is implemented in libgit2 with simple bitwise ops; we offer Rubyland an array
83
- * of symbols representing the capabilities.
86
+ * Returns an array representing the 'capabilities' that libgit2 was compiled
87
+ * with — this includes GIT_CAP_THREADS (thread support) and GIT_CAP_HTTPS (https).
88
+ * This is implemented in libgit2 with simple bitwise ops; we offer Rubyland an array
89
+ * of symbols representing the capabilities.
84
90
  *
85
- * The possible capabilities are "threads" and "https".
91
+ * The possible capabilities are "threads" and "https".
86
92
  *
87
- * Rugged.capabilities
88
- * #=> [:threads, :https]
93
+ * Rugged.capabilities #=> [:threads, :https]
89
94
  */
90
95
  static VALUE rb_git_capabilities(VALUE self)
91
96
  {
@@ -103,14 +108,14 @@ static VALUE rb_git_capabilities(VALUE self)
103
108
  }
104
109
 
105
110
  /*
106
- * call-seq:
107
- * Rugged.hex_to_raw(oid) -> raw_buffer
111
+ * call-seq:
112
+ * Rugged.hex_to_raw(oid) -> raw_buffer
108
113
  *
109
- * Turn a string of 40 hexadecimal characters into the buffer of
110
- * 20 bytes it represents.
114
+ * Turn a string of 40 hexadecimal characters into the buffer of
115
+ * 20 bytes it represents.
111
116
  *
112
- * Rugged.hex_to_raw('d8786bfc97485e8d7b19b21fb88c8ef1f199fc3f')
113
- * #=> "\330xk\374\227H^\215{\031\262\037\270\214\216\361\361\231\374?"
117
+ * Rugged.hex_to_raw('d8786bfc97485e8d7b19b21fb88c8ef1f199fc3f')
118
+ * #=> "\330xk\374\227H^\215{\031\262\037\270\214\216\361\361\231\374?"
114
119
  */
115
120
  static VALUE rb_git_hex_to_raw(VALUE self, VALUE hex)
116
121
  {
@@ -119,18 +124,18 @@ static VALUE rb_git_hex_to_raw(VALUE self, VALUE hex)
119
124
  Check_Type(hex, T_STRING);
120
125
  rugged_exception_check(git_oid_fromstr(&oid, StringValueCStr(hex)));
121
126
 
122
- return rugged_str_ascii((const char *)oid.id, 20);
127
+ return rb_str_new((const char *)oid.id, 20);
123
128
  }
124
129
 
125
130
  /*
126
- * call-seq:
127
- * Rugged.raw_to_hex(buffer) -> hex_oid
131
+ * call-seq:
132
+ * Rugged.raw_to_hex(buffer) -> hex_oid
128
133
  *
129
- * Turn a buffer of 20 bytes (representing a SHA1 OID) into its
130
- * readable hexadecimal representation.
134
+ * Turn a buffer of 20 bytes (representing a SHA1 OID) into its
135
+ * readable hexadecimal representation.
131
136
  *
132
- * Rugged.raw_to_hex("\330xk\374\227H^\215{\031\262\037\270\214\216\361\361\231\374?")
133
- * #=> "d8786bfc97485e8d7b19b21fb88c8ef1f199fc3f"
137
+ * Rugged.raw_to_hex("\330xk\374\227H^\215{\031\262\037\270\214\216\361\361\231\374?")
138
+ * #=> "d8786bfc97485e8d7b19b21fb88c8ef1f199fc3f"
134
139
  */
135
140
  static VALUE rb_git_raw_to_hex(VALUE self, VALUE raw)
136
141
  {
@@ -145,15 +150,15 @@ static VALUE rb_git_raw_to_hex(VALUE self, VALUE raw)
145
150
  git_oid_fromraw(&oid, (const unsigned char *)RSTRING_PTR(raw));
146
151
  git_oid_fmt(out, &oid);
147
152
 
148
- return rugged_str_new(out, 40, NULL);
153
+ return rb_str_new(out, 40);
149
154
  }
150
155
 
151
156
  /*
152
- * call-seq:
153
- * Rugged.prettify_message(message, strip_comments) -> clean_message
157
+ * call-seq:
158
+ * Rugged.prettify_message(message, strip_comments) -> clean_message
154
159
  *
155
- * Process a commit or tag message into standard form, by stripping trailing spaces and
156
- * comments, and making sure that the message has a proper header line.
160
+ * Process a commit or tag message into standard form, by stripping trailing spaces and
161
+ * comments, and making sure that the message has a proper header line.
157
162
  */
158
163
  static VALUE rb_git_prettify_message(VALUE self, VALUE rb_message, VALUE rb_strip_comments)
159
164
  {
@@ -170,7 +175,7 @@ static VALUE rb_git_prettify_message(VALUE self, VALUE rb_message, VALUE rb_stri
170
175
  message_len = git_message_prettify(message, message_len, StringValueCStr(rb_message), strip_comments);
171
176
  rugged_exception_check(message_len);
172
177
 
173
- result = rugged_str_new(message, message_len - 1, rb_utf8_encoding());
178
+ result = rb_enc_str_new(message, message_len - 1, rb_utf8_encoding());
174
179
  xfree(message);
175
180
 
176
181
  return result;
@@ -191,45 +196,45 @@ static VALUE minimize_yield(VALUE rb_oid, VALUE *data)
191
196
  }
192
197
 
193
198
  /*
194
- * call-seq:
195
- * Rugged.minimize_oid(oid_iterator, min_length = 7) { |short_oid| block }
196
- * Rugged.minimize_oid(oid_iterator, min_length = 7) -> min_length
199
+ * call-seq:
200
+ * Rugged.minimize_oid(oid_iterator, min_length = 7) { |short_oid| block }
201
+ * Rugged.minimize_oid(oid_iterator, min_length = 7) -> min_length
197
202
  *
198
- * Iterate through +oid_iterator+, which should yield any number of SHA1 OIDs
199
- * (represented as 40-character hexadecimal strings), and tries to minify them.
203
+ * Iterate through +oid_iterator+, which should yield any number of SHA1 OIDs
204
+ * (represented as 40-character hexadecimal strings), and tries to minify them.
200
205
  *
201
- * Minifying a set of a SHA1 strings means finding the shortest root substring
202
- * for each string that uniquely identifies it.
206
+ * Minifying a set of a SHA1 strings means finding the shortest root substring
207
+ * for each string that uniquely identifies it.
203
208
  *
204
- * If no +block+ is given, the function will return the minimal length as an
205
- * integer value:
209
+ * If no +block+ is given, the function will return the minimal length as an
210
+ * integer value:
206
211
  *
207
- * oids = [
208
- * 'd8786bfc974aaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
209
- * 'd8786bfc974bbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
210
- * 'd8786bfc974ccccccccccccccccccccccccccccc',
211
- * '68d041ee999cb07c6496fbdd4f384095de6ca9e1',
212
- * ]
212
+ * oids = [
213
+ * 'd8786bfc974aaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
214
+ * 'd8786bfc974bbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
215
+ * 'd8786bfc974ccccccccccccccccccccccccccccc',
216
+ * '68d041ee999cb07c6496fbdd4f384095de6ca9e1',
217
+ * ]
213
218
  *
214
- * Rugged.minimize_oids(oids) #=> 12
219
+ * Rugged.minimize_oids(oids) #=> 12
215
220
  *
216
- * If a +block+ is given, it will be called with each OID from +iterator+
217
- * in its minified form:
221
+ * If a +block+ is given, it will be called with each OID from +iterator+
222
+ * in its minified form:
218
223
  *
219
- * Rugged.minimize_oids(oids) { |oid| puts oid }
224
+ * Rugged.minimize_oid(oids) { |oid| puts oid }
220
225
  *
221
- * produces:
226
+ * produces:
222
227
  *
223
- * d8786bfc974a
224
- * d8786bfc974b
225
- * d8786bfc974c
226
- * 68d041ee999c
228
+ * d8786bfc974a
229
+ * d8786bfc974b
230
+ * d8786bfc974c
231
+ * 68d041ee999c
227
232
  *
228
- * The optional +min_length+ argument allows you to specify a lower bound for
229
- * the minified strings; returned strings won't be shorter than the given value,
230
- * even if they would still be uniquely represented.
233
+ * The optional +min_length+ argument allows you to specify a lower bound for
234
+ * the minified strings; returned strings won't be shorter than the given value,
235
+ * even if they would still be uniquely represented.
231
236
  *
232
- * Rugged.minimize_oids(oids, 18) #=> 18
237
+ * Rugged.minimize_oid(oids, 18) #=> 18
233
238
  */
234
239
  static VALUE rb_git_minimize_oid(int argc, VALUE *argv, VALUE self)
235
240
  {
@@ -251,20 +256,20 @@ static VALUE rb_git_minimize_oid(int argc, VALUE *argv, VALUE self)
251
256
 
252
257
  rb_iterate(rb_each, rb_enum, &minimize_cb, (VALUE)shrt);
253
258
  length = git_oid_shorten_add(shrt, NULL);
259
+
260
+ git_oid_shorten_free(shrt);
254
261
  rugged_exception_check(length);
255
262
 
256
- if (RTEST(rb_block)) {
263
+ if (!NIL_P(rb_block)) {
257
264
  VALUE yield_data[2];
258
265
 
259
266
  yield_data[0] = rb_block;
260
267
  yield_data[1] = INT2FIX(length);
261
268
 
262
269
  rb_iterate(rb_each, rb_enum, &minimize_yield, (VALUE)yield_data);
263
- git_oid_shorten_free(shrt);
264
270
  return Qnil;
265
271
  }
266
272
 
267
- git_oid_shorten_free(shrt);
268
273
  return INT2FIX(length);
269
274
  }
270
275
 
@@ -274,10 +279,9 @@ static void cleanup_cb(void *unused)
274
279
  git_threads_shutdown();
275
280
  }
276
281
 
277
- void rugged_exception_raise(int errorcode)
282
+ void rugged_exception_raise(void)
278
283
  {
279
- VALUE err_klass = rb_eRuggedError;
280
- VALUE err_obj;
284
+ VALUE err_klass, err_obj;
281
285
  const git_error *error;
282
286
  const char *err_message;
283
287
 
@@ -296,7 +300,64 @@ void rugged_exception_raise(int errorcode)
296
300
  rb_exc_raise(err_obj);
297
301
  }
298
302
 
299
- void Init_rugged()
303
+ /*
304
+ * call-seq:
305
+ * Rugged.__cache_usage__ -> [current, max]
306
+ *
307
+ * Returns an array representing the current bytes in the internal
308
+ * libgit2 cache and the maximum size of the cache.
309
+ */
310
+ static VALUE rb_git_cache_usage(VALUE self)
311
+ {
312
+ int64_t used, max;
313
+ git_libgit2_opts(GIT_OPT_GET_CACHED_MEMORY, &used, &max);
314
+ return rb_ary_new3(2, LL2NUM(used), LL2NUM(max));
315
+ }
316
+
317
+ VALUE rugged_strarray_to_rb_ary(git_strarray *str_array)
318
+ {
319
+ VALUE rb_array = rb_ary_new2(str_array->count);
320
+ size_t i;
321
+
322
+ for (i = 0; i < str_array->count; ++i) {
323
+ rb_ary_push(rb_array, rb_str_new_utf8(str_array->strings[i]));
324
+ }
325
+
326
+ return rb_array;
327
+ }
328
+
329
+ void rugged_rb_ary_to_strarray(VALUE rb_array, git_strarray *str_array)
330
+ {
331
+ int i;
332
+
333
+ str_array->strings = NULL;
334
+ str_array->count = 0;
335
+
336
+ if (NIL_P(rb_array))
337
+ return;
338
+
339
+ if (TYPE(rb_array) == T_STRING) {
340
+ str_array->count = 1;
341
+ str_array->strings = xmalloc(sizeof(char *));
342
+ str_array->strings[0] = StringValueCStr(rb_array);
343
+ return;
344
+ }
345
+
346
+ Check_Type(rb_array, T_ARRAY);
347
+
348
+ for (i = 0; i < RARRAY_LEN(rb_array); ++i)
349
+ Check_Type(rb_ary_entry(rb_array, i), T_STRING);
350
+
351
+ str_array->count = RARRAY_LEN(rb_array);
352
+ str_array->strings = xmalloc(str_array->count * sizeof(char *));
353
+
354
+ for (i = 0; i < RARRAY_LEN(rb_array); ++i) {
355
+ VALUE rb_string = rb_ary_entry(rb_array, i);
356
+ str_array->strings[i] = StringValueCStr(rb_string);
357
+ }
358
+ }
359
+
360
+ void Init_rugged(void)
300
361
  {
301
362
  rb_mRugged = rb_define_module("Rugged");
302
363
 
@@ -316,11 +377,12 @@ void Init_rugged()
316
377
  }
317
378
 
318
379
  rb_define_module_function(rb_mRugged, "libgit2_version", rb_git_libgit2_version, 0);
319
- rb_define_module_function(rb_mRugged, "capabilities", rb_git_capabilities, 0);
380
+ rb_define_module_function(rb_mRugged, "capabilities", rb_git_capabilities, 0);
320
381
  rb_define_module_function(rb_mRugged, "hex_to_raw", rb_git_hex_to_raw, 1);
321
382
  rb_define_module_function(rb_mRugged, "raw_to_hex", rb_git_raw_to_hex, 1);
322
383
  rb_define_module_function(rb_mRugged, "minimize_oid", rb_git_minimize_oid, -1);
323
384
  rb_define_module_function(rb_mRugged, "prettify_message", rb_git_prettify_message, 2);
385
+ rb_define_module_function(rb_mRugged, "__cache_usage__", rb_git_cache_usage, 0);
324
386
 
325
387
  Init_rugged_object();
326
388
  Init_rugged_commit();
@@ -337,6 +399,11 @@ void Init_rugged()
337
399
  Init_rugged_remote();
338
400
  Init_rugged_notes();
339
401
  Init_rugged_settings();
402
+ Init_rugged_diff();
403
+ Init_rugged_diff_patch();
404
+ Init_rugged_diff_delta();
405
+ Init_rugged_diff_hunk();
406
+ Init_rugged_diff_line();
340
407
 
341
408
  /* Constants */
342
409
  rb_define_const(rb_mRugged, "SORT_NONE", INT2FIX(0));
data/ext/rugged/rugged.h CHANGED
@@ -31,34 +31,41 @@
31
31
  #define RSTRING_NOT_MODIFIED
32
32
 
33
33
  #include <ruby.h>
34
-
35
- #ifdef HAVE_RUBY_ENCODING_H
36
- # include <ruby/encoding.h>
34
+ #ifndef HAVE_RUBY_ENCODING_H
35
+ #error "Rugged requires Ruby 1.9+ to build"
36
+ #else
37
+ #include <ruby/encoding.h>
37
38
  #endif
38
39
 
39
40
  #include <assert.h>
40
41
  #include <git2.h>
41
42
  #include <git2/odb_backend.h>
42
43
 
44
+ #define rb_str_new_utf8(str) rb_enc_str_new(str, strlen(str), rb_utf8_encoding())
43
45
  #define CSTR2SYM(s) (ID2SYM(rb_intern((s))))
44
46
 
45
47
  /*
46
48
  * Initialization functions
47
49
  */
48
- void Init_rugged_object();
49
- void Init_rugged_branch();
50
- void Init_rugged_commit();
51
- void Init_rugged_tree();
52
- void Init_rugged_tag();
53
- void Init_rugged_blob();
54
- void Init_rugged_index();
55
- void Init_rugged_repo();
56
- void Init_rugged_revwalk();
57
- void Init_rugged_reference();
58
- void Init_rugged_config();
59
- void Init_rugged_remote();
60
- void Init_rugged_notes();
61
- void Init_rugged_settings();
50
+ void Init_rugged_object(void);
51
+ void Init_rugged_branch(void);
52
+ void Init_rugged_commit(void);
53
+ void Init_rugged_tree(void);
54
+ void Init_rugged_tag(void);
55
+ void Init_rugged_blob(void);
56
+ void Init_rugged_index(void);
57
+ void Init_rugged_repo(void);
58
+ void Init_rugged_revwalk(void);
59
+ void Init_rugged_reference(void);
60
+ void Init_rugged_config(void);
61
+ void Init_rugged_remote(void);
62
+ void Init_rugged_notes(void);
63
+ void Init_rugged_settings(void);
64
+ void Init_rugged_diff(void);
65
+ void Init_rugged_diff_patch(void);
66
+ void Init_rugged_diff_delta(void);
67
+ void Init_rugged_diff_hunk(void);
68
+ void Init_rugged_diff_line(void);
62
69
 
63
70
  VALUE rb_git_object_init(git_otype type, int argc, VALUE *argv, VALUE self);
64
71
 
@@ -69,14 +76,25 @@ VALUE rugged_signature_new(const git_signature *sig, const char *encoding_name);
69
76
  VALUE rugged_index_new(VALUE klass, VALUE owner, git_index *index);
70
77
  VALUE rugged_config_new(VALUE klass, VALUE owner, git_config *cfg);
71
78
  VALUE rugged_object_new(VALUE owner, git_object *object);
79
+ VALUE rugged_object_rev_parse(VALUE rb_repo, VALUE rb_spec, int as_obj);
72
80
  VALUE rugged_ref_new(VALUE klass, VALUE owner, git_reference *ref);
81
+ VALUE rugged_diff_new(VALUE klass, VALUE owner, git_diff_list *diff);
82
+ VALUE rugged_diff_patch_new(VALUE owner, git_diff_patch *patch);
83
+ VALUE rugged_diff_delta_new(VALUE owner, const git_diff_delta *delta);
84
+ VALUE rugged_diff_hunk_new(VALUE owner, int hunk_idx, const git_diff_range *range, const char *header, size_t header_len, size_t lines_in_hunk);
85
+ VALUE rugged_diff_line_new(VALUE owner, const char line_origin, const char *content, size_t content_len, int old_lineno, int new_lineno);
86
+
87
+ void rugged_parse_diff_options(git_diff_options *opts, VALUE rb_options);
73
88
 
74
89
  VALUE rugged_otype_new(git_otype t);
75
90
  git_otype rugged_otype_get(VALUE rb_type);
76
91
 
77
92
  git_signature *rugged_signature_get(VALUE rb_person);
78
93
  git_object *rugged_object_get(git_repository *repo, VALUE object_value, git_otype type);
79
- void rugged_oid_get(git_oid *oid, git_repository *repo, VALUE p);
94
+ int rugged_oid_get(git_oid *oid, git_repository *repo, VALUE p);
95
+
96
+ void rugged_rb_ary_to_strarray(VALUE rb_array, git_strarray *str_array);
97
+ VALUE rugged_strarray_to_rb_ary(git_strarray *str_array);
80
98
 
81
99
  static inline void rugged_set_owner(VALUE object, VALUE owner)
82
100
  {
@@ -88,12 +106,12 @@ static inline VALUE rugged_owner(VALUE object)
88
106
  return rb_iv_get(object, "@owner");
89
107
  }
90
108
 
91
- extern void rugged_exception_raise(int errorcode);
109
+ extern void rugged_exception_raise(void);
92
110
 
93
111
  static inline void rugged_exception_check(int errorcode)
94
112
  {
95
113
  if (errorcode < 0)
96
- rugged_exception_raise(errorcode);
114
+ rugged_exception_raise();
97
115
  }
98
116
 
99
117
  static inline int rugged_parse_bool(VALUE boolean)
@@ -106,29 +124,22 @@ static inline int rugged_parse_bool(VALUE boolean)
106
124
 
107
125
  extern VALUE rb_cRuggedRepo;
108
126
 
127
+ struct rugged_cb_payload {
128
+ VALUE rb_data;
129
+ int exception;
130
+ };
131
+
109
132
  static inline void rugged_check_repo(VALUE rb_repo)
110
133
  {
111
134
  if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo))
112
135
  rb_raise(rb_eTypeError, "Expecting a Rugged Repository");
113
136
  }
114
137
 
115
- /* support for string encodings in 1.9 */
116
- #ifdef HAVE_RUBY_ENCODING_H
117
- # define rugged_str_new(str, len, enc) rb_enc_str_new(str, len, enc)
118
- # define rugged_str_new2(str, enc) rb_enc_str_new(str, strlen(str), enc)
119
- # define rugged_str_ascii(str, len) rb_enc_str_new(str, len, rb_ascii8bit_encoding());
120
-
121
- #else
122
- # define rugged_str_new(str, len, rb_enc) rb_str_new(str, len)
123
- # define rugged_str_new2(str, rb_enc) rb_str_new2(str)
124
- # define rugged_str_ascii(str, len) rb_str_new(str, len)
125
- #endif
126
-
127
138
  static inline VALUE rugged_create_oid(const git_oid *oid)
128
139
  {
129
140
  char out[40];
130
141
  git_oid_fmt(out, oid);
131
- return rugged_str_new(out, 40, NULL);
142
+ return rb_str_new(out, 40);
132
143
  }
133
144
 
134
145
  #endif