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



37
38
39
40
41
# File 'ext/rugged/rugged_tag_collection.c', line 37

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.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'ext/rugged/rugged_tag_collection.c', line 54

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.



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
# File 'ext/rugged/rugged_tag_collection.c', line 124

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.



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
# File 'ext/rugged/rugged_tag_collection.c', line 203

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)


89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'ext/rugged/rugged_tag_collection.c', line 89

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)


327
328
329
330
# File 'ext/rugged/rugged_tag_collection.c', line 327

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)


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

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