rugged 0.21.4 → 0.22.0b1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (224) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +12 -5
  3. data/ext/rugged/extconf.rb +9 -9
  4. data/ext/rugged/rugged.c +4 -2
  5. data/ext/rugged/rugged.h +3 -7
  6. data/ext/rugged/rugged_blob.c +57 -0
  7. data/ext/rugged/rugged_cred.c +23 -0
  8. data/ext/rugged/rugged_index.c +6 -2
  9. data/ext/rugged/rugged_remote.c +65 -52
  10. data/ext/rugged/rugged_remote_collection.c +59 -10
  11. data/ext/rugged/rugged_repo.c +345 -11
  12. data/ext/rugged/rugged_revwalk.c +10 -0
  13. data/ext/rugged/rugged_submodule.c +1042 -0
  14. data/ext/rugged/rugged_submodule_collection.c +236 -0
  15. data/ext/rugged/rugged_tag_collection.c +70 -2
  16. data/ext/rugged/rugged_tree.c +29 -10
  17. data/lib/rugged.rb +3 -0
  18. data/lib/rugged/attributes.rb +41 -0
  19. data/lib/rugged/blob.rb +28 -0
  20. data/lib/rugged/diff.rb +0 -1
  21. data/lib/rugged/diff/line.rb +1 -3
  22. data/lib/rugged/patch.rb +12 -2
  23. data/lib/rugged/repository.rb +7 -0
  24. data/lib/rugged/submodule_collection.rb +48 -0
  25. data/lib/rugged/version.rb +1 -1
  26. data/vendor/libgit2/CMakeLists.txt +27 -3
  27. data/vendor/libgit2/cmake/Modules/FindGSSAPI.cmake +324 -0
  28. data/vendor/libgit2/deps/http-parser/http_parser.h +2 -0
  29. data/vendor/libgit2/deps/zlib/adler32.c +39 -29
  30. data/vendor/libgit2/deps/zlib/crc32.c +33 -50
  31. data/vendor/libgit2/deps/zlib/crc32.h +1 -1
  32. data/vendor/libgit2/deps/zlib/deflate.c +198 -65
  33. data/vendor/libgit2/deps/zlib/deflate.h +8 -4
  34. data/vendor/libgit2/deps/zlib/infback.c +640 -0
  35. data/vendor/libgit2/deps/zlib/inffast.c +3 -3
  36. data/vendor/libgit2/deps/zlib/inffixed.h +3 -3
  37. data/vendor/libgit2/deps/zlib/inflate.c +84 -52
  38. data/vendor/libgit2/deps/zlib/inftrees.c +15 -39
  39. data/vendor/libgit2/deps/zlib/trees.c +18 -36
  40. data/vendor/libgit2/deps/zlib/zconf.h +4 -0
  41. data/vendor/libgit2/deps/zlib/zlib.h +250 -95
  42. data/vendor/libgit2/deps/zlib/zutil.c +13 -10
  43. data/vendor/libgit2/deps/zlib/zutil.h +41 -62
  44. data/vendor/libgit2/include/git2.h +4 -0
  45. data/vendor/libgit2/include/git2/annotated_commit.h +99 -0
  46. data/vendor/libgit2/include/git2/attr.h +16 -13
  47. data/vendor/libgit2/include/git2/branch.h +11 -0
  48. data/vendor/libgit2/include/git2/buffer.h +16 -0
  49. data/vendor/libgit2/include/git2/checkout.h +12 -12
  50. data/vendor/libgit2/include/git2/cherrypick.h +15 -15
  51. data/vendor/libgit2/include/git2/clone.h +77 -69
  52. data/vendor/libgit2/include/git2/common.h +13 -1
  53. data/vendor/libgit2/include/git2/config.h +0 -14
  54. data/vendor/libgit2/include/git2/describe.h +162 -0
  55. data/vendor/libgit2/include/git2/diff.h +13 -8
  56. data/vendor/libgit2/include/git2/errors.h +5 -0
  57. data/vendor/libgit2/include/git2/global.h +38 -0
  58. data/vendor/libgit2/include/git2/merge.h +38 -64
  59. data/vendor/libgit2/include/git2/net.h +2 -2
  60. data/vendor/libgit2/include/git2/notes.h +17 -0
  61. data/vendor/libgit2/include/git2/oid.h +8 -4
  62. data/vendor/libgit2/include/git2/oidarray.h +40 -0
  63. data/vendor/libgit2/include/git2/rebase.h +261 -0
  64. data/vendor/libgit2/include/git2/reflog.h +1 -1
  65. data/vendor/libgit2/include/git2/remote.h +25 -47
  66. data/vendor/libgit2/include/git2/repository.h +4 -1
  67. data/vendor/libgit2/include/git2/reset.h +10 -1
  68. data/vendor/libgit2/include/git2/revert.h +1 -1
  69. data/vendor/libgit2/include/git2/revwalk.h +28 -23
  70. data/vendor/libgit2/include/git2/status.h +19 -15
  71. data/vendor/libgit2/include/git2/submodule.h +18 -0
  72. data/vendor/libgit2/include/git2/sys/config.h +0 -1
  73. data/vendor/libgit2/{src → include/git2/sys}/hashsig.h +11 -7
  74. data/vendor/libgit2/include/git2/sys/refdb_backend.h +13 -0
  75. data/vendor/libgit2/include/git2/sys/refs.h +0 -11
  76. data/vendor/libgit2/include/git2/sys/repository.h +13 -0
  77. data/vendor/libgit2/include/git2/sys/transport.h +352 -0
  78. data/vendor/libgit2/include/git2/threads.h +10 -20
  79. data/vendor/libgit2/include/git2/transaction.h +111 -0
  80. data/vendor/libgit2/include/git2/transport.h +79 -313
  81. data/vendor/libgit2/include/git2/tree.h +4 -2
  82. data/vendor/libgit2/include/git2/types.h +77 -8
  83. data/vendor/libgit2/include/git2/version.h +2 -2
  84. data/vendor/libgit2/src/annotated_commit.c +121 -0
  85. data/vendor/libgit2/src/annotated_commit.h +22 -0
  86. data/vendor/libgit2/src/attr.c +8 -4
  87. data/vendor/libgit2/src/attr_file.c +24 -2
  88. data/vendor/libgit2/src/blame.c +0 -1
  89. data/vendor/libgit2/src/branch.c +32 -3
  90. data/vendor/libgit2/src/buf_text.c +9 -5
  91. data/vendor/libgit2/src/buf_text.h +3 -2
  92. data/vendor/libgit2/src/buffer.c +67 -10
  93. data/vendor/libgit2/src/buffer.h +4 -2
  94. data/vendor/libgit2/src/cache.c +9 -9
  95. data/vendor/libgit2/src/cache.h +1 -1
  96. data/vendor/libgit2/src/cc-compat.h +2 -0
  97. data/vendor/libgit2/src/checkout.c +263 -82
  98. data/vendor/libgit2/src/checkout.h +1 -0
  99. data/vendor/libgit2/src/cherrypick.c +41 -44
  100. data/vendor/libgit2/src/clone.c +96 -58
  101. data/vendor/libgit2/src/commit.c +5 -31
  102. data/vendor/libgit2/src/commit_list.h +3 -1
  103. data/vendor/libgit2/src/config.c +0 -17
  104. data/vendor/libgit2/src/config_cache.c +0 -2
  105. data/vendor/libgit2/src/config_file.c +12 -15
  106. data/vendor/libgit2/src/crlf.c +2 -1
  107. data/vendor/libgit2/src/describe.c +886 -0
  108. data/vendor/libgit2/src/diff.c +29 -3
  109. data/vendor/libgit2/src/diff_file.c +1 -0
  110. data/vendor/libgit2/src/diff_patch.c +2 -3
  111. data/vendor/libgit2/src/diff_print.c +11 -9
  112. data/vendor/libgit2/src/diff_tform.c +4 -4
  113. data/vendor/libgit2/src/errors.c +9 -7
  114. data/vendor/libgit2/src/fetch.c +6 -6
  115. data/vendor/libgit2/src/fetchhead.h +2 -4
  116. data/vendor/libgit2/src/filebuf.c +0 -2
  117. data/vendor/libgit2/src/filebuf.h +2 -3
  118. data/vendor/libgit2/src/fileops.c +9 -7
  119. data/vendor/libgit2/src/global.c +44 -35
  120. data/vendor/libgit2/src/global.h +2 -0
  121. data/vendor/libgit2/src/graph.c +2 -2
  122. data/vendor/libgit2/src/hash.h +3 -1
  123. data/vendor/libgit2/src/hash/hash_common_crypto.h +44 -0
  124. data/vendor/libgit2/src/hash/hash_win32.c +1 -1
  125. data/vendor/libgit2/src/hashsig.c +1 -1
  126. data/vendor/libgit2/src/ignore.c +5 -88
  127. data/vendor/libgit2/src/index.c +70 -57
  128. data/vendor/libgit2/src/index.h +1 -0
  129. data/vendor/libgit2/src/indexer.c +16 -5
  130. data/vendor/libgit2/src/iterator.c +70 -1
  131. data/vendor/libgit2/src/iterator.h +5 -1
  132. data/vendor/libgit2/src/map.h +0 -1
  133. data/vendor/libgit2/src/merge.c +203 -327
  134. data/vendor/libgit2/src/merge.h +3 -13
  135. data/vendor/libgit2/src/mwindow.c +119 -8
  136. data/vendor/libgit2/src/mwindow.h +9 -1
  137. data/vendor/libgit2/src/netops.c +7 -8
  138. data/vendor/libgit2/src/netops.h +6 -16
  139. data/vendor/libgit2/src/notes.c +31 -4
  140. data/vendor/libgit2/src/notes.h +3 -0
  141. data/vendor/libgit2/src/odb.c +23 -1
  142. data/vendor/libgit2/src/odb_loose.c +1 -1
  143. data/vendor/libgit2/src/odb_pack.c +6 -3
  144. data/vendor/libgit2/src/oid.c +9 -1
  145. data/vendor/libgit2/src/oid.h +11 -0
  146. data/vendor/libgit2/src/oidarray.c +21 -0
  147. data/vendor/libgit2/src/oidarray.h +18 -0
  148. data/vendor/libgit2/src/oidmap.h +16 -0
  149. data/vendor/libgit2/src/pack.c +20 -7
  150. data/vendor/libgit2/src/pack.h +3 -0
  151. data/vendor/libgit2/src/path.c +120 -293
  152. data/vendor/libgit2/src/path.h +21 -44
  153. data/vendor/libgit2/src/pathspec.c +1 -1
  154. data/vendor/libgit2/src/pool.c +5 -11
  155. data/vendor/libgit2/src/pool.h +0 -2
  156. data/vendor/libgit2/src/posix.c +6 -6
  157. data/vendor/libgit2/src/posix.h +48 -28
  158. data/vendor/libgit2/src/push.c +19 -48
  159. data/vendor/libgit2/src/push.h +2 -4
  160. data/vendor/libgit2/src/rebase.c +1125 -0
  161. data/vendor/libgit2/src/refdb.c +19 -0
  162. data/vendor/libgit2/src/refdb.h +2 -1
  163. data/vendor/libgit2/src/refdb_fs.c +101 -29
  164. data/vendor/libgit2/src/reflog.c +1 -1
  165. data/vendor/libgit2/src/refs.c +38 -3
  166. data/vendor/libgit2/src/refs.h +13 -2
  167. data/vendor/libgit2/src/refspec.c +20 -2
  168. data/vendor/libgit2/src/remote.c +288 -154
  169. data/vendor/libgit2/src/remote.h +5 -1
  170. data/vendor/libgit2/src/repository.c +75 -36
  171. data/vendor/libgit2/src/repository.h +3 -25
  172. data/vendor/libgit2/src/reset.c +5 -1
  173. data/vendor/libgit2/src/revert.c +4 -6
  174. data/vendor/libgit2/src/revparse.c +15 -18
  175. data/vendor/libgit2/src/revwalk.c +96 -22
  176. data/vendor/libgit2/src/revwalk.h +5 -4
  177. data/vendor/libgit2/src/settings.c +22 -0
  178. data/vendor/libgit2/src/signature.c +37 -2
  179. data/vendor/libgit2/src/signature.h +3 -0
  180. data/vendor/libgit2/src/stash.c +17 -12
  181. data/vendor/libgit2/src/status.c +13 -3
  182. data/vendor/libgit2/src/strnlen.h +2 -1
  183. data/vendor/libgit2/src/submodule.c +75 -35
  184. data/vendor/libgit2/src/thread-utils.h +4 -9
  185. data/vendor/libgit2/src/trace.h +9 -1
  186. data/vendor/libgit2/src/transaction.c +352 -0
  187. data/vendor/libgit2/src/transport.c +91 -97
  188. data/vendor/libgit2/src/transports/auth.c +71 -0
  189. data/vendor/libgit2/src/transports/auth.h +63 -0
  190. data/vendor/libgit2/src/transports/auth_negotiate.c +275 -0
  191. data/vendor/libgit2/src/transports/auth_negotiate.h +27 -0
  192. data/vendor/libgit2/src/transports/cred.c +58 -0
  193. data/vendor/libgit2/src/transports/cred.h +14 -0
  194. data/vendor/libgit2/src/transports/cred_helpers.c +3 -0
  195. data/vendor/libgit2/src/transports/git.c +1 -0
  196. data/vendor/libgit2/src/transports/http.c +208 -82
  197. data/vendor/libgit2/src/transports/local.c +2 -2
  198. data/vendor/libgit2/src/transports/smart.c +2 -0
  199. data/vendor/libgit2/src/transports/smart.h +2 -0
  200. data/vendor/libgit2/src/transports/smart_protocol.c +10 -10
  201. data/vendor/libgit2/src/transports/ssh.c +243 -57
  202. data/vendor/libgit2/src/transports/winhttp.c +139 -35
  203. data/vendor/libgit2/src/tree-cache.c +118 -31
  204. data/vendor/libgit2/src/tree-cache.h +12 -7
  205. data/vendor/libgit2/src/tree.c +83 -64
  206. data/vendor/libgit2/src/tree.h +2 -3
  207. data/vendor/libgit2/src/unix/map.c +8 -2
  208. data/vendor/libgit2/src/unix/posix.h +23 -9
  209. data/vendor/libgit2/src/unix/realpath.c +8 -7
  210. data/vendor/libgit2/src/userdiff.h +3 -3
  211. data/vendor/libgit2/src/util.c +2 -92
  212. data/vendor/libgit2/src/util.h +3 -15
  213. data/vendor/libgit2/src/win32/findfile.c +0 -1
  214. data/vendor/libgit2/src/win32/map.c +3 -2
  215. data/vendor/libgit2/src/win32/mingw-compat.h +5 -12
  216. data/vendor/libgit2/src/win32/msvc-compat.h +3 -32
  217. data/vendor/libgit2/src/win32/posix.h +20 -32
  218. data/vendor/libgit2/src/win32/posix_w32.c +103 -31
  219. data/vendor/libgit2/src/win32/utf-conv.c +6 -36
  220. data/vendor/libgit2/src/win32/utf-conv.h +39 -0
  221. data/vendor/libgit2/src/win32/w32_util.h +0 -1
  222. metadata +32 -7
  223. data/vendor/libgit2/src/win32/path_w32.c +0 -305
  224. data/vendor/libgit2/src/win32/path_w32.h +0 -82
