Class: Rugged::Tree::Builder

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

Instance Method Summary collapse

Constructor Details

#new([tree]) ⇒ Object

Create a new Rugged::Trebuilder instance.

If an optional tree is given, the returned TreeBuilder will be initialized with the entry of tree. Otherwise, the TreeBuilder will be empty and has to be filled manually.



492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
# File 'ext/rugged/rugged_tree.c', line 492

static VALUE rb_git_treebuilder_init(int argc, VALUE *argv, VALUE self)
{
	git_treebuilder *builder;
	git_tree *tree = NULL;
	VALUE rb_object;
	int error;

	if (rb_scan_args(argc, argv, "01", &rb_object) == 1) {
		if (!rb_obj_is_kind_of(rb_object, rb_cRuggedTree))
			rb_raise(rb_eTypeError, "A Rugged::Tree instance is required");

		Data_Get_Struct(rb_object, git_tree, tree);
	}

	error = git_treebuilder_create(&builder, tree);
	rugged_exception_check(error);

	DATA_PTR(self) = builder;
	return Qnil;
}

Instance Method Details

#<<(entry) ⇒ nil #insert(entry) ⇒ nil

Inser a new entry into builder.

Overloads:

  • #<<(entry) ⇒ nil

    Returns:

    • (nil)
  • #insert(entry) ⇒ nil

    Returns:

    • (nil)


550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
# File 'ext/rugged/rugged_tree.c', line 550

static VALUE rb_git_treebuilder_insert(VALUE self, VALUE rb_entry)
{
	git_treebuilder *builder;
	VALUE rb_path, rb_oid, rb_attr;
	git_oid oid;
	int error;

	Data_Get_Struct(self, git_treebuilder, builder);
	Check_Type(rb_entry, T_HASH);

	rb_path = rb_hash_aref(rb_entry, CSTR2SYM("name"));
	Check_Type(rb_path, T_STRING);

	rb_oid = rb_hash_aref(rb_entry, CSTR2SYM("oid"));
	Check_Type(rb_oid, T_STRING);
	rugged_exception_check(git_oid_fromstr(&oid, StringValueCStr(rb_oid)));

	rb_attr = rb_hash_aref(rb_entry, CSTR2SYM("filemode"));
	Check_Type(rb_attr, T_FIXNUM);

	error = git_treebuilder_insert(NULL,
		builder,
		StringValueCStr(rb_path),
		&oid,
		FIX2INT(rb_attr));

	rugged_exception_check(error);
	return Qnil;
}

#[](path) ⇒ Object

Return an entry from builder based on its relative path.



533
534
535
536
537
538
539
540
541
# File 'ext/rugged/rugged_tree.c', line 533

static VALUE rb_git_treebuilder_get(VALUE self, VALUE path)
{
	git_treebuilder *builder;
	Data_Get_Struct(self, git_treebuilder, builder);

	Check_Type(path, T_STRING);

	return rb_git_treeentry_fromC(git_treebuilder_get(builder, StringValueCStr(path)));
}

#clearnil

Clear all entries in builder.

Returns:

  • (nil)


519
520
521
522
523
524
525
# File 'ext/rugged/rugged_tree.c', line 519

static VALUE rb_git_treebuilder_clear(VALUE self)
{
	git_treebuilder *builder;
	Data_Get_Struct(self, git_treebuilder, builder);
	git_treebuilder_clear(builder);
	return Qnil;
}

#<<(entry) ⇒ nil #insert(entry) ⇒ nil

Inser a new entry into builder.

Overloads:

  • #<<(entry) ⇒ nil

    Returns:

    • (nil)
  • #insert(entry) ⇒ nil

    Returns:

    • (nil)


550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
# File 'ext/rugged/rugged_tree.c', line 550

static VALUE rb_git_treebuilder_insert(VALUE self, VALUE rb_entry)
{
	git_treebuilder *builder;
	VALUE rb_path, rb_oid, rb_attr;
	git_oid oid;
	int error;

	Data_Get_Struct(self, git_treebuilder, builder);
	Check_Type(rb_entry, T_HASH);

	rb_path = rb_hash_aref(rb_entry, CSTR2SYM("name"));
	Check_Type(rb_path, T_STRING);

	rb_oid = rb_hash_aref(rb_entry, CSTR2SYM("oid"));
	Check_Type(rb_oid, T_STRING);
	rugged_exception_check(git_oid_fromstr(&oid, StringValueCStr(rb_oid)));

	rb_attr = rb_hash_aref(rb_entry, CSTR2SYM("filemode"));
	Check_Type(rb_attr, T_FIXNUM);

	error = git_treebuilder_insert(NULL,
		builder,
		StringValueCStr(rb_path),
		&oid,
		FIX2INT(rb_attr));

	rugged_exception_check(error);
	return Qnil;
}

#reject! {|entry| ... } ⇒ nil

Deletes every tree entry from builder for which the given block evaluates to true.

Yields:

  • (entry)

Returns:

  • (nil)


645
646
647
648
649
650
651
652
653
654
# File 'ext/rugged/rugged_tree.c', line 645

static VALUE rb_git_treebuilder_filter(VALUE self)
{
	git_treebuilder *builder;

	rb_need_block();
	Data_Get_Struct(self, git_treebuilder, builder);

	git_treebuilder_filter(builder, &treebuilder_cb, (void *)rb_block_proc());
	return Qnil;
}

#remove(path) ⇒ Boolean

Remove an entry from builder by its relative path.

Returns true if the entry was successfully removed, or false if the entry was not found.

Returns:

  • (Boolean)


589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
# File 'ext/rugged/rugged_tree.c', line 589

static VALUE rb_git_treebuilder_remove(VALUE self, VALUE path)
{
	git_treebuilder *builder;
	int error;

	Data_Get_Struct(self, git_treebuilder, builder);
	Check_Type(path, T_STRING);

	error = git_treebuilder_remove(builder, StringValueCStr(path));
	if (error == GIT_ENOTFOUND)
		return Qfalse;

	rugged_exception_check(error);
	return Qtrue;
}

#write(repo) ⇒ Object

Write builder‘s content as a tree to the given repo and return the oid for the newly created tree.



612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
# File 'ext/rugged/rugged_tree.c', line 612

static VALUE rb_git_treebuilder_write(VALUE self, VALUE rb_repo)
{
	git_treebuilder *builder;
	git_repository *repo;
	git_oid written_id;
	int error;

	if (!rb_obj_is_kind_of(rb_repo, rb_cRuggedRepo))
		rb_raise(rb_eTypeError, "Expecting a Rugged::Repository instance");

	Data_Get_Struct(self, git_treebuilder, builder);
	Data_Get_Struct(rb_repo, git_repository, repo);

	error = git_treebuilder_write(&written_id, repo, builder);
	rugged_exception_check(error);

	return rugged_create_oid(&written_id);
}