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
@@ -0,0 +1,94 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2012 GitHub, Inc
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+
25
+ #include "rugged.h"
26
+
27
+ extern VALUE rb_cRuggedDiff;
28
+ VALUE rb_cRuggedDiffDelta;
29
+
30
+ static VALUE rb_git_delta_file_fromC(const git_diff_file *file)
31
+ {
32
+ VALUE rb_file;
33
+
34
+ if (!file)
35
+ return Qnil;
36
+
37
+ rb_file = rb_hash_new();
38
+
39
+ rb_hash_aset(rb_file, CSTR2SYM("oid"), rugged_create_oid(&file->oid));
40
+ rb_hash_aset(rb_file, CSTR2SYM("path"), file->path ? rb_str_new2(file->path) : Qnil);
41
+ rb_hash_aset(rb_file, CSTR2SYM("size"), INT2FIX(file->size));
42
+ rb_hash_aset(rb_file, CSTR2SYM("flags"), UINT2NUM(file->flags));
43
+ rb_hash_aset(rb_file, CSTR2SYM("mode"), UINT2NUM(file->mode));
44
+
45
+ return rb_file;
46
+ }
47
+
48
+ static VALUE rb_git_delta_status_fromC(git_delta_t status)
49
+ {
50
+ switch(status) {
51
+ case GIT_DELTA_UNMODIFIED:
52
+ return CSTR2SYM("unmodified");
53
+ case GIT_DELTA_ADDED:
54
+ return CSTR2SYM("added");
55
+ case GIT_DELTA_DELETED:
56
+ return CSTR2SYM("deleted");
57
+ case GIT_DELTA_MODIFIED:
58
+ return CSTR2SYM("modified");
59
+ case GIT_DELTA_RENAMED:
60
+ return CSTR2SYM("renamed");
61
+ case GIT_DELTA_COPIED:
62
+ return CSTR2SYM("copied");
63
+ case GIT_DELTA_IGNORED:
64
+ return CSTR2SYM("ignored");
65
+ case GIT_DELTA_UNTRACKED:
66
+ return CSTR2SYM("untracked");
67
+ case GIT_DELTA_TYPECHANGE:
68
+ return CSTR2SYM("typechange");
69
+ default:
70
+ return CSTR2SYM("unknown");
71
+ }
72
+ }
73
+
74
+ VALUE rugged_diff_delta_new(VALUE owner, const git_diff_delta *delta)
75
+ {
76
+ VALUE rb_delta = rb_class_new_instance(0, NULL, rb_cRuggedDiffDelta);
77
+
78
+ rugged_set_owner(rb_delta, owner);
79
+ rb_iv_set(rb_delta, "@old_file", rb_git_delta_file_fromC(&delta->old_file));
80
+ rb_iv_set(rb_delta, "@new_file", rb_git_delta_file_fromC(&delta->new_file));
81
+ rb_iv_set(rb_delta, "@similarity", INT2FIX(delta->similarity));
82
+ rb_iv_set(rb_delta, "@status", rb_git_delta_status_fromC(delta->status));
83
+ rb_iv_set(rb_delta, "@binary",
84
+ (!(delta->flags & GIT_DIFF_FLAG_NOT_BINARY) &&
85
+ (delta->flags & GIT_DIFF_FLAG_BINARY)) ? Qtrue : Qfalse
86
+ );
87
+
88
+ return rb_delta;
89
+ }
90
+
91
+ void Init_rugged_diff_delta(void)
92
+ {
93
+ rb_cRuggedDiffDelta = rb_define_class_under(rb_cRuggedDiff, "Delta", rb_cObject);
94
+ }
@@ -0,0 +1,100 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2012 GitHub, Inc
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+
25
+ #include "rugged.h"
26
+
27
+ extern VALUE rb_cRuggedDiff;
28
+ VALUE rb_cRuggedDiffHunk;
29
+
30
+ VALUE rugged_diff_hunk_new(
31
+ VALUE owner, int hunk_idx,
32
+ const git_diff_range *range,
33
+ const char *header,
34
+ size_t header_len,
35
+ size_t lines_in_hunk)
36
+ {
37
+ VALUE rb_hunk;
38
+ VALUE rb_range;
39
+
40
+ rb_hunk = rb_class_new_instance(0, NULL, rb_cRuggedDiffHunk);
41
+ rugged_set_owner(rb_hunk, owner);
42
+
43
+ rb_range = rb_hash_new();
44
+ rb_hash_aset(rb_range, CSTR2SYM("old_start"), INT2FIX(range->old_start));
45
+ rb_hash_aset(rb_range, CSTR2SYM("old_lines"), INT2FIX(range->old_lines));
46
+ rb_hash_aset(rb_range, CSTR2SYM("new_start"), INT2FIX(range->new_start));
47
+ rb_hash_aset(rb_range, CSTR2SYM("new_lines"), INT2FIX(range->new_lines));
48
+ rb_iv_set(rb_hunk, "@range", rb_range);
49
+
50
+ rb_iv_set(rb_hunk, "@header", rb_str_new(header, header_len));
51
+ rb_iv_set(rb_hunk, "@line_count", INT2FIX(lines_in_hunk));
52
+ rb_iv_set(rb_hunk, "@hunk_index", INT2FIX(hunk_idx));
53
+
54
+ return rb_hunk;
55
+ }
56
+
57
+ /*
58
+ * call-seq:
59
+ * hunk.each_line { |line| } -> self
60
+ * hunk.each_line -> Enumerator
61
+ *
62
+ * If given a block, yields each line that is part of the current hunk.
63
+ *
64
+ * If no block is given, an enumerator is returned instead.
65
+ */
66
+ static VALUE rb_git_diff_hunk_each_line(VALUE self)
67
+ {
68
+ git_diff_patch *patch;
69
+ char line_origin;
70
+ const char *content;
71
+ size_t content_len = 0;
72
+ int error = 0, l, old_lineno, new_lineno, lines_count, hunk_idx;
73
+
74
+ if (!rb_block_given_p()) {
75
+ return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each_line"), self);
76
+ }
77
+
78
+ Data_Get_Struct(rugged_owner(self), git_diff_patch, patch);
79
+
80
+ lines_count = FIX2INT(rb_iv_get(self, "@line_count"));
81
+ hunk_idx = FIX2INT(rb_iv_get(self, "@hunk_index"));
82
+
83
+ for (l = 0; l < lines_count; ++l) {
84
+ error = git_diff_patch_get_line_in_hunk(
85
+ &line_origin, &content, &content_len, &old_lineno, &new_lineno, patch, hunk_idx, l);
86
+ if (error) break;
87
+
88
+ rb_yield(rugged_diff_line_new(self, line_origin, content, content_len, old_lineno, new_lineno));
89
+ }
90
+ rugged_exception_check(error);
91
+
92
+ return self;
93
+ }
94
+
95
+ void Init_rugged_diff_hunk(void)
96
+ {
97
+ rb_cRuggedDiffHunk = rb_define_class_under(rb_cRuggedDiff, "Hunk", rb_cObject);
98
+
99
+ rb_define_method(rb_cRuggedDiffHunk, "each_line", rb_git_diff_hunk_each_line, 0);
100
+ }
@@ -0,0 +1,79 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2012 GitHub, Inc
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+
25
+ #include "rugged.h"
26
+
27
+ extern VALUE rb_cRuggedDiff;
28
+ VALUE rb_cRuggedDiffLine;
29
+
30
+ VALUE rugged_diff_line_new(
31
+ VALUE owner,
32
+ const char line_origin,
33
+ const char *content,
34
+ size_t content_len,
35
+ int old_lineno,
36
+ int new_lineno)
37
+ {
38
+ VALUE rb_line;
39
+ VALUE rb_line_origin;
40
+
41
+ rb_line = rb_class_new_instance(0, NULL, rb_cRuggedDiffLine);
42
+ rugged_set_owner(rb_line, owner);
43
+
44
+ switch(line_origin) {
45
+ case GIT_DIFF_LINE_CONTEXT:
46
+ rb_line_origin = CSTR2SYM("context");
47
+ break;
48
+ case GIT_DIFF_LINE_ADDITION:
49
+ rb_line_origin = CSTR2SYM("addition");
50
+ break;
51
+ case GIT_DIFF_LINE_DELETION:
52
+ rb_line_origin = CSTR2SYM("deletion");
53
+ break;
54
+ case GIT_DIFF_LINE_CONTEXT_EOFNL: /* neither file has newline at the end */
55
+ rb_line_origin = CSTR2SYM("eof_no_newline");
56
+ break;
57
+ case GIT_DIFF_LINE_ADD_EOFNL: /* added at end of old file */
58
+ rb_line_origin = CSTR2SYM("eof_newline_added");
59
+ break;
60
+ case GIT_DIFF_LINE_DEL_EOFNL: /* removed at end of old file */
61
+ rb_line_origin = CSTR2SYM("eof_newline_removed");
62
+ break;
63
+ default:
64
+ /* FIXME: raise here instead? */
65
+ rb_line_origin = CSTR2SYM("unknown");
66
+ }
67
+
68
+ rb_iv_set(rb_line, "@line_origin", rb_line_origin);
69
+ rb_iv_set(rb_line, "@content", rb_str_new(content, content_len));
70
+ rb_iv_set(rb_line, "@old_lineno", INT2FIX(old_lineno));
71
+ rb_iv_set(rb_line, "@new_lineno", INT2FIX(new_lineno));
72
+
73
+ return rb_line;
74
+ }
75
+
76
+ void Init_rugged_diff_line(void)
77
+ {
78
+ rb_cRuggedDiffLine = rb_define_class_under(rb_cRuggedDiff, "Line", rb_cObject);
79
+ }
@@ -0,0 +1,169 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2012 GitHub, Inc
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in
14
+ * all copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ * THE SOFTWARE.
23
+ */
24
+
25
+ #include "rugged.h"
26
+
27
+ extern VALUE rb_cRuggedDiff;
28
+ extern VALUE rb_cRuggedDiffDelta;
29
+ VALUE rb_cRuggedDiffPatch;
30
+
31
+ static void rb_git_diff_patch__free(git_diff_patch *patch)
32
+ {
33
+ git_diff_patch_free(patch);
34
+ }
35
+
36
+ VALUE rugged_diff_patch_new(VALUE owner, git_diff_patch *patch)
37
+ {
38
+ VALUE rb_patch = Data_Wrap_Struct(rb_cRuggedDiffPatch, NULL, rb_git_diff_patch__free, patch);
39
+ rugged_set_owner(rb_patch, owner);
40
+ return rb_patch;
41
+ }
42
+
43
+ /*
44
+ * call-seq:
45
+ * patch.each_hunk { |hunk| } -> self
46
+ * patch.each_hunk -> enumerator
47
+ *
48
+ * If given a block, yields each hunk that is part of the patch.
49
+ *
50
+ * If no block is given, an enumerator is returned instead.
51
+ */
52
+ static VALUE rb_git_diff_patch_each_hunk(VALUE self)
53
+ {
54
+ git_diff_patch *patch;
55
+ const git_diff_range *range;
56
+ const char *header;
57
+ size_t header_len, lines_in_hunk;
58
+ int error = 0, hooks_count, h;
59
+
60
+ if (!rb_block_given_p()) {
61
+ return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each_hunk"), self);
62
+ }
63
+
64
+ Data_Get_Struct(self, git_diff_patch, patch);
65
+
66
+ hooks_count = git_diff_patch_num_hunks(patch);
67
+ for (h = 0; h < hooks_count; ++h) {
68
+ error = git_diff_patch_get_hunk(&range, &header, &header_len, &lines_in_hunk, patch, h);
69
+ if (error) break;
70
+
71
+ rb_yield(rugged_diff_hunk_new(self, h, range, header, header_len, lines_in_hunk));
72
+ }
73
+ rugged_exception_check(error);
74
+
75
+ return self;
76
+ }
77
+
78
+ /*
79
+ * call-seq:
80
+ * patch.hunk_count -> int
81
+ *
82
+ * Returns the number of hunks in the patch.
83
+ */
84
+ static VALUE rb_git_diff_patch_hunk_count(VALUE self)
85
+ {
86
+ git_diff_patch *patch;
87
+ Data_Get_Struct(self, git_diff_patch, patch);
88
+
89
+ return INT2FIX(git_diff_patch_num_hunks(patch));
90
+ }
91
+
92
+ /*
93
+ * call-seq:
94
+ * patch.delta -> delta
95
+ *
96
+ * Returns the delta object associated with the patch.
97
+ */
98
+ static VALUE rb_git_diff_patch_delta(VALUE self)
99
+ {
100
+ git_diff_patch *patch;
101
+ Data_Get_Struct(self, git_diff_patch, patch);
102
+
103
+ return rugged_diff_delta_new(rugged_owner(self), git_diff_patch_delta(patch));
104
+ }
105
+
106
+ /*
107
+ * call-seq:
108
+ * patch.additions -> int
109
+ *
110
+ * Returns the number of addition lines in the patch.
111
+ */
112
+ static VALUE rb_git_diff_patch_additions(VALUE self)
113
+ {
114
+ git_diff_patch *patch;
115
+ size_t additions;
116
+ Data_Get_Struct(self, git_diff_patch, patch);
117
+
118
+ git_diff_patch_line_stats(NULL, &additions, NULL, patch);
119
+
120
+ return INT2FIX(additions);
121
+ }
122
+
123
+ /*
124
+ * call-seq:
125
+ * patch.deletions -> int
126
+ *
127
+ * Returns the number of deletion lines in the patch.
128
+ */
129
+ static VALUE rb_git_diff_patch_deletions(VALUE self)
130
+ {
131
+ git_diff_patch *patch;
132
+ size_t deletions;
133
+ Data_Get_Struct(self, git_diff_patch, patch);
134
+
135
+ git_diff_patch_line_stats(NULL, NULL, &deletions, patch);
136
+
137
+ return INT2FIX(deletions);
138
+ }
139
+
140
+ /*
141
+ * call-seq:
142
+ * patch.context -> int
143
+ *
144
+ * Returns the number of context lines in the patch.
145
+ */
146
+ static VALUE rb_git_diff_patch_context(VALUE self)
147
+ {
148
+ git_diff_patch *patch;
149
+ size_t context;
150
+ Data_Get_Struct(self, git_diff_patch, patch);
151
+
152
+ git_diff_patch_line_stats(&context, NULL, NULL, patch);
153
+
154
+ return INT2FIX(context);
155
+ }
156
+
157
+ void Init_rugged_diff_patch(void)
158
+ {
159
+ rb_cRuggedDiffPatch = rb_define_class_under(rb_cRuggedDiff, "Patch", rb_cObject);
160
+
161
+ rb_define_method(rb_cRuggedDiffPatch, "context", rb_git_diff_patch_context, 0);
162
+ rb_define_method(rb_cRuggedDiffPatch, "additions", rb_git_diff_patch_additions, 0);
163
+ rb_define_method(rb_cRuggedDiffPatch, "deletions", rb_git_diff_patch_deletions, 0);
164
+
165
+ rb_define_method(rb_cRuggedDiffPatch, "delta", rb_git_diff_patch_delta, 0);
166
+
167
+ rb_define_method(rb_cRuggedDiffPatch, "each_hunk", rb_git_diff_patch_each_hunk, 0);
168
+ rb_define_method(rb_cRuggedDiffPatch, "hunk_count", rb_git_diff_patch_hunk_count, 0);
169
+ }
@@ -24,8 +24,11 @@
24
24
 