@@ -0,0 +1,236 @@
1
+ /*
2
+ * The MIT License
3
+ *
4
+ * Copyright (c) 2014 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_mRugged;
28
+ extern VALUE rb_cRuggedSubmodule;
29
+ VALUE rb_cRuggedSubmoduleCollection;
30
+
31
+ /*
32
+ * call-seq:
33
+ * SubmoduleCollection.new(repo) -> submodules
34
+ *
35
+ * Creates and returns a new collection of submodules for the given +repo+.
36
+ */
37
+ static VALUE rb_git_submodule_collection_initialize(VALUE self, VALUE rb_repo)
38
+ {
39
+ rugged_check_repo(rb_repo);
40
+ rugged_set_owner(self, rb_repo);
41
+ return self;
42
+ }
43
+
44
+ static void rb_git_submodule__free(git_submodule *submodule)
45
+ {
46
+ git_submodule_free(submodule);
47
+ }
48
+
49
+ VALUE rugged_submodule_new(VALUE owner, git_submodule *submodule)
50
+ {
51
+ VALUE rb_submodule;
52
+
53
+ rb_submodule = Data_Wrap_Struct(
54
+ rb_cRuggedSubmodule,
55
+ NULL,
56
+ &rb_git_submodule__free,
57
+ submodule);
58
+ rugged_set_owner(rb_submodule, owner);
59
+
60
+ return rb_submodule;
61
+ }
62
+
63
+ /*
64
+ * call-seq:
65
+ * submodules[name] -> submodule or nil
66
+ *
67
+ * Lookup +submodule+ by +name+ or +path+ (they are usually the same) in
68
+ * +repository+.
69
+ *
70
+ * Returns +nil+ if submodule does not exist.
71
+ *
72
+ * Raises <tt>Rugged::SubmoduleError</tt> if submodule exists only in working
73
+ * directory (i.e. there is a subdirectory that is a valid self-contained git
74
+ * repository) and is not mentioned in the +HEAD+, the index and the config.
75
+ */
76
+ static VALUE rb_git_submodule_collection_aref(VALUE self, VALUE rb_name)
77
+ {
78
+ git_repository *repo;
79
+ git_submodule *submodule;
80
+ int error;
81
+
82
+ VALUE rb_repo = rugged_owner(self);
83
+ Data_Get_Struct(rb_repo, git_repository, repo);
84
+
85
+ Check_Type(rb_name, T_STRING);
86
+
87
+ error = git_submodule_lookup(
88
+ &submodule,
89
+ repo,
90
+ StringValueCStr(rb_name)
91
+ );
92
+
93
+ if (error == GIT_ENOTFOUND)
94
+ return Qnil;
95
+
96
+ rugged_exception_check(error);
97
+
98
+ return rugged_submodule_new(rb_repo, submodule);
99
+ }
100
+
101
+ static int cb_submodule__each(git_submodule *submodule, const char *name, void *data)
102
+ {
103
+ struct rugged_cb_payload *payload = data;
104
+ git_repository *repo;
105
+ git_submodule *dummy_sm;
106
+ VALUE rb_repo;
107
+
108
+ rb_repo = payload->rb_data;
109
+ Data_Get_Struct(rb_repo, git_repository, repo);
110
+
111
+ /* The submodule passed here has it's refcount decreased just after
112
+ * the foreach finishes. The only way to increase that refcount is
113
+ * to lookup the submodule.
114
+ *
115
+ * This should not return an error as the submodule name here is valid
116
+ * and exists, as it was just passed to this callback.
117
+ */
118
+ git_submodule_lookup(&dummy_sm, repo, git_submodule_name(submodule));
119
+
120
+ rb_protect(
121
+ rb_yield,
122
+ rugged_submodule_new(rb_repo, dummy_sm),
123
+ &payload->exception
124
+ );
125
+ return (payload->exception) ? GIT_ERROR : GIT_OK;
126
+ }
127
+
128
+ /*
129
+ * call-seq:
130
+ * submodules.each { |submodule| block }
131
+ * submodules.each -> enumerator
132
+ *
133
+ * Iterate through all the tracked submodules in the collection's +repository+.
134
+ *
135
+ * The given +block+ will be called once with each +submodule+
136
+ * as a Rugged::Submodule instance.
137
+ * If no block is given, an enumerator will be returned.
138
+ */
139
+ static VALUE rb_git_submodule_collection_each(VALUE self)
140
+ {
141
+ git_repository *repo;
142
+ int error;
143
+ struct rugged_cb_payload payload;
144
+
145
+ VALUE rb_repo = rugged_owner(self);
146
+ Data_Get_Struct(rb_repo, git_repository, repo);
147
+
148
+ if (!rb_block_given_p())
149
+ return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each"));
150
+
151
+ payload.exception = 0;
152
+ payload.rb_data = rb_repo;
153
+
154
+ error = git_submodule_foreach(repo, &cb_submodule__each, &payload);
155
+
156
+ if (payload.exception)
157
+ rb_jump_tag(payload.exception);
158
+ rugged_exception_check(error);
159
+
160
+ return Qnil;
161
+ }
162
+
163
+ /*
164
+ * call-seq:
165
+ * submodules.setup_add(url, path[, options]) -> submodule
166
+ *
167
+ * Setup a new +submodule+ for checkout in +repository+.
168
+ *
169
+ * This does <tt>"git submodule add"</tt> up to the fetch and checkout of the
170
+ * submodule contents. It prepares a new submodule, creates an entry in
171
+ * +.gitmodules+ and creates an empty initialized repository either at the
172
+ * given +path+ in the working directory or in +.git/modules+ with a gitlink
173
+ * from the working directory to the new repository.
174
+ *
175
+ * To fully emulate <tt>"git submodule add"</tt> call this function, then open
176
+ * the submodule repository and perform the clone step as needed.
177
+ * Lastly, call Submodule#finalize_add to wrap up adding the new submodule and
178
+ * +.gitmodules+ to the index to be ready to commit.
179
+ *
180
+ * - +url+: URL for the submodule's remote
181
+ * - +path+: path at which the submodule should be created
182
+ *
183
+ * The following options can be passed in the +options+ Hash:
184
+ * :gitlink ::
185
+ * (defaults to +true+) should workdir contain a
186
+ * gitlink to the repository in +.git/modules+ vs. repository
187
+ * directly in workdir.
188
+ *
189
+ * Returns the newly created +submodule+
190
+ */
191
+ static VALUE rb_git_submodule_setup_add(int argc, VALUE *argv, VALUE self)
192
+ {
193
+ git_submodule *submodule;
194
+ git_repository *repo;
195
+ int error;
196
+ int use_gitlink = 1;
197
+ VALUE rb_repo, rb_url, rb_path, rb_options;
198
+
199
+ rb_scan_args(argc, argv, "20:", &rb_url, &rb_path, &rb_options);
200
+
201
+ Check_Type(rb_url, T_STRING);
202
+ Check_Type(rb_path, T_STRING);
203
+
204
+ rb_repo = rugged_owner(self);
205
+ Data_Get_Struct(rb_repo, git_repository, repo);
206
+
207
+ if (!NIL_P(rb_options)) {
208
+ VALUE rb_val;
209
+
210
+ rb_val = rb_hash_aref(rb_options, CSTR2SYM("gitlink"));
211
+ use_gitlink = (rb_val != Qfalse);
212
+ }
213
+
214
+ error = git_submodule_add_setup(
215
+ &submodule,
216
+ repo,
217
+ StringValueCStr(rb_url),
218
+ StringValueCStr(rb_path),
219
+ use_gitlink
220
+ );
221
+
222
+ rugged_exception_check(error);
223
+
224
+ return rugged_submodule_new(rb_repo, submodule);
225
+ }
226
+
227
+ void Init_rugged_submodule_collection(void)
228
+ {
229
+ rb_cRuggedSubmoduleCollection = rb_define_class_under(rb_mRugged, "SubmoduleCollection", rb_cObject);
230
+ rb_include_module(rb_cRuggedSubmoduleCollection, rb_mEnumerable);
231
+
232
+ rb_define_method(rb_cRuggedSubmoduleCollection, "initialize", rb_git_submodule_collection_initialize, 1);
233
+ rb_define_method(rb_cRuggedSubmoduleCollection, "[]", rb_git_submodule_collection_aref, 1);
234
+ rb_define_method(rb_cRuggedSubmoduleCollection, "each", rb_git_submodule_collection_each, 0);
235
+ rb_define_method(rb_cRuggedSubmoduleCollection, "setup_add", rb_git_submodule_setup_add, -1);
236
+ }
@@ -177,6 +177,73 @@ static VALUE rb_git_tag_collection_create(int argc, VALUE *argv, VALUE self)
177
177
  return rb_git_tag_collection_aref(self, rb_name);
