Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Immutable references
  • Loading branch information
vmg committed Mar 7, 2013
1 parent 11604de commit b587d68
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 128 deletions.
9 changes: 1 addition & 8 deletions ext/rugged/rugged.h
Expand Up @@ -67,8 +67,8 @@ VALUE rugged_raw_read(git_repository *repo, const git_oid *oid);
VALUE rugged_signature_new(const git_signature *sig, const char *encoding_name);

VALUE rugged_index_new(VALUE klass, VALUE owner, git_index *index);
VALUE rugged_object_new(VALUE owner, git_object *object);
VALUE rugged_config_new(VALUE klass, VALUE owner, git_config *cfg);
VALUE rugged_object_new(VALUE owner, git_object *object);
VALUE rugged_ref_new(VALUE klass, VALUE owner, git_reference *ref);

VALUE rugged_otype_new(git_otype t);
Expand Down Expand Up @@ -131,11 +131,4 @@ static inline VALUE rugged_create_oid(const git_oid *oid)
return rugged_str_new(out, 40, NULL);
}

#define RUGGED_UNPACK_REFERENCE(_rb_obj, _rugged_obj) {\
if (DATA_PTR(_rb_obj) == NULL)\
rb_raise(rb_eRuntimeError,\
"This Git Reference has been deleted and no longer exists on the repository");\
Data_Get_Struct(_rb_obj, git_reference, _rugged_obj);\
}

#endif
15 changes: 6 additions & 9 deletions ext/rugged/rugged_branch.c
Expand Up @@ -142,7 +142,6 @@ static VALUE rb_git_branch_lookup(int argc, VALUE *argv, VALUE self)
return Qnil;

rugged_exception_check(error);

return rugged_branch_new(rb_repo, branch);
}

Expand All @@ -157,14 +156,12 @@ static VALUE rb_git_branch_delete(VALUE self)
{
git_reference *branch = NULL;

RUGGED_UNPACK_REFERENCE(self, branch);
Data_Get_Struct(self, git_reference, branch);

rugged_exception_check(
git_branch_delete(branch)
);

DATA_PTR(self) = NULL; /* this reference has been free'd */
rugged_set_owner(self, Qnil); /* and is no longer owned */
return Qnil;
}

Expand All @@ -188,7 +185,7 @@ static int cb_branch__each_obj(const char *branch_name, git_branch_t branch_type
);

rb_yield(rugged_branch_new(rb_repo, branch));
return GIT_OK;
return 0;
}

static VALUE each_branch(int argc, VALUE *argv, VALUE self, int branch_names_only)
Expand Down Expand Up @@ -274,21 +271,21 @@ static VALUE rb_git_branch_each(int argc, VALUE *argv, VALUE self)
static VALUE rb_git_branch_move(int argc, VALUE *argv, VALUE self)
{
VALUE rb_new_branch_name, rb_force;
git_reference *old_branch = NULL;
git_reference *old_branch = NULL, *new_branch = NULL;
int error, force = 0;

rb_scan_args(argc, argv, "11", &rb_new_branch_name, &rb_force);

RUGGED_UNPACK_REFERENCE(self, old_branch);
Data_Get_Struct(self, git_reference, old_branch);
Check_Type(rb_new_branch_name, T_STRING);

if (!NIL_P(rb_force))
force = rugged_parse_bool(rb_force);

error = git_branch_move(old_branch, StringValueCStr(rb_new_branch_name), force);
error = git_branch_move(&new_branch, old_branch, StringValueCStr(rb_new_branch_name), force);
rugged_exception_check(error);

return Qnil;
return rugged_branch_new(rugged_owner(self), new_branch);
}

void Init_rugged_branch()
Expand Down

0 comments on commit b587d68

Please sign in to comment.