25
25
  #include "rugged.h"
26
26
 
27
- extern VALUE rb_mRugged;
28
27
  VALUE rb_cRuggedIndex;
28
+ extern VALUE rb_mRugged;
29
+ extern VALUE rb_cRuggedCommit;
30
+ extern VALUE rb_cRuggedDiff;
31
+ extern VALUE rb_cRuggedTree;
29
32
 
30
33
  static void rb_git_indexentry_toC(git_index_entry *entry, VALUE rb_entry);
31
34
  static VALUE rb_git_indexentry_fromC(const git_index_entry *entry);
@@ -46,6 +49,15 @@ VALUE rugged_index_new(VALUE klass, VALUE owner, git_index *index)
46
49
  return rb_index;
47
50
  }
48
51
 
52
+ /*
53
+ * call-seq:
54
+ * Index.new([path])
55
+ *
56
+ * Create a bare index object based on the index file at +path+.
57
+ *
58
+ * Any index methods that rely on the ODB or a working directory (e.g. #add)
59
+ * will raise a Rugged::IndexError.
60
+ */
49
61
  static VALUE rb_git_index_new(int argc, VALUE *argv, VALUE klass)
50
62
  {
51
63
  git_index *index;
@@ -65,6 +77,13 @@ static VALUE rb_git_index_new(int argc, VALUE *argv, VALUE klass)
65
77
  return rugged_index_new(klass, Qnil, index);
66
78
  }
