Class: Rugged::Index

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/rugged/index.rb,
ext/rugged/rugged_index.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.index_pack(rb_packfile_path) ⇒ Object



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
# File 'ext/rugged/rugged_index.c', line 370

VALUE rb_git_indexer(VALUE self, VALUE rb_packfile_path)
{
	int error;
	git_indexer *indexer;
	VALUE rb_oid;

	Check_Type(rb_packfile_path, T_STRING);

	error = git_indexer_new(&indexer, StringValueCStr(rb_packfile_path));
	rugged_exception_check(error);

	error = git_indexer_run(indexer, NULL);
	rugged_exception_check(error);

	error = git_indexer_write(indexer);
	rugged_exception_check(error);

	rb_oid = rugged_create_oid(git_indexer_hash(indexer));

	git_indexer_free(indexer);
	return rb_oid;
}

.new(path) ⇒ Object



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

static VALUE rb_git_index_new(VALUE klass, VALUE path)
{
	git_index *index;
	int error;

	Check_Type(path, T_STRING);

	error = git_index_open(&index, StringValueCStr(path));
	rugged_exception_check(error);

	return rugged_index_new(klass, Qnil, index);
}

Instance Method Details

#<<(*args) ⇒ Object



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

static VALUE rb_git_index_append(int argc, VALUE *argv, VALUE self)
{
	git_index *index;
	int error;
	VALUE rb_entry, rb_stage;

	rb_scan_args(argc, argv, "11", &rb_entry, &rb_stage);

	Data_Get_Struct(self, git_index, index);

	if (TYPE(rb_entry) == T_HASH) {
		git_index_entry entry;
		rb_git_indexentry_toC(&entry, rb_entry);
		error = git_index_append2(index, &entry);
	} else if (TYPE(rb_entry) == T_STRING) {
		Check_Type(rb_stage, T_FIXNUM);
		error = git_index_append(index, StringValueCStr(rb_entry), FIX2INT(rb_stage));
	} else {
		rb_raise(rb_eTypeError,
			"Expecting a hash defining an Index Entry or a path to a file in the repository");
	}

	rugged_exception_check(error);
	return Qnil;
}

#[](entry) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
# File 'ext/rugged/rugged_index.c', line 119

static VALUE rb_git_index_get(VALUE self, VALUE entry)
{
	git_index *index;
	Data_Get_Struct(self, git_index, index);

	if (TYPE(entry) == T_STRING)
		entry = INT2FIX(git_index_find(index, StringValueCStr(entry)));

	Check_Type(entry, T_FIXNUM);
	return rb_git_indexentry_fromC(git_index_get(index, FIX2INT(entry)));
}

#add(*args) ⇒ Object



182
183
184
185
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
# File 'ext/rugged/rugged_index.c', line 182

static VALUE rb_git_index_add(int argc, VALUE *argv, VALUE self)
{
	git_index *index;
	int error;
	VALUE rb_entry, rb_stage;

	rb_scan_args(argc, argv, "11", &rb_entry, &rb_stage);

	Data_Get_Struct(self, git_index, index);

	if (TYPE(rb_entry) == T_HASH) {
		git_index_entry entry;
		if (argc > 1)
			rb_raise(rb_eTypeError,
				"Wrong number or arguments (only an Index Entry is expected");

		rb_git_indexentry_toC(&entry, rb_entry);
		error = git_index_add2(index, &entry);
	} else if (TYPE(rb_entry) == T_STRING) {
		int stage = 0;
		if (!NIL_P(rb_stage))
			stage = NUM2INT(rb_stage);
		error = git_index_add(index, StringValueCStr(rb_entry), stage);
	} else {
		rb_raise(rb_eTypeError, 
			"Expecting a hash defining an Index Entry or a path to a file in the repository");
	}

	rugged_exception_check(error);
	return Qnil;
}

#append(*args) ⇒ Object



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

static VALUE rb_git_index_append(int argc, VALUE *argv, VALUE self)
{
	git_index *index;
	int error;
	VALUE rb_entry, rb_stage;

	rb_scan_args(argc, argv, "11", &rb_entry, &rb_stage);

	Data_Get_Struct(self, git_index, index);

	if (TYPE(rb_entry) == T_HASH) {
		git_index_entry entry;
		rb_git_indexentry_toC(&entry, rb_entry);
		error = git_index_append2(index, &entry);
	} else if (TYPE(rb_entry) == T_STRING) {
		Check_Type(rb_stage, T_FIXNUM);
		error = git_index_append(index, StringValueCStr(rb_entry), FIX2INT(rb_stage));
	} else {
		rb_raise(rb_eTypeError,
			"Expecting a hash defining an Index Entry or a path to a file in the repository");
	}

	rugged_exception_check(error);
	return Qnil;
}

#clearObject



63
64
65
66
67
68
69
# File 'ext/rugged/rugged_index.c', line 63

static VALUE rb_git_index_clear(VALUE self)
{
	git_index *index;
	Data_Get_Struct(self, git_index, index);
	git_index_clear(index);
	return Qnil;
}

#countObject



105
106
107
108
109
110
# File 'ext/rugged/rugged_index.c', line 105

static VALUE rb_git_index_count(VALUE self)
{
	git_index *index;
	Data_Get_Struct(self, git_index, index);
	return INT2FIX(git_index_entrycount(index));
}

