Class: Rugged::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/rugged/repository.rb,
ext/rugged/rugged_repo.c

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeObject



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
162
163
164
165
166
167
168
169
# File 'ext/rugged/rugged_repo.c', line 118

static VALUE rb_git_repo_init(int argc, VALUE *argv, VALUE self)
{
	rugged_repository *r_repo;
	git_repository *repo;
	int error = 0;
	VALUE rb_dir, rb_obj_dir, rb_index_file, rb_work_tree;

	if (rb_scan_args(argc, argv, "13", 
				&rb_dir, 
				&rb_obj_dir, 
				&rb_index_file, 
				&rb_work_tree) > 1) {

		const char *git_obj_dir = NULL;
		const char *git_index_file = NULL;
		const char *git_work_tree = NULL;

		Check_Type(rb_dir, T_STRING);

		if (!NIL_P(rb_obj_dir)) {
			Check_Type(rb_obj_dir, T_STRING);
			git_obj_dir = RSTRING_PTR(rb_obj_dir);
		}

		if (!NIL_P(rb_index_file)) {
			Check_Type(rb_index_file, T_STRING);
			git_index_file = RSTRING_PTR(rb_index_file);
		}

		if (!NIL_P(rb_work_tree)) {
			Check_Type(rb_work_tree, T_STRING);
			git_work_tree = RSTRING_PTR(rb_work_tree);
		}

		error = git_repository_open2(&repo,
				RSTRING_PTR(rb_dir),
				git_obj_dir,
				git_index_file,
				git_work_tree);
	} else {
		Check_Type(rb_dir, T_STRING);
		error = git_repository_open(&repo, RSTRING_PTR(rb_dir));
	}

	rugged_exception_check(error);
	assert(repo);

	Data_Get_Struct(self, rugged_repository, r_repo);
	r_repo->repo = repo;

	return Qnil;
}

Class Method Details

.hashObject



264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# File 'ext/rugged/rugged_repo.c', line 264

static VALUE rb_git_repo_obj_hash(VALUE self, VALUE rb_rawobj)
{
	git_rawobj obj;
	char out[40];
	int error;
	git_oid oid;

	rugged_rawobject_get(&obj, rb_rawobj);

	error = git_rawobj_hash(&oid, &obj);
	rugged_exception_check(error);

	git_oid_fmt(out, &oid);
	return rugged_str_new(out, 40, NULL);
}

.init_atObject



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

static VALUE rb_git_repo_init_at(VALUE klass, VALUE path, VALUE rb_is_bare)
{
	rugged_repository *r_repo;
	git_repository *repo;
	int error, is_bare;

	is_bare = rugged_parse_bool(rb_is_bare);
	Check_Type(path, T_STRING);
	error = git_repository_init(&repo, RSTRING_PTR(path), is_bare);

	rugged_exception_check(error);

	/* manually allocate a new repository */
	r_repo = malloc(sizeof(rugged_repository));
	if (r_repo == NULL)
		rb_raise(rb_eNoMemError, "out of memory");

	r_repo->repo = repo;
	r_repo->backends = rb_ary_new();

	return Data_Wrap_Struct(klass, rb_git_repo__mark, rb_git_repo__free, r_repo);
}

Instance Method Details

#add_backendObject



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

static VALUE rb_git_repo_add_backend(VALUE self, VALUE rb_backend, VALUE rb_priority)
{
	rugged_repository *repo;
	rugged_backend *backend;
	int error;

	Data_Get_Struct(self, rugged_repository, repo);

	Check_Type(rb_priority, T_FIXNUM);

	if (!rb_obj_is_kind_of(rb_backend, rb_cRuggedBackend))
		rb_raise(rb_eTypeError, "expecting a subclass of Rugged::Backend");

	if (rb_obj_is_instance_of(rb_backend, rb_cRuggedBackend))
		rb_raise(rb_eTypeError, "create a subclass of Rugged::Backend to define your custom backend");

	Data_Get_Struct(rb_backend, rugged_backend, backend);

	error = git_odb_add_backend(git_repository_database(repo->repo), (git_odb_backend *)backend, FIX2INT(rb_priority));
	rugged_exception_check(error);

	rb_ary_push(repo->backends, rb_backend);

	return Qnil;
}