67
79
 
80
+ /*
81
+ * call-seq:
82
+ * index.clear -> nil
83
+ *
84
+ * Clear the contents (remove all entries) of the index object. Changes are in-memory only
85
+ * and can be saved by calling #write.
86
+ */
68
87
  static VALUE rb_git_index_clear(VALUE self)
69
88
  {
70
89
  git_index *index;
@@ -73,6 +92,13 @@ static VALUE rb_git_index_clear(VALUE self)
73
92
  return Qnil;
74
93
  }
75
94
 
95
+ /*
96
+ * call-seq:
97
+ * index.reload -> nil
98
+ *
99
+ * Reloads the index contents from the disk, discarding any changes that
100
+ * have not been saved through #write.
101
+ */
76
102
  static VALUE rb_git_index_read(VALUE self)
77
103
  {
78
104
  git_index *index;
@@ -86,6 +112,12 @@ static VALUE rb_git_index_read(VALUE self)
86
112
  return Qnil;
87
113
  }
88
114
 
115
+ /*
116
+ * call-seq:
117
+ * index.write -> nil
118
+ *
119
+ * Writes the index object from memory back to the disk, persisting all changes.
120
+ */
89
121
  static VALUE rb_git_index_write(VALUE self)
90
122
  {
91
123
  git_index *index;
@@ -99,6 +131,12 @@ static VALUE rb_git_index_write(VALUE self)
99
131
  return Qnil;
100
132
  }
