Skip to content

Commit

Permalink
Remove all of the old backend code.
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurschreiber committed Oct 13, 2015
1 parent fe7acc7 commit b4978cf
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 146 deletions.
1 change: 0 additions & 1 deletion ext/rugged/rugged.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,6 @@ void Init_rugged(void)
Init_rugged_diff_line();
Init_rugged_blame();
Init_rugged_cred();
Init_rugged_backend();

Init_rugged_refdb();
Init_rugged_refdb_backend();
Expand Down
7 changes: 0 additions & 7 deletions ext/rugged/rugged.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ void Init_rugged_diff_hunk(void);
void Init_rugged_diff_line(void);
void Init_rugged_blame(void);
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_fs(void);
Expand Down Expand Up @@ -191,10 +190,4 @@ static inline VALUE rugged_create_oid(const git_oid *oid)
return rb_str_new(out, 40);
}


typedef struct _rugged_backend {
int (* odb_backend)(git_odb_backend **backend_out, struct _rugged_backend *backend, const char* path);
int (* refdb_backend)(git_refdb_backend **backend_out, struct _rugged_backend *backend, const char* path);
} rugged_backend;

#endif
34 changes: 0 additions & 34 deletions ext/rugged/rugged_backend.c

This file was deleted.

108 changes: 4 additions & 104 deletions ext/rugged/rugged_repo.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,16 @@
*/

#include "rugged.h"
#include <git2/sys/repository.h>
#include <git2/sys/odb_backend.h>
#include <git2/sys/refdb_backend.h>
#include <git2/refs.h>

extern VALUE rb_mRugged;
extern VALUE rb_eRuggedError;
extern VALUE rb_cRuggedIndex;
extern VALUE rb_cRuggedConfig;
extern VALUE rb_cRuggedBackend;
extern VALUE rb_cRuggedRemote;
extern VALUE rb_cRuggedCommit;
extern VALUE rb_cRuggedTag;
extern VALUE rb_cRuggedTree;
extern VALUE rb_cRuggedReference;
extern VALUE rb_cRuggedBackend;
extern VALUE rb_cRuggedOdb;
extern VALUE rb_cRuggedRefdb;

Expand Down Expand Up @@ -189,74 +183,6 @@ static void load_alternates(git_repository *repo, VALUE rb_alternates)
rugged_exception_check(error);
}

static void rugged_repo_new_with_backend(git_repository **repo, VALUE rb_path, VALUE rb_backend)
{
char *path;

git_odb *odb = NULL;
git_odb_backend *odb_backend = NULL;
git_refdb *refdb = NULL;
git_refdb_backend *refdb_backend = NULL;
git_reference *head = NULL;
rugged_backend *backend;

int error = 0;

Check_Type(rb_path, T_STRING);
path = StringValueCStr(rb_path);

if (rb_obj_is_kind_of(rb_backend, rb_cRuggedBackend) == Qfalse) {
rb_raise(rb_eRuggedError, "Backend must be an instance of Rugged::Backend");
}

Data_Get_Struct(rb_backend, rugged_backend, backend);

error = git_odb_new(&odb);
if (error) goto cleanup;

error = backend->odb_backend(&odb_backend, backend, path);
if (error) goto cleanup;

error = git_odb_add_backend(odb, odb_backend, 1);
if (error) goto cleanup;

error = git_repository_wrap_odb(repo, odb);
if (error) goto cleanup;

error = git_refdb_new(&refdb, *repo);
if (error) goto cleanup;

error = backend->refdb_backend(&refdb_backend, backend, path);
if (error) goto cleanup;

error = git_refdb_set_backend(refdb, refdb_backend);
if (error) goto cleanup;

git_repository_set_refdb(*repo, refdb);

error = git_reference_lookup(&head, *repo, "HEAD");

if (error == GIT_ENOTFOUND) {
giterr_clear();
error = git_reference_symbolic_create(&head, *repo, "HEAD", "refs/heads/master", 0, NULL);
}

if (!error) {
git_reference_free(head);
return;
}

cleanup:
git_repository_free(*repo);
git_odb_free(odb);
git_refdb_free(refdb);

if (odb_backend != NULL) odb_backend->free(odb_backend);
if (refdb_backend != NULL) refdb_backend->free(refdb_backend);

rugged_exception_check(error);
}

/*
* call-seq:
* Repository.bare(path[, alternates]) -> repository OR
Expand All @@ -276,8 +202,6 @@ static void rugged_repo_new_with_backend(git_repository **repo, VALUE rb_path, V
*
* The following options can be passed in the +options+ Hash:
*
* :backend ::
* A Rugged::Backend instance
* :alternates ::
* A list of alternate object folders.
* Rugged::Repository.bare(path, :alternates => ['./other/repo/.git/objects'])
Expand All @@ -294,13 +218,6 @@ static VALUE rb_git_repo_open_bare(int argc, VALUE *argv, VALUE klass)
rb_alternates = rb_options;

if (!NIL_P(rb_options) && TYPE(rb_options) == T_HASH) {
/* Check for `:backend` */
VALUE rb_backend = rb_hash_aref(rb_options, CSTR2SYM("backend"));

if (!NIL_P(rb_backend)) {
rugged_repo_new_with_backend(&repo, rb_path, rb_backend);
}

/* Check for `:alternates` */
rb_alternates = rb_hash_aref(rb_options, CSTR2SYM("alternates"));
}
Expand Down Expand Up @@ -377,36 +294,19 @@ static VALUE rb_git_repo_new(int argc, VALUE *argv, VALUE klass)
* of +path+. Non-bare repositories are created in a +.git+ folder and
* use +path+ as working directory.
*
* The following options can be passed in the +options+ Hash:
*
* :backend ::
* A Rugged::Backend instance
*
*
* Rugged::Repository.init_at('repository', :bare) #=> #<Rugged::Repository:0x108849488>
*/
static VALUE rb_git_repo_init_at(int argc, VALUE *argv, VALUE klass)
{
git_repository *repo = NULL;
VALUE rb_path, rb_is_bare, rb_options;
VALUE rb_path, rb_is_bare;
int error;

rb_scan_args(argc, argv, "11:", &rb_path, &rb_is_bare, &rb_options);
rb_scan_args(argc, argv, "11", &rb_path, &rb_is_bare);
Check_Type(rb_path, T_STRING);

if (!NIL_P(rb_options)) {
/* Check for `:backend` */
VALUE rb_backend = rb_hash_aref(rb_options, CSTR2SYM("backend"));

if (rb_backend && !NIL_P(rb_backend)) {
rugged_repo_new_with_backend(&repo, rb_path, rb_backend);
}
}

if(!repo) {
error = git_repository_init(&repo, StringValueCStr(rb_path), RTEST(rb_is_bare));
rugged_exception_check(error);
}
error = git_repository_init(&repo, StringValueCStr(rb_path), RTEST(rb_is_bare));
rugged_exception_check(error);

return rugged_repo_new(klass, repo);
}
Expand Down

0 comments on commit b4978cf

Please sign in to comment.