struct entry_srch_key {
const char *path;
- int path_len;
+ size_t path_len;
int stage;
};
{
const struct entry_srch_key *srch_key = key;
const git_index_entry *entry = array_member;
- int cmp, len1, len2, len;
+ int cmp;
+ size_t len1, len2, len;
len1 = srch_key->path_len;
len2 = strlen(entry->path);
{
const struct entry_srch_key *srch_key = key;
const git_index_entry *entry = array_member;
- int cmp, len1, len2, len;
+ int cmp;
+ size_t len1, len2, len;
len1 = srch_key->path_len;
len2 = strlen(entry->path);
assert(index);
- git_vector_sort(&index->entries);
-
- if (git_index__find(&pos, index, path, strlen(path), stage) < 0) {
+ if (git_index__find(&pos, index, path, 0, stage) < 0) {
giterr_set(GITERR_INDEX, "Index does not contain %s", path);
return NULL;
}
/* look if an entry with this path already exists */
if (!git_index__find(
- &position, index, entry->path, strlen(entry->path),
- GIT_IDXENTRY_STAGE(entry))) {
+ &position, index, entry->path, 0, GIT_IDXENTRY_STAGE(entry))) {
existing = (git_index_entry **)&index->entries.contents[position];
/* update filemode to existing values if stat is not trusted */
entry->mode = index_merge_mode(index, *existing, entry->mode);
int error;
git_index_entry *entry;
- git_vector_sort(&index->entries);
-
- if (git_index__find(&position, index, path, strlen(path), stage) < 0) {
+ if (git_index__find(&position, index, path, 0, stage) < 0) {
giterr_set(GITERR_INDEX, "Index does not contain %s at stage %d",
path, stage);
return GIT_ENOTFOUND;
}
int git_index__find(
- size_t *at_pos, git_index *index, const char *path, int path_len, int stage)
+ size_t *out, git_index *index, const char *path, size_t path_len, int stage)
{
struct entry_srch_key srch_key;
assert(path);
+ git_vector_sort(&index->entries);
+
srch_key.path = path;
- srch_key.path_len = path_len;
+ srch_key.path_len = !path_len ? strlen(path) : path_len;
srch_key.stage = stage;
return git_vector_bsearch2(
- at_pos, &index->entries, index->entries_search, &srch_key);
+ out, &index->entries, index->entries_search, &srch_key);
}
int git_index_find(size_t *at_pos, git_index *index, const char *path)
/* skip ignored items that are not already in the index */
if ((flags & GIT_INDEX_ADD_FORCE) == 0 &&
git_iterator_current_is_ignored(wditer) &&
- git_index__find(&existing, index, wd->path, strlen(wd->path), 0) < 0)
+ git_index__find(&existing, index, wd->path, 0, 0) < 0)
continue;
/* issue notification callback if requested */
#include "posix.h"
static git_repository *_repo;
-static git_buf _path;
-static git_buf _actual;
void test_repo_message__initialize(void)
{
- _repo = cl_git_sandbox_init("testrepo.git");
- git_buf_init(&_actual, 0);
+ _repo = cl_git_sandbox_init("testrepo.git");
}
void test_repo_message__cleanup(void)
{
- cl_git_sandbox_cleanup();
- git_buf_free(&_path);
- git_buf_free(&_actual);
+ cl_git_sandbox_cleanup();
}
void test_repo_message__none(void)
{
- cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&_actual, _repo));
+ git_buf actual = GIT_BUF_INIT;
+ cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&actual, _repo));
}
void test_repo_message__message(void)
{
+ git_buf path = GIT_BUF_INIT, actual = GIT_BUF_INIT;
const char expected[] = "Test\n\nThis is a test of the emergency broadcast system\n";
- cl_git_pass(git_buf_joinpath(&_path, git_repository_path(_repo), "MERGE_MSG"));
- cl_git_mkfile(git_buf_cstr(&_path), expected);
+ cl_git_pass(git_buf_joinpath(&path, git_repository_path(_repo), "MERGE_MSG"));
+ cl_git_mkfile(git_buf_cstr(&path), expected);
- cl_git_pass(git_repository_message(&_actual, _repo));
- cl_assert_equal_s(expected, _actual);
- git_buf_free(&_actual);
+ cl_git_pass(git_repository_message(&actual, _repo));
+ cl_assert_equal_s(expected, git_buf_cstr(&actual));
+ git_buf_free(&actual);
- cl_git_pass(p_unlink(git_buf_cstr(&_path)));
- cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&_actual, _repo));
+ cl_git_pass(p_unlink(git_buf_cstr(&path)));
+ cl_assert_equal_i(GIT_ENOTFOUND, git_repository_message(&actual, _repo));
+ git_buf_free(&path);
}