@@ -384,6 +384,65 @@ static VALUE rb_git_config_transaction(VALUE self)
384
384
return rb_result ;
385
385
}
386
386
387
+ /*
388
+ * call-seq:
389
+ * config.add_backend(backend, level, force = false) -> config
390
+ *
391
+ * Add a backend to be used by the config.
392
+ *
393
+ * A backend can only be assigned once, and becomes unusable from that
394
+ * point on. Trying to assign a backend a second time will raise an
395
+ * exception.
396
+ */
397
+ static VALUE rb_git_config_add_backend (int argc , VALUE * argv , VALUE self )
398
+ {
399
+ git_config * config ;
400
+ git_config_backend * backend ;
401
+ ID id_level ;
402
+ git_config_level_t level ;
403
+ VALUE rb_backend , rb_level , rb_force ;
404
+
405
+ rb_scan_args (argc , argv , "21" , & rb_backend , & rb_level , & rb_force );
406
+
407
+ // TODO: Check rb_backend
408
+
409
+ Check_Type (rb_level , T_SYMBOL );
410
+
411
+ id_level = SYM2ID (rb_level );
412
+
413
+ if (id_level == rb_intern ("system" )) {
414
+ level = GIT_CONFIG_LEVEL_SYSTEM ;
415
+ } else if (id_level == rb_intern ("xdg" )) {
416
+ level = GIT_CONFIG_LEVEL_XDG ;
417
+ } else if (id_level == rb_intern ("global" )) {
418
+ level = GIT_CONFIG_LEVEL_GLOBAL ;
419
+ } else if (id_level == rb_intern ("local" )) {
420
+ level = GIT_CONFIG_LEVEL_LOCAL ;
421
+ } else if (id_level == rb_intern ("app" )) {
422
+ level = GIT_CONFIG_LEVEL_APP ;
423
+ } else if (id_level == rb_intern ("highest" )) {
424
+ level = GIT_CONFIG_HIGHEST_LEVEL ;
425
+ } else {
426
+ rb_raise (rb_eArgError , "Invalid config backend level." );
427
+ }
428
+
429
+ // TODO: if (!NIL_P(rb_force) && rb_force != Qtrue && rb_force != Qfalse)
430
+
431
+ Data_Get_Struct (self , git_config , config );
432
+ Data_Get_Struct (rb_backend , git_config_backend , backend );
433
+
434
+ if (!backend )
435
+ rb_exc_raise (rb_exc_new2 (rb_eRuntimeError , "Can not reuse config backend instances" ));
436
+
437
+ rugged_exception_check (git_config_add_backend (config , backend , level , RTEST (rb_force )));
438
+
439
+ // libgit2 has taken ownership of the backend, so we should make sure
440
+ // we don't try to free it.
441
+ ((struct RData * )rb_backend )-> data = NULL ;
442
+
443
+ return self ;
444
+ }
445
+
387
446
void Init_rugged_config (void )
388
447
{
389
448
/*
@@ -397,6 +456,8 @@ void Init_rugged_config(void)
397
456
398
457
rb_define_method (rb_cRuggedConfig , "delete" , rb_git_config_delete , 1 );
399
458
459
+ rb_define_method (rb_cRuggedConfig , "add_backend" , rb_git_config_add_backend , -1 );
460
+
400
461
rb_define_method (rb_cRuggedConfig , "store" , rb_git_config_store , 2 );
401
462
rb_define_method (rb_cRuggedConfig , "[]=" , rb_git_config_store , 2 );
402
463
0 commit comments