101
133
 
134
+ /*
135
+ * call-seq:
136
+ * index.count -> int
137
+ *
138
+ * Returns the number of entries currently in the index.
139
+ */
102
140
  static VALUE rb_git_index_count(VALUE self)
103
141
  {
104
142
  git_index *index;
@@ -106,6 +144,18 @@ static VALUE rb_git_index_count(VALUE self)
106
144
  return INT2FIX(git_index_entrycount(index));
107
145
  }
108
146
 
147
+ /*
148
+ * call-seq:
149
+ * index[path[, stage = 0]] -> entry or nil
150
+ * index[position] -> entry or nil
151
+ * index.get(path[, stage = 0]) -> entry or nil
152
+ * index.get(position) -> entry or nil
153
+ *
154
+ * Return a specific entry in the index.
155
+ *
156
+ * The first two forms returns entries based on their +path+ in the index and an optional +stage+,
157
+ * while the last two forms return entries based on their position in the index.
158
+ */
109
159
  static VALUE rb_git_index_get(int argc, VALUE *argv, VALUE self)
110
160
  {
111
161
  git_index *index;
@@ -143,6 +193,15 @@ static VALUE rb_git_index_get(int argc, VALUE *argv, VALUE self)
143
193
  return entry ? rb_git_indexentry_fromC(entry) : Qnil;
144
194
  }
145
195
 
196
+ /*
197
+ * call-seq:
198
+ * index.each { |entry| } -> nil
199
+ * index.each -> Enumerator
200
+ *
201
+ * Passes each entry of the index to the given block.
202
+ *
203
+ * If no block is given, an enumerator is returned instead.
204
+ */
146
205
  static VALUE rb_git_index_each(VALUE self)
147
206
  {
148
207
  git_index *index;
@@ -163,6 +222,13 @@ static VALUE rb_git_index_each(VALUE self)
163
222
  return Qnil;
164
223
  }
165
224
 
225
+ /*
226
+ * call-seq:
227
+ * index.remove(path[, stage = 0]) -> nil
228
+ *
229
+ * Removes the entry at the given +path+ with the given +stage+
230
+ * from the index.
231
+ */
166
232
  static VALUE rb_git_index_remove(int argc, VALUE *argv, VALUE self)
167
233
  {
168
234
  git_index *index;
@@ -185,6 +251,59 @@ static VALUE rb_git_index_remove(int argc, VALUE *argv, VALUE self)
185
251
  return Qnil;
186
252
  }
187
253
 