178
178
  }
179
179
 
180
+ /*
181
+ * call-seq:
182
+ * tags.create_annotation(name, target, annotation) -> annotation
183
+ *
184
+ * Create a new annotated tag object with the specified +name+ on +target+ in
185
+ * +repo+.
186
+ *
187
+ * Unlike the +create+ method, +create_annotation+ simply creates a tag
188
+ * object. It does not write a tag ref.
189
+ *
190
+ * +annotation+ must have the following keys:
191
+ *
192
+ * :tagger ::
193
+ * An optional Hash containing a git signature. Defaults to the signature
194
+ * from the configuration if only `:message` is given. Will cause the
195
+ * creation of an annotated tag object if present.
196
+ *
197
+ * :message ::
198
+ * An optional string containing the message for the new tag.
199
+ *
200
+ * Returns an instance of Rugged::Tag::Annotation representing the newly
201
+ * created annotation.
202
+ */
203
+ static VALUE rb_git_tag_collection_create_annotation(VALUE self, VALUE rb_name, VALUE rb_target, VALUE rb_annotation)
204
+ {
205
+ git_oid tag_oid;
206
+ git_repository *repo = NULL;
207
+ git_object *target = NULL, *tag = NULL;
208
+ git_signature *tagger = NULL;
209
+ VALUE rb_message;
210
+ int error;
211
+
212
+ VALUE rb_repo = rugged_owner(self);
213
+ rugged_check_repo(rb_repo);
214
+ Data_Get_Struct(rb_repo, git_repository, repo);
215
+
216
+ Check_Type(rb_name, T_STRING);
217
+
218
+ target = rugged_object_get(repo, rb_target, GIT_OBJ_ANY);
219
+
220
+ rb_message = rb_hash_aref(rb_annotation, CSTR2SYM("message"));
221
+ Check_Type(rb_message, T_STRING);
222
+
223
+ tagger = rugged_signature_get(
224
+ rb_hash_aref(rb_annotation, CSTR2SYM("tagger")), repo
225
+ );
226
+
227
+ error = git_tag_annotation_create(
228
+ &tag_oid,
229
+ repo,
230
+ StringValueCStr(rb_name),
231
+ target,
232
+ tagger,
233
+ StringValueCStr(rb_message)
234
+ );
235
+
236
+ git_object_free(target);
237
+ git_signature_free(tagger);
238
+
239
+ rugged_exception_check(error);
240
+
241
+ error = git_object_lookup(&tag, repo, &tag_oid, GIT_OBJ_TAG);
242
+ rugged_exception_check(error);
243
+
244
+ return rugged_object_new(rb_repo, tag);
245
+ }
246
+
180
247
  static VALUE each_tag(int argc, VALUE *argv, VALUE self, int tag_names_only)
