Skip to content

Commit aa1ec36

Browse files
Allow getting/setting a repo's odb.
1 parent 028275e commit aa1ec36

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

ext/rugged/rugged.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ VALUE rugged_signature_new(const git_signature *sig, const char *encoding_name);
9898
VALUE rugged_repo_new(VALUE klass, git_repository *repo);
9999
VALUE rugged_index_new(VALUE klass, VALUE owner, git_index *index);
100100
VALUE rugged_config_new(VALUE klass, VALUE owner, git_config *cfg);
101+
VALUE rugged_odb_new(VALUE klass, VALUE owner, git_odb *odb);
101102
VALUE rugged_object_new(VALUE owner, git_object *object);
102103
VALUE rugged_object_rev_parse(VALUE rb_repo, VALUE rb_spec, int as_obj);
103104
VALUE rugged_ref_new(VALUE klass, VALUE owner, git_reference *ref);

ext/rugged/rugged_odb.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@
2727
extern VALUE rb_mRugged;
2828
VALUE rb_cRuggedOdb;
2929

30+
VALUE rugged_odb_new(VALUE klass, VALUE owner, git_odb *odb)
31+
{
32+
VALUE rb_odb = Data_Wrap_Struct(klass, NULL, &git_odb_free, odb);
33+
34+
rugged_set_owner(rb_odb, owner);
35+
36+
return rb_odb;
37+
}
38+
3039
/*
3140
* call-seq:
3241
* Odb.new() -> odb
@@ -38,8 +47,10 @@ VALUE rb_cRuggedOdb;
3847
*/
3948
static VALUE rb_git_odb_new(VALUE klass) {
4049
git_odb *odb;
50+
4151
rugged_exception_check(git_odb_new(&odb));
42-
return Data_Wrap_Struct(klass, NULL, git_odb_free, odb);
52+
53+
return rugged_odb_new(klass, Qnil, odb);
4354
}
4455

4556
/*
@@ -57,7 +68,7 @@ static VALUE rb_git_odb_open(VALUE klass, VALUE rb_path) {
5768

5869
rugged_exception_check(git_odb_open(&odb, StringValueCStr(rb_path)));
5970

60-
return Data_Wrap_Struct(klass, NULL, git_odb_free, odb);
71+
return rugged_odb_new(klass, Qnil, odb);
6172
}
6273

6374
/*

ext/rugged/rugged_repo.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern VALUE rb_cRuggedTag;
3939
extern VALUE rb_cRuggedTree;
4040
extern VALUE rb_cRuggedReference;
4141
extern VALUE rb_cRuggedBackend;
42+
extern VALUE rb_cRuggedOdb;
4243

4344
extern VALUE rb_cRuggedCredPlaintext;
4445
extern VALUE rb_cRuggedCredSshKey;
@@ -590,6 +591,24 @@ static VALUE rb_git_repo_get_config(VALUE self)
590591
RB_GIT_REPO_OWNED_GET(rb_cRuggedConfig, config);
591592
}
592593

594+
/*
595+
* call-seq:
596+
* repo.odb = odb
597+
*/
598+
static VALUE rb_git_repo_set_odb(VALUE self, VALUE rb_data)
599+
{
600+
RB_GIT_REPO_OWNED_SET(rb_cRuggedOdb, odb);
601+
}
602+
603+
/*
604+
* call-seq:
605+
* repo.odb -> odb
606+
*/
607+
static VALUE rb_git_repo_get_odb(VALUE self)
608+
{
609+
RB_GIT_REPO_OWNED_GET(rb_cRuggedOdb, odb);
610+
}
611+
593612
/*
594613
* call-seq:
595614
* repo.ident = ident
@@ -2512,6 +2531,8 @@ void Init_rugged_repo(void)
25122531
rb_define_method(rb_cRuggedRepo, "index=", rb_git_repo_set_index, 1);
25132532
rb_define_method(rb_cRuggedRepo, "config", rb_git_repo_get_config, 0);
25142533
rb_define_method(rb_cRuggedRepo, "config=", rb_git_repo_set_config, 1);
2534+
rb_define_method(rb_cRuggedRepo, "odb", rb_git_repo_get_odb, 0);
2535+
rb_define_method(rb_cRuggedRepo, "odb=", rb_git_repo_set_odb, 1);
25152536
rb_define_method(rb_cRuggedRepo, "refdb=", rb_git_repository_set_refdb, 1);
25162537

25172538
rb_define_method(rb_cRuggedRepo, "ident", rb_git_repo_get_ident, 0);

0 commit comments

Comments
 (0)