254
+ /*
255
+ * call-seq:
256
+ * index.remove_dir(dir[, stage = 0]) -> nil
257
+ *
258
+ * Removes all entries under the given +dir+ with the given +stage+
259
+ * from the index.
260
+ */
261
+ static VALUE rb_git_index_remove_directory(int argc, VALUE *argv, VALUE self)
262
+ {
263
+ git_index *index;
264
+ int error, stage = 0;
265
+
266
+ VALUE rb_dir, rb_stage;
267
+
268
+ Data_Get_Struct(self, git_index, index);
269
+
270
+ if (rb_scan_args(argc, argv, "11", &rb_dir, &rb_stage) > 1) {
271
+ Check_Type(rb_stage, T_FIXNUM);
272
+ stage = FIX2INT(rb_stage);
273
+ }
274
+
275
+ Check_Type(rb_dir, T_STRING);
276
+
277
+ error = git_index_remove_directory(index, StringValueCStr(rb_dir), stage);
278
+ rugged_exception_check(error);
279
+
280
+ return Qnil;
281
+ }
282
+
283
+ /*
284
+ * call-seq:
285
+ * index << entry -> nil
286
+ * index << path -> nil
287
+ * index.add(entry) -> nil
288
+ * index.add(path) -> nil
289
+ * index.update(entry) -> nil
290
+ * index.update(path) -> nil
291
+ *
292
+ * Add a new entry to the index or update an existing entry in the index.
293
+ *
294
+ * If passed a +path+ to an existing, readable file relative to the workdir,
295
+ * creates a new index entry based on this file.
296
+ *
297
+ * Alternatively, a new index entry can be created by passing a Hash containing
298
+ * all key/value pairs of an index entry.
299
+ *
300
+ * Any gitignore rules that might match +path+ (or the +:path+ value of the
301
+ * entry hash) are ignored.
302
+ *
303
+ * If the index entry at +path+ (or +:path+) currently contains a merge conflict,
304
+ * it will no longer be marked as conflicting and the data about the conflict
305
+ * will be moved into the "resolve undo" (REUC) section of the index.
306
+ */
188
307
  static VALUE rb_git_index_add(VALUE self, VALUE rb_entry)
189
308
  {
190
309
  git_index *index;
@@ -212,6 +331,194 @@ static VALUE rb_git_index_add(VALUE self, VALUE rb_entry)
212
331
  return Qnil;
213
332
  }
214
333
 
334
+ int rugged__index_matched_path_cb(const char *path, const char *matched_pathspec, void *payload)
335
+ {
336
+ int *exception = (int *)payload;
337
+
338
+ VALUE rb_result, rb_args = rb_ary_new2(2);
339
+ rb_ary_push(rb_args, rb_str_new2(path));
340
+ rb_ary_push(rb_args, matched_pathspec == NULL ? Qnil : rb_str_new2(matched_pathspec));
341
+
342
+ rb_result = rb_protect(rb_yield_splat, rb_args, exception);
343
+
344
+ if (*exception)
345
+ return GIT_ERROR;
346
+
347
+ return RTEST(rb_result) ? 0 : 1;
348
+ }
349
+
350
+ /*
351
+ * call-seq:
352
+ * index.add_all(pathspec = [][, options]) -> nil
353
+ * index.add_all(pathspec = [][, options]) { |path, pathspec| block } -> nil
354
+ *
355
+ * Add or update index entries matching files in the working directory.
356
+ *
357
+ * Searches the working directory for files that +pathspec+ and adds them
358
+ * to +index+ (by updating an existing entry or adding a new entry).
359
+ *
360
+ * +pathspec+ can either be a String, or an Array of Strings.
361
+ * If +pathspec+ is empty, all entries in the index will be matched.
362
+ *
363
+ * Files that are ignored due to +.gitignore+ rules will be skipped,
364
+ * unless they're already have an entry in +index+.
365
+ *
366
+ * Files that are marked as the result of a merge request, will have this
367
+ * marking removed and the merge conflict information will be moved into the
368
+ * "resolve undo" (REUC) section of +index+.
369
+ *
370
+ * If a block is given, each matched +path+ and the +pathspec+ that matched
371
+ * it will be passed to the block. If the return value of +block+ is
372
+ * falsy, the matching item will not be added to the index.
373
+ *
374
+ * This method will fail in bare index instances.
375
+ *
376
+ * The following options can be passed in the +options+ Hash:
377
+ *
378
+ * :force ::
379
+ * If +true+, any +.gitignore+ rules will be ignored.
380
+ *
381
+ * :disable_pathspec_match ::
382
+ * If +true+, glob expansion will be disabled and exact matching will be forced.
383
+ *
384
+ * :check_pathspec ::
385
+ * If +true+, and the +:force+ options is +false+ or not given, exact matches
386
+ * of ignored files or files that are not already in +index+ will raise a
387
+ * Rugged::InvalidError. This emulates <code>git add -A</code>.
388
+ */
389
+ static VALUE rb_git_index_add_all(int argc, VALUE *argv, VALUE self)
390
+ {
391
+ VALUE rb_pathspecs, rb_options;
392
+
393
+ git_index *index;
394
+ git_strarray pathspecs;
395
+ int error, exception = 0;
396
+ unsigned int flags = GIT_INDEX_ADD_DEFAULT;
397
+
398
+ Data_Get_Struct(self, git_index, index);
399
+
400
+ if (rb_scan_args(argc, argv, "02", &rb_pathspecs, &rb_options) > 1) {
401
+ Check_Type(rb_options, T_HASH);
402
+
403
+ if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("force"))))
404
+ flags |= GIT_INDEX_ADD_FORCE;
405
+
406
+ if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("disable_pathspec_match"))))
407
+ flags |= GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH;
408
+
409
+ if (RTEST(rb_hash_aref(rb_options, CSTR2SYM("check_pathspec"))))
410
+ flags |= GIT_INDEX_ADD_CHECK_PATHSPEC;
411
+ }
412
+
413
+ rugged_rb_ary_to_strarray(rb_pathspecs, &pathspecs);
414
+
415
+ error = git_index_add_all(index, &pathspecs, flags,
416
+ rb_block_given_p() ? rugged__index_matched_path_cb : NULL, &exception);
417
+
418
+ xfree(pathspecs.strings);
419
+
420
+ if (exception)
421
+ rb_jump_tag(exception);
422
+
423
+ rugged_exception_check(error);
424
+ return Qnil;
425
+ }
426
+
427
+ /*
428
+ * call-seq:
429
+ * index.update_all(pathspec = []) -> nil
430
+ * index.update_all(pathspec = []) { |path, pathspec| block } -> nil
431
+ *
432
+ * Update all index entries to match the working directory.
433
+ *
434
+ * Searches +index+ for entries that match +pathspec+ and synchronizes
435
+ * them with the content of the working directory.
436
+ *
437
+ * +pathspec+ can either be a String, or an Array of Strings.
438
+ * If +pathspec+ is empty, all entries in the index will be matched.
439
+ *
440
+ * Entries where the corresponding working directory file no longer exists
441
+ * get deleted, all other matched entries will get updated to reflect their
442
+ * working directory state (the latest version of the a file's content will
443
+ * automatically be added to the ODB).
444
+ *
445
+ * If a block is given, each matched +path+ and the +pathspec+ that matched
446
+ * it will be passed to the block. If the return value of +block+ is
447
+ * falsy, the matching item will not be updated in the index.
448
+ *
449
+ * This method will fail in bare index instances.
450
+ */
451
+ static VALUE rb_git_index_update_all(int argc, VALUE *argv, VALUE self)
452
+ {
453
+ VALUE rb_pathspecs = rb_ary_new();;
454
+
455
+ git_index *index;
456
+ git_strarray pathspecs;
457
+ int error, exception = 0;
458
+
459
+ Data_Get_Struct(self, git_index, index);
460
+
461
+ rb_scan_args(argc, argv, "01", &rb_pathspecs);
462
+
463
+ rugged_rb_ary_to_strarray(rb_pathspecs, &pathspecs);
464
+
465
+ error = git_index_update_all(index, &pathspecs,
466
+ rb_block_given_p() ? rugged__index_matched_path_cb : NULL, &exception);
467
+
468
+ xfree(pathspecs.strings);
469
+
470
+ if (exception)
471
+ rb_jump_tag(exception);
472
+ rugged_exception_check(error);
473
+
474
+ return Qnil;
475
+ }
476
+
477
+ /*
478
+ * call-seq:
479
+ * index.remove_all(pathspec = []) -> nil
480
+ * index.remove_all(pathspec = []) { |path, pathspec| block } -> nil
481
+ *
482
+ * Remove all matching index entries.
483
+ *
484
+ * Searches +index+ for entries that match +pathspec+ and removes them
485
+ * from the index.
486
+ *
487
+ * +pathspec+ can either be a String, or an Array of Strings.
488
+ * If +pathspec+ is empty, all entries in the index will be matched.
489
+ *
490
+ * If a block is given, each matched +path+ and the +pathspec+ that matched
491
+ * it will be passed to the block. If the return value of +block+ is
492
+ * falsy, the matching item will not be removed from the index.
493
+ */
494
+ static VALUE rb_git_index_remove_all(int argc, VALUE *argv, VALUE self)
495
+ {
496
+ VALUE rb_pathspecs = rb_ary_new();
497
+
498
+ git_index *index;
499
+ git_strarray pathspecs;
500
+ int error, exception = 0;
501
+
502
+ Data_Get_Struct(self, git_index, index);
503
+
504
+ rb_scan_args(argc, argv, "01", &rb_pathspecs);
505
+
506
+ if (NIL_P(rb_pathspecs))
507
+ rb_pathspecs = rb_ary_new();
508
+
509
+ rugged_rb_ary_to_strarray(rb_ary_to_ary(rb_pathspecs), &pathspecs);
510
+
511
+ error = git_index_remove_all(index, &pathspecs,
512
+ rb_block_given_p() ? rugged__index_matched_path_cb : NULL, &exception);
513
+
514
+ xfree(pathspecs.strings);
515
+
516
+ if (exception)
517
+ rb_jump_tag(exception);
518
+ rugged_exception_check(error);
519
+
520
+ return Qnil;
521
+ }
215
522
 
