Exemplo n.º 1
0
void test_object_tree_attributes__normalize_attributes_when_creating_a_tree_from_an_existing_one(void)
{
	git_repository *repo;
	git_treebuilder *builder;
	git_oid tid, tid2;
	git_tree *tree;
	const git_tree_entry *entry;

	repo = cl_git_sandbox_init("deprecated-mode.git");

	cl_git_pass(git_oid_fromstr(&tid, tree_oid));
	cl_git_pass(git_tree_lookup(&tree, repo, &tid));

	cl_git_pass(git_treebuilder_create(&builder, tree));
	
	entry = git_treebuilder_get(builder, "old_mode.txt");
	cl_assert_equal_i(
		GIT_FILEMODE_BLOB,
		git_tree_entry_filemode(entry));

	cl_git_pass(git_treebuilder_write(&tid2, repo, builder));
	git_treebuilder_free(builder);
	git_tree_free(tree);

	cl_git_pass(git_tree_lookup(&tree, repo, &tid2));
	entry = git_tree_entry_byname(tree, "old_mode.txt");
	cl_assert_equal_i(
		GIT_FILEMODE_BLOB,
		git_tree_entry_filemode(entry));

	git_tree_free(tree);
	cl_git_sandbox_cleanup();
}
Exemplo n.º 2
0
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)));
}
Exemplo n.º 3
0
int git_treebuilder_remove(git_treebuilder *bld, const char *filename)
{
	git_tree_entry *remove_ptr = (git_tree_entry *)git_treebuilder_get(bld, filename);

	if (remove_ptr == NULL || remove_ptr->removed)
		return GIT_ENOTFOUND;

	remove_ptr->removed = 1;
	bld->entry_count--;
	return GIT_SUCCESS;
}
Exemplo n.º 4
0
void test_object_tree_write__filtering(void)
{
	git_treebuilder *builder;
	int i;
	git_oid entry_oid, tree_oid;
	git_tree *tree;

	git_oid_fromstr(&entry_oid, blob_oid);

	cl_git_pass(git_treebuilder_new(&builder, g_repo, NULL));

	for (i = 0; _entries[i].filename; ++i)
		cl_git_pass(git_treebuilder_insert(NULL,
			builder, _entries[i].filename, &entry_oid, _entries[i].attr));

	cl_assert_equal_i(6, (int)git_treebuilder_entrycount(builder));

	cl_assert(git_treebuilder_get(builder, "apple") != NULL);
	cl_assert(git_treebuilder_get(builder, "aardvark") != NULL);
	cl_assert(git_treebuilder_get(builder, "last") != NULL);

	git_treebuilder_filter(builder, treebuilder_filter_prefixed, "apple");

	cl_assert_equal_i(4, (int)git_treebuilder_entrycount(builder));

	cl_assert(git_treebuilder_get(builder, "apple") == NULL);
	cl_assert(git_treebuilder_get(builder, "aardvark") != NULL);
	cl_assert(git_treebuilder_get(builder, "last") != NULL);

	git_treebuilder_filter(builder, treebuilder_filter_prefixed, "a");

	cl_assert_equal_i(2, (int)git_treebuilder_entrycount(builder));

	cl_assert(git_treebuilder_get(builder, "aardvark") == NULL);
	cl_assert(git_treebuilder_get(builder, "last") != NULL);

	cl_git_pass(git_treebuilder_write(&tree_oid, builder));

	git_treebuilder_free(builder);

	cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_oid));

	cl_assert_equal_i(2, (int)git_tree_entrycount(tree));

	git_tree_free(tree);
}
Exemplo n.º 5
0
static int tree_insert(git_treebuilder *dir, const char *name, int mkunique, git_oid *id, unsigned mode)
{
	int ret;
	struct membuffer uniquename = { 0 };

	if (mkunique && git_treebuilder_get(dir, name)) {
		char hex[8];
		git_oid_nfmt(hex, 7, id);
		hex[7] = 0;
		put_format(&uniquename, "%s~%s", name, hex);
		name = mb_cstring(&uniquename);
	}
	ret = git_treebuilder_insert(NULL, dir, name, id, mode);
	free_buffer(&uniquename);
	return ret;
}
Exemplo n.º 6
0
int luagi_tree_builder_get( lua_State *L )
{
   git_treebuilder** builder = checktreebuilder( L );
   const char* filename = luaL_checkstring( L, 2 );
   const git_tree_entry* entry = git_treebuilder_get( *builder, filename );
   if( entry == NULL )
   {
      lua_pushnil( L );
      lua_pushstring( L, "no result found" );
      return 2;
   }
   git_tree_entry** e = (git_tree_entry**) lua_newuserdata( L, sizeof( git_tree_entry*) );
   int ret = git_tree_entry_dup( e, entry );
   if( ret != 0 )
   {
      lua_pushnil( L );
      lua_pushfstring( L, "git_tree_entry_dup failed %d", ret );
      return 2;
   }
   ltk_setmetatable( L, LUAGI_TREE_ENTRY_FUNCS );
   return 1;
}
Exemplo n.º 7
0
PyObject *
TreeBuilder_get(TreeBuilder *self, PyObject *py_filename)
{
    char *filename;
    const git_tree_entry *entry_src;
    git_tree_entry *entry;

    filename = py_path_to_c_str(py_filename);
    if (filename == NULL)
        return NULL;

    entry_src = git_treebuilder_get(self->bld, filename);
    free(filename);
    if (entry_src == NULL)
        Py_RETURN_NONE;

    if (git_tree_entry_dup(&entry, entry_src) < 0) {
        PyErr_SetNone(PyExc_MemoryError);
        return NULL;
    }
    return (PyObject*)wrap_tree_entry(entry);
}