Skip to content

Commit

Permalink
Fix commit creation
Browse files Browse the repository at this point in the history
The test example now works properly
  • Loading branch information
vmg committed Dec 27, 2011
1 parent 729eeef commit 8a72b42
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
14 changes: 10 additions & 4 deletions ext/rugged/rugged_commit.c
Expand Up @@ -124,7 +124,8 @@ static VALUE rb_git_commit_create(VALUE self, VALUE rb_repo, VALUE rb_data)
{
VALUE rb_message, rb_tree, rb_parents;
int parent_count, i, error;
const git_commit **parents;
const git_commit **parents = NULL;
git_commit **free_list = NULL;
git_tree *tree;
git_signature *author, *committer;
git_oid commit_oid;
Expand Down Expand Up @@ -155,10 +156,12 @@ static VALUE rb_git_commit_create(VALUE self, VALUE rb_repo, VALUE rb_data)

parent_count = (int)RARRAY_LEN(rb_parents);
parents = xmalloc(parent_count * sizeof(void*));
free_list = xmalloc(parent_count * sizeof(void*));

for (i = 0; i < parent_count; ++i) {
VALUE p = rb_ary_entry(rb_parents, i);
git_commit *parent = NULL;
git_commit *free_ptr = NULL;

if (TYPE(p) == T_STRING) {
git_oid oid;
Expand All @@ -171,14 +174,16 @@ static VALUE rb_git_commit_create(VALUE self, VALUE rb_repo, VALUE rb_data)
if (error < GIT_SUCCESS)
goto cleanup;

free_ptr = parent;

} else if (rb_obj_is_kind_of(p, rb_cRuggedCommit)) {
Data_Get_Struct(p, git_commit, parent);
} else {
error = GIT_EINVALIDTYPE;
goto cleanup;
rb_raise(rb_eTypeError, "Invalid type for parent object");
}

parents[i] = parent;
free_list[i] = free_ptr;
}

error = git_commit_create(
Expand All @@ -200,9 +205,10 @@ static VALUE rb_git_commit_create(VALUE self, VALUE rb_repo, VALUE rb_data)
git_object_free((git_object *)tree);

for (i = 0; i < parent_count; ++i)
git_object_free((git_object *)parents[i]);
git_object_free((git_object *)free_list[i]);

xfree(parents);
xfree(free_list);
rugged_exception_check(error);

return rugged_create_oid(&commit_oid);
Expand Down
6 changes: 3 additions & 3 deletions ext/rugged/rugged_signature.c
Expand Up @@ -55,9 +55,9 @@ git_signature *rugged_signature_get(VALUE rb_sig)

Check_Type(rb_sig, T_HASH);

rb_name = rb_hash_aref(rb_sig, rb_intern("name"));
rb_email = rb_hash_aref(rb_sig, rb_intern("email"));
rb_time = rb_hash_aref(rb_sig, rb_intern("time"));
rb_name = rb_hash_aref(rb_sig, CSTR2SYM("name"));
rb_email = rb_hash_aref(rb_sig, CSTR2SYM("email"));
rb_time = rb_hash_aref(rb_sig, CSTR2SYM("time"));

Check_Type(rb_name, T_STRING);
Check_Type(rb_email, T_STRING);
Expand Down
24 changes: 11 additions & 13 deletions test/commit_test.rb
Expand Up @@ -37,19 +37,17 @@
assert parents.include?("c47800c7266a2be04c571c04d5a6614691ea99bd")
end

xtest "can write new commit data" do
toid = "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b"
tree = @repo.lookup(toid)

obj = Rugged::Commit.new(@repo)
person = Rugged::Signature.new('Scott', 'schacon@gmail.com', Time.now)

obj.message = 'new message'
obj.author = person
obj.committer = person
obj.tree = tree
obj.write
rm_loose(obj.oid)
test "can write new commit data" do
person = {:name => 'Scott', :email => 'schacon@gmail.com', :time => Time.now }

commit_oid = Rugged::Commit.create(@repo,
:message => "This is the commit message\n\nThis commit is created from Rugged",
:committer => person,
:author => person,
:parents => [@repo.head.target],
:tree => "c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b")

rm_loose(commit_oid)
end

end

0 comments on commit 8a72b42

Please sign in to comment.