Class: Rugged::Reference

Inherits:
Object
  • Object
show all
Defined in:
ext/rugged/rugged_reference.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create(*args) ⇒ Object



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

static VALUE rb_git_ref_create(int argc, VALUE *argv, VALUE klass)
{
	VALUE rb_repo, rb_name, rb_target, rb_force;
	git_repository *repo;
	git_reference *ref;
	git_oid oid;
	int error, force = 0;

	rb_scan_args(argc, argv, "31", &rb_repo, &rb_name, &rb_target, &rb_force);

	Data_Get_Struct(rb_repo, git_repository, repo);
	Check_Type(rb_name, T_STRING);
	Check_Type(rb_target, T_STRING);

	if (!NIL_P(rb_force))
		force = rugged_parse_bool(rb_force);

	if (git_oid_fromstr(&oid, StringValueCStr(rb_target)) == GIT_SUCCESS) {
		error = git_reference_create_oid(
			&ref, repo, StringValueCStr(rb_name), &oid, force);
	} else {
		error = git_reference_create_symbolic(
			&ref, repo, StringValueCStr(rb_name), RSTRING_PTR(rb_target), force);
	}

	rugged_exception_check(error);

	return rugged_ref_new(klass, rb_repo, ref);
}

.each(*args) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'ext/rugged/rugged_reference.c', line 78

static VALUE rb_git_ref_each(int argc, VALUE *argv, VALUE self)
{
	git_repository *repo;
	int error, flags = 0;
	VALUE rb_repo, rb_list, rb_block;

	rb_scan_args(argc, argv, "11&", &rb_repo, &rb_list, &rb_block);

	if (!rb_block_given_p())
		return rb_funcall(self, rb_intern("to_enum"), 3, CSTR2SYM("each"), rb_repo, rb_list);

	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 (!NIL_P(rb_list)) {
		ID list;

		Check_Type(rb_list, T_SYMBOL);
		list = SYM2ID(rb_list);

		if (list == rb_intern("all"))
			flags = GIT_REF_LISTALL;
		else if (list == rb_intern("direct"))
			flags = GIT_REF_OID|GIT_REF_PACKED;
		else if (list == rb_intern("symbolic"))
			flags = GIT_REF_SYMBOLIC|GIT_REF_PACKED;
	} else {
		flags = GIT_REF_LISTALL;
	}

	error = git_reference_foreach(repo, flags, &ref_foreach__block, (void *)rb_block);
	rugged_exception_check(error);
	return Qnil;
}

.lookup(rb_repo, rb_name) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'ext/rugged/rugged_reference.c', line 115

static VALUE rb_git_ref_lookup(VALUE klass, VALUE rb_repo, VALUE rb_name)
{
	git_repository *repo;
	git_reference *ref;
	int error;

	Data_Get_Struct(rb_repo, git_repository, repo);
	Check_Type(rb_name, T_STRING);

	error = git_reference_lookup(&ref, repo, StringValueCStr(rb_name));
	rugged_exception_check(error);

	return rugged_ref_new(klass, rb_repo, ref);
}

.pack_all(rb_repo) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'ext/rugged/rugged_reference.c', line 50

static VALUE rb_git_ref_packall(VALUE klass, VALUE rb_repo)
{
	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);

	error = git_reference_packall(repo);
	rugged_exception_check(error);

	return Qnil;
}

Instance Method Details

#delete!Object



267
268
269
270
271
272
273
274
275
276
277
278
279
280
# File 'ext/rugged/rugged_reference.c', line 267

static VALUE rb_git_ref_delete(VALUE self)
{
	git_reference *ref;
	int error;

	UNPACK_REFERENCE(self, ref);

	error = git_reference_delete(ref);
	rugged_exception_check(error);

	DATA_PTR(self) = NULL; /* this reference has been free'd */
	rugged_set_owner(self, Qnil); /* and is no longer owned */
	return Qnil;
}

#logObject



309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'ext/rugged/rugged_reference.c', line 309

static VALUE rb_git_reflog(VALUE self)
{
	git_reflog *reflog;
	git_reference *ref;
	int error;
	VALUE rb_log;
	unsigned int i, ref_count;

	UNPACK_REFERENCE(self, ref);

	error = git_reflog_read(&reflog, ref);
	rugged_exception_check(error);

	ref_count = git_reflog_entrycount(reflog);
	rb_log = rb_ary_new2(ref_count);

	for (i = 0; i < ref_count; ++i) {
		const git_reflog_entry *entry =
			git_reflog_entry_byindex(reflog, i);

		rb_ary_push(rb_log, reflog_entry_new(entry));
	}

	git_reflog_free(reflog);
	return rb_log;
}

#log!(rb_oid_old, rb_committer, rb_message) ⇒ Object



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
# File 'ext/rugged/rugged_reference.c', line 336

