Permalink
Browse files

Immutable references

  • Loading branch information...
vmg committed Mar 7, 2013
1 parent 11604de commit b587d68d1be6bc73dc19f81bb35be5b3dd3466be
Showing with 110 additions and 128 deletions.
  1. +1 −8 ext/rugged/rugged.h
  2. +6 −9 ext/rugged/rugged_branch.c
  3. +97 −105 ext/rugged/rugged_reference.c
  4. +6 −6 test/reference_test.rb
View
@@ -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);
@@ -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
View
@@ -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);
}
@@ -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;
}
@@ -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)
@@ -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()
Oops, something went wrong.

0 comments on commit b587d68

Please sign in to comment.