181
248
  {
182
249
  git_repository *repo;
@@ -269,8 +336,9 @@ void Init_rugged_tag_collection(void)
269
336
 
270
337
  rb_define_method(rb_cRuggedTagCollection, "initialize", rb_git_tag_collection_initialize, 1);
271
338
 
272
- rb_define_method(rb_cRuggedTagCollection, "create", rb_git_tag_collection_create, -1);
273
- rb_define_method(rb_cRuggedTagCollection, "[]", rb_git_tag_collection_aref, 1);
339
+ rb_define_method(rb_cRuggedTagCollection, "create", rb_git_tag_collection_create, -1);
340
+ rb_define_method(rb_cRuggedTagCollection, "create_annotation", rb_git_tag_collection_create_annotation, 3);
341
+ rb_define_method(rb_cRuggedTagCollection, "[]", rb_git_tag_collection_aref, 1);
274
342
 
275
343
  rb_define_method(rb_cRuggedTagCollection, "each", rb_git_tag_collection_each, -1);
276
344
  rb_define_method(rb_cRuggedTagCollection, "each_name", rb_git_tag_collection_each_name, -1);
@@ -188,14 +188,26 @@ static VALUE rb_git_tree_each(VALUE self)
188
188
  return Qnil;
189
189
  }
190
190
 
