rdavila-rugged 0.24.0b13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +21 -0
  3. data/README.md +619 -0
  4. data/ext/rugged/extconf.rb +105 -0
  5. data/ext/rugged/rugged.c +527 -0
  6. data/ext/rugged/rugged.h +185 -0
  7. data/ext/rugged/rugged_backend.c +34 -0
  8. data/ext/rugged/rugged_blame.c +292 -0
  9. data/ext/rugged/rugged_blob.c +638 -0
  10. data/ext/rugged/rugged_branch.c +195 -0
  11. data/ext/rugged/rugged_branch_collection.c +408 -0
  12. data/ext/rugged/rugged_commit.c +691 -0
  13. data/ext/rugged/rugged_config.c +404 -0
  14. data/ext/rugged/rugged_cred.c +148 -0
  15. data/ext/rugged/rugged_diff.c +686 -0
  16. data/ext/rugged/rugged_diff_delta.c +105 -0
  17. data/ext/rugged/rugged_diff_hunk.c +103 -0
  18. data/ext/rugged/rugged_diff_line.c +83 -0
  19. data/ext/rugged/rugged_index.c +1255 -0
  20. data/ext/rugged/rugged_note.c +376 -0
  21. data/ext/rugged/rugged_object.c +383 -0
  22. data/ext/rugged/rugged_patch.c +245 -0
  23. data/ext/rugged/rugged_reference.c +396 -0
  24. data/ext/rugged/rugged_reference_collection.c +446 -0
  25. data/ext/rugged/rugged_remote.c +691 -0
  26. data/ext/rugged/rugged_remote_collection.c +457 -0
  27. data/ext/rugged/rugged_repo.c +2669 -0
  28. data/ext/rugged/rugged_revwalk.c +495 -0
  29. data/ext/rugged/rugged_settings.c +155 -0
  30. data/ext/rugged/rugged_signature.c +106 -0
  31. data/ext/rugged/rugged_submodule.c +852 -0
  32. data/ext/rugged/rugged_submodule_collection.c +384 -0
  33. data/ext/rugged/rugged_tag.c +251 -0
  34. data/ext/rugged/rugged_tag_collection.c +347 -0
  35. data/ext/rugged/rugged_tree.c +919 -0
  36. data/lib/rugged.rb +23 -0
  37. data/lib/rugged/attributes.rb +41 -0
  38. data/lib/rugged/blob.rb +28 -0
  39. data/lib/rugged/branch.rb +19 -0
  40. data/lib/rugged/commit.rb +54 -0
  41. data/lib/rugged/console.rb +9 -0
  42. data/lib/rugged/credentials.rb +43 -0
  43. data/lib/rugged/diff.rb +20 -0
  44. data/lib/rugged/diff/delta.rb +53 -0
  45. data/lib/rugged/diff/hunk.rb +18 -0
  46. data/lib/rugged/diff/line.rb +47 -0
  47. data/lib/rugged/index.rb +13 -0
  48. data/lib/rugged/object.rb +7 -0
  49. data/lib/rugged/patch.rb +36 -0
  50. data/lib/rugged/reference.rb +7 -0
  51. data/lib/rugged/remote.rb +4 -0
  52. data/lib/rugged/repository.rb +227 -0
  53. data/lib/rugged/submodule_collection.rb +48 -0
  54. data/lib/rugged/tag.rb +50 -0
  55. data/lib/rugged/tree.rb +38 -0
  56. data/lib/rugged/version.rb +3 -0
  57. data/lib/rugged/walker.rb +5 -0
  58. metadata +146 -0