216
523
  static VALUE rb_git_indexentry_fromC(const git_index_entry *entry)
217
524
  {
@@ -223,7 +530,7 @@ static VALUE rb_git_indexentry_fromC(const git_index_entry *entry)
223
530
 
224
531
  rb_entry = rb_hash_new();
225
532
 
226
- rb_hash_aset(rb_entry, CSTR2SYM("path"), rugged_str_new2(entry->path, NULL));
533
+ rb_hash_aset(rb_entry, CSTR2SYM("path"), rb_str_new_utf8(entry->path));
227
534
  rb_hash_aset(rb_entry, CSTR2SYM("oid"), rugged_create_oid(&entry->oid));
228
535
 
229
536
  rb_hash_aset(rb_entry, CSTR2SYM("dev"), INT2FIX(entry->dev));
@@ -322,6 +629,17 @@ static void rb_git_indexentry_toC(git_index_entry *entry, VALUE rb_entry)
322
629
  }
323
630
  }
324
631
 
632
+ /*
633
+ * call-seq:
634
+ * index.write_tree([repo]) -> oid
635
+ *
636
+ * Write the index to a tree, either in the index's repository, or in
637
+ * the given +repo+.
638
+ *
639
+ * If the index contains any files in conflict, writing the tree will fail.
640
+ *
641
+ * Returns the OID string of the written tree object.
642
+ */
325
643
  static VALUE rb_git_index_writetree(int argc, VALUE *argv, VALUE self)
326
644
  {
327
645
  git_index *index;
@@ -346,13 +664,13 @@ static VALUE rb_git_index_writetree(int argc, VALUE *argv, VALUE self)
346
664
  }
