예제 #1
0
파일: index.c 프로젝트: boyski/libgit2
const git_index_entry_unmerged *git_index_get_unmerged_bypath(git_index *index, const char *path)
{
	int pos;
	assert(index && path);

	if (!index->unmerged.length)
		return NULL;

	if ((pos = git_vector_bsearch2(&index->unmerged, unmerged_srch, path)) < GIT_SUCCESS)
		return NULL;

	return git_vector_get(&index->unmerged, pos);
}
예제 #2
0
const git_tree_entry *git_tree_entry_byname(git_tree *tree, const char *filename)
{
	int idx;
	struct tree_key_search ksearch;

	assert(tree && filename);

	if (build_ksearch(&ksearch, filename) < GIT_SUCCESS)
		return NULL;

	idx = git_vector_bsearch2(&tree->entries, entry_search_cmp, &ksearch);
	if (idx == GIT_ENOTFOUND)
		return NULL;

	return git_vector_get(&tree->entries, idx);
}
예제 #3
0
파일: tree.c 프로젝트: sakari/libgit2
const git_tree_entry *git_treebuilder_get(git_treebuilder *bld, const char *filename)
{
	int idx;
	git_tree_entry *entry;

	assert(bld && filename);

	sort_entries(bld);
	idx = git_vector_bsearch2(&bld->entries, entry_search_cmp, filename);
	if (idx == GIT_ENOTFOUND)
		return NULL;

	entry = git_vector_get(&bld->entries, idx);
	if (entry->removed)
		return NULL;

	return entry;
}
예제 #4
0
파일: tree.c 프로젝트: sakari/libgit2
const git_tree_entry *git_tree_entry_byname(git_tree *tree, const char *filename)
{
	int idx;

	assert(tree && filename);

	/* HACK to sort alphabetically the list */
	tree->entries._cmp = &entry_alpha_sort_cmp;
	tree->entries.sorted = 0;
	idx = git_vector_bsearch2(&tree->entries, entry_search_cmp, filename);
	tree->entries._cmp = &entry_sort_cmp;
	tree->entries.sorted = 0;

	if (idx == GIT_ENOTFOUND)
		return NULL;

	return git_vector_get(&tree->entries, idx);
}
예제 #5
0
int git_treebuilder_insert(git_tree_entry **entry_out, git_treebuilder *bld, const char *filename, const git_oid *id, unsigned int attributes)
{
	git_tree_entry *entry;
	int pos;
	struct tree_key_search ksearch;

	assert(bld && id && filename);

	if (!valid_attributes(attributes))
		return git__throw(GIT_ERROR, "Failed to insert entry. Invalid attributes");

	if (build_ksearch(&ksearch, filename) < GIT_SUCCESS)
		return git__throw(GIT_ERROR, "Failed to insert entry. Invalid filename '%s'", filename);

	if ((pos = git_vector_bsearch2(&bld->entries, entry_search_cmp, &ksearch)) != GIT_ENOTFOUND) {
		entry = git_vector_get(&bld->entries, pos);
		if (entry->removed) {
			entry->removed = 0;
			bld->entry_count++;
		}
	} else {
		if ((entry = git__malloc(sizeof(git_tree_entry))) == NULL)
			return GIT_ENOMEM;

		memset(entry, 0x0, sizeof(git_tree_entry));
		entry->filename = git__strdup(filename);
		entry->filename_len = strlen(entry->filename);

		bld->entry_count++;
	}

	git_oid_cpy(&entry->oid, id);
	entry->attr = attributes;

	if (pos == GIT_ENOTFOUND) {
		if (git_vector_insert(&bld->entries, entry) < 0)
			return GIT_ENOMEM;
	}

	if (entry_out != NULL)
		*entry_out = entry;

	return GIT_SUCCESS;
}
예제 #6
0
static git_tree_entry *treebuilder_get(git_treebuilder *bld, const char *filename)
{
	int idx;
	git_tree_entry *entry;
	struct tree_key_search ksearch;

	assert(bld && filename);

	if (build_ksearch(&ksearch, filename) < GIT_SUCCESS)
		return NULL;

	idx = git_vector_bsearch2(&bld->entries, entry_search_cmp, &ksearch);
	if (idx == GIT_ENOTFOUND)
		return NULL;

	entry = git_vector_get(&bld->entries, idx);
	if (entry->removed)
		return NULL;

	return entry;
}
예제 #7
0
파일: vector.c 프로젝트: dflemstr/libgit2
int git_vector_bsearch(git_vector *v, const void *key)
{
	return git_vector_bsearch2(v, v->_cmp, key);
}
예제 #8
0
파일: index.c 프로젝트: boyski/libgit2
int git_index_find(git_index *index, const char *path)
{
	return git_vector_bsearch2(&index->entries, index_srch, path);
}