static VALUE rb_git_reflog_write(
	VALUE self,
	VALUE rb_oid_old,
	VALUE rb_committer,
	VALUE rb_message)
{
	git_reference *ref;
	int error;
	git_signature *committer;
	const char *message = NULL;
	git_oid oid_old;

	UNPACK_REFERENCE(self, ref);

	if (!NIL_P(rb_message)) {
		Check_Type(rb_message, T_STRING);
		message = StringValueCStr(rb_message);
	}

	if (!NIL_P(rb_oid_old)) {
		Check_Type(rb_oid_old, T_STRING);
		error = git_oid_fromstr(&oid_old, StringValueCStr(rb_oid_old));
		rugged_exception_check(error);
	}

	committer = rugged_signature_get(rb_committer);

	error = git_reflog_write(
		ref,
		NIL_P(rb_oid_old) ? NULL : &oid_old,
		committer,
		message
	);

	git_signature_free(committer);

	rugged_exception_check(error);
	return Qnil;
}

#nameObject



227
228
229
230
231
232
# File 'ext/rugged/rugged_reference.c', line 227

static VALUE rb_git_ref_name(VALUE self)
{
	git_reference *ref;
	UNPACK_REFERENCE(self, ref);
	return rugged_str_new2(git_reference_name(ref), NULL);
}

#packed?Boolean

Returns:

  • (Boolean)


203
204
205
206
207
208
209
# File 'ext/rugged/rugged_reference.c', line 203

static VALUE rb_git_ref_packed(VALUE self)
{
	git_reference *ref;
	UNPACK_REFERENCE(self, ref);

	return git_reference_is_packed(ref) ? Qtrue : Qfalse;
}

#reload!Object



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'ext/rugged/rugged_reference.c', line 211

static VALUE rb_git_ref_reload(VALUE self)
{
	int error;
	git_reference *ref;
	UNPACK_REFERENCE(self, ref);

	error = git_reference_reload(ref);

	/* If reload fails, the reference is invalidated */
	if (error < GIT_SUCCESS)
		ref = NULL;

	rugged_exception_check(error);
	return Qnil;
}

#rename(*args) ⇒ Object



248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'ext/rugged/rugged_reference.c', line 248

static VALUE rb_git_ref_rename(int argc, VALUE *argv, VALUE self)
{
	git_reference *ref;
	VALUE rb_name, rb_force;
	int error, force = 0;

	UNPACK_REFERENCE(self, ref);
	rb_scan_args(argc, argv, "11", &rb_name, &rb_force);

	Check_Type(rb_name, T_STRING);
	if (!NIL_P(rb_force))
		force = rugged_parse_bool(rb_force);

	error = git_reference_rename(ref, StringValueCStr(rb_name), force);
	rugged_exception_check(error);

	return Qnil;
}

#resolveObject



234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'ext/rugged/rugged_reference.c', line 234

static VALUE rb_git_ref_resolve(VALUE self)
{
	git_reference *ref;
	git_reference *resolved;
	int error;

	UNPACK_REFERENCE(self, ref);

	error = git_reference_resolve(&resolved, ref);
	rugged_exception_check(error);

	return rugged_ref_new(rb_cRuggedReference, rugged_owner(self), resolved);
}

#targetObject



160
161
162
163
164
165
166
167
168
169
170
171
# File 'ext/rugged/rugged_reference.c', line 160

static VALUE rb_git_ref_target(VALUE self)
{
	git_reference *ref;

	UNPACK_REFERENCE(self, ref);

	if (git_reference_type(ref) == GIT_REF_OID) {
		return rugged_create_oid(git_reference_oid(ref));
	} else {
		return rugged_str_new2(git_reference_target(ref), NULL);
	}
}

#target=(rb_target) ⇒ Object



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# File 'ext/rugged/rugged_reference.c', line 173

static VALUE rb_git_ref_set_target(VALUE self, VALUE rb_target)
{
	git_reference *ref;
	int error;

	UNPACK_REFERENCE(self, ref);
	Check_Type(rb_target, T_STRING);

	if (git_reference_type(ref) == GIT_REF_OID) {
		git_oid target;

		error = git_oid_fromstr(&target, StringValueCStr(rb_target));
		rugged_exception_check(error);

		error = git_reference_set_oid(ref, &target);
	} else {
		error = git_reference_set_target(ref, StringValueCStr(rb_target));
	}

	rugged_exception_check(error);
	return Qnil;
}

#typeObject



196
197
198
199
200
201
# File 'ext/rugged/rugged_reference.c', line 196

static VALUE rb_git_ref_type(VALUE self)
{
	git_reference *ref;
	UNPACK_REFERENCE(self, ref);
	return rugged_str_new2(git_object_type2string(git_reference_type(ref)), NULL);
}