rdavila-rugged 0.24.0b13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +619 -0
- data/ext/rugged/extconf.rb +105 -0
- data/ext/rugged/rugged.c +527 -0
- data/ext/rugged/rugged.h +185 -0
- data/ext/rugged/rugged_backend.c +34 -0
- data/ext/rugged/rugged_blame.c +292 -0
- data/ext/rugged/rugged_blob.c +638 -0
- data/ext/rugged/rugged_branch.c +195 -0
- data/ext/rugged/rugged_branch_collection.c +408 -0
- data/ext/rugged/rugged_commit.c +691 -0
- data/ext/rugged/rugged_config.c +404 -0
- data/ext/rugged/rugged_cred.c +148 -0
- data/ext/rugged/rugged_diff.c +686 -0
- data/ext/rugged/rugged_diff_delta.c +105 -0
- data/ext/rugged/rugged_diff_hunk.c +103 -0
- data/ext/rugged/rugged_diff_line.c +83 -0
- data/ext/rugged/rugged_index.c +1255 -0
- data/ext/rugged/rugged_note.c +376 -0
- data/ext/rugged/rugged_object.c +383 -0
- data/ext/rugged/rugged_patch.c +245 -0
- data/ext/rugged/rugged_reference.c +396 -0
- data/ext/rugged/rugged_reference_collection.c +446 -0
- data/ext/rugged/rugged_remote.c +691 -0
- data/ext/rugged/rugged_remote_collection.c +457 -0
- data/ext/rugged/rugged_repo.c +2669 -0
- data/ext/rugged/rugged_revwalk.c +495 -0
- data/ext/rugged/rugged_settings.c +155 -0
- data/ext/rugged/rugged_signature.c +106 -0
- data/ext/rugged/rugged_submodule.c +852 -0
- data/ext/rugged/rugged_submodule_collection.c +384 -0
- data/ext/rugged/rugged_tag.c +251 -0
- data/ext/rugged/rugged_tag_collection.c +347 -0
- data/ext/rugged/rugged_tree.c +919 -0
- data/lib/rugged.rb +23 -0
- data/lib/rugged/attributes.rb +41 -0
- data/lib/rugged/blob.rb +28 -0
- data/lib/rugged/branch.rb +19 -0
- data/lib/rugged/commit.rb +54 -0
- data/lib/rugged/console.rb +9 -0
- data/lib/rugged/credentials.rb +43 -0
- data/lib/rugged/diff.rb +20 -0
- data/lib/rugged/diff/delta.rb +53 -0
- data/lib/rugged/diff/hunk.rb +18 -0
- data/lib/rugged/diff/line.rb +47 -0
- data/lib/rugged/index.rb +13 -0
- data/lib/rugged/object.rb +7 -0
- data/lib/rugged/patch.rb +36 -0
- data/lib/rugged/reference.rb +7 -0
- data/lib/rugged/remote.rb +4 -0
- data/lib/rugged/repository.rb +227 -0
- data/lib/rugged/submodule_collection.rb +48 -0
- data/lib/rugged/tag.rb +50 -0
- data/lib/rugged/tree.rb +38 -0
- data/lib/rugged/version.rb +3 -0
- data/lib/rugged/walker.rb +5 -0
- metadata +146 -0
@@ -0,0 +1,404 @@
|
|
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
|
+
VALUE rb_cRuggedConfig;
|
29
|
+
|
30
|
+
void rb_git_config__free(git_config *config)
|
31
|
+
{
|
32
|
+
git_config_free(config);
|
33
|
+
}
|
34
|
+
|
35
|
+
VALUE rugged_config_new(VALUE klass, VALUE owner, git_config *cfg)
|
36
|
+
{
|
37
|
+
VALUE rb_config = Data_Wrap_Struct(klass, NULL, &rb_git_config__free, cfg);
|
38
|
+
rugged_set_owner(rb_config, owner);
|
39
|
+
return rb_config;
|
40
|
+
}
|
41
|
+
|
42
|
+
/*
|
43
|
+
* call-seq:
|
44
|
+
* Config.new(path) -> new_config
|
45
|
+
*
|
46
|
+
* Open the file specified in +path+ as a +Rugged::Config+ file.
|
47
|
+
* If +path+ cannot be found, or the file is an invalid Git config,
|
48
|
+
* an exception will be raised.
|
49
|
+
*/
|
50
|
+
static VALUE rb_git_config_new(VALUE klass, VALUE rb_path)
|
51
|
+
{
|
52
|
+
git_config *config = NULL;
|
53
|
+
|
54
|
+
if (TYPE(rb_path) == T_ARRAY) {
|
55
|
+
int error, i;
|
56
|
+
|
57
|
+
error = git_config_new(&config);
|
58
|
+
rugged_exception_check(error);
|
59
|
+
|
60
|
+
for (i = 0; i < RARRAY_LEN(rb_path) && !error; ++i) {
|
61
|
+
VALUE f = rb_ary_entry(rb_path, i);
|
62
|
+
Check_Type(f, T_STRING);
|
63
|
+
error = git_config_add_file_ondisk(config, StringValueCStr(f), i + 1, 1);
|
64
|
+
}
|
65
|
+
|
66
|
+
if (error) {
|
67
|
+
git_config_free(config);
|
68
|
+
rugged_exception_check(error);
|
69
|
+
}
|
70
|
+
} else if (TYPE(rb_path) == T_STRING) {
|
71
|
+
rugged_exception_check(
|
72
|
+
git_config_open_ondisk(&config, StringValueCStr(rb_path))
|
73
|
+
);
|
74
|
+
} else {
|
75
|
+
rb_raise(rb_eTypeError, "Expecting a filename or an array of filenames");
|
76
|
+
}
|
77
|
+
|
78
|
+
return rugged_config_new(klass, Qnil, config);
|
79
|
+
}
|
80
|
+
|
81
|
+
/*
|
82
|
+
* call-seq:
|
83
|
+
* cfg.get(key) -> value
|
84
|
+
* cfg[key] -> value
|
85
|
+
*
|
86
|
+
* Get the value for the given config +key+. Values are always
|
87
|
+
* returned as +String+, or +nil+ if the given key doesn't exist
|
88
|
+
* in the Config file.
|
89
|
+
*
|
90
|
+
* cfg['apply.whitespace'] #=> 'fix'
|
91
|
+
* cfg['diff.renames'] #=> 'true'
|
92
|
+
*/
|
93
|
+
static VALUE rb_git_config_get(VALUE self, VALUE rb_key)
|
94
|
+
{
|
95
|
+
git_config *config;
|
96
|
+
git_buf buf = { NULL };
|
97
|
+
int error;
|
98
|
+
VALUE rb_result;
|
99
|
+
|
100
|
+
Data_Get_Struct(self, git_config, config);
|
101
|
+
Check_Type(rb_key, T_STRING);
|
102
|
+
|
103
|
+
error = git_config_get_string_buf(&buf, config, StringValueCStr(rb_key));
|
104
|
+
if (error == GIT_ENOTFOUND)
|
105
|
+
return Qnil;
|
106
|
+
|
107
|
+
rugged_exception_check(error);
|
108
|
+
rb_result = rb_str_new_utf8(buf.ptr);
|
109
|
+
git_buf_free(&buf);
|
110
|
+
|
111
|
+
return rb_result;
|
112
|
+
}
|
113
|
+
|
114
|
+
/*
|
115
|
+
* call-seq:
|
116
|
+
* cfg.store(key, value)
|
117
|
+
* cfg[key] = value
|
118
|
+
*
|
119
|
+
* Store the given +value+ in the Config file, under the section
|
120
|
+
* and name specified by +key+. Value can be any of the following
|
121
|
+
* Ruby types: +String+, +true+, +false+ and +Fixnum+.
|
122
|
+
*
|
123
|
+
* The config file will be automatically stored to disk.
|
124
|
+
*
|
125
|
+
* cfg['apply.whitespace'] = 'fix'
|
126
|
+
* cfg['diff.renames'] = true
|
127
|
+
* cfg['gc.reflogexpre'] = 90
|
128
|
+
*/
|
129
|
+
static VALUE rb_git_config_store(VALUE self, VALUE rb_key, VALUE rb_val)
|
130
|
+
{
|
131
|
+
git_config *config;
|
132
|
+
const char *key;
|
133
|
+
int error;
|
134
|
+
|
135
|
+
Data_Get_Struct(self, git_config, config);
|
136
|
+
Check_Type(rb_key, T_STRING);
|
137
|
+
|
138
|
+
key = StringValueCStr(rb_key);
|
139
|
+
|
140
|
+
switch (TYPE(rb_val)) {
|
141
|
+
case T_STRING:
|
142
|
+
error = git_config_set_string(config, key, StringValueCStr(rb_val));
|
143
|
+
break;
|
144
|
+
|
145
|
+
case T_TRUE:
|
146
|
+
case T_FALSE:
|
147
|
+
error = git_config_set_bool(config, key, (rb_val == Qtrue));
|
148
|
+
break;
|
149
|
+
|
150
|
+
case T_FIXNUM:
|
151
|
+
error = git_config_set_int32(config, key, FIX2INT(rb_val));
|
152
|
+
break;
|
153
|
+
|
154
|
+
default:
|
155
|
+
rb_raise(rb_eTypeError,
|
156
|
+
"Invalid value; config files can only store string, bool or int keys");
|
157
|
+
}
|
158
|
+
|
159
|
+
rugged_exception_check(error);
|
160
|
+
return Qnil;
|
161
|
+
}
|
162
|
+
|
163
|
+
/*
|
164
|
+
* call-seq:
|
165
|
+
* cfg.delete(key) -> true or false
|
166
|
+
*
|
167
|
+
* Delete the given +key+ from the config file. Return +true+ if
|
168
|
+
* the deletion was successful, or +false+ if the key was not
|
169
|
+
* found in the Config file.
|
170
|
+
*
|
171
|
+
* The config file is immediately updated on disk.
|
172
|
+
*/
|
173
|
+
static VALUE rb_git_config_delete(VALUE self, VALUE rb_key)
|
174
|
+
{
|
175
|
+
git_config *config;
|
176
|
+
int error;
|
177
|
+
|
178
|
+
Data_Get_Struct(self, git_config, config);
|
179
|
+
Check_Type(rb_key, T_STRING);
|
180
|
+
|
181
|
+
error = git_config_delete_entry(config, StringValueCStr(rb_key));
|
182
|
+
if (error == GIT_ENOTFOUND)
|
183
|
+
return Qfalse;
|
184
|
+
|
185
|
+
rugged_exception_check(error);
|
186
|
+
return Qtrue;
|
187
|
+
}
|
188
|
+
|
189
|
+
static int cb_config__each_key(const git_config_entry *entry, void *opaque)
|
190
|
+
{
|
191
|
+
rb_funcall((VALUE)opaque, rb_intern("call"), 1, rb_str_new_utf8(entry->name));
|
192
|
+
return GIT_OK;
|
193
|
+
}
|
194
|
+
|
195
|
+
static int cb_config__each_pair(const git_config_entry *entry, void *opaque)
|
196
|
+
{
|
197
|
+
rb_funcall((VALUE)opaque, rb_intern("call"), 2,
|
198
|
+
rb_str_new_utf8(entry->name),
|
199
|
+
rb_str_new_utf8(entry->value)
|
200
|
+
);
|
201
|
+
|
202
|
+
return GIT_OK;
|
203
|
+
}
|
204
|
+
|
205
|
+
static int cb_config__to_hash(const git_config_entry *entry, void *opaque)
|
206
|
+
{
|
207
|
+
rb_hash_aset((VALUE)opaque,
|
208
|
+
rb_str_new_utf8(entry->name),
|
209
|
+
rb_str_new_utf8(entry->value)
|
210
|
+
);
|
211
|
+
|
212
|
+
return GIT_OK;
|
213
|
+
}
|
214
|
+
|
215
|
+
/*
|
216
|
+
* call-seq:
|
217
|
+
* cfg.each_key { |key| block }
|
218
|
+
* cfg.each_key -> enumarator
|
219
|
+
*
|
220
|
+
* Call the given block once for each key in the config file. If no block
|
221
|
+
* is given, an enumerator is returned.
|
222
|
+
*
|
223
|
+
* cfg.each_key do |key|
|
224
|
+
* puts key
|
225
|
+
* end
|
226
|
+
*/
|
227
|
+
static VALUE rb_git_config_each_key(VALUE self)
|
228
|
+
{
|
229
|
+
git_config *config;
|
230
|
+
int error;
|
231
|
+
|
232
|
+
Data_Get_Struct(self, git_config, config);
|
233
|
+
|
234
|
+
if (!rb_block_given_p())
|
235
|
+
return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each_key"));
|
236
|
+
|
237
|
+
error = git_config_foreach(config, &cb_config__each_key, (void *)rb_block_proc());
|
238
|
+
rugged_exception_check(error);
|
239
|
+
return Qnil;
|
240
|
+
}
|
241
|
+
|
242
|
+
/*
|
243
|
+
* call-seq:
|
244
|
+
* cfg.each_pair { |key, value| block }
|
245
|
+
* cfg.each_pair -> enumerator
|
246
|
+
* cfg.each { |key, value| block }
|
247
|
+
* cfg.each -> enumerator
|
248
|
+
*
|
249
|
+
* Call the given block once for each key/value pair in the config file.
|
250
|
+
* If no block is given, an enumerator is returned.
|
251
|
+
*
|
252
|
+
* cfg.each do |key, value|
|
253
|
+
* puts "#{key} => #{value}"
|
254
|
+
* end
|
255
|
+
*/
|
256
|
+
static VALUE rb_git_config_each_pair(VALUE self)
|
257
|
+
{
|
258
|
+
git_config *config;
|
259
|
+
int error;
|
260
|
+
|
261
|
+
Data_Get_Struct(self, git_config, config);
|
262
|
+
|
263
|
+
if (!rb_block_given_p())
|
264
|
+
return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each_pair"));
|
265
|
+
|
266
|
+
error = git_config_foreach(config, &cb_config__each_pair, (void *)rb_block_proc());
|
267
|
+
rugged_exception_check(error);
|
268
|
+
return Qnil;
|
269
|
+
}
|
270
|
+
|
271
|
+
/*
|
272
|
+
* call-seq:
|
273
|
+
* cfg.to_hash -> hash
|
274
|
+
*
|
275
|
+
* Returns the config file represented as a Ruby hash, where
|
276
|
+
* each configuration entry appears as a key with its
|
277
|
+
* corresponding value.
|
278
|
+
*
|
279
|
+
* cfg.to_hash #=> {"core.autolf" => "true", "core.bare" => "true"}
|
280
|
+
*/
|
281
|
+
static VALUE rb_git_config_to_hash(VALUE self)
|
282
|
+
{
|
283
|
+
git_config *config;
|
284
|
+
int error;
|
285
|
+
VALUE hash;
|
286
|
+
|
287
|
+
Data_Get_Struct(self, git_config, config);
|
288
|
+
hash = rb_hash_new();
|
289
|
+
|
290
|
+
error = git_config_foreach(config, &cb_config__to_hash, (void *)hash);
|
291
|
+
rugged_exception_check(error);
|
292
|
+
return hash;
|
293
|
+
}
|
294
|
+
|
295
|
+
/*
|
296
|
+
* call-seq:
|
297
|
+
* Config.global() -> new_config
|
298
|
+
* Config.open_global() -> new_config
|
299
|
+
*
|
300
|
+
* Open the default global config file as a new +Rugged::Config+ object.
|
301
|
+
* An exception will be raised if the global config file doesn't
|
302
|
+
* exist.
|
303
|
+
*/
|
304
|
+
static VALUE rb_git_config_open_default(VALUE klass)
|
305
|
+
{
|
306
|
+
git_config *cfg;
|
307
|
+
int error;
|
308
|
+
|
309
|
+
error = git_config_open_default(&cfg);
|
310
|
+
rugged_exception_check(error);
|
311
|
+
|
312
|
+
return rugged_config_new(klass, Qnil, cfg);
|
313
|
+
}
|
314
|
+
|
315
|
+
/*
|
316
|
+
* call-seq:
|
317
|
+
* config.snapshot -> snapshot
|
318
|
+
*
|
319
|
+
* Create a snapshot of the configuration.
|
320
|
+
*
|
321
|
+
* Provides a consistent, read-only view of the configuration for
|
322
|
+
* looking up complex values from a configuration.
|
323
|
+
*/
|
324
|
+
static VALUE rb_git_config_snapshot(VALUE self)
|
325
|
+
{
|
326
|
+
git_config *config, *snapshot;
|
327
|
+
|
328
|
+
Data_Get_Struct(self, git_config, config);
|
329
|
+
|
330
|
+
rugged_exception_check(
|
331
|
+
git_config_snapshot(&snapshot, config)
|
332
|
+
);
|
333
|
+
|
334
|
+
return rugged_config_new(rb_obj_class(self), Qnil, snapshot);
|
335
|
+
}
|
336
|
+
|
337
|
+
/*
|
338
|
+
* call-seq:
|
339
|
+
* config.transaction { |config| }
|
340
|
+
*
|
341
|
+
* Perform configuration changes in a transaction.
|
342
|
+
*
|
343
|
+
* Locks the configuration, executes the given block and stores
|
344
|
+
* any changes that were made to the configuration. If the block
|
345
|
+
* throws an exception, all changes are rolled back automatically.
|
346
|
+
*
|
347
|
+
* During the execution of the block, configuration changes don't
|
348
|
+
* get stored to disk immediately, so reading from the configuration
|
349
|
+
* will continue to return the values that were stored in the configuration
|
350
|
+
* when the transaction was started.
|
351
|
+
*/
|
352
|
+
static VALUE rb_git_config_transaction(VALUE self)
|
353
|
+
{
|
354
|
+
git_config *config;
|
355
|
+
git_transaction *tx;
|
356
|
+
VALUE rb_result;
|
357
|
+
int error = 0, exception = 0;
|
358
|
+
|
359
|
+
Data_Get_Struct(self, git_config, config);
|
360
|
+
|
361
|
+
git_config_lock(&tx, config);
|
362
|
+
|
363
|
+
rb_result = rb_protect(rb_yield, self, &exception);
|
364
|
+
|
365
|
+
if (!exception)
|
366
|
+
error = git_transaction_commit(tx);
|
367
|
+
|
368
|
+
git_transaction_free(tx);
|
369
|
+
|
370
|
+
if (exception)
|
371
|
+
rb_jump_tag(exception);
|
372
|
+
else if (error)
|
373
|
+
rugged_exception_check(error);
|
374
|
+
|
375
|
+
return rb_result;
|
376
|
+
}
|
377
|
+
|
378
|
+
void Init_rugged_config(void)
|
379
|
+
{
|
380
|
+
/*
|
381
|
+
* Config
|
382
|
+
*/
|
383
|
+
rb_cRuggedConfig = rb_define_class_under(rb_mRugged, "Config", rb_cObject);
|
384
|
+
rb_define_singleton_method(rb_cRuggedConfig, "new", rb_git_config_new, 1);
|
385
|
+
|
386
|
+
rb_define_singleton_method(rb_cRuggedConfig, "global", rb_git_config_open_default, 0);
|
387
|
+
rb_define_singleton_method(rb_cRuggedConfig, "open_global", rb_git_config_open_default, 0);
|
388
|
+
|
389
|
+
rb_define_method(rb_cRuggedConfig, "delete", rb_git_config_delete, 1);
|
390
|
+
|
391
|
+
rb_define_method(rb_cRuggedConfig, "store", rb_git_config_store, 2);
|
392
|
+
rb_define_method(rb_cRuggedConfig, "[]=", rb_git_config_store, 2);
|
393
|
+
|
394
|
+
rb_define_method(rb_cRuggedConfig, "get", rb_git_config_get, 1);
|
395
|
+
rb_define_method(rb_cRuggedConfig, "[]", rb_git_config_get, 1);
|
396
|
+
|
397
|
+
rb_define_method(rb_cRuggedConfig, "each_key", rb_git_config_each_key, 0);
|
398
|
+
rb_define_method(rb_cRuggedConfig, "each_pair", rb_git_config_each_pair, 0);
|
399
|
+
rb_define_method(rb_cRuggedConfig, "each", rb_git_config_each_pair, 0);
|
400
|
+
rb_define_method(rb_cRuggedConfig, "to_hash", rb_git_config_to_hash, 0);
|
401
|
+
|
402
|
+
rb_define_method(rb_cRuggedConfig, "snapshot", rb_git_config_snapshot, 0);
|
403
|
+
rb_define_method(rb_cRuggedConfig, "transaction", rb_git_config_transaction, 0);
|
404
|
+
}
|
@@ -0,0 +1,148 @@
|
|
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
|
+
VALUE rb_mRuggedCred;
|
29
|
+
VALUE rb_cRuggedCredUserPassword;
|
30
|
+
VALUE rb_cRuggedCredSshKey;
|
31
|
+
VALUE rb_cRuggedCredSshKeyFromAgent;
|
32
|
+
VALUE rb_cRuggedCredDefault;
|
33
|
+
|
34
|
+
static void rugged_cred_extract_userpass(git_cred **cred, VALUE rb_credential)
|
35
|
+
{
|
36
|
+
VALUE rb_username = rb_iv_get(rb_credential, "@username");
|
37
|
+
VALUE rb_password = rb_iv_get(rb_credential, "@password");
|
38
|
+
|
39
|
+
Check_Type(rb_username, T_STRING);
|
40
|
+
Check_Type(rb_password, T_STRING);
|
41
|
+
|
42
|
+
rugged_exception_check(
|
43
|
+
git_cred_userpass_plaintext_new(cred,
|
44
|
+
StringValueCStr(rb_username),
|
45
|
+
StringValueCStr(rb_password)
|
46
|
+
)
|
47
|
+
);
|
48
|
+
}
|
49
|
+
|
50
|
+
static void rugged_cred_extract_ssh_key(git_cred **cred, VALUE rb_credential)
|
51
|
+
{
|
52
|
+
VALUE rb_username = rb_iv_get(rb_credential, "@username");
|
53
|
+
VALUE rb_publickey = rb_iv_get(rb_credential, "@publickey");
|
54
|
+
VALUE rb_privatekey = rb_iv_get(rb_credential, "@privatekey");
|
55
|
+
VALUE rb_passphrase = rb_iv_get(rb_credential, "@passphrase");
|
56
|
+
|
57
|
+
Check_Type(rb_username, T_STRING);
|
58
|
+
Check_Type(rb_privatekey, T_STRING);
|
59
|
+
|
60
|
+
if (!NIL_P(rb_publickey))
|
61
|
+
Check_Type(rb_publickey, T_STRING);
|
62
|
+
if (!NIL_P(rb_passphrase))
|
63
|
+
Check_Type(rb_passphrase, T_STRING);
|
64
|
+
|
65
|
+
rugged_exception_check(
|
66
|
+
git_cred_ssh_key_new(cred,
|
67
|
+
StringValueCStr(rb_username),
|
68
|
+
NIL_P(rb_publickey) ? NULL : StringValueCStr(rb_publickey),
|
69
|
+
StringValueCStr(rb_privatekey),
|
70
|
+
NIL_P(rb_passphrase) ? NULL : StringValueCStr(rb_passphrase)
|
71
|
+
)
|
72
|
+
);
|
73
|
+
}
|
74
|
+
|
75
|
+
static void rugged_credential_extract_ssh_key_from_agent(git_cred **cred, VALUE rb_credential)
|
76
|
+
{
|
77
|
+
VALUE rb_username = rb_iv_get(rb_credential, "@username");
|
78
|
+
|
79
|
+
Check_Type(rb_username, T_STRING);
|
80
|
+
|
81
|
+
rugged_exception_check(
|
82
|
+
git_cred_ssh_key_from_agent(cred, StringValueCStr(rb_username))
|
83
|
+
);
|
84
|
+
}
|
85
|
+
|
86
|
+
static void rugged_cred_extract_default(git_cred **cred, VALUE rb_credential)
|
87
|
+
{
|
88
|
+
rugged_exception_check(git_cred_default_new(cred));
|
89
|
+
}
|
90
|
+
|
91
|
+
static void rugged_cred_extract_username(git_cred **cred, VALUE rb_credential)
|
92
|
+
{
|
93
|
+
VALUE rb_username = rb_iv_get(rb_credential, "@username");
|
94
|
+
Check_Type(rb_username, T_STRING);
|
95
|
+
|
96
|
+
rugged_exception_check(git_cred_username_new(cred, StringValueCStr(rb_username)));
|
97
|
+
}
|
98
|
+
|
99
|
+
void rugged_cred_extract(git_cred **cred, int allowed_types, VALUE rb_credential)
|
100
|
+
{
|
101
|
+
if (rb_obj_is_kind_of(rb_credential, rb_cRuggedCredUserPassword)) {
|
102
|
+
if (allowed_types & GIT_CREDTYPE_USERNAME) {
|
103
|
+
rugged_cred_extract_username(cred, rb_credential);
|
104
|
+
return;
|
105
|
+
}
|
106
|
+
|
107
|
+
if (!(allowed_types & GIT_CREDTYPE_USERPASS_PLAINTEXT))
|
108
|
+
rb_raise(rb_eArgError, "Invalid credential type");
|
109
|
+
|
110
|
+
rugged_cred_extract_userpass(cred, rb_credential);
|
111
|
+
} else if (rb_obj_is_kind_of(rb_credential, rb_cRuggedCredSshKey)) {
|
112
|
+
if (allowed_types & GIT_CREDTYPE_USERNAME) {
|
113
|
+
rugged_cred_extract_username(cred, rb_credential);
|
114
|
+
return;
|
115
|
+
}
|
116
|
+
|
117
|
+
if (!(allowed_types & GIT_CREDTYPE_SSH_KEY))
|
118
|
+
rb_raise(rb_eArgError, "Invalid credential type");
|
119
|
+
|
120
|
+
rugged_cred_extract_ssh_key(cred, rb_credential);
|
121
|
+
} else if (rb_obj_is_kind_of(rb_credential, rb_cRuggedCredSshKeyFromAgent)) {
|
122
|
+
if (allowed_types & GIT_CREDTYPE_USERNAME) {
|
123
|
+
rugged_cred_extract_username(cred, rb_credential);
|
124
|
+
return;
|
125
|
+
}
|
126
|
+
|
127
|
+
if (!(allowed_types & GIT_CREDTYPE_SSH_KEY))
|
128
|
+
rb_raise(rb_eArgError, "Invalid credential type");
|
129
|
+
|
130
|
+
rugged_credential_extract_ssh_key_from_agent(cred, rb_credential);
|
131
|
+
} else if (rb_obj_is_kind_of(rb_credential, rb_cRuggedCredDefault)) {
|
132
|
+
if (!(allowed_types & GIT_CREDTYPE_DEFAULT))
|
133
|
+
rb_raise(rb_eArgError, "Invalid credential type");
|
134
|
+
|
135
|
+
rugged_cred_extract_default(cred, rb_credential);
|
136
|
+
}
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
void Init_rugged_cred(void)
|
141
|
+
{
|
142
|
+
rb_mRuggedCred = rb_define_module_under(rb_mRugged, "Credentials");
|
143
|
+
|
144
|
+
rb_cRuggedCredUserPassword = rb_define_class_under(rb_mRuggedCred, "UserPassword", rb_cObject);
|
145
|
+
rb_cRuggedCredSshKey = rb_define_class_under(rb_mRuggedCred, "SshKey", rb_cObject);
|
146
|
+
rb_cRuggedCredSshKeyFromAgent = rb_define_class_under(rb_mRuggedCred, "SshKeyFromAgent", rb_cObject);
|
147
|
+
rb_cRuggedCredDefault = rb_define_class_under(rb_mRuggedCred, "Default", rb_cObject);
|
148
|
+
}
|