191
- static int rugged__treewalk_cb(const char *root, const git_tree_entry *entry, void *proc)
191
+ static int rugged__treewalk_cb(const char *root, const git_tree_entry *entry, void *payload)
192
192
  {
193
- rb_funcall((VALUE)proc, rb_intern("call"), 2,
194
- rb_str_new_utf8(root),
195
- rb_git_treeentry_fromC(entry)
196
- );
193
+ int *exception = (int *)payload;
197
194
 
198
- return GIT_OK;
195
+ VALUE rb_result, rb_args = rb_ary_new2(2);
196
+
197
+ rb_ary_push(rb_args, rb_str_new_utf8(root));
198
+ rb_ary_push(rb_args, rb_git_treeentry_fromC(entry));
199
+
200
+ rb_result = rb_protect(rb_yield_splat, rb_args, exception);
201
+
202
+ if (*exception)
203
+ return -1;
204
+
205
+ /* skip entry when 'false' is returned */
206
+ if (TYPE(rb_result) == T_FALSE)
207
+ return 1;
208
+
209
+ /* otherwise continue normal iteration */
210
+ return 0;
199
211
  }
200
212
 
201
213
  /*
@@ -208,6 +220,9 @@ static int rugged__treewalk_cb(const char *root, const git_tree_entry *entry, vo
208
220
  * also takes a +root+, the relative path in the traversal, starting from the root
209
221
  * of the original tree.
210
222
  *
223
+ * If the +block+ returns a falsy value, that entry and its sub-entries (in the case
224
+ * of a folder) will be skipped for the iteration.
225
+ *
211
226
  * If no +block+ is given, an +Iterator+ is returned instead.
212
227
  *
213
228
  * tree.walk(:postorder) { |root, entry| puts "#{root}#{entry[:name]} [#{entry[:oid]}]" }
@@ -223,7 +238,7 @@ static int rugged__treewalk_cb(const char *root, const git_tree_entry *entry, vo
223
238
  static VALUE rb_git_tree_walk(VALUE self, VALUE rb_mode)
224
239
  {
225
240
  git_tree *tree;
226
- int error, mode = 0;
241
+ int error, mode = 0, exception = 0;
227
242
  ID id_mode;
228
243
 
229
244
  Data_Get_Struct(self, git_tree, tree);
@@ -242,7 +257,11 @@ static VALUE rb_git_tree_walk(VALUE self, VALUE rb_mode)
242
257
  rb_raise(rb_eTypeError,
243
258
  "Invalid iteration mode. Expected `:preorder` or `:postorder`");
244
259
 
245
- error = git_tree_walk(tree, mode, &rugged__treewalk_cb, (void *)rb_block_proc());
260
+ error = git_tree_walk(tree, mode, &rugged__treewalk_cb, (void *)&exception);
261
+
262
+ if (exception)
263
+ rb_jump_tag(exception);
264
+
246
265
  rugged_exception_check(error);
247
266
 
248
267
  return Qnil;
@@ -454,7 +473,7 @@ static VALUE rb_git_tree_diff_(int argc, VALUE *argv, VALUE self)
454
473
  xfree(opts.pathspec.strings);
455
474
  rugged_exception_check(error);
456
475
 
457
- return rugged_diff_new(rb_cRuggedDiff, self, diff);
476
+ return rugged_diff_new(rb_cRuggedDiff, rb_repo, diff);
458
477
  }
459
478
 
460
479
  /*
@@ -489,7 +508,7 @@ static VALUE rb_git_tree_diff_workdir(int argc, VALUE *argv, VALUE self)
489
508
  xfree(opts.pathspec.strings);
490
509
  rugged_exception_check(error);
491
510
 
492
- return rugged_diff_new(rb_cRuggedDiff, self, diff);
511
+ return rugged_diff_new(rb_cRuggedDiff, owner, diff);
493
512
  }
494
513
 
495
514
  void rugged_parse_merge_options(git_merge_options *opts, VALUE rb_options)
data/lib/rugged.rb CHANGED
@@ -18,3 +18,6 @@ require 'rugged/diff'
18
18
  require 'rugged/patch'
19
19
  require 'rugged/remote'
20
20
  require 'rugged/credentials'
21
+ require 'rugged/attributes'
22
+ require 'rugged/blob'
23
+ require 'rugged/submodule_collection'
@@ -0,0 +1,41 @@
1
+ module Rugged
2
+ class Repository
3
+ def attributes(path, options = {})
4
+ Attributes.new(self, path, options)
5
+ end
6
+
7
+ class Attributes
8
+ include Enumerable
9
+
10
+ LOAD_PRIORITIES = {
11
+ [:file, :index] => 0,
12
+ [:index, :file] => 1,
13
+ [:index] => 2,
14
+ }
15
+
16
+ def self.parse_opts(opt)
17
+ flags = LOAD_PRIORITIES[opt[:priority]] || 0
18
+ flags |= 4 if opt[:skip_system]
19
+ flags
20
+ end
21
+
22
+ def initialize(repository, path, options = {})
23
+ @repository = repository
24
+ @path = path
25
+ @load_flags = Attributes.parse_opts(options)
26
+ end
27
+
28
+ def [](attribute)
29
+ @repository.fetch_attributes(@path, attribute, @load_flags)
30
+ end
31
+
32
+ def to_h
33
+ @hash ||= @repository.fetch_attributes(@path, nil, @load_flags)
34
+ end
35
+
36
+ def each(&block)
37
+ to_h.each(&block)
38
+ end
39
+ end
40
+ end
41
+ end