#count_unmergedObject



112
113
114
115
116
117
# File 'ext/rugged/rugged_index.c', line 112

static VALUE rb_git_index_count_unmerged(VALUE self)
{
	git_index *index;
	Data_Get_Struct(self, git_index, index);
	return INT2FIX(git_index_entrycount_unmerged(index));
}

#eachObject



131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'ext/rugged/rugged_index.c', line 131

static VALUE rb_git_index_each(VALUE self)
{
	git_index *index;
	unsigned int i, count;

	Data_Get_Struct(self, git_index, index);

	if (!rb_block_given_p())
		return rb_funcall(self, rb_intern("to_enum"), 0);

	count = git_index_entrycount(index);
	for (i = 0; i < count; ++i) {
		git_index_entry *entry = git_index_get(index, i);
		if (entry)
			rb_yield(rb_git_indexentry_fromC(entry));
	}

	return Qnil;
}

#get_entry(entry) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
# File 'ext/rugged/rugged_index.c', line 119

static VALUE rb_git_index_get(VALUE self, VALUE entry)
{
	git_index *index;
	Data_Get_Struct(self, git_index, index);

	if (TYPE(entry) == T_STRING)
		entry = INT2FIX(git_index_find(index, StringValueCStr(entry)));

	Check_Type(entry, T_FIXNUM);
	return rb_git_indexentry_fromC(git_index_get(index, FIX2INT(entry)));
}

#get_unmerged(entry) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'ext/rugged/rugged_index.c', line 151

static VALUE rb_git_index_get_unmerged(VALUE self, VALUE entry)
{
	git_index *index;
	Data_Get_Struct(self, git_index, index);

	if (TYPE(entry) == T_STRING)
		return rb_git_unmerged_fromC(git_index_get_unmerged_bypath(index, StringValueCStr(entry)));

	if (TYPE(entry) == T_FIXNUM)
		return rb_git_unmerged_fromC(git_index_get_unmerged_byindex(index, FIX2INT(entry)));

	rb_raise(rb_eTypeError, "Expecting a path name or index for unmerged entries");
}

#reloadObject



71
72
73
74
75
76
77
78
79
80
81
82
# File 'ext/rugged/rugged_index.c', line 71

static VALUE rb_git_index_read(VALUE self)
{
	git_index *index;
	int error;

	Data_Get_Struct(self, git_index, index);

	error = git_index_read(index);
	rugged_exception_check(error);

	return Qnil;
}

#remove(entry) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'ext/rugged/rugged_index.c', line 165

static VALUE rb_git_index_remove(VALUE self, VALUE entry)
{
	git_index *index;
	int error;
	Data_Get_Struct(self, git_index, index);

	if (TYPE(entry) == T_STRING)
		entry = INT2FIX(git_index_find(index, StringValueCStr(entry)));

	Check_Type(entry, T_FIXNUM);
	
	error = git_index_remove(index, FIX2INT(entry));
	rugged_exception_check(error);

	return Qnil;
}

#uniq!Object



97
98
99
100
101
102
103
# File 'ext/rugged/rugged_index.c', line 97

static VALUE rb_git_index_uniq(VALUE self)
{
	git_index *index;
	Data_Get_Struct(self, git_index, index);
	git_index_uniq(index);
	return Qnil;
}

#update(*args) ⇒ Object



182
183
184
185
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
# File 'ext/rugged/rugged_index.c', line 182

static VALUE rb_git_index_add(int argc, VALUE *argv, VALUE self)
{
	git_index *index;
	int error;
	VALUE rb_entry, rb_stage;

	rb_scan_args(argc, argv, "11", &rb_entry, &rb_stage);

	Data_Get_Struct(self, git_index, index);

	if (TYPE(rb_entry) == T_HASH) {
		git_index_entry entry;
		if (argc > 1)
			rb_raise(rb_eTypeError,
				"Wrong number or arguments (only an Index Entry is expected");

		rb_git_indexentry_toC(&entry, rb_entry);
		error = git_index_add2(index, &entry);
	} else if (TYPE(rb_entry) == T_STRING) {
		int stage = 0;
		if (!NIL_P(rb_stage))
			stage = NUM2INT(rb_stage);
		error = git_index_add(index, StringValueCStr(rb_entry), stage);
	} else {
		rb_raise(rb_eTypeError, 
			"Expecting a hash defining an Index Entry or a path to a file in the repository");
	}

	rugged_exception_check(error);
	return Qnil;
}

#writeObject



84
85
86
87
88
89
90
91
92
93
94
95
# File 'ext/rugged/rugged_index.c', line 84

static VALUE rb_git_index_write(VALUE self)
{
	git_index *index;
	int error;

	Data_Get_Struct(self, git_index, index);

	error = git_index_write(index);
	rugged_exception_check(error);
		
	return Qnil;
}

#write_treeObject



393
394
395
396
397
398
399
400
401
402
403
404
405
# File 'ext/rugged/rugged_index.c', line 393

VALUE rb_git_index_writetree(VALUE self)
{
	git_index *index;
	git_oid tree_oid;
	int error;

	Data_Get_Struct(self, git_index, index);

	error = git_tree_create_fromindex(&tree_oid, index);
	rugged_exception_check(error);

	return rugged_create_oid(&tree_oid);
}