347
665
 
348
666
  /*
349
- * call-seq:
350
- * index.read_tree(tree)
667
+ * call-seq:
668
+ * index.read_tree(tree)
351
669
  *
352
- * Clear the current index and start the index again on top of +tree+
670
+ * Clear the current index and start the index again on top of +tree+
353
671
  *
354
- * Further index operations (+add+, +update+, +remove+, etc) will
355
- * be considered changes on top of +tree+.
672
+ * Further index operations (+add+, +update+, +remove+, etc) will
673
+ * be considered changes on top of +tree+.
356
674
  */
357
675
  static VALUE rb_git_index_readtree(VALUE self, VALUE rb_tree)
358
676
  {
@@ -369,7 +687,212 @@ static VALUE rb_git_index_readtree(VALUE self, VALUE rb_tree)
369
687
  return Qnil;
370
688
  }
371
689
 
372
- void Init_rugged_index()
690
+ /*
691
+ * call-seq:
692
+ * index.diff([options]) -> diff
693
+ * index.diff(diffable[, options]) -> diff
694
+ *
695
+ * The first form returns a diff between the index and the current working
696
+ * directory.
697
+ *
698
+ * The second form returns a diff between the index and the given diffable object.
699
+ * +diffable+ can either be a +Rugged::Commit+ or a +Rugged::Tree+.
700
+ *
701
+ * The index will be used as the "old file" side of the diff, while the working
702
+ * directory or the +diffable+ will be used for the "new file" side.
703
+ *
704
+ * The following options can be passed in the +options+ Hash:
705
+ *
706
+ * :paths ::
707
+ * An array of paths / fnmatch patterns to constrain the diff to a specific
708
+ * set of files. Also see +:disable_pathspec_match+.
709
+ *
710
+ * :max_size ::
711
+ * An integer specifying the maximum byte size of a file before a it will
712
+ * be treated as binary. The default value is 512MB.
713
+ *
714
+ * :context_lines ::
715
+ * The number of unchanged lines that define the boundary of a hunk (and
716
+ * to display before and after the actual changes). The default is 3.
717
+ *
718
+ * :interhunk_lines ::
719
+ * The maximum number of unchanged lines between hunk boundaries before the hunks
720
+ * will be merged into a one. The default is 0.
721
+ *
722
+ * :reverse ::
723
+ * If true, the sides of the diff will be reversed.
724
+ *
725
+ * :force_text ::
726
+ * If true, all files will be treated as text, disabling binary attributes & detection.
727
+ *
728
+ * :ignore_whitespace ::
729
+ * If true, all whitespace will be ignored.
730
+ *
731
+ * :ignore_whitespace_change ::
732
+ * If true, changes in amount of whitespace will be ignored.
733
+ *
734
+ * :ignore_whitespace_eol ::
735
+ * If true, whitespace at end of line will be ignored.
736
+ *
737
+ * :ignore_submodules ::
738
+ * if true, submodules will be excluded from the diff completely.
739
+ *
740
+ * :patience ::
741
+ * If true, the "patience diff" algorithm will be used (currenlty unimplemented).
742
+ *
743
+ * :include_ignored ::
744
+ * If true, ignored files will be included in the diff.
745
+ *
746
+ * :include_untracked ::
747
+ * If true, untracked files will be included in the diff.
748
+ *
749
+ * :include_unmodified ::
750
+ * If true, unmodified files will be included in the diff.
751
+ *
752
+ * :recurse_untracked_dirs ::
753
+ * Even if +:include_untracked+ is true, untracked directories will only be
754
+ * marked with a single entry in the diff. If this flag is set to true,
755
+ * all files under ignored directories will be included in the di ff, too.
756
+ *
757
+ * :disable_pathspec_match ::
758
+ * If true, the given +:paths+ will be applied as exact matches, instead of
759
+ * as fnmatch patterns.
760
+ *
761
+ * :deltas_are_icase ::
762
+ * If true, filename comparisons will be made with case-insensitivity.
763
+ *
764
+ * :include_untracked_content ::
765
+ * if true, untracked content will be contained in the the diff patch text.
766
+ *
767
+ * :skip_binary_check ::
768
+ * If true, diff deltas will be generated without spending time on binary
769
+ * detection. This is useful to improve performance in cases where the actual
770
+ * file content difference is not needed.
771
+ *
772
+ * :include_typechange ::
773
+ * If true, type changes for files will not be interpreted as deletion of
774
+ * the "old file" and addition of the "new file", but will generate
775
+ * typechange records.
776
+ *
777
+ * :include_typechange_trees ::
778
+ * Even if +:include_typechange+ is true, blob -> tree changes will still
779
+ * usually be handled as a deletion of the blob. If this flag is set to true,
780
+ * blob -> tree changes will be marked as typechanges.
781
+ *
782
+ * :ignore_filemode ::
783
+ * If true, file mode changes will be ignored.
784
+ *
785
+ * :recurse_ignored_dirs ::
786
+ * Even if +:include_ignored+ is true, ignored directories will only be
787
+ * marked with a single entry in the diff. If this flag is set to true,
788
+ * all files under ignored directories will be included in the diff, too.
789
+ */
790
+ static VALUE rb_git_index_diff(int argc, VALUE *argv, VALUE self)
791
+ {
792
+ git_index *index;
793
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
794
+ git_repository *repo;
795
+ git_diff_list *diff = NULL;
796
+ VALUE owner, rb_other, rb_options;
797
+ int error;
798
+
799
+ rb_scan_args(argc, argv, "01:", &rb_other, &rb_options);
800
+ rugged_parse_diff_options(&opts, rb_options);
801
+
802
+ Data_Get_Struct(self, git_index, index);
803
+ owner = rugged_owner(self);
804
+ Data_Get_Struct(owner, git_repository, repo);
805
+
806
+ if (NIL_P(rb_other)) {
807
+ error = git_diff_index_to_workdir(&diff, repo, index, &opts);
808
+ } else {
809
+ // Need to flip the reverse option, so that the index is by default
810
+ // the "old file" side of the diff.
811
+ opts.flags ^= GIT_DIFF_REVERSE;
812
+
813
+ if (rb_obj_is_kind_of(rb_other, rb_cRuggedCommit)) {
814
+ git_tree *other_tree;
815
+ git_commit *commit;
816
+ Data_Get_Struct(rb_other, git_commit, commit);
817
+ error = git_commit_tree(&other_tree, commit);
818
+
819
+ if (!error)
820
+ error = git_diff_tree_to_index(&diff, repo, other_tree, index, &opts);
821
+ } else if (rb_obj_is_kind_of(rb_other, rb_cRuggedTree)) {
822
+ git_tree *other_tree;
823
+ Data_Get_Struct(rb_other, git_tree, other_tree);
824
+ error = git_diff_tree_to_index(&diff, repo, other_tree, index, &opts);
825
+ } else {
826
+ xfree(opts.pathspec.strings);
827
+ rb_raise(rb_eTypeError, "A Rugged::Commit or Rugged::Tree instance is required");
828
+ }
829
+ }
830
+
831
+ xfree(opts.pathspec.strings);
832
+ rugged_exception_check(error);
833
+
834
+ return rugged_diff_new(rb_cRuggedDiff, self, diff);
835
+ }
836
+
837
+ /*
838
+ * call-seq:
839
+ * index.conflicts? -> true or false
840
+ *
841
+ * Determines if the index contains entries representing conflicts.
842
+ */
843
+ static VALUE rb_git_index_conflicts_p(VALUE self)
844
+ {
845
+ git_index *index;
846
+ Data_Get_Struct(self, git_index, index);
847
+ return git_index_has_conflicts(index) ? Qtrue : Qfalse;
848
+ }
849
+
850
+
851
+ /*
852
+ * Document-class: Rugged::Index
853
+ *
854
+ * == Index Entries
855
+ *
856
+ * Index entries are represented as Hash instances with the following key/value pairs:
857
+ *
858
+ * path: ::
859
+ * The entry's path in the index.
860
+ *
861
+ * oid: ::
862
+ * The oid of the entry's git object (blob / tree).
863
+ *
864
+ * dev: ::
865
+ * The device for the index entry.
866
+ *
867
+ * ino: ::
868
+ * The inode for the index entry.
869
+ *
870
+ * mode: ::
871
+ * The current permissions of the index entry.
872
+ *
873
+ * gid: ::
874
+ * Group ID of the index entry's owner.
875
+ *
876
+ * uid: ::
877
+ * User ID of the index entry's owner.
878
+ *
879
+ * file_size: ::
880
+ * The index entry's size, in bytes.
881
+ *
882
+ * valid: ::
883
+ * +true+ if the index entry is valid, +false+ otherwise.
884
+ *
885
+ * stage: ::
886
+ * The current stage of the index entry.
887
+ *
888
+ * mtime: ::
889
+ * A Time instance representing the index entry's time of last modification.
890
+ *
891
+ * mtime: ::
892
+ * A Time instance representing the index entry's time of last status change
893
+ * (ie. change of owner, group, mode, etc.).
894
+ */
895
+ void Init_rugged_index(void)
373
896
  {
374
897
  /*
375
898
  * Index
@@ -384,12 +907,20 @@ void Init_rugged_index()
384
907
  rb_define_method(rb_cRuggedIndex, "get", rb_git_index_get, -1);
385
908
  rb_define_method(rb_cRuggedIndex, "[]", rb_git_index_get, -1);
386
909
  rb_define_method(rb_cRuggedIndex, "each", rb_git_index_each, 0);
910
+ rb_define_method(rb_cRuggedIndex, "diff", rb_git_index_diff, -1);
911
+
912
+ rb_define_method(rb_cRuggedIndex, "conflicts?", rb_git_index_conflicts_p, 0);
387
913
 
388
914
  rb_define_method(rb_cRuggedIndex, "add", rb_git_index_add, 1);
389
915
  rb_define_method(rb_cRuggedIndex, "update", rb_git_index_add, 1);
390
916
  rb_define_method(rb_cRuggedIndex, "<<", rb_git_index_add, 1);
391
917
 
392
918
  rb_define_method(rb_cRuggedIndex, "remove", rb_git_index_remove, -1);
919
+ rb_define_method(rb_cRuggedIndex, "remove_dir", rb_git_index_remove_directory, -1);
920
+
921
+ rb_define_method(rb_cRuggedIndex, "add_all", rb_git_index_add_all, -1);
922
+ rb_define_method(rb_cRuggedIndex, "update_all", rb_git_index_update_all, -1);
923
+ rb_define_method(rb_cRuggedIndex, "remove_all", rb_git_index_remove_all, -1);
393
924
 
394
925
  rb_define_method(rb_cRuggedIndex, "write_tree", rb_git_index_writetree, -1);
395
926
  rb_define_method(rb_cRuggedIndex, "read_tree", rb_git_index_readtree, 1);