Commit 523f893f by Edward Thomson

index: add sha256 support

parent c616ba2d
......@@ -30,7 +30,11 @@ int lg2_show_index(git_repository *repo, int argc, char **argv)
dirlen = strlen(dir);
if (dirlen > 5 && strcmp(dir + dirlen - 5, "index") == 0) {
#ifdef GIT_EXPERIMENTAL_SHA256
check_lg2(git_index_open(&index, dir, GIT_OID_SHA1), "could not open index", dir);
#else
check_lg2(git_index_open(&index, dir), "could not open index", dir);
#endif
} else {
check_lg2(git_repository_open_ext(&repo, dir, 0, NULL), "could not open repository", dir);
check_lg2(git_repository_index(&index, repo), "could not open repository index", NULL);
......
......@@ -184,7 +184,12 @@ typedef enum {
* @param index_path the path to the index file in disk
* @return 0 or an error code
*/
#ifdef GIT_EXPERIMENTAL_SHA256
GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path, git_oid_t oid_type);
#else
GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path);
#endif
/**
* Create an in-memory index object.
......@@ -197,7 +202,11 @@ GIT_EXTERN(int) git_index_open(git_index **out, const char *index_path);
* @param out the pointer for the new index
* @return 0 or an error code
*/
#ifdef GIT_EXPERIMENTAL_SHA256
GIT_EXTERN(int) git_index_new(git_index **out, git_oid_t oid_type);
#else
GIT_EXTERN(int) git_index_new(git_index **out);
#endif
/**
* Free an existing index object.
......
......@@ -19,6 +19,7 @@
#include "zstream.h"
#include "reader.h"
#include "index.h"
#include "repository.h"
#include "apply.h"
typedef struct {
......@@ -644,7 +645,7 @@ int git_apply_to_tree(
* put the current tree into the postimage as-is - the diff will
* replace any entries contained therein
*/
if ((error = git_index_new(&postimage)) < 0 ||
if ((error = git_index__new(&postimage, repo->oid_type)) < 0 ||
(error = git_index_read_tree(postimage, preimage)) < 0 ||
(error = git_reader_for_index(&post_reader, repo, postimage)) < 0)
goto done;
......@@ -851,8 +852,8 @@ int git_apply(
* having the full repo index, so we will limit our checkout
* to only write these files that were affected by the diff.
*/
if ((error = git_index_new(&preimage)) < 0 ||
(error = git_index_new(&postimage)) < 0 ||
if ((error = git_index__new(&preimage, repo->oid_type)) < 0 ||
(error = git_index__new(&postimage, repo->oid_type)) < 0 ||
(error = git_reader_for_index(&post_reader, repo, postimage)) < 0)
goto done;
......
......@@ -27,7 +27,7 @@ struct git_index {
char *index_file_path;
git_futils_filestamp stamp;
unsigned char checksum[GIT_HASH_SHA1_SIZE];
unsigned char checksum[GIT_HASH_MAX_SIZE];
git_vector entries;
git_idxmap *entries_map;
......@@ -35,6 +35,8 @@ struct git_index {
git_vector deleted; /* deleted entries if readers > 0 */
git_atomic32 readers; /* number of active iterators */
git_oid_t oid_type;
unsigned int on_disk:1;
unsigned int ignore_case:1;
unsigned int distrust_filemode:1;
......@@ -141,6 +143,17 @@ GIT_INLINE(unsigned char *) git_index__checksum(git_index *index)
return index->checksum;
}
/* SHA256-aware internal functions */
extern int git_index__new(
git_index **index_out,
git_oid_t oid_type);
extern int git_index__open(
git_index **index_out,
const char *index_path,
git_oid_t oid_type);
/* Copy the current entries vector *and* increment the index refcount.
* Call `git_index__release_snapshot` when done.
*/
......
......@@ -1997,8 +1997,11 @@ static int index_update_reuc(git_index *index, git_merge_diff_list *diff_list)
return 0;
}
static int index_from_diff_list(git_index **out,
git_merge_diff_list *diff_list, bool skip_reuc)
static int index_from_diff_list(
git_index **out,
git_merge_diff_list *diff_list,
git_oid_t oid_type,
bool skip_reuc)
{
git_index *index;
size_t i;
......@@ -2007,7 +2010,7 @@ static int index_from_diff_list(git_index **out,
*out = NULL;
if ((error = git_index_new(&index)) < 0)
if ((error = git_index__new(&index, oid_type)) < 0)
return error;
if ((error = git_index__fill(index, &diff_list->staged)) < 0)
......@@ -2157,7 +2160,7 @@ int git_merge__iterators(
}
}
error = index_from_diff_list(out, diff_list,
error = index_from_diff_list(out, diff_list, repo->oid_type,
(opts.flags & GIT_MERGE_SKIP_REUC));
done:
......@@ -2200,7 +2203,7 @@ int git_merge_trees(
result = our_tree;
if (result) {
if ((error = git_index_new(out)) == 0)
if ((error = git_index__new(out, repo->oid_type)) == 0)
error = git_index_read_tree(*out, result);
return error;
......
......@@ -1547,7 +1547,8 @@ int git_repository_index__weakptr(git_index **out, git_repository *repo)
if ((error = repository_index_path(&index_path, repo)) < 0)
return error;
error = git_index_open(&index, index_path.ptr);
error = git_index__open(&index, index_path.ptr, repo->oid_type);
if (!error) {
GIT_REFCOUNT_OWN(index, repo);
......
......@@ -284,7 +284,7 @@ static int build_untracked_tree(
struct stash_update_rules data = {0};
int error;
if ((error = git_index_new(&i_index)) < 0)
if ((error = git_index__new(&i_index, repo->oid_type)) < 0)
goto cleanup;
if (flags & GIT_STASH_INCLUDE_UNTRACKED) {
......@@ -487,7 +487,7 @@ static int commit_worktree(
int error = 0, ignorecase;
if ((error = git_repository_index(&r_index, repo) < 0) ||
(error = git_index_new(&i_index)) < 0 ||
(error = git_index__new(&i_index, repo->oid_type)) < 0 ||
(error = git_index__fill(i_index, &r_index->entries) < 0) ||
(error = git_repository__configmap_lookup(&ignorecase, repo, GIT_CONFIGMAP_IGNORECASE)) < 0)
goto cleanup;
......@@ -732,7 +732,7 @@ int git_stash_save_with_opts(
i_commit, b_commit, u_commit)) < 0)
goto cleanup;
} else {
if ((error = git_index_new(&paths_index)) < 0 ||
if ((error = git_index__new(&paths_index, repo->oid_type)) < 0 ||
(error = retrieve_head(&head, repo)) < 0 ||
(error = git_reference_peel((git_object**)&tree, head, GIT_OBJECT_TREE)) < 0 ||
(error = git_index_read_tree(paths_index, tree)) < 0 ||
......@@ -1003,6 +1003,7 @@ static int stage_new_file(const git_index_entry **entries, void *data)
static int stage_new_files(
git_index **out,
git_repository *repo,
git_tree *parent_tree,
git_tree *tree)
{
......@@ -1011,7 +1012,7 @@ static int stage_new_files(
git_index *index = NULL;
int error;
if ((error = git_index_new(&index)) < 0 ||
if ((error = git_index__new(&index, repo->oid_type)) < 0 ||
(error = git_iterator_for_tree(
&iterators[0], parent_tree, &iterator_options)) < 0 ||
(error = git_iterator_for_tree(
......@@ -1095,10 +1096,10 @@ int git_stash_apply(
* previously unstaged contents are staged, not the previously staged.)
*/
} else if ((opts.flags & GIT_STASH_APPLY_REINSTATE_INDEX) == 0) {
if ((error = stage_new_files(
&stash_adds, stash_parent_tree, stash_tree)) < 0 ||
(error = merge_indexes(
&unstashed_index, repo, stash_parent_tree, repo_index, stash_adds)) < 0)
if ((error = stage_new_files(&stash_adds, repo,
stash_parent_tree, stash_tree)) < 0 ||
(error = merge_indexes(&unstashed_index, repo,
stash_parent_tree, repo_index, stash_adds)) < 0)
goto cleanup;
}
......
......@@ -71,12 +71,16 @@ const git_tree_cache *git_tree_cache_get(const git_tree_cache *tree, const char
}
}
static int read_tree_internal(git_tree_cache **out,
const char **buffer_in, const char *buffer_end,
static int read_tree_internal(
git_tree_cache **out,
const char **buffer_in,
const char *buffer_end,
git_oid_t oid_type,
git_pool *pool)
{
git_tree_cache *tree = NULL;
const char *name_start, *buffer;
size_t oid_size = git_oid_size(oid_type);
int count;
buffer = name_start = *buffer_in;
......@@ -87,7 +91,7 @@ static int read_tree_internal(git_tree_cache **out,
if (++buffer >= buffer_end)
goto corrupted;
if (git_tree_cache_new(&tree, name_start, pool) < 0)
if (git_tree_cache_new(&tree, name_start, oid_type, pool) < 0)
return -1;
/* Blank-terminated ASCII decimal number of entries in this tree */
......@@ -108,14 +112,14 @@ static int read_tree_internal(git_tree_cache **out,
if (*buffer != '\n' || ++buffer > buffer_end)
goto corrupted;
/* The SHA1 is only there if it's not invalidated */
/* The OID is only there if it's not invalidated */
if (tree->entry_count >= 0) {
/* 160-bit SHA-1 for this tree and it's children */
if (buffer + GIT_OID_SHA1_SIZE > buffer_end)
if (buffer + oid_size > buffer_end)
goto corrupted;
git_oid__fromraw(&tree->oid, (const unsigned char *)buffer, GIT_OID_SHA1);
buffer += GIT_OID_SHA1_SIZE;
git_oid__fromraw(&tree->oid, (const unsigned char *)buffer, oid_type);
buffer += oid_size;
}
/* Parse children: */
......@@ -130,7 +134,7 @@ static int read_tree_internal(git_tree_cache **out,
memset(tree->children, 0x0, bufsize);
for (i = 0; i < tree->children_count; ++i) {
if (read_tree_internal(&tree->children[i], &buffer, buffer_end, pool) < 0)
if (read_tree_internal(&tree->children[i], &buffer, buffer_end, oid_type, pool) < 0)
goto corrupted;
}
}
......@@ -144,11 +148,16 @@ static int read_tree_internal(git_tree_cache **out,
return -1;
}
int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer_size, git_pool *pool)
int git_tree_cache_read(
git_tree_cache **tree,
const char *buffer,
size_t buffer_size,
git_oid_t oid_type,
git_pool *pool)
{
const char *buffer_end = buffer + buffer_size;
if (read_tree_internal(tree, &buffer, buffer_end, pool) < 0)
if (read_tree_internal(tree, &buffer, buffer_end, oid_type, pool) < 0)
return -1;
if (buffer < buffer_end) {
......@@ -201,7 +210,7 @@ static int read_tree_recursive(git_tree_cache *cache, const git_tree *tree, git_
continue;
}
if ((error = git_tree_cache_new(&cache->children[j], git_tree_entry_name(entry), pool)) < 0)
if ((error = git_tree_cache_new(&cache->children[j], git_tree_entry_name(entry), cache->oid_type, pool)) < 0)
return error;
if ((error = git_tree_lookup(&subtree, repo, git_tree_entry_id(entry))) < 0)
......@@ -219,12 +228,12 @@ static int read_tree_recursive(git_tree_cache *cache, const git_tree *tree, git_
return 0;
}
int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_pool *pool)
int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_oid_t oid_type, git_pool *pool)
{
int error;
git_tree_cache *cache;
if ((error = git_tree_cache_new(&cache, "", pool)) < 0)
if ((error = git_tree_cache_new(&cache, "", oid_type, pool)) < 0)
return error;
if ((error = read_tree_recursive(cache, tree, pool)) < 0)
......@@ -234,7 +243,7 @@ int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_poo
return 0;
}
int git_tree_cache_new(git_tree_cache **out, const char *name, git_pool *pool)
int git_tree_cache_new(git_tree_cache **out, const char *name, git_oid_t oid_type, git_pool *pool)
{
size_t name_len, alloc_size;
git_tree_cache *tree;
......@@ -248,6 +257,7 @@ int git_tree_cache_new(git_tree_cache **out, const char *name, git_pool *pool)
memset(tree, 0x0, sizeof(git_tree_cache));
/* NUL-terminated tree name */
tree->oid_type = oid_type;
tree->namelen = name_len;
memcpy(tree->name, name, name_len);
tree->name[name_len] = '\0';
......@@ -263,7 +273,7 @@ static void write_tree(git_str *out, git_tree_cache *tree)
git_str_printf(out, "%s%c%"PRIdZ" %"PRIuZ"\n", tree->name, 0, tree->entry_count, tree->children_count);
if (tree->entry_count != -1)
git_str_put(out, (char *)&tree->oid.id, GIT_OID_SHA1_SIZE);
git_str_put(out, (char *)&tree->oid.id, git_oid_size(tree->oid_type));
for (i = 0; i < tree->children_count; i++)
write_tree(out, tree->children[i]);
......
......@@ -18,6 +18,8 @@ typedef struct git_tree_cache {
struct git_tree_cache **children;
size_t children_count;
git_oid_t oid_type;
ssize_t entry_count;
git_oid oid;
size_t namelen;
......@@ -25,14 +27,14 @@ typedef struct git_tree_cache {
} git_tree_cache;
int git_tree_cache_write(git_str *out, git_tree_cache *tree);
int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer_size, git_pool *pool);
int git_tree_cache_read(git_tree_cache **tree, const char *buffer, size_t buffer_size, git_oid_t oid_type, git_pool *pool);
void git_tree_cache_invalidate_path(git_tree_cache *tree, const char *path);
const git_tree_cache *git_tree_cache_get(const git_tree_cache *tree, const char *path);
int git_tree_cache_new(git_tree_cache **out, const char *name, git_pool *pool);
int git_tree_cache_new(git_tree_cache **out, const char *name, git_oid_t oid_type, git_pool *pool);
/**
* Read a tree as the root of the tree cache (like for `git read-tree`)
*/
int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_pool *pool);
int git_tree_cache_read_tree(git_tree_cache **out, const git_tree *tree, git_oid_t oid_type, git_pool *pool);
void git_tree_cache_free(git_tree_cache *tree);
#endif
......@@ -731,7 +731,7 @@ int git_tree__write_index(
return ret;
/* Read the tree cache into the index */
ret = git_tree_cache_read_tree(&index->tree, tree, &index->tree_pool);
ret = git_tree_cache_read_tree(&index->tree, tree, index->oid_type, &index->tree_pool);
git_tree_free(tree);
return ret;
......
......@@ -4,6 +4,7 @@
#include "git2/checkout.h"
#include "futils.h"
#include "repository.h"
#include "index.h"
#include "remote.h"
#include "repo/repo_helpers.h"
......@@ -834,7 +835,7 @@ void test_checkout_index__adding_conflict_removes_stage_0(void)
git_index *new_index, *index;
git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT;
cl_git_pass(git_index_new(&new_index));
cl_git_pass(git_index__new(&new_index, GIT_OID_SHA1));
add_conflict(new_index, "new.txt");
cl_git_pass(git_checkout_index(g_repo, new_index, &opts));
......
......@@ -5,6 +5,7 @@
#include "remote.h"
#include "futils.h"
#include "repository.h"
#include "index.h"
#define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository"
......@@ -271,7 +272,7 @@ void test_clone_nonetwork__clone_tag_to_tree(void)
stage = cl_git_sandbox_init("testrepo.git");
cl_git_pass(git_repository_odb(&odb, stage));
cl_git_pass(git_index_new(&index));
cl_git_pass(git_index__new(&index, GIT_OID_SHA1));
memset(&entry, 0, sizeof(git_index_entry));
entry.path = file_path;
......
#include "clar_libgit2.h"
#include "diff_helpers.h"
#include "index.h"
static git_repository *g_repo = NULL;
......@@ -278,7 +279,7 @@ void test_diff_index__to_index(void)
git_diff *diff;
diff_expects exp;
cl_git_pass(git_index_new(&old_index));
cl_git_pass(git_index__new(&old_index, GIT_OID_SHA1));
old_tree = resolve_commit_oid_to_tree(g_repo, a_commit);
cl_git_pass(git_index_read_tree(old_index, old_tree));
......
......@@ -24,7 +24,7 @@ void test_index_cache__write_extension_at_root(void)
const char *tree_id_str = "45dd856fdd4d89b884c340ba0e047752d9b085d6";
const char *index_file = "index-tree";
cl_git_pass(git_index_open(&index, index_file));
cl_git_pass(git_index__open(&index, index_file, GIT_OID_SHA1));
cl_assert(index->tree == NULL);
cl_git_pass(git_oid__fromstr(&id, tree_id_str, GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
......@@ -35,7 +35,7 @@ void test_index_cache__write_extension_at_root(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
cl_git_pass(git_index_open(&index, index_file));
cl_git_pass(git_index__open(&index, index_file, GIT_OID_SHA1));
cl_assert(index->tree);
cl_assert_equal_i(git_index_entrycount(index), index->tree->entry_count);
......@@ -56,7 +56,7 @@ void test_index_cache__write_extension_invalidated_root(void)
const char *index_file = "index-tree-invalidated";
git_index_entry entry;
cl_git_pass(git_index_open(&index, index_file));
cl_git_pass(git_index__open(&index, index_file, GIT_OID_SHA1));
cl_assert(index->tree == NULL);
cl_git_pass(git_oid__fromstr(&id, tree_id_str, GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
......@@ -77,7 +77,7 @@ void test_index_cache__write_extension_invalidated_root(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
cl_git_pass(git_index_open(&index, index_file));
cl_git_pass(git_index__open(&index, index_file, GIT_OID_SHA1));
cl_assert(index->tree);
cl_assert_equal_i(-1, index->tree->entry_count);
......@@ -96,7 +96,7 @@ void test_index_cache__read_tree_no_children(void)
git_tree *tree;
git_oid id;
cl_git_pass(git_index_new(&index));
cl_git_pass(git_index__new(&index, GIT_OID_SHA1));
cl_assert(index->tree == NULL);
cl_git_pass(git_oid__fromstr(&id, "45dd856fdd4d89b884c340ba0e047752d9b085d6", GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, g_repo, &id));
......
#include "clar_libgit2.h"
#include "index.h"
void test_index_inmemory__can_create_an_inmemory_index(void)
{
git_index *index;
cl_git_pass(git_index_new(&index));
cl_git_pass(git_index__new(&index, GIT_OID_SHA1));
cl_assert_equal_i(0, (int)git_index_entrycount(index));
git_index_free(index);
......@@ -14,7 +15,7 @@ void test_index_inmemory__cannot_add_bypath_to_an_inmemory_index(void)
{
git_index *index;
cl_git_pass(git_index_new(&index));
cl_git_pass(git_index__new(&index, GIT_OID_SHA1));
cl_assert_equal_i(GIT_ERROR, git_index_add_bypath(index, "test.txt"));
......
......@@ -287,7 +287,7 @@ void test_index_racy__read_index_smudges(void)
setup_race();
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_index_new(&newindex));
cl_git_pass(git_index__new(&newindex, GIT_OID_SHA1));
cl_git_pass(git_index_read_index(newindex, index));
cl_assert(entry = git_index_get_bypath(newindex, "A", 0));
......@@ -305,7 +305,7 @@ void test_index_racy__read_index_clears_uptodate_bit(void)
setup_uptodate_files();
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_index_new(&newindex));
cl_git_pass(git_index__new(&newindex, GIT_OID_SHA1));
cl_git_pass(git_index_read_index(newindex, index));
/* ensure that files brought in from the other index are not uptodate */
......
......@@ -42,7 +42,7 @@ void test_index_read_index__maintains_stat_cache(void)
/* read-tree, then read index */
git_tree_lookup(&tree, _repo, &index_id);
cl_git_pass(git_index_new(&new_index));
cl_git_pass(git_index__new(&new_index, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(new_index, tree));
git_tree_free(tree);
......@@ -81,7 +81,7 @@ static bool roundtrip_with_read_index(const char *tree_idstr)
cl_git_pass(git_oid__fromstr(&tree_id, tree_idstr, GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
cl_git_pass(git_index_new(&tree_index));
cl_git_pass(git_index__new(&tree_index, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(tree_index, tree));
cl_git_pass(git_index_read_index(_index, tree_index));
cl_git_pass(git_index_write_tree(&new_tree_id, _index));
......@@ -113,12 +113,12 @@ void test_index_read_index__read_and_writes(void)
cl_git_pass(git_oid__fromstr(&tree_id, "ae90f12eea699729ed24555e40b9fd669da12a12", GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
cl_git_pass(git_index_new(&tree_index));
cl_git_pass(git_index__new(&tree_index, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(tree_index, tree));
cl_git_pass(git_index_read_index(_index, tree_index));
cl_git_pass(git_index_write(_index));
cl_git_pass(git_index_open(&new_index, git_index_path(_index)));
cl_git_pass(git_index__open(&new_index, git_index_path(_index), GIT_OID_SHA1));
cl_git_pass(git_index_write_tree_to(&new_tree_id, new_index, _repo));
cl_assert_equal_oid(&tree_id, &new_tree_id);
......@@ -174,8 +174,8 @@ void test_index_read_index__handles_conflicts(void)
cl_git_pass(git_oid__fromstr(&tree_id, "ae90f12eea699729ed24555e40b9fd669da12a12", GIT_OID_SHA1));
cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
cl_git_pass(git_index_new(&index));
cl_git_pass(git_index_new(&new_index));
cl_git_pass(git_index__new(&index, GIT_OID_SHA1));
cl_git_pass(git_index__new(&new_index, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(index, tree));
cl_git_pass(git_index_read_tree(new_index, tree));
......
......@@ -81,7 +81,7 @@ void test_index_tests__empty_index(void)
{
git_index *index;
cl_git_pass(git_index_open(&index, "in-memory-index"));
cl_git_pass(git_index__open(&index, "in-memory-index", GIT_OID_SHA1));
cl_assert(index->on_disk == 0);
cl_assert(git_index_entrycount(index) == 0);
......@@ -96,7 +96,7 @@ void test_index_tests__default_test_index(void)
unsigned int i;
git_index_entry **entries;
cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_assert(index->on_disk);
cl_assert(git_index_entrycount(index) == index_entry_count);
......@@ -119,7 +119,7 @@ void test_index_tests__gitgit_index(void)
{
git_index *index;
cl_git_pass(git_index_open(&index, TEST_INDEX2_PATH));
cl_git_pass(git_index__open(&index, TEST_INDEX2_PATH, GIT_OID_SHA1));
cl_assert(index->on_disk);
cl_assert(git_index_entrycount(index) == index_entry_count_2);
......@@ -134,7 +134,7 @@ void test_index_tests__find_in_existing(void)
git_index *index;
unsigned int i;
cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
size_t idx;
......@@ -151,7 +151,7 @@ void test_index_tests__find_in_empty(void)
git_index *index;
unsigned int i;
cl_git_pass(git_index_open(&index, "fake-index"));
cl_git_pass(git_index__open(&index, "fake-index", GIT_OID_SHA1));
for (i = 0; i < ARRAY_SIZE(test_entries); ++i) {
cl_assert(GIT_ENOTFOUND == git_index_find(NULL, index, test_entries[i].path));
......@@ -166,7 +166,7 @@ void test_index_tests__find_prefix(void)
const git_index_entry *entry;
size_t pos;
cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_git_pass(git_index_find_prefix(&pos, index, "src"));
entry = git_index_get_byindex(index, pos);
......@@ -187,7 +187,7 @@ void test_index_tests__write(void)
copy_file(TEST_INDEXBIG_PATH, "index_rewrite");
cl_git_pass(git_index_open(&index, "index_rewrite"));
cl_git_pass(git_index__open(&index, "index_rewrite", GIT_OID_SHA1));
cl_assert(index->on_disk);
cl_git_pass(git_index_write(index));
......@@ -218,7 +218,7 @@ void test_index_tests__sort1(void)
/* sort the entries in an empty index */
git_index *index;
cl_git_pass(git_index_open(&index, "fake-index"));
cl_git_pass(git_index__open(&index, "fake-index", GIT_OID_SHA1));
/* FIXME: this test is slightly dumb */
cl_assert(git_vector_is_sorted(&index->entries));
......@@ -703,7 +703,7 @@ void test_index_tests__write_tree_invalid_unowned_index(void)
git_index_entry entry = {{0}};
git_oid tree_id;
cl_git_pass(git_index_new(&idx));
cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_oid__fromstr(&entry.id, "8312e0a89a9cbab77c732b6bc39b51a783e3a318", GIT_OID_SHA1));
entry.path = "foo";
......@@ -966,7 +966,7 @@ void test_index_tests__reload_from_disk(void)
cl_git_pass(git_repository_index(&write_index, repo));
cl_assert_equal_i(false, write_index->on_disk);
cl_git_pass(git_index_open(&read_index, write_index->index_file_path));
cl_git_pass(git_index__open(&read_index, write_index->index_file_path, GIT_OID_SHA1));
cl_assert_equal_i(false, read_index->on_disk);
/* Stage two new files against the write_index */
......@@ -1004,7 +1004,7 @@ void test_index_tests__corrupted_extension(void)
{
git_index *index;
cl_git_fail_with(git_index_open(&index, TEST_INDEXBAD_PATH), GIT_ERROR);
cl_git_fail_with(git_index__open(&index, TEST_INDEXBAD_PATH, GIT_OID_SHA1), GIT_ERROR);
}
void test_index_tests__reload_while_ignoring_case(void)
......@@ -1012,7 +1012,7 @@ void test_index_tests__reload_while_ignoring_case(void)
git_index *index;
unsigned int caps;
cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_git_pass(git_vector_verify_sorted(&index->entries));
caps = git_index_caps(index);
......@@ -1037,7 +1037,7 @@ void test_index_tests__change_icase_on_instance(void)
unsigned int caps;
const git_index_entry *e;
cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_git_pass(git_vector_verify_sorted(&index->entries));
caps = git_index_caps(index);
......@@ -1093,7 +1093,7 @@ void test_index_tests__can_iterate(void)
size_t i, iterator_idx = 0, found = 0;
int ret;
cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_git_pass(git_index_iterator_new(&iterator, index));
cl_assert(git_vector_is_sorted(&iterator->snap));
......@@ -1136,7 +1136,7 @@ void test_index_tests__can_modify_while_iterating(void)
size_t expected = 0, seen = 0;
int ret;
cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
cl_git_pass(git_index__open(&index, TEST_INDEX_PATH, GIT_OID_SHA1));
cl_git_pass(git_index_iterator_new(&iterator, index));
expected = git_index_entrycount(index);
......
#include "clar_libgit2.h"
#include "tree.h"
#include "index.h"
static git_repository *g_repo;
......@@ -28,7 +29,7 @@ void test_object_tree_update__remove_blob(void)
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
/* Create it with an index */
cl_git_pass(git_index_new(&idx));
cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(idx, base_tree));
cl_git_pass(git_index_remove(idx, path, 0));
cl_git_pass(git_index_write_tree_to(&tree_index_id, idx, g_repo));
......@@ -57,7 +58,7 @@ void test_object_tree_update__remove_blob_deeper(void)
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
/* Create it with an index */
cl_git_pass(git_index_new(&idx));
cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(idx, base_tree));
cl_git_pass(git_index_remove(idx, path, 0));
cl_git_pass(git_index_write_tree_to(&tree_index_id, idx, g_repo));
......@@ -88,7 +89,7 @@ void test_object_tree_update__remove_all_entries(void)
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
/* Create it with an index */
cl_git_pass(git_index_new(&idx));
cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(idx, base_tree));
cl_git_pass(git_index_remove(idx, path1, 0));
cl_git_pass(git_index_remove(idx, path2, 0));
......@@ -119,7 +120,7 @@ void test_object_tree_update__replace_blob(void)
cl_git_pass(git_tree_lookup(&base_tree, g_repo, &base_id));
/* Create it with an index */
cl_git_pass(git_index_new(&idx));
cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_index_read_tree(idx, base_tree));
entry.path = path;
......@@ -171,7 +172,7 @@ void test_object_tree_update__add_blobs(void)
int j;
/* Create it with an index */
cl_git_pass(git_index_new(&idx));
cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
base_tree = NULL;
if (i == 1) {
......@@ -228,7 +229,7 @@ void test_object_tree_update__add_blobs_unsorted(void)
int j;
/* Create it with an index */
cl_git_pass(git_index_new(&idx));
cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
base_tree = NULL;
if (i == 1) {
......
#include "clar_libgit2.h"
#include "git2/sys/repository.h"
#include "index.h"
#include "odb.h"
#include "posix.h"
#include "util.h"
......@@ -70,7 +71,7 @@ void test_repo_setters__setting_a_new_index_on_a_repo_which_has_already_loaded_o
{
git_index *new_index;
cl_git_pass(git_index_open(&new_index, "./my-index"));
cl_git_pass(git_index__open(&new_index, "./my-index", GIT_OID_SHA1));
cl_assert(((git_refcount *)new_index)->refcount.val == 1);
git_repository_set_index(repo, new_index);
......
......@@ -3,6 +3,7 @@
#include "reset_helpers.h"
#include "path.h"
#include "futils.h"
#include "index.h"
static git_repository *repo;
static git_object *target;
......@@ -252,7 +253,7 @@ void test_reset_hard__switch_file_to_dir(void)
git_odb_free(odb);
entry.mode = GIT_FILEMODE_BLOB;
cl_git_pass(git_index_new(&idx));
cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
cl_git_pass(git_signature_now(&sig, "foo", "bar"));
/* Create the old tree */
......
......@@ -7,6 +7,7 @@
#include "posix.h"
#include "util.h"
#include "path.h"
#include "index.h"
static void cleanup_new_repo(void *path)
{
......@@ -65,7 +66,7 @@ void test_status_worktree_init__status_file_without_index_or_workdir(void)
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_repository_set_workdir(repo, "wd", false));
cl_git_pass(git_index_open(&index, "empty-index"));
cl_git_pass(git_index__open(&index, "empty-index", GIT_OID_SHA1));
cl_assert_equal_i(0, (int)git_index_entrycount(index));
git_repository_set_index(repo, index);
......@@ -106,7 +107,7 @@ void test_status_worktree_init__status_file_with_clean_index_and_empty_workdir(v
cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git")));
cl_git_pass(git_repository_set_workdir(repo, "wd", false));
cl_git_pass(git_index_open(&index, "my-index"));
cl_git_pass(git_index__open(&index, "my-index", GIT_OID_SHA1));
fill_index_wth_head_entries(repo, index);
git_repository_set_index(repo, index);
......
......@@ -3,6 +3,7 @@
#include "git2/sys/repository.h"
#include "repository.h"
#include "futils.h"
#include "index.h"
static git_repository *g_repo = NULL;
......@@ -210,7 +211,7 @@ void test_submodule_lookup__lookup_even_with_missing_index(void)
git_index *idx;
/* give the repo an empty index */
cl_git_pass(git_index_new(&idx));
cl_git_pass(git_index__new(&idx, GIT_OID_SHA1));
git_repository_set_index(g_repo, idx);
git_index_free(idx);
......
[core]
repositoryformatversion = 1
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = /Users/ethomson/Personal/Projects/libgit2/libgit2/tests/resources/testrepo_256.git
fetch = +refs/heads/*:refs/remotes/origin/*
[extensions]
objectformat = sha256
[branch "master"]
remote = origin
merge = refs/heads/master
Unnamed repository; edit this file 'description' to name the repository.
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
0000000000000000000000000000000000000000000000000000000000000000 decaff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f Edward Thomson <ethomson@vercel.com> 1680595792 +0100 clone: from /Users/ethomson/Personal/Projects/libgit2/libgit2/tests/resources/testrepo_256.git
0000000000000000000000000000000000000000000000000000000000000000 decaff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f Edward Thomson <ethomson@vercel.com> 1680595792 +0100 clone: from /Users/ethomson/Personal/Projects/libgit2/libgit2/tests/resources/testrepo_256.git
0000000000000000000000000000000000000000000000000000000000000000 decaff3051968d1f3a2defd3d4a80ced03101555e1fd8913b3544026c0717d4f Edward Thomson <ethomson@vercel.com> 1680595792 +0100 clone: from /Users/ethomson/Personal/Projects/libgit2/libgit2/tests/resources/testrepo_256.git
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment