diff --git a/ext/rugged/rugged.c b/ext/rugged/rugged.c index b94eb31e5..faaf734aa 100644 --- a/ext/rugged/rugged.c +++ b/ext/rugged/rugged.c @@ -485,7 +485,6 @@ void Init_rugged(void) Init_rugged_refdb(); Init_rugged_refdb_backend(); - Init_rugged_refdb_backend_custom(); Init_rugged_refdb_backend_fs(); Init_rugged_odb(); diff --git a/ext/rugged/rugged.h b/ext/rugged/rugged.h index ec3a9b4ba..bad8e71b9 100644 --- a/ext/rugged/rugged.h +++ b/ext/rugged/rugged.h @@ -82,7 +82,6 @@ void Init_rugged_cred(void); void Init_rugged_backend(void); void Init_rugged_refdb(void); void Init_rugged_refdb_backend(void); -void Init_rugged_refdb_backend_custom(void); void Init_rugged_refdb_backend_fs(void); void Init_rugged_odb(void); void Init_rugged_odb_backend(void); diff --git a/ext/rugged/rugged_refdb_backend_custom.c b/ext/rugged/rugged_refdb_backend_custom.c deleted file mode 100644 index f2c45ddc5..000000000 --- a/ext/rugged/rugged_refdb_backend_custom.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * The MIT License - * - * Copyright (c) 2015 GitHub, Inc - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -#include "rugged.h" - -extern VALUE rb_cRuggedRefdbBackend; -VALUE rb_cRuggedRefdbBackendCustom; - -typedef struct { - git_refdb_backend parent; - VALUE self; -} rugged_refdb_backend_custom; - -static int rugged_refdb_backend_custom__exists( - int *exists, - git_refdb_backend *_backend, - const char *ref_name) -{ - rugged_refdb_backend_custom *backend = (rugged_refdb_backend_custom *)_backend; - - // TODO: Proper exception handling - *exists = RTEST(rb_funcall(backend->self, rb_intern("exists"), 1, rb_str_new2(ref_name))); - - return GIT_OK; -} - -static int rugged_refdb_backend_custom__lookup( - git_reference **out, - git_refdb_backend *_backend, - const char *ref_name) -{ - rugged_refdb_backend_custom *backend = (rugged_refdb_backend_custom *)_backend; - git_oid oid; - VALUE rb_result; - - // TODO: Proper exception handling - rb_result = rb_funcall(backend->self, rb_intern("lookup"), 1, rb_str_new2(ref_name)); - if (TYPE(rb_result) == T_STRING) { - // TODO: Handle symbolic refs as well - // TODO: Proper exception handling - rugged_exception_check(git_oid_fromstr(&oid, StringValueCStr(rb_result))); - *out = git_reference__alloc(ref_name, &oid, NULL); - return GIT_OK; - } else { - // TODO: Better error handling - *out = NULL; - return GIT_ENOTFOUND; - } -} - -static int rugged_refdb_backend_custom__compress(git_refdb_backend *_backend) -{ - rugged_refdb_backend_custom *backend = (rugged_refdb_backend_custom *)_backend; - - // TODO: Proper exception handling - rb_funcall(backend->self, rb_intern("compress"), 0); - - return GIT_OK; -} - -static void rb_git_refdb_backend__free(git_refdb_backend *backend) -{ - if (backend) backend->free(backend); -} - -static VALUE rb_git_refdb_backend_custom_new(VALUE self, VALUE rb_repo) -{ - rugged_refdb_backend_custom *backend; - - backend = xcalloc(1, sizeof(rugged_refdb_backend_custom)); - - backend->parent.exists = &rugged_refdb_backend_custom__exists; - backend->parent.compress = &rugged_refdb_backend_custom__compress; - backend->parent.lookup = &rugged_refdb_backend_custom__lookup; - backend->parent.free = (void (*)(git_refdb_backend *)) &xfree; - - backend->self = Data_Wrap_Struct(self, NULL, rb_git_refdb_backend__free, backend); - return backend->self; -} - -void Init_rugged_refdb_backend_custom(void) -{ - rb_cRuggedRefdbBackendCustom = rb_define_class_under(rb_cRuggedRefdbBackend, "Custom", rb_cRuggedRefdbBackend); - - rb_define_singleton_method(rb_cRuggedRefdbBackendCustom, "new", rb_git_refdb_backend_custom_new, 1); -} diff --git a/test/refdb_test.rb b/test/refdb_test.rb index adf2fb6ed..a7d3e4758 100644 --- a/test/refdb_test.rb +++ b/test/refdb_test.rb @@ -24,42 +24,4 @@ def test_set_backend_reuse_error refdb.backend = backend end end - - def test_custom_backend - refdb = Rugged::Refdb.new(@repo) - - compress_calls = 0 - backend = Rugged::Refdb::Backend::Custom.new(@repo) - backend.send(:define_singleton_method, :compress) do - compress_calls += 1 - end - - refdb.backend = backend - refdb.compress - - assert_equal 1, compress_calls - end -end - -class RefdbBackendCustomTest < Rugged::TestCase - def setup - @repo = FixtureRepo.from_rugged("testrepo.git") - @refdb = Rugged::Refdb.new(@repo) - @backend = Rugged::Refdb::Backend::Custom.new(@repo) - @refdb.backend = @backend - @repo.refdb = @refdb - end - - def test_lookup - @backend.send(:define_singleton_method, :lookup) do |ref_name| - "1385f264afb75a56a5bec74243be9b367ba4ca08" if ref_name == "refs/heads/master" - end - - ref = @repo.references["refs/heads/master"] - assert ref - assert_equal "refs/heads/master", ref.name - assert_equal "1385f264afb75a56a5bec74243be9b367ba4ca08", ref.target_id - - assert_nil @repo.references["refs/heads/development"] - end end