Class: Rugged::Tag
- Inherits:
-
RuggedObject
- Object
- RuggedObject
- Rugged::Tag
- Defined in:
- lib/rugged/tag.rb,
ext/rugged/rugged_tag.c
Class Method Summary collapse
-
.create(repo, data) ⇒ Object
Create a new tag in
repo
. -
.delete(repo, name) ⇒ nil
Delete the tag reference identified by
name
fromrepo
. -
.each(*args) ⇒ Object
Iterate through all the tag names in
repo
. - .prettify_message(msg, strip_comments = true) ⇒ Object
Instance Method Summary collapse
- #inspect ⇒ Object
-
#message ⇒ Object
Return the message of this
tag
. - #modify(new_args, force = True) ⇒ Object
-
#name ⇒ Object
Return a string with the name of this
tag
. -
#tagger ⇒ Object
Return the signature for the author of this
tag
. -
#target ⇒ Object
Return the
object
pointed at by this tag, as aRugged::Object
instance. -
#target_id ⇒ Object
Return the oid pointed at by this tag, as a
String
instance. -
#target_oid ⇒ Object
Return the oid pointed at by this tag, as a
String
instance. -
#type ⇒ Object
Return a symbol representing the type of the objeced pointed at by this
tag
. - #to_hash ⇒ Object
Class Method Details
.create(repo, data) ⇒ Object
Create a new tag in repo
.
If data
is a String, it has to contain the raw tag data.
If data
is a Hash, it has to contain the following key value pairs:
- :name
-
A String holding the tag’s new name.
- :force
-
If
true
, existing tags will be overwritten. Defaults tofalse
. - :tagger
-
An optional Hash containing a git signature. Will cause the creation of an annotated tag object if present.
- :message
-
An optional string containing the message for the new tag. Will cause the creation of an annotated tag if present.
- :target
-
The OID of the object that the new tag should point to.
Returns the OID of the newly created tag.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
# File 'ext/rugged/rugged_tag.c', line 191
static VALUE rb_git_tag_create(VALUE self, VALUE rb_repo, VALUE rb_data)
{
git_oid tag_oid;
git_repository *repo = NULL;
int error, force = 0;
VALUE rb_name, rb_target, rb_tagger, rb_message, rb_force;
if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo))
rb_raise(rb_eTypeError, "Expecting a Rugged::Repository instance");
Data_Get_Struct(rb_repo, git_repository, repo);
if (TYPE(rb_data) == T_STRING) {
error = git_tag_create_frombuffer(
&tag_oid,
repo,
StringValueCStr(rb_data),
force
);
} else if (TYPE(rb_data) == T_HASH) {
git_object *target = NULL;
rb_name = rb_hash_aref(rb_data, CSTR2SYM("name"));
Check_Type(rb_name, T_STRING);
rb_force = rb_hash_aref(rb_data, CSTR2SYM("force"));
if (!NIL_P(rb_force))
force = rugged_parse_bool(rb_force);
/* only for heavy tags */
rb_tagger = rb_hash_aref(rb_data, CSTR2SYM("tagger"));
rb_message = rb_hash_aref(rb_data, CSTR2SYM("message"));
if (!NIL_P(rb_message))
Check_Type(rb_message, T_STRING);
rb_target = rb_hash_aref(rb_data, CSTR2SYM("target"));
target = rugged_object_get(repo, rb_target, GIT_OBJ_ANY);
if (!NIL_P(rb_tagger) && !NIL_P(rb_message)) {
git_signature *tagger = NULL;
tagger = rugged_signature_get(rb_tagger);
error = git_tag_create(
&tag_oid,
repo,
StringValueCStr(rb_name),
target,
tagger,
StringValueCStr(rb_message),
force
);
git_signature_free(tagger);
} else {
error = git_tag_create_lightweight(
&tag_oid,
repo,
StringValueCStr(rb_name),
target,
force
);
}
git_object_free(target);
} else {
rb_raise(rb_eTypeError, "Invalid tag data: expected a String or a Hash");
}
rugged_exception_check(error);
return rugged_create_oid(&tag_oid);
}
|
.delete(repo, name) ⇒ nil
Delete the tag reference identified by name
from repo
.
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'ext/rugged/rugged_tag.c', line 325
static VALUE rb_git_tag_delete(VALUE self, VALUE rb_repo, VALUE rb_name)
{
git_repository *repo;
int error;
if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo))
rb_raise(rb_eTypeError, "Expecting a Rugged::Repository instance");
Data_Get_Struct(rb_repo, git_repository, repo);
Check_Type(rb_name, T_STRING);
error = git_tag_delete(repo, StringValueCStr(rb_name));
rugged_exception_check(error);
return Qnil;
}
|
.each(repo[, pattern]) {|name| ... } ⇒ nil .each(repo[, pattern]) ⇒ Object
Iterate through all the tag names in repo
. Iteration can be optionally filtered to the ones matching the given pattern
, a standard Unix filename glob.
If pattern
is empty or not given, all tag names will be returned.
The given block will be called once with the name for each tag.
If no block is given, an enumerator will be returned.
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'ext/rugged/rugged_tag.c', line 281
static VALUE rb_git_tag_each(int argc, VALUE *argv, VALUE self)
{
git_repository *repo;
git_strarray tags;
size_t i;
int error, exception = 0;
VALUE rb_repo, rb_pattern;
const char *pattern = NULL;
rb_scan_args(argc, argv, "11", &rb_repo, &rb_pattern);
if (!rb_block_given_p())
return rb_funcall(self, rb_intern("to_enum"), 3, CSTR2SYM("each"), rb_repo, rb_pattern);
if (!NIL_P(rb_pattern)) {
Check_Type(rb_pattern, T_STRING);
pattern = StringValueCStr(rb_pattern);
}
if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo))
rb_raise(rb_eTypeError, "Expecting a Rugged::Repository instance");
Data_Get_Struct(rb_repo, git_repository, repo);
error = git_tag_list_match(&tags, pattern ? pattern : "", repo);
rugged_exception_check(error);
for (i = 0; !exception && i < tags.count; ++i)
rb_protect(rb_yield, rb_str_new_utf8(tags.strings[i]), &exception);
git_strarray_free(&tags);
if (exception)
rb_jump_tag(exception);
return Qnil;
}
|
Instance Method Details
#inspect ⇒ Object
8 9 10 |
# File 'lib/rugged/tag.rb', line 8 def inspect "#<Rugged::Tag:#{object_id} {name: #{name.inspect}, message: #{.inspect}, target: #{target.inspect}>" end |
#message ⇒ Object
Return the message of this tag
. This includes the full body of the message and any optional footers or signatures after it.
tag. #=> "Release v0.16.0, codename 'broken stuff'"
148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'ext/rugged/rugged_tag.c', line 148
static VALUE rb_git_tag_message_GET(VALUE self)
{
git_tag *tag;
const char *message;
Data_Get_Struct(self, git_tag, tag);
message = git_tag_message(tag);
if (!message)
return Qnil;
return rb_str_new_utf8(message);
}
|
#modify(new_args, force = True) ⇒ Object
21 22 23 24 |
# File 'lib/rugged/tag.rb', line 21 def modify(new_args, force=True) args = self.to_hash.merge(new_args) Tag.create(args, force) end |
#name ⇒ Object
Return a string with the name of this tag
.
tag.name #=> "v0.16.0"
107 108 109 110 111 112 113 |
# File 'ext/rugged/rugged_tag.c', line 107
static VALUE rb_git_tag_name_GET(VALUE self)
{
git_tag *tag;
Data_Get_Struct(self, git_tag, tag);
return rb_str_new_utf8(git_tag_name(tag));
}
|
#tagger ⇒ Object
Return the signature for the author of this tag
. The signature is returned as a Hash
containing :name
, :email
of the author and :time
of the tagging.
tag.tagger #=> {:email=>"[email protected]", :time=>Tue Jan 24 05:42:45 UTC 2012, :name=>"Vicent Mart\303\255"}
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'ext/rugged/rugged_tag.c', line 125
static VALUE rb_git_tag_tagger_GET(VALUE self)
{
git_tag *tag;
const git_signature *tagger;
Data_Get_Struct(self, git_tag, tag);
tagger = git_tag_tagger(tag);
if (!tagger)
return Qnil;
return rugged_signature_new(tagger, NULL);
}
|
#target ⇒ Object
Return the object
pointed at by this tag, as a Rugged::Object
instance.
tag.target #=> #<Rugged::Commit:0x108828918>
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'ext/rugged/rugged_tag.c', line 41
static VALUE rb_git_tag_target_GET(VALUE self)
{
git_tag *tag;
git_object *target;
int error;
VALUE owner;
Data_Get_Struct(self, git_tag, tag);
owner = rugged_owner(self);
error = git_tag_target(&target, tag);
rugged_exception_check(error);
return rugged_object_new(owner, target);
}
|
#target_oid ⇒ Object #target_id ⇒ Object
Return the oid pointed at by this tag, as a String
instance.
tag.target_id #=> "2cb831a8aea28b2c1b9c63385585b864e4d3bad1"
67 68 69 70 71 72 73 74 75 76 77 |
# File 'ext/rugged/rugged_tag.c', line 67
static VALUE rb_git_tag_target_id_GET(VALUE self)
{
git_tag *tag;
const git_oid *target_oid;
Data_Get_Struct(self, git_tag, tag);
target_oid = git_tag_target_id(tag);
return rugged_create_oid(target_oid);
}
|
#target_oid ⇒ Object #target_id ⇒ Object
Return the oid pointed at by this tag, as a String
instance.
tag.target_id #=> "2cb831a8aea28b2c1b9c63385585b864e4d3bad1"
67 68 69 70 71 72 73 74 75 76 77 |
# File 'ext/rugged/rugged_tag.c', line 67
static VALUE rb_git_tag_target_id_GET(VALUE self)
{
git_tag *tag;
const git_oid *target_oid;
Data_Get_Struct(self, git_tag, tag);
target_oid = git_tag_target_id(tag);
return rugged_create_oid(target_oid);
}
|
#type ⇒ Object
Return a symbol representing the type of the objeced pointed at by this tag
. Possible values are :blob
, :commit
, :tree
and :tag
.
This is always the same as the type
of the returned tag.target
tag.type #=> :commit
tag.target.type == tag.type #=> true
91 92 93 94 95 96 97 |
# File 'ext/rugged/rugged_tag.c', line 91
static VALUE rb_git_tag_target_type_GET(VALUE self)
{
git_tag *tag;
Data_Get_Struct(self, git_tag, tag);
return rugged_otype_new(git_tag_target_type(tag));
}
|
#to_hash ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/rugged/tag.rb', line 12 def to_hash { :message => , :name => name, :target => target, :tagger => tagger, } end |