/* * call-seq: * tags.create(name, target[, force = false][, annotation = nil]) -> oid * * Create a new tag with the specified +name+ on +target+ in +repo+. * * If +annotation+ is not +nil+, it will cause the creation of an annotated tag object. * +annotation+ has to contain the following key value pairs: * * :tagger :: * An optional Hash containing a git signature. Defaults to the signature * from the configuration if only `:message` is given. Will cause the * creation of an annotated tag object if present. * * :message :: * An optional string containing the message for the new tag. * * Returns the OID of the newly created tag. */ static VALUE rb_git_tag_collection_create(int argc, VALUE *argv, VALUE self) { git_oid tag_oid; git_repository *repo = NULL; git_object *target = NULL; int error, force = 0; VALUE rb_repo = rugged_owner(self), rb_name, rb_target, rb_force, rb_annotation; rb_scan_args(argc, argv, "21:", &rb_name, &rb_target, &rb_force, &rb_annotation); rugged_check_repo(rb_repo); Data_Get_Struct(rb_repo, git_repository, repo); Check_Type(rb_name, T_STRING); if (!NIL_P(rb_force)) force = rugged_parse_bool(rb_force); target = rugged_object_get(repo, rb_target, GIT_OBJ_ANY); if (NIL_P(rb_annotation)) { error = git_tag_create_lightweight( &tag_oid, repo, StringValueCStr(rb_name), target, force ); } else { git_signature *tagger = rugged_signature_get( rb_hash_aref(rb_annotation, CSTR2SYM("tagger")), repo ); VALUE rb_message = rb_hash_aref(rb_annotation, CSTR2SYM("message")); Check_Type(rb_message, T_STRING); error = git_tag_create( &tag_oid, repo, StringValueCStr(rb_name), target, tagger, StringValueCStr(rb_message), force ); git_signature_free(tagger); } git_object_free(target); rugged_exception_check(error); return rb_git_tag_collection_aref(self, rb_name); }
/* * call-seq: * Rugged.prettify_message(message, strip_comments) -> clean_message * * Process a commit or tag message into standard form, by stripping trailing spaces and * comments, and making sure that the message has a proper header line. */ static VALUE rb_git_prettify_message(VALUE self, VALUE rb_message, VALUE rb_strip_comments) { char *message; int strip_comments, message_len; VALUE result; Check_Type(rb_message, T_STRING); strip_comments = rugged_parse_bool(rb_strip_comments); message_len = (int)RSTRING_LEN(rb_message) + 2; message = xmalloc(message_len); message_len = git_message_prettify(message, message_len, StringValueCStr(rb_message), strip_comments); rugged_exception_check(message_len); result = rb_enc_str_new(message, message_len - 1, rb_utf8_encoding()); xfree(message); return result; }
static int certificate_check_cb(git_cert *cert, int valid, const char *host, void *data) { struct rugged_remote_cb_payload *payload = data; VALUE args = rb_ary_new2(3); VALUE ret; if (NIL_P(payload->certificate_check)) return valid ? 0 : GIT_ECERTIFICATE; rb_ary_push(args, payload->certificate_check); rb_ary_push(args, valid ? Qtrue : Qfalse); rb_ary_push(args, rb_str_new_utf8(host)); ret = rb_protect(rugged__block_yield_splat, args, &payload->exception); if (payload->exception) return GIT_ERROR; return rugged_parse_bool(ret) ? GIT_OK : GIT_ECERTIFICATE; }
/* * call-seq: * obj.create_note(data = {}) -> oid * * Write a new +note+ to +object+, with the given +data+ * arguments, passed as a +Hash+: * * - +:message+: the content of the note to add to the object * - +:committer+: a hash with the signature for the committer * - +:author+: a hash with the signature for the author * - +:ref+: (optional): cannonical name of the reference to use, defaults to "refs/notes/commits" * - +:force+: (optional): overwrite existing note (disabled by default) * * When the note is successfully written to disk, its +oid+ will be * returned as a hex +String+. * * author = {:email=>"*****@*****.**", :time=>Time.now, :name=>"Vicent Mart\303\255"} * * obj.create_note( * :author => author, * :committer => author, * :message => "Hello world\n\n", * :ref => 'refs/notes/builds' * ) */ static VALUE rb_git_note_create(VALUE self, VALUE rb_data) { VALUE rb_ref, rb_message, rb_force; git_repository *repo = NULL; const char *notes_ref = NULL; VALUE owner; git_signature *author, *committer; git_oid note_oid; git_object *target = NULL; int error = 0; int force = 0; Check_Type(rb_data, T_HASH); Data_Get_Struct(self, git_object, target); owner = rugged_owner(self); Data_Get_Struct(owner, git_repository, repo); rb_ref = rb_hash_aref(rb_data, CSTR2SYM("ref")); rb_force = rb_hash_aref(rb_data, CSTR2SYM("force")); if (!NIL_P(rb_force)) force = rugged_parse_bool(rb_force); if (!NIL_P(rb_ref)) { Check_Type(rb_ref, T_STRING); notes_ref = StringValueCStr(rb_ref); } 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")) ); error = git_note_create( ¬e_oid, repo, author, committer, notes_ref, git_object_id(target), StringValueCStr(rb_message), force); git_signature_free(author); git_signature_free(committer); rugged_exception_check(error); return rugged_create_oid(¬e_oid); }
static void rb_git_indexentry_toC(git_index_entry *entry, VALUE rb_entry) { VALUE val; Check_Type(rb_entry, T_HASH); val = rb_hash_aref(rb_entry, CSTR2SYM("path")); Check_Type(val, T_STRING); entry->path = StringValueCStr(val); val = rb_hash_aref(rb_entry, CSTR2SYM("oid")); Check_Type(val, T_STRING); rugged_exception_check( git_oid_fromstr(&entry->id, StringValueCStr(val)) ); entry->dev = default_entry_value(rb_entry, "dev"); entry->ino = default_entry_value(rb_entry, "ino"); entry->mode = default_entry_value(rb_entry, "mode"); entry->gid = default_entry_value(rb_entry, "gid"); entry->uid = default_entry_value(rb_entry, "uid"); entry->file_size = default_entry_value(rb_entry, "file_size"); if ((val = rb_hash_aref(rb_entry, CSTR2SYM("mtime"))) != Qnil) { if (!rb_obj_is_kind_of(val, rb_cTime)) rb_raise(rb_eTypeError, ":mtime must be a Time instance"); entry->mtime.seconds = NUM2INT(rb_funcall(val, rb_intern("to_i"), 0)); entry->mtime.nanoseconds = NUM2INT(rb_funcall(val, rb_intern("usec"), 0)) * 1000; } else { entry->mtime.seconds = entry->mtime.nanoseconds = 0; } if ((val = rb_hash_aref(rb_entry, CSTR2SYM("ctime"))) != Qnil) { if (!rb_obj_is_kind_of(val, rb_cTime)) rb_raise(rb_eTypeError, ":ctime must be a Time instance"); entry->ctime.seconds = NUM2INT(rb_funcall(val, rb_intern("to_i"), 0)); entry->ctime.nanoseconds = NUM2INT(rb_funcall(val, rb_intern("usec"), 0)) * 1000; } else { entry->ctime.seconds = entry->ctime.nanoseconds = 0; } entry->flags = 0x0; entry->flags_extended = 0x0; val = rb_hash_aref(rb_entry, CSTR2SYM("stage")); if (!NIL_P(val)) { unsigned int stage = NUM2INT(val); entry->flags &= ~GIT_IDXENTRY_STAGEMASK; entry->flags |= (stage << GIT_IDXENTRY_STAGESHIFT) & GIT_IDXENTRY_STAGEMASK; } val = rb_hash_aref(rb_entry, CSTR2SYM("valid")); if (!NIL_P(val)) { entry->flags &= ~GIT_IDXENTRY_VALID; if (rugged_parse_bool(val)) entry->flags |= GIT_IDXENTRY_VALID; } else { entry->flags |= GIT_IDXENTRY_VALID; } }
/* * call-seq: * submodules.update(submodule, settings) -> nil * submodules.update(name, settings) -> nil * * Update settings for the given submodule in the submodule config. * * Existing `Rugged::Submodule` instances are not updated, but can be * reloaded by calling `#reload`. * * The following options can be passed in the +settings+ Hash: * * :url :: * Updates the URL for the submodule. * * :ignore_rule :: * See `Rugged::Submodule#ignore_rule` for a list of accepted rules. * * :update_rule :: * See `Rugged::Submodule#update_rule` for a list of accepted rules. * * :fetch_recurse_submodules :: * Updates the +fetchRecurseSubmodules+ rule. */ static VALUE rb_git_submodule_update(VALUE self, VALUE rb_name_or_submodule, VALUE rb_settings) { git_repository *repo; git_submodule_ignore_t ignore_rule = GIT_SUBMODULE_IGNORE_UNSPECIFIED; git_submodule_update_t update_rule = GIT_SUBMODULE_UPDATE_DEFAULT; const char *submodule_name; int fetch_recurse_submodules = 0; VALUE rb_repo = rugged_owner(self); VALUE rb_url, rb_fetch_recurse_submodules, rb_ignore_rule, rb_update_rule; rugged_check_repo(rb_repo); Data_Get_Struct(rb_repo, git_repository, repo); if (rb_obj_is_kind_of(rb_name_or_submodule, rb_cRuggedSubmodule)) rb_name_or_submodule = rb_funcall(rb_name_or_submodule, rb_intern("name"), 0); if (TYPE(rb_name_or_submodule) != T_STRING) rb_raise(rb_eTypeError, "Expecting a String or Rugged::Submodule instance"); rb_url = rb_hash_aref(rb_settings, CSTR2SYM("url")); rb_fetch_recurse_submodules = rb_hash_aref(rb_settings, CSTR2SYM("fetch_recurse_submodules")); rb_ignore_rule = rb_hash_aref(rb_settings, CSTR2SYM("ignore_rule")); rb_update_rule = rb_hash_aref(rb_settings, CSTR2SYM("update_rule")); if (!NIL_P(rb_url)) { Check_Type(rb_url, T_STRING); } if (!NIL_P(rb_fetch_recurse_submodules)) { fetch_recurse_submodules = rugged_parse_bool(rb_fetch_recurse_submodules); } if (!NIL_P(rb_ignore_rule)) { ignore_rule = rb_git_subm_ignore_rule_toC(rb_ignore_rule); } if (!NIL_P(rb_update_rule)) { update_rule = rb_git_subm_update_rule_toC(rb_update_rule); } submodule_name = StringValueCStr(rb_name_or_submodule); if (!NIL_P(rb_url)) { rugged_exception_check( git_submodule_set_url(repo, submodule_name, StringValueCStr(rb_url) ) ); } if (!NIL_P(rb_fetch_recurse_submodules)) { rugged_exception_check( git_submodule_set_fetch_recurse_submodules(repo, submodule_name, fetch_recurse_submodules ) ); } if (!NIL_P(rb_ignore_rule)) { rugged_exception_check( git_submodule_set_ignore(repo, submodule_name, ignore_rule ) ); } if (!NIL_P(rb_update_rule)) { rugged_exception_check( git_submodule_set_update(repo, submodule_name, update_rule ) ); } return Qnil; }
static int treebuilder_cb(const git_tree_entry *entry, void *opaque) { VALUE proc = (VALUE)opaque; VALUE ret = rb_funcall(proc, rb_intern("call"), 1, rb_git_treeentry_fromC(entry)); return rugged_parse_bool(ret); }