Class: Rugged::Commit
- Inherits:
-
RuggedObject
- Object
- RuggedObject
- Rugged::Commit
- Defined in:
- lib/rugged/objects.rb,
ext/rugged/rugged_commit.c
Class Method Summary collapse
Instance Method Summary collapse
- #author ⇒ Object
- #committer ⇒ Object
-
#message ⇒ Object
Commit code.
- #modify(new_args, update_ref = nil) ⇒ Object
- #parents ⇒ Object
- #time ⇒ Object
- #to_hash ⇒ Object
- #tree ⇒ Object
Class Method Details
.create(rb_repo, rb_data) ⇒ Object
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'ext/rugged/rugged_commit.c', line 123
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;
git_tree *tree;
git_signature *author, *committer;
git_oid commit_oid;
git_repository *repo;
Check_Type(rb_data, T_HASH);
if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo))
rb_raise(rb_eTypeError, "Expeting a Rugged::Repository instance");
Data_Get_Struct(rb_repo, git_repository, repo);
rb_message = rb_hash_aref(rb_data, CSTR2SYM("message"));
Check_Type(rb_message, T_STRING);
committer = rugged_signature_get(
rb_hash_aref(rb_data, CSTR2SYM("committer"))
);
author = rugged_signature_get(
rb_hash_aref(rb_data, CSTR2SYM("author"))
);
rb_parents = rb_hash_aref(rb_data, CSTR2SYM("parents"));
Check_Type(rb_parents, T_ARRAY);
rb_tree = rb_hash_aref(rb_data, CSTR2SYM("tree"));
tree = (git_tree *)rugged_object_load(repo, rb_tree, GIT_OBJ_TREE);
parent_count = (int)RARRAY_LEN(rb_parents);
parents = malloc(parent_count * sizeof(void*));
for (i = 0; i < parent_count; ++i) {
VALUE p = rb_ary_entry(rb_parents, i);
git_commit *parent = NULL;
if (TYPE(p) == T_STRING) {
git_oid oid;
error = git_oid_fromstr(&oid, StringValueCStr(p));
if (error < GIT_SUCCESS)
goto cleanup;
error = git_commit_lookup(&parent, repo, &oid);
if (error < GIT_SUCCESS)
goto cleanup;
} else if (rb_obj_is_kind_of(p, rb_cRuggedCommit)) {
Data_Get_Struct(p, git_commit, parent);
} else {
error = GIT_EINVALIDTYPE;
goto cleanup;
}
parents[i] = parent;
}
error = git_commit_create(
&commit_oid,
repo,
NULL,
author,
committer,
NULL,
StringValueCStr(rb_message),
tree,
parent_count,
parents);
cleanup:
git_signature_free(author);
git_signature_free(committer);
git_object_free((git_object *)tree);
for (i = 0; i < parent_count; ++i)
git_object_free((git_object *)parents[i]);
free(parents);
rugged_exception_check(error);
return rugged_create_oid(&commit_oid);
}
|
Instance Method Details
#author ⇒ Object
66 67 68 69 70 71 72 73 74 |
# File 'ext/rugged/rugged_commit.c', line 66
static VALUE rb_git_commit_author_GET(VALUE self)
{
git_commit *commit;
Data_Get_Struct(self, git_commit, commit);
return rugged_signature_new(
git_commit_author(commit),
git_commit_message_encoding(commit));
}
|
#committer ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'ext/rugged/rugged_commit.c', line 56
static VALUE rb_git_commit_committer_GET(VALUE self)
{
git_commit *commit;
Data_Get_Struct(self, git_commit, commit);
return rugged_signature_new(
git_commit_committer(commit),
git_commit_message_encoding(commit));
}
|
#message ⇒ Object
Commit code
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'ext/rugged/rugged_commit.c', line 36
static VALUE rb_git_commit_message_GET(VALUE self)
{
git_commit *commit;
#ifdef HAVE_RUBY_ENCODING_H
rb_encoding *encoding = NULL;
const char *encoding_name;
#endif
Data_Get_Struct(self, git_commit, commit);
#ifdef HAVE_RUBY_ENCODING_H
encoding_name = git_commit_message_encoding(commit);
if (encoding_name != NULL)
encoding = rb_enc_find(encoding_name);
#endif
return rugged_str_new2(git_commit_message(commit), encoding);
}
|
#modify(new_args, update_ref = nil) ⇒ Object
24 25 26 27 |
# File 'lib/rugged/objects.rb', line 24 def modify(new_args, update_ref=nil) args = self.to_hash.merge(new_args) Commit.create(args, update_ref) end |
#parents ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'ext/rugged/rugged_commit.c', line 100
static VALUE rb_git_commit_parents_GET(VALUE self)
{
git_commit *commit;
git_commit *parent;
unsigned int n, parent_count;
VALUE ret_arr, owner;
int error;
Data_Get_Struct(self, git_commit, commit);
owner = rugged_owner(self);
parent_count = git_commit_parentcount(commit);
ret_arr = rb_ary_new2((long)parent_count);
for (n = 0; n < parent_count; n++) {
error = git_commit_parent(&parent, commit, n);
rugged_exception_check(error);
rb_ary_push(ret_arr, rugged_object_new(owner, (git_object *)parent));
}
return ret_arr;
}
|
#time ⇒ Object
76 77 78 79 80 81 82 |
# File 'ext/rugged/rugged_commit.c', line 76
static VALUE rb_git_commit_time_GET(VALUE self)
{
git_commit *commit;
Data_Get_Struct(self, git_commit, commit);
return ULONG2NUM(git_commit_time(commit));
}
|
#to_hash ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/rugged/objects.rb', line 14 def to_hash { :message => , :committer => committer, :author => , :tree => tree, :parents => parents, } end |
#tree ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'ext/rugged/rugged_commit.c', line 84
static VALUE rb_git_commit_tree_GET(VALUE self)
{
git_commit *commit;
git_tree *tree;
VALUE owner;
int error;
Data_Get_Struct(self, git_commit, commit);
owner = rugged_owner(self);
error = git_commit_tree(&tree, commit);
rugged_exception_check(error);
return rugged_object_new(owner, (git_object *)tree);
}
|