#existsObject



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

static VALUE rb_git_repo_exists(VALUE self, VALUE hex)
{
	rugged_repository *repo;
	git_odb *odb;
	git_oid oid;

	Data_Get_Struct(self, rugged_repository, repo);
	Check_Type(hex, T_STRING);

	odb = git_repository_database(repo->repo);
	rugged_exception_check(git_oid_mkstr(&oid, RSTRING_PTR(hex)));

	return git_odb_exists(odb, &oid) ? Qtrue : Qfalse;
}

#headObject



14
15
16
17
# File 'lib/rugged/repository.rb', line 14

def head
  ref = Reference.lookup(self, "HEAD")
  ref.resolve
end

#indexObject



220
221
222
223
224
225
226
227
228
229
230
231
232
# File 'ext/rugged/rugged_repo.c', line 220

static VALUE rb_git_repo_index(VALUE self)
{
	rugged_repository *repo;
	git_index *index;
	int error;

	Data_Get_Struct(self, rugged_repository, repo);

	error = git_repository_index(&index, repo->repo);
	rugged_exception_check(error);

	return rugged_index_new(self, index);
}

#lookupObject



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
# File 'ext/rugged/rugged_repo.c', line 303

static VALUE rb_git_repo_lookup_object(int argc, VALUE *argv, VALUE self)
{
	rugged_repository *repo;
	git_otype type;
	git_object *obj;
	git_oid oid;
	int error;

	VALUE rb_type, rb_sha;

	Data_Get_Struct(self, rugged_repository, repo);

	rb_scan_args(argc, argv, "11", &rb_sha, &rb_type);

	type = NIL_P(rb_type) ? GIT_OBJ_ANY : FIX2INT(rb_type);

	Check_Type(rb_sha, T_STRING);
	error = git_oid_mkstr(&oid, RSTRING_PTR(rb_sha));
	rugged_exception_check(error);

	error = git_object_lookup(&obj, repo->repo, &oid, type);
	rugged_exception_check(error);

	return obj ? rugged_object_new(self, obj) : Qnil;
}

#readObject



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

static VALUE rb_git_repo_read(VALUE self, VALUE hex)
{
	rugged_repository *repo;
	git_oid oid;
	int error;

	Data_Get_Struct(self, rugged_repository, repo);
	Check_Type(hex, T_STRING);

	error = git_oid_mkstr(&oid, RSTRING_PTR(hex));
	rugged_exception_check(error);

	return rugged_raw_read(repo->repo, &oid);
}

#walk(from, sorting = Rugged::SORT_DATE) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/rugged/repository.rb', line 4

def walk(from, sorting=Rugged::SORT_DATE)
  walker = Rugged::Walker.new(self)
  walker.sorting(sorting)
  walker.push(from)

  while commit = walker.next
    yield commit
  end
end

#writeObject



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'ext/rugged/rugged_repo.c', line 280

static VALUE rb_git_repo_write(VALUE self, VALUE rb_rawobj)
{
	rugged_repository *repo;
	git_odb *odb;
	git_rawobj obj;
	git_oid oid;
	int error;
	char out[40];

	Data_Get_Struct(self, rugged_repository, repo);
	odb = git_repository_database(repo->repo);

	rugged_rawobject_get(&obj, rb_rawobj);

	error = git_odb_write(&oid, odb, &obj);
	git_rawobj_close(&obj);

	rugged_exception_check(error);

	git_oid_fmt(out, &oid);
	return rugged_str_new(out, 40, NULL);
}