@@ -0,0 +1,105 @@
1
+ require 'mkmf'
2
+
3
+ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
4
+
5
+ $CFLAGS << " #{ENV["CFLAGS"]}"
6
+ $CFLAGS << " -g"
7
+ $CFLAGS << " -O3" unless $CFLAGS[/-O\d/]
8
+ $CFLAGS << " -Wall -Wno-comment"
9
+
10
+ def sys(cmd)
11
+ puts " -- #{cmd}"
12
+ unless ret = xsystem(cmd)
13
+ raise "ERROR: '#{cmd}' failed"
14
+ end
15
+ ret
16
+ end
17
+
18
+ def windows?
19
+ RbConfig::CONFIG['host_os'] =~ /mswin|mingw/
20
+ end
21
+
22
+ if !(MAKE = find_executable('gmake') || find_executable('make'))
23
+ abort "ERROR: GNU make is required to build Rugged."
24
+ end
25
+
26
+ CWD = File.expand_path(File.dirname(__FILE__))
27
+ LIBGIT2_DIR = File.join(CWD, '..', '..', 'vendor', 'libgit2')
28
+
29
+ if arg_config("--use-system-libraries", !!ENV['RUGGED_USE_SYSTEM_LIBRARIES'])
30
+ puts "Building Rugged using system libraries.\n"
31
+
32
+ dir_config('git2').any? or pkg_config('libgit2')
33
+
34
+ major = minor = nil
35
+
36
+ File.readlines(File.join(LIBGIT2_DIR, "include", "git2", "version.h")).each do |line|
37
+ if !major && (matches = line.match(/^#define LIBGIT2_VER_MAJOR ([0-9]+)$/))
38
+ major = matches[1]
39
+ next
40
+ end
41
+
42
+ if !minor && (matches = line.match(/^#define LIBGIT2_VER_MINOR ([0-9]+)$/))
43
+ minor = matches[1]
44
+ next
45
+ end
46
+
47
+ break if major && minor
48
+ end
49
+
50
+ try_compile(<<-SRC) or abort "libgit2 version is not compatible, expected ~> #{major}.#{minor}.0"
51
+ #include <git2/version.h>
52
+
53
+ #if LIBGIT2_VER_MAJOR != #{major} || LIBGIT2_VER_MINOR != #{minor}
54
+ #error libgit2 version is not compatible
55
+ #endif
56
+ SRC
57
+ else
58
+ if !find_executable('cmake')
59
+ abort "ERROR: CMake is required to build Rugged."
60
+ end
61
+
62
+ if !windows? && !find_executable('pkg-config')
63
+ abort "ERROR: pkg-config is required to build Rugged."
64
+ end
65
+
66
+ Dir.chdir(LIBGIT2_DIR) do
67
+ Dir.mkdir("build") if !Dir.exists?("build")
68
+
69
+ Dir.chdir("build") do
70
+ sys("cmake .. -DBUILD_CLAR=OFF -DTHREADSAFE=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_C_FLAGS=-fPIC -DCMAKE_BUILD_TYPE=RelWithDebInfo -G \"Unix Makefiles\"")
71
+ sys(MAKE)
72
+
73
+ # "normal" libraries (and libgit2 builds) get all these when they build but we're doing it
74
+ # statically so we put the libraries in by hand. It's important that we put the libraries themselves
75
+ # in $LIBS or the final linking stage won't pick them up
76
+ if windows?
77
+ $LDFLAGS << " " + "-L#{Dir.pwd}/deps/winhttp"
78
+ $LIBS << " -lwinhttp -lcrypt32 -lrpcrt4 -lole32"
79
+ else
80
+ pcfile = File.join(LIBGIT2_DIR, "build", "libgit2.pc")
81
+ $LDFLAGS << " " + `pkg-config --libs --static #{pcfile}`.strip
82
+ end
83
+ end
84
+ end
85
+
86
+ # Prepend the vendored libgit2 build dir to the $DEFLIBPATH.
87
+ #
88
+ # By default, $DEFLIBPATH includes $(libpath), which usually points
89
+ # to something like /usr/lib for system ruby versions (not those
90
+ # installed through rbenv or rvm).
91
+ #
92
+ # This was causing system-wide libgit2 installations to be preferred
93
+ # over of our vendored libgit2 version when building rugged.
94
+ #
95
+ # By putting the path to the vendored libgit2 library at the front of
96
+ # $DEFLIBPATH, we can ensure that our bundled version is always used.
97
+ $DEFLIBPATH.unshift("#{LIBGIT2_DIR}/build")
98
+ dir_config('git2', "#{LIBGIT2_DIR}/include", "#{LIBGIT2_DIR}/build")
99
+ end
100
+
101
+ unless have_library 'git2' and have_header 'git2.h'
102
+ abort "ERROR: Failed to build libgit2"
103
+ end
104
+
105
+ create_makefile("rugged/rugged")
@@ -0,0 +1,527 @@
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
+ const char *RUGGED_ERROR_NAMES[] = {
28
+ "None", /* GITERR_NONE */
29
+ "NoMemError", /* GITERR_NOMEMORY */
30
+ "OSError", /* GITERR_OS */
31
+ "InvalidError", /* GITERR_INVALID */
32
+ "ReferenceError", /* GITERR_REFERENCE */
33
+ "ZlibError", /* GITERR_ZLIB */
34
+ "RepositoryError", /* GITERR_REPOSITORY */
35
+ "ConfigError", /* GITERR_CONFIG */
36
+ "RegexError", /* GITERR_REGEX */
37
+ "OdbError", /* GITERR_ODB */
38
+ "IndexError", /* GITERR_INDEX */
39
+ "ObjectError", /* GITERR_OBJECT */
40
+ "NetworkError", /* GITERR_NET */
41
+ "TagError", /* GITERR_TAG */
42
+ "TreeError", /* GITERR_TREE */
43
+ "IndexerError", /* GITERR_INDEXER */
44
+ "SslError", /* GITERR_SSL */
45
+ "SubmoduleError", /* GITERR_SUBMODULE */
46
+ "ThreadError", /* GITERR_THREAD */
47
+ "StashError", /* GITERR_STASH */
48
+ "CheckoutError", /* GITERR_CHECKOUT */
49
+ "FetchheadError", /* GITERR_FETCHHEAD */
50
+ "MergeError", /* GITERR_MERGE */
51
+ "SshError", /* GITERR_SSH */
52
+ "FilterError", /* GITERR_FILTER */
53
+ "RevertError", /* GITERR_REVERT */
54
+ "CallbackError", /* GITERR_CALLBACK */
55
+ "CherrypickError", /* GITERR_CHERRYPICK */
56
+ "DescribeError", /* GITERR_DESCRIBE */
57
+ "RebaseError", /* GITERR_REBASE */
58
+ "FilesystemError", /* GITERR_FILESYSTEM */
59
+ };
60
+
61
+ #define RUGGED_ERROR_COUNT (int)((sizeof(RUGGED_ERROR_NAMES)/sizeof(RUGGED_ERROR_NAMES[0])))
62
+
63
+ VALUE rb_mRugged;
64
+ VALUE rb_eRuggedError;
65
+ VALUE rb_eRuggedErrors[RUGGED_ERROR_COUNT];
66
+
67
+ static VALUE rb_mShutdownHook;
68
+
69
+ /*
70
+ * call-seq:
71
+ * Rugged.libgit2_version -> version
72
+ *
73
+ * Returns an array representing the current libgit2 version in use. Using
74
+ * the array makes it easier for the end-user to take conditional actions
75
+ * based on each respective version attribute: major, minor, rev.
76
+ *
77
+ * Rugged.libgit2_version #=> [0, 17, 0]
78
+ */
79
+ static VALUE rb_git_libgit2_version(VALUE self)
80
+ {
81
+ int major;
82
+ int minor;
83
+ int rev;
84
+
85
+ git_libgit2_version(&major, &minor, &rev);
86
+
87
+ // We return an array of three elements to represent the version components
88
+ return rb_ary_new3(3, INT2NUM(major), INT2NUM(minor), INT2NUM(rev));
89
+ }
90
+
91
+ /*
92
+ * call-seq:
93
+ * Rugged.features -> [feature, ...]
94
+ *
95
+ * Returns an array representing the features that libgit2 was compiled
96
+ * with — this includes `:threads` (thread support), `:https` and `:ssh`.
97
+ *
98
+ * Rugged.features #=> [:threads, :https]
99
+ */
100
+ static VALUE rb_git_features(VALUE self)
101
+ {
102
+ VALUE ret_arr = rb_ary_new();
103
+
104
+ int caps = git_libgit2_features();
105
+
106
+ if (caps & GIT_FEATURE_THREADS)
107
+ rb_ary_push(ret_arr, CSTR2SYM("threads"));
108
+
109
+ if (caps & GIT_FEATURE_HTTPS)
110
+ rb_ary_push(ret_arr, CSTR2SYM("https"));
111
+
112
+ if (caps & GIT_FEATURE_SSH)
113
+ rb_ary_push(ret_arr, CSTR2SYM("ssh"));
114
+
115
+ return ret_arr;
116
+ }
117
+
118
+ /*
119
+ * call-seq:
120
+ * Rugged.valid_full_oid?(oid) -> true or false
121
+ *
122
+ * Checks to see if a string contains a full 40-character sha1.
123
+ *
124
+ * Rugged.valid_full_oid?('d8786bfc97485e8d7b19b21fb88c8ef1f199fc3f')
125
+ * #=> true
126
+ */
127
+ static VALUE rb_git_valid_full_oid(VALUE self, VALUE hex)
128
+ {
129
+ git_oid oid;
130
+ int errorcode;
131
+
132
+ Check_Type(hex, T_STRING);
133
+ errorcode = git_oid_fromstr(&oid, StringValueCStr(hex));
134
+ if (errorcode < 0) {
135
+ return Qfalse;
136
+ } else {
137
+ return Qtrue;
138
+ }
139
+ }
140
+
141
+ /*
142
+ * call-seq:
143
+ * Rugged.hex_to_raw(oid) -> raw_buffer
144
+ *
145
+ * Turn a string of 40 hexadecimal characters into the buffer of
146
+ * 20 bytes it represents.
147
+ *
148
+ * Rugged.hex_to_raw('d8786bfc97485e8d7b19b21fb88c8ef1f199fc3f')
149
+ * #=> "\330xk\374\227H^\215{\031\262\037\270\214\216\361\361\231\374?"
150
+ */
151
+ static VALUE rb_git_hex_to_raw(VALUE self, VALUE hex)
152
+ {
153
+ git_oid oid;
154
+
155
+ Check_Type(hex, T_STRING);
156
+ rugged_exception_check(git_oid_fromstr(&oid, StringValueCStr(hex)));
157
+
158
+ return rb_str_new((const char *)oid.id, 20);
159
+ }
160
+
161
+ /*
162
+ * call-seq:
163
+ * Rugged.raw_to_hex(buffer) -> hex_oid
164
+ *
165
+ * Turn a buffer of 20 bytes (representing a SHA1 OID) into its
166
+ * readable hexadecimal representation.
167
+ *
168
+ * Rugged.raw_to_hex("\330xk\374\227H^\215{\031\262\037\270\214\216\361\361\231\374?")
169
+ * #=> "d8786bfc97485e8d7b19b21fb88c8ef1f199fc3f"
170
+ */
171
+ static VALUE rb_git_raw_to_hex(VALUE self, VALUE raw)
172
+ {
173
+ git_oid oid;
174
+ char out[40];
175
+
176
+ Check_Type(raw, T_STRING);
177
+
178
+ if (RSTRING_LEN(raw) != GIT_OID_RAWSZ)
179
+ rb_raise(rb_eTypeError, "Invalid buffer size for an OID");
180
+
181
+ git_oid_fromraw(&oid, (const unsigned char *)RSTRING_PTR(raw));
182
+ git_oid_fmt(out, &oid);
183
+
184
+ return rb_str_new(out, 40);
185
+ }
186
+
187
+ /*
188
+ * call-seq:
189
+ * Rugged.prettify_message(message, strip_comments = '#') -> clean_message
190
+ *
191
+ * Process a commit or tag message into standard form, by stripping trailing spaces and
192
+ * comments, and making sure that the message has a proper header line.
193
+ */
194
+ static VALUE rb_git_prettify_message(int argc, VALUE *argv, VALUE self)
195
+ {
196
+ char comment_char = '#';
197
+ int strip_comments = 1;
198
+
199
+ git_buf message = { NULL };
200
+ VALUE rb_message, rb_strip;
201
+ int error;
202
+ VALUE result = Qnil;
203
+
204
+ rb_scan_args(argc, argv, "11", &rb_message, &rb_strip);
205
+
206
+ Check_Type(rb_message, T_STRING);
207
+
208
+ switch (TYPE(rb_strip)) {
209
+ case T_FALSE:
210
+ strip_comments = 0;
211
+ break;
212
+
213
+ case T_STRING:
214
+ if (RSTRING_LEN(rb_strip) > 0)
215
+ comment_char = RSTRING_PTR(rb_strip)[0];
216
+ break;
217
+
218
+ case T_TRUE:
219
+ case T_NIL:
220
+ default:
221
+ break;
222
+ }
223
+
224
+ error = git_message_prettify(&message,
225
+ StringValueCStr(rb_message), strip_comments, comment_char);
226
+
227
+ if (!error)
228
+ result = rb_enc_str_new(message.ptr, message.size, rb_utf8_encoding());
229
+
230
+ git_buf_free(&message);
231
+ rugged_exception_check(error);
232
+
233
+ return result;
234
+ }
235
+
236
+ static VALUE minimize_cb(VALUE rb_oid, git_oid_shorten *shortener)
237
+ {
238
+ Check_Type(rb_oid, T_STRING);
239
+ git_oid_shorten_add(shortener, RSTRING_PTR(rb_oid));
240
+ return Qnil;
241
+ }
242
+
243
+ static VALUE minimize_yield(VALUE rb_oid, VALUE *data)
244
+ {
245
+ rb_funcall(data[0], rb_intern("call"), 1,
246
+ rb_str_substr(rb_oid, 0, FIX2INT(data[1])));
247
+ return Qnil;
248
+ }
249
+
250
+ /*
251
+ * call-seq:
252
+ * Rugged.minimize_oid(oid_iterator, min_length = 7) { |short_oid| block }
253
+ * Rugged.minimize_oid(oid_iterator, min_length = 7) -> min_length
254
+ *
255
+ * Iterate through +oid_iterator+, which should yield any number of SHA1 OIDs
256
+ * (represented as 40-character hexadecimal strings), and tries to minify them.
257
+ *
258
+ * Minifying a set of a SHA1 strings means finding the shortest root substring
259
+ * for each string that uniquely identifies it.
260
+ *
261
+ * If no +block+ is given, the function will return the minimal length as an
262
+ * integer value:
263
+ *
264
+ * oids = [
265
+ * 'd8786bfc974aaaaaaaaaaaaaaaaaaaaaaaaaaaaa',
266
+ * 'd8786bfc974bbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
267
+ * 'd8786bfc974ccccccccccccccccccccccccccccc',
268
+ * '68d041ee999cb07c6496fbdd4f384095de6ca9e1',
269
+ * ]
270
+ *
271
+ * Rugged.minimize_oids(oids) #=> 12
272
+ *
273
+ * If a +block+ is given, it will be called with each OID from +iterator+
274
+ * in its minified form:
275
+ *
276
+ * Rugged.minimize_oid(oids) { |oid| puts oid }
277
+ *
278
+ * produces:
279
+ *
280
+ * d8786bfc974a
281
+ * d8786bfc974b
282
+ * d8786bfc974c
283
+ * 68d041ee999c
284
+ *
285
+ * The optional +min_length+ argument allows you to specify a lower bound for
286
+ * the minified strings; returned strings won't be shorter than the given value,
287
+ * even if they would still be uniquely represented.
288
+ *
289
+ * Rugged.minimize_oid(oids, 18) #=> 18
290
+ */
291
+ static VALUE rb_git_minimize_oid(int argc, VALUE *argv, VALUE self)
292
+ {
293
+ git_oid_shorten *shrt;
294
+ int length, minlen = 7;
295
+ VALUE rb_enum, rb_minlen, rb_block;
296
+
297
+ rb_scan_args(argc, argv, "11&", &rb_enum, &rb_minlen, &rb_block);
298
+
299
+ if (!NIL_P(rb_minlen)) {
300
+ Check_Type(rb_minlen, T_FIXNUM);
301
+ minlen = FIX2INT(rb_minlen);
302
+ }
303
+
304
+ if (!rb_respond_to(rb_enum, rb_intern("each")))
305
+ rb_raise(rb_eTypeError, "Expecting an Enumerable instance");
306
+
307
+ shrt = git_oid_shorten_new(minlen);
308
+
309
+ rb_iterate(rb_each, rb_enum, &minimize_cb, (VALUE)shrt);
310
+ length = git_oid_shorten_add(shrt, NULL);
311
+
312
+ git_oid_shorten_free(shrt);
313
+ rugged_exception_check(length);
314
+
315
+ if (!NIL_P(rb_block)) {
316
+ VALUE yield_data[2];
317
+
318
+ yield_data[0] = rb_block;
319
+ yield_data[1] = INT2FIX(length);
320
+
321
+ rb_iterate(rb_each, rb_enum, &minimize_yield, (VALUE)yield_data);
322
+ return Qnil;
323
+ }
324
+
325
+ return INT2FIX(length);
326
+ }
327
+
328
+ static void cleanup_cb(void *unused)
329
+ {
330
+ (void)unused;
331
+ git_libgit2_shutdown();
332
+ }
333
+
334
+ void rugged_exception_raise(void)
335
+ {
336
+ VALUE err_klass, err_obj;
337
+ const git_error *error;
338
+ const char *err_message;
339
+
340
+ error = giterr_last();
341
+
342
+ if (error && error->klass > 0 && error->klass < RUGGED_ERROR_COUNT) {
343
+ err_klass = rb_eRuggedErrors[error->klass];
344
+ err_message = error->message;
345
+ } else {
346
+ err_klass = rb_eRuntimeError;
347
+ err_message = "Rugged operation failed";
348
+ }
349
+
350
+ err_obj = rb_exc_new2(err_klass, err_message);
351
+ giterr_clear();
352
+ rb_exc_raise(err_obj);
353
+ }
354
+
355
+ VALUE rugged__block_yield_splat(VALUE args) {
356
+ VALUE block = rb_ary_shift(args);
357
+ int n = RARRAY_LENINT(args);
358
+
359
+ if (n == 0) {
360
+ return rb_funcall(block, rb_intern("call"), 0);
361
+ } else {
362
+ int i;
363
+ VALUE *argv;
364
+ argv = ALLOCA_N(VALUE, n);
365
+
366
+ for (i=0; i < n; i++) {
367
+ argv[i] = rb_ary_entry(args, i);
368
+ }
369
+
370
+ return rb_funcall2(block, rb_intern("call"), n, argv);
371
+ }
372
+ }
373
+
374
+ /*
375
+ * call-seq:
376
+ * Rugged.__cache_usage__ -> [current, max]
377
+ *
378
+ * Returns an array representing the current bytes in the internal
379
+ * libgit2 cache and the maximum size of the cache.
380
+ */
381
+ static VALUE rb_git_cache_usage(VALUE self)
382
+ {
383
+ int64_t used, max;
384
+ git_libgit2_opts(GIT_OPT_GET_CACHED_MEMORY, &used, &max);
385
+ return rb_ary_new3(2, LL2NUM(used), LL2NUM(max));
386
+ }
387
+
388
+ VALUE rugged_strarray_to_rb_ary(git_strarray *str_array)
389
+ {
390
+ VALUE rb_array = rb_ary_new2(str_array->count);
391
+ size_t i;
392
+
393
+ for (i = 0; i < str_array->count; ++i) {
394
+ rb_ary_push(rb_array, rb_str_new_utf8(str_array->strings[i]));
395
+ }
396
+
397
+ return rb_array;
398
+ }
399
+
400
+ void rugged_rb_ary_to_strarray(VALUE rb_array, git_strarray *str_array)
401
+ {
402
+ int i;
403
+
404
+ str_array->strings = NULL;
405
+ str_array->count = 0;
406
+
407
+ if (NIL_P(rb_array))
408
+ return;
409
+
410
+ if (TYPE(rb_array) == T_STRING) {
411
+ str_array->count = 1;
412
+ str_array->strings = xmalloc(sizeof(char *));
413
+ str_array->strings[0] = StringValueCStr(rb_array);
414
+ return;
415
+ }
416
+
417
+ Check_Type(rb_array, T_ARRAY);
418
+
419
+ for (i = 0; i < RARRAY_LEN(rb_array); ++i)
420
+ Check_Type(rb_ary_entry(rb_array, i), T_STRING);
421
+
422
+ str_array->count = RARRAY_LEN(rb_array);
423
+ str_array->strings = xmalloc(str_array->count * sizeof(char *));
424
+
425
+ for (i = 0; i < RARRAY_LEN(rb_array); ++i) {
426
+ VALUE rb_string = rb_ary_entry(rb_array, i);
427
+ str_array->strings[i] = StringValueCStr(rb_string);
428
+ }
429
+ }
430
+
431
+ void Init_rugged(void)
432
+ {
433
+ rb_mRugged = rb_define_module("Rugged");
434
+
435
+ /* Initialize the Error classes */
436
+ {
437
+ int i;
438
+
439
+ rb_eRuggedError = rb_define_class_under(rb_mRugged, "Error", rb_eStandardError);
440
+
441
+ rb_eRuggedErrors[0] = Qnil; /* 0 return value -- no exception */
442
+ rb_eRuggedErrors[1] = rb_define_class_under(rb_mRugged, RUGGED_ERROR_NAMES[1], rb_eNoMemError);
443
+ rb_eRuggedErrors[2] = rb_define_class_under(rb_mRugged, RUGGED_ERROR_NAMES[2], rb_eIOError);
444
+ rb_eRuggedErrors[3] = rb_define_class_under(rb_mRugged, RUGGED_ERROR_NAMES[3], rb_eArgError);
445
+
446
+ for (i = 4; i < RUGGED_ERROR_COUNT; ++i) {
447
+ rb_eRuggedErrors[i] = rb_define_class_under(rb_mRugged, RUGGED_ERROR_NAMES[i], rb_eRuggedError);
448
+ }
449
+ }
450
+
451
+ rb_define_module_function(rb_mRugged, "libgit2_version", rb_git_libgit2_version, 0);
452
+ rb_define_module_function(rb_mRugged, "features", rb_git_features, 0);
453
+ rb_define_module_function(rb_mRugged, "valid_full_oid?", rb_git_valid_full_oid, 1);
454
+ rb_define_module_function(rb_mRugged, "hex_to_raw", rb_git_hex_to_raw, 1);
455
+ rb_define_module_function(rb_mRugged, "raw_to_hex", rb_git_raw_to_hex, 1);
456
+ rb_define_module_function(rb_mRugged, "minimize_oid", rb_git_minimize_oid, -1);
457
+ rb_define_module_function(rb_mRugged, "prettify_message", rb_git_prettify_message, -1);
458
+ rb_define_module_function(rb_mRugged, "__cache_usage__", rb_git_cache_usage, 0);
459
+
460
+ Init_rugged_reference();
461
+ Init_rugged_reference_collection();
462
+
463
+ Init_rugged_object();
464
+ Init_rugged_commit();
465
+ Init_rugged_tree();
466
+ Init_rugged_tag();
467
+ Init_rugged_tag_collection();
468
+ Init_rugged_blob();
469
+
470
+ Init_rugged_index();
471
+ Init_rugged_repo();
472
+ Init_rugged_revwalk();
473
+ Init_rugged_branch();
474
+ Init_rugged_branch_collection();
475
+ Init_rugged_config();
476
+ Init_rugged_remote();
477
+ Init_rugged_remote_collection();
478
+ Init_rugged_notes();
479
+ Init_rugged_settings();
480
+ Init_rugged_submodule();
481
+ Init_rugged_submodule_collection();
482
+ Init_rugged_diff();
483
+ Init_rugged_patch();
484
+ Init_rugged_diff_delta();
485
+ Init_rugged_diff_hunk();
486
+ Init_rugged_diff_line();
487
+ Init_rugged_blame();
488
+ Init_rugged_cred();
489
+ Init_rugged_backend();
490
+
491
+ /*
492
+ * Sort the repository contents in no particular ordering;
493
+ * this sorting is arbitrary, implementation-specific
494
+ * and subject to change at any time.
495
+ * This is the default sorting for new walkers.
496
+ */
497
+ rb_define_const(rb_mRugged, "SORT_NONE", INT2FIX(GIT_SORT_NONE));
498
+
499
+ /*
500
+ * Sort the repository contents in topological order
501
+ * (parents before children); this sorting mode
502
+ * can be combined with time sorting.
503
+ */
504
+ rb_define_const(rb_mRugged, "SORT_TOPO", INT2FIX(GIT_SORT_TOPOLOGICAL));
505
+
506
+ /*
507
+ * Sort the repository contents by commit time;
508
+ * this sorting mode can be combined with
509
+ * topological sorting.
510
+ */
511
+ rb_define_const(rb_mRugged, "SORT_DATE", INT2FIX(GIT_SORT_TIME));
512
+
513
+ /*
514
+ * Iterate through the repository contents in reverse
515
+ * order; this sorting mode can be combined with
516
+ * any of the above.
517
+ */
518
+ rb_define_const(rb_mRugged, "SORT_REVERSE", INT2FIX(GIT_SORT_REVERSE));
519
+
520
+ /* Initialize libgit2 */
521
+ git_libgit2_init();
522
+
523
+ /* Hook a global object to cleanup the library
524
+ * on shutdown */
525
+ rb_mShutdownHook = Data_Wrap_Struct(rb_cObject, NULL, &cleanup_cb, NULL);
526
+ rb_global_variable(&rb_mShutdownHook);
527
+ }