Class: Rugged::TagCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
ext/rugged/rugged_tag_collection.c

Instance Method Summary collapse

Constructor Details

#new(repo) ⇒ Object



20
21
22
23
24
# File 'ext/rugged/rugged_tag_collection.c', line 20

static VALUE rb_git_tag_collection_initialize(VALUE self, VALUE repo)
{
	rugged_set_owner(self, repo);
	return self;
}

Instance Method Details

#[](name) ⇒ Object

Lookup a tag in repo, with the given name.

name can be a short or canonical tag name (e.g. v0.1.0 or refs/tags/v0.1.0).

Returns the looked up tag, or nil if the tag doesn’t exist.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'ext/rugged/rugged_tag_collection.c', line 37

static VALUE rb_git_tag_collection_aref(VALUE self, VALUE rb_name)
{
	git_reference *tag;
	git_repository *repo;
	int error;
	VALUE rb_repo = rugged_owner(self);

	rugged_check_repo(rb_repo);
	Data_Get_Struct(rb_repo, git_repository, repo);

	Check_Type(rb_name, T_STRING);

	error = git_reference_lookup(&tag, repo, StringValueCStr(rb_name));
	if (error == GIT_ENOTFOUND || error == GIT_EINVALIDSPEC) {
		char *canonical_ref = xmalloc((RSTRING_LEN(rb_name) + strlen("refs/tags/") + 1) * sizeof(char));
		strcpy(canonical_ref, "refs/tags/");
		strcat(canonical_ref, StringValueCStr(rb_name));

		error = git_reference_lookup(&tag, repo, canonical_ref);
		xfree(canonical_ref);
		if (error == GIT_ENOTFOUND)
			return Qnil;
	}

	rugged_exception_check(error);

	return rugged_ref_new(rb_cRuggedTag, rb_repo, tag);
}

#create(name, target[, force = false][, annotation = nil]) ⇒ Object

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.



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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
# File 'ext/rugged/rugged_tag_collection.c', line 107

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);
}

#create_annotation(name, target, annotation) ⇒ Object

Create a new annotated tag object with the specified name on target in repo.

Unlike the create method, create_annotation simply creates a tag object. It does not write a tag ref.

annotation must have the following keys:

: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 an instance of Rugged::Tag::Annotation representing the newly created annotation.



186
187
188
189
190
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
# File 'ext/rugged/rugged_tag_collection.c', line 186

static VALUE rb_git_tag_collection_create_annotation(VALUE self, VALUE rb_name, VALUE rb_target, VALUE rb_annotation)
{
	git_oid tag_oid;
	git_repository *repo = NULL;
	git_object *target = NULL, *tag = NULL;
	git_signature *tagger = NULL;
	VALUE rb_message;
	int error;

	VALUE rb_repo = rugged_owner(self);
	rugged_check_repo(rb_repo);
	Data_Get_Struct(rb_repo, git_repository, repo);

	Check_Type(rb_name, T_STRING);

	target = rugged_object_get(repo, rb_target, GIT_OBJ_ANY);

	rb_message = rb_hash_aref(rb_annotation, CSTR2SYM("message"));
	Check_Type(rb_message, T_STRING);

	tagger = rugged_signature_get(
		rb_hash_aref(rb_annotation, CSTR2SYM("tagger")), repo
	);

	error = git_tag_annotation_create(
		&tag_oid,
		repo,
		StringValueCStr(rb_name),
		target,
		tagger,
		StringValueCStr(rb_message)
	);

	git_object_free(target);
	git_signature_free(tagger);

	rugged_exception_check(error);

	error = git_object_lookup(&tag, repo, &tag_oid, GIT_OBJ_TAG);
	rugged_exception_check(error);

	return rugged_object_new(rb_repo, tag);
}

#delete(name) ⇒ nil

Delete the tag reference identified by name.

Returns:

  • (nil)


72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'ext/rugged/rugged_tag_collection.c', line 72

static VALUE rb_git_tag_collection_delete(VALUE self, VALUE rb_name)
{
	VALUE rb_repo = rugged_owner(self);
	git_repository *repo;
	int error;

	rugged_check_repo(rb_repo);
	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([pattern]) {|name| ... } ⇒ nil #each([pattern]) ⇒ Object

Iterate through all the tags 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.

Overloads:

  • #each([pattern]) {|name| ... } ⇒ nil

    Yields:

    • (name)

    Returns:

    • (nil)


306
307
308
309
# File 'ext/rugged/rugged_tag_collection.c', line 306

static VALUE rb_git_tag_collection_each(int argc, VALUE *argv, VALUE self)
{
	return each_tag(argc, argv, self, 0);
}

#each_name([pattern]) {|name| ... } ⇒ nil #each_name([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.

Overloads:

  • #each_name([pattern]) {|name| ... } ⇒ nil

    Yields:

    • (name)

    Returns:

    • (nil)


286
287
288
289
# File 'ext/rugged/rugged_tag_collection.c', line 286

static VALUE rb_git_tag_collection_each_name(int argc, VALUE *argv, VALUE self)
{
	return each_tag(argc, argv, self, 1);
}