Unverified Commit 487233fa by Patrick Steinhardt Committed by GitHub

Merge pull request #4895 from pks-t/pks/unused-warnings

Unused function warnings
parents a904fc6d ffe39bab
...@@ -228,8 +228,8 @@ ELSE () ...@@ -228,8 +228,8 @@ ELSE ()
ENABLE_WARNINGS(strict-prototypes) ENABLE_WARNINGS(strict-prototypes)
ENABLE_WARNINGS(declaration-after-statement) ENABLE_WARNINGS(declaration-after-statement)
ENABLE_WARNINGS(shift-count-overflow) ENABLE_WARNINGS(shift-count-overflow)
DISABLE_WARNINGS(unused-const-variable) ENABLE_WARNINGS(unused-const-variable)
DISABLE_WARNINGS(unused-function) ENABLE_WARNINGS(unused-function)
ENABLE_WARNINGS(format) ENABLE_WARNINGS(format)
ENABLE_WARNINGS(format-security) ENABLE_WARNINGS(format-security)
ENABLE_WARNINGS(int-conversion) ENABLE_WARNINGS(int-conversion)
......
...@@ -33,7 +33,7 @@ GIT_INLINE(void) attr_cache_unlock(git_attr_cache *cache) ...@@ -33,7 +33,7 @@ GIT_INLINE(void) attr_cache_unlock(git_attr_cache *cache)
GIT_INLINE(git_attr_file_entry *) attr_cache_lookup_entry( GIT_INLINE(git_attr_file_entry *) attr_cache_lookup_entry(
git_attr_cache *cache, const char *path) git_attr_cache *cache, const char *path)
{ {
khiter_t pos = git_strmap_lookup_index(cache->files, path); size_t pos = git_strmap_lookup_index(cache->files, path);
if (git_strmap_valid_index(cache->files, pos)) if (git_strmap_valid_index(cache->files, pos))
return git_strmap_value_at(cache->files, pos); return git_strmap_value_at(cache->files, pos);
...@@ -266,7 +266,7 @@ bool git_attr_cache__is_cached( ...@@ -266,7 +266,7 @@ bool git_attr_cache__is_cached(
{ {
git_attr_cache *cache = git_repository_attr_cache(repo); git_attr_cache *cache = git_repository_attr_cache(repo);
git_strmap *files; git_strmap *files;
khiter_t pos; size_t pos;
git_attr_file_entry *entry; git_attr_file_entry *entry;
if (!cache || !(files = cache->files)) if (!cache || !(files = cache->files))
...@@ -457,7 +457,7 @@ git_attr_rule *git_attr_cache__lookup_macro( ...@@ -457,7 +457,7 @@ git_attr_rule *git_attr_cache__lookup_macro(
git_repository *repo, const char *name) git_repository *repo, const char *name)
{ {
git_strmap *macros = git_repository_attr_cache(repo)->macros; git_strmap *macros = git_repository_attr_cache(repo)->macros;
khiter_t pos; size_t pos;
pos = git_strmap_lookup_index(macros, name); pos = git_strmap_lookup_index(macros, name);
......
...@@ -123,7 +123,7 @@ static void cache_evict_entries(git_cache *cache) ...@@ -123,7 +123,7 @@ static void cache_evict_entries(git_cache *cache)
} }
while (evict_count > 0) { while (evict_count > 0) {
khiter_t pos = seed++ % git_oidmap_end(cache->map); size_t pos = seed++ % git_oidmap_end(cache->map);
if (git_oidmap_has_data(cache->map, pos)) { if (git_oidmap_has_data(cache->map, pos)) {
git_cached_obj *evict = git_oidmap_value_at(cache->map, pos); git_cached_obj *evict = git_oidmap_value_at(cache->map, pos);
...@@ -148,7 +148,7 @@ static bool cache_should_store(git_otype object_type, size_t object_size) ...@@ -148,7 +148,7 @@ static bool cache_should_store(git_otype object_type, size_t object_size)
static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags) static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
{ {
khiter_t pos; size_t pos;
git_cached_obj *entry = NULL; git_cached_obj *entry = NULL;
if (!git_cache__enabled || git_rwlock_rdlock(&cache->lock) < 0) if (!git_cache__enabled || git_rwlock_rdlock(&cache->lock) < 0)
...@@ -172,7 +172,7 @@ static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags) ...@@ -172,7 +172,7 @@ static void *cache_get(git_cache *cache, const git_oid *oid, unsigned int flags)
static void *cache_store(git_cache *cache, git_cached_obj *entry) static void *cache_store(git_cache *cache, git_cached_obj *entry)
{ {
khiter_t pos; size_t pos;
git_cached_obj_incref(entry); git_cached_obj_incref(entry);
......
...@@ -131,9 +131,9 @@ void git_config_entries_free(git_config_entries *entries) ...@@ -131,9 +131,9 @@ void git_config_entries_free(git_config_entries *entries)
int git_config_entries_append(git_config_entries *entries, git_config_entry *entry) int git_config_entries_append(git_config_entries *entries, git_config_entry *entry)
{ {
git_strmap_iter pos;
config_entry_list *existing, *var; config_entry_list *existing, *var;
int error = 0; int error = 0;
size_t pos;
var = git__calloc(1, sizeof(config_entry_list)); var = git__calloc(1, sizeof(config_entry_list));
GITERR_CHECK_ALLOC(var); GITERR_CHECK_ALLOC(var);
...@@ -171,7 +171,7 @@ int git_config_entries_append(git_config_entries *entries, git_config_entry *ent ...@@ -171,7 +171,7 @@ int git_config_entries_append(git_config_entries *entries, git_config_entry *ent
int config_entry_get(config_entry_list **out, git_config_entries *entries, const char *key) int config_entry_get(config_entry_list **out, git_config_entries *entries, const char *key)
{ {
khiter_t pos; size_t pos;
pos = git_strmap_lookup_index(entries->map, key); pos = git_strmap_lookup_index(entries->map, key);
......
...@@ -36,7 +36,7 @@ struct commit_name { ...@@ -36,7 +36,7 @@ struct commit_name {
static void *oidmap_value_bykey(git_oidmap *map, const git_oid *key) static void *oidmap_value_bykey(git_oidmap *map, const git_oid *key)
{ {
khint_t pos = git_oidmap_lookup_index(map, key); size_t pos = git_oidmap_lookup_index(map, key);
if (!git_oidmap_valid_index(map, pos)) if (!git_oidmap_valid_index(map, pos))
return NULL; return NULL;
......
...@@ -234,8 +234,7 @@ static int git_diff_driver_load( ...@@ -234,8 +234,7 @@ static int git_diff_driver_load(
int error = 0; int error = 0;
git_diff_driver_registry *reg; git_diff_driver_registry *reg;
git_diff_driver *drv = NULL; git_diff_driver *drv = NULL;
size_t namelen; size_t namelen, pos;
khiter_t pos;
git_config *cfg = NULL; git_config *cfg = NULL;
git_buf name = GIT_BUF_INIT; git_buf name = GIT_BUF_INIT;
git_config_entry *ce = NULL; git_config_entry *ce = NULL;
......
...@@ -7,6 +7,16 @@ ...@@ -7,6 +7,16 @@
#include "idxmap.h" #include "idxmap.h"
#define kmalloc git__malloc
#define kcalloc git__calloc
#define krealloc git__realloc
#define kreallocarray git__reallocarray
#define kfree git__free
#include "khash.h"
__KHASH_TYPE(idx, const git_index_entry *, git_index_entry *)
__KHASH_TYPE(idxicase, const git_index_entry *, git_index_entry *)
/* This is __ac_X31_hash_string but with tolower and it takes the entry's stage into account */ /* This is __ac_X31_hash_string but with tolower and it takes the entry's stage into account */
static kh_inline khint_t idxentry_hash(const git_index_entry *e) static kh_inline khint_t idxentry_hash(const git_index_entry *e)
{ {
...@@ -104,11 +114,21 @@ void git_idxmap_free(git_idxmap *map) ...@@ -104,11 +114,21 @@ void git_idxmap_free(git_idxmap *map)
kh_destroy(idx, map); kh_destroy(idx, map);
} }
void git_idxmap_icase_free(git_idxmap_icase *map)
{
kh_destroy(idxicase, map);
}
void git_idxmap_clear(git_idxmap *map) void git_idxmap_clear(git_idxmap *map)
{ {
kh_clear(idx, map); kh_clear(idx, map);
} }
void git_idxmap_icase_clear(git_idxmap_icase *map)
{
kh_clear(idxicase, map);
}
void git_idxmap_delete_at(git_idxmap *map, size_t idx) void git_idxmap_delete_at(git_idxmap *map, size_t idx)
{ {
kh_del(idx, map, idx); kh_del(idx, map, idx);
......
...@@ -9,23 +9,10 @@ ...@@ -9,23 +9,10 @@
#include "common.h" #include "common.h"
#include <ctype.h>
#include "git2/index.h" #include "git2/index.h"
#define kmalloc git__malloc typedef struct kh_idx_s git_idxmap;
#define kcalloc git__calloc typedef struct kh_idxicase_s git_idxmap_icase;
#define krealloc git__realloc
#define kreallocarray git__reallocarray
#define kfree git__free
#include "khash.h"
__KHASH_TYPE(idx, const git_index_entry *, git_index_entry *)
__KHASH_TYPE(idxicase, const git_index_entry *, git_index_entry *)
typedef khash_t(idx) git_idxmap;
typedef khash_t(idxicase) git_idxmap_icase;
typedef khiter_t git_idxmap_iter;
int git_idxmap_alloc(git_idxmap **map); int git_idxmap_alloc(git_idxmap **map);
int git_idxmap_icase_alloc(git_idxmap_icase **map); int git_idxmap_icase_alloc(git_idxmap_icase **map);
...@@ -41,7 +28,9 @@ int git_idxmap_has_data(git_idxmap *map, size_t idx); ...@@ -41,7 +28,9 @@ int git_idxmap_has_data(git_idxmap *map, size_t idx);
void git_idxmap_resize(git_idxmap *map, size_t size); void git_idxmap_resize(git_idxmap *map, size_t size);
void git_idxmap_icase_resize(git_idxmap_icase *map, size_t size); void git_idxmap_icase_resize(git_idxmap_icase *map, size_t size);
void git_idxmap_free(git_idxmap *map); void git_idxmap_free(git_idxmap *map);
void git_idxmap_icase_free(git_idxmap_icase *map);
void git_idxmap_clear(git_idxmap *map); void git_idxmap_clear(git_idxmap *map);
void git_idxmap_icase_clear(git_idxmap_icase *map);
void git_idxmap_delete_at(git_idxmap *map, size_t idx); void git_idxmap_delete_at(git_idxmap *map, size_t idx);
void git_idxmap_icase_delete_at(git_idxmap_icase *map, size_t idx); void git_idxmap_icase_delete_at(git_idxmap_icase *map, size_t idx);
...@@ -49,7 +38,4 @@ void git_idxmap_icase_delete_at(git_idxmap_icase *map, size_t idx); ...@@ -49,7 +38,4 @@ void git_idxmap_icase_delete_at(git_idxmap_icase *map, size_t idx);
void git_idxmap_delete(git_idxmap *map, const git_index_entry *key); void git_idxmap_delete(git_idxmap *map, const git_index_entry *key);
void git_idxmap_icase_delete(git_idxmap_icase *map, const git_index_entry *key); void git_idxmap_icase_delete(git_idxmap_icase *map, const git_index_entry *key);
#define git_idxmap_begin kh_begin
#define git_idxmap_end kh_end
#endif #endif
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#define INSERT_IN_MAP_EX(idx, map, e, err) do { \ #define INSERT_IN_MAP_EX(idx, map, e, err) do { \
if ((idx)->ignore_case) \ if ((idx)->ignore_case) \
git_idxmap_icase_insert((khash_t(idxicase) *) (map), (e), (e), (err)); \ git_idxmap_icase_insert((git_idxmap_icase *) (map), (e), (e), (err)); \
else \ else \
git_idxmap_insert((map), (e), (e), (err)); \ git_idxmap_insert((map), (e), (e), (err)); \
} while (0) } while (0)
...@@ -38,14 +38,14 @@ ...@@ -38,14 +38,14 @@
#define LOOKUP_IN_MAP(p, idx, k) do { \ #define LOOKUP_IN_MAP(p, idx, k) do { \
if ((idx)->ignore_case) \ if ((idx)->ignore_case) \
(p) = git_idxmap_icase_lookup_index((khash_t(idxicase) *) index->entries_map, (k)); \ (p) = git_idxmap_icase_lookup_index((git_idxmap_icase *) index->entries_map, (k)); \
else \ else \
(p) = git_idxmap_lookup_index(index->entries_map, (k)); \ (p) = git_idxmap_lookup_index(index->entries_map, (k)); \
} while (0) } while (0)
#define DELETE_IN_MAP(idx, e) do { \ #define DELETE_IN_MAP(idx, e) do { \
if ((idx)->ignore_case) \ if ((idx)->ignore_case) \
git_idxmap_icase_delete((khash_t(idxicase) *) (idx)->entries_map, (e)); \ git_idxmap_icase_delete((git_idxmap_icase *) (idx)->entries_map, (e)); \
else \ else \
git_idxmap_delete((idx)->entries_map, (e)); \ git_idxmap_delete((idx)->entries_map, (e)); \
} while (0) } while (0)
...@@ -851,8 +851,8 @@ const git_index_entry *git_index_get_byindex( ...@@ -851,8 +851,8 @@ const git_index_entry *git_index_get_byindex(
const git_index_entry *git_index_get_bypath( const git_index_entry *git_index_get_bypath(
git_index *index, const char *path, int stage) git_index *index, const char *path, int stage)
{ {
khiter_t pos;
git_index_entry key = {{ 0 }}; git_index_entry key = {{ 0 }};
size_t pos;
assert(index); assert(index);
...@@ -1619,7 +1619,7 @@ int git_index__fill(git_index *index, const git_vector *source_entries) ...@@ -1619,7 +1619,7 @@ int git_index__fill(git_index *index, const git_vector *source_entries)
return 0; return 0;
git_vector_size_hint(&index->entries, source_entries->length); git_vector_size_hint(&index->entries, source_entries->length);
git_idxmap_resize(index->entries_map, (khint_t)(source_entries->length * 1.3)); git_idxmap_resize(index->entries_map, (size_t)(source_entries->length * 1.3));
git_vector_foreach(source_entries, i, source_entry) { git_vector_foreach(source_entries, i, source_entry) {
git_index_entry *entry = NULL; git_index_entry *entry = NULL;
...@@ -2603,7 +2603,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size) ...@@ -2603,7 +2603,7 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
assert(!index->entries.length); assert(!index->entries.length);
if (index->ignore_case) if (index->ignore_case)
git_idxmap_icase_resize((khash_t(idxicase) *) index->entries_map, header.entry_count); git_idxmap_icase_resize((git_idxmap_icase *) index->entries_map, header.entry_count);
else else
git_idxmap_resize(index->entries_map, header.entry_count); git_idxmap_resize(index->entries_map, header.entry_count);
...@@ -3124,7 +3124,7 @@ int git_index_read_tree(git_index *index, const git_tree *tree) ...@@ -3124,7 +3124,7 @@ int git_index_read_tree(git_index *index, const git_tree *tree)
goto cleanup; goto cleanup;
if (index->ignore_case) if (index->ignore_case)
git_idxmap_icase_resize((khash_t(idxicase) *) entries_map, entries.length); git_idxmap_icase_resize((git_idxmap_icase *) entries_map, entries.length);
else else
git_idxmap_resize(entries_map, entries.length); git_idxmap_resize(entries_map, entries.length);
...@@ -3184,7 +3184,7 @@ static int git_index_read_iterator( ...@@ -3184,7 +3184,7 @@ static int git_index_read_iterator(
goto done; goto done;
if (index->ignore_case && new_length_hint) if (index->ignore_case && new_length_hint)
git_idxmap_icase_resize((khash_t(idxicase) *) new_entries_map, new_length_hint); git_idxmap_icase_resize((git_idxmap_icase *) new_entries_map, new_length_hint);
else if (new_length_hint) else if (new_length_hint)
git_idxmap_resize(new_entries_map, new_length_hint); git_idxmap_resize(new_entries_map, new_length_hint);
......
...@@ -402,7 +402,7 @@ out: ...@@ -402,7 +402,7 @@ out:
static int store_object(git_indexer *idx) static int store_object(git_indexer *idx)
{ {
int i, error; int i, error;
khiter_t k; size_t k;
git_oid oid; git_oid oid;
struct entry *entry; struct entry *entry;
git_off_t entry_size; git_off_t entry_size;
...@@ -483,7 +483,7 @@ GIT_INLINE(bool) has_entry(git_indexer *idx, git_oid *id) ...@@ -483,7 +483,7 @@ GIT_INLINE(bool) has_entry(git_indexer *idx, git_oid *id)
static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_entry *pentry, git_off_t entry_start) static int save_entry(git_indexer *idx, struct entry *entry, struct git_pack_entry *pentry, git_off_t entry_start)
{ {
int i, error; int i, error;
khiter_t k; size_t k;
if (entry_start > UINT31_MAX) { if (entry_start > UINT31_MAX) {
entry->offset = UINT32_MAX; entry->offset = UINT32_MAX;
...@@ -1292,7 +1292,7 @@ on_error: ...@@ -1292,7 +1292,7 @@ on_error:
void git_indexer_free(git_indexer *idx) void git_indexer_free(git_indexer *idx)
{ {
khiter_t pos; size_t pos;
if (idx == NULL) if (idx == NULL)
return; return;
......
...@@ -478,14 +478,6 @@ GIT_INLINE(int) tree_entry_cmp( ...@@ -478,14 +478,6 @@ GIT_INLINE(int) tree_entry_cmp(
icase ? git__strncasecmp : git__strncmp); icase ? git__strncasecmp : git__strncmp);
} }
GIT_INLINE(int) tree_iterator_entry_cmp(const void *ptr_a, const void *ptr_b)
{
const tree_iterator_entry *a = (const tree_iterator_entry *)ptr_a;
const tree_iterator_entry *b = (const tree_iterator_entry *)ptr_b;
return tree_entry_cmp(a->tree_entry, b->tree_entry, false);
}
GIT_INLINE(int) tree_iterator_entry_cmp_icase( GIT_INLINE(int) tree_iterator_entry_cmp_icase(
const void *ptr_a, const void *ptr_b) const void *ptr_a, const void *ptr_b)
{ {
......
...@@ -1105,7 +1105,7 @@ static void deletes_by_oid_free(git_oidmap *map) { ...@@ -1105,7 +1105,7 @@ static void deletes_by_oid_free(git_oidmap *map) {
} }
static int deletes_by_oid_enqueue(git_oidmap *map, git_pool* pool, const git_oid *id, size_t idx) { static int deletes_by_oid_enqueue(git_oidmap *map, git_pool* pool, const git_oid *id, size_t idx) {
khint_t pos; size_t pos;
deletes_by_oid_queue *queue; deletes_by_oid_queue *queue;
size_t *array_entry; size_t *array_entry;
int error; int error;
...@@ -1133,7 +1133,7 @@ static int deletes_by_oid_enqueue(git_oidmap *map, git_pool* pool, const git_oid ...@@ -1133,7 +1133,7 @@ static int deletes_by_oid_enqueue(git_oidmap *map, git_pool* pool, const git_oid
} }
static int deletes_by_oid_dequeue(size_t *idx, git_oidmap *map, const git_oid *id) { static int deletes_by_oid_dequeue(size_t *idx, git_oidmap *map, const git_oid *id) {
khint_t pos; size_t pos;
deletes_by_oid_queue *queue; deletes_by_oid_queue *queue;
size_t *array_entry; size_t *array_entry;
......
...@@ -51,7 +51,7 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path) ...@@ -51,7 +51,7 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
{ {
int error; int error;
char *packname; char *packname;
git_strmap_iter pos; size_t pos;
struct git_pack_file *pack; struct git_pack_file *pack;
if ((error = git_packfile__name(&packname, path)) < 0) if ((error = git_packfile__name(&packname, path)) < 0)
...@@ -97,7 +97,7 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path) ...@@ -97,7 +97,7 @@ int git_mwindow_get_pack(struct git_pack_file **out, const char *path)
void git_mwindow_put_pack(struct git_pack_file *pack) void git_mwindow_put_pack(struct git_pack_file *pack)
{ {
int count; int count;
git_strmap_iter pos; size_t pos;
if (git_mutex_lock(&git__mwindow_mutex) < 0) if (git_mutex_lock(&git__mwindow_mutex) < 0)
return; return;
......
...@@ -37,7 +37,7 @@ static int impl__write(git_odb_backend *_backend, const git_oid *oid, const void ...@@ -37,7 +37,7 @@ static int impl__write(git_odb_backend *_backend, const git_oid *oid, const void
{ {
struct memory_packer_db *db = (struct memory_packer_db *)_backend; struct memory_packer_db *db = (struct memory_packer_db *)_backend;
struct memobject *obj = NULL; struct memobject *obj = NULL;
khiter_t pos; size_t pos;
size_t alloc_len; size_t alloc_len;
int rval; int rval;
...@@ -80,7 +80,7 @@ static int impl__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_odb ...@@ -80,7 +80,7 @@ static int impl__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_odb
{ {
struct memory_packer_db *db = (struct memory_packer_db *)backend; struct memory_packer_db *db = (struct memory_packer_db *)backend;
struct memobject *obj = NULL; struct memobject *obj = NULL;
khiter_t pos; size_t pos;
pos = git_oidmap_lookup_index(db->objects, oid); pos = git_oidmap_lookup_index(db->objects, oid);
if (!git_oidmap_valid_index(db->objects, pos)) if (!git_oidmap_valid_index(db->objects, pos))
...@@ -101,7 +101,7 @@ static int impl__read_header(size_t *len_p, git_otype *type_p, git_odb_backend * ...@@ -101,7 +101,7 @@ static int impl__read_header(size_t *len_p, git_otype *type_p, git_odb_backend *
{ {
struct memory_packer_db *db = (struct memory_packer_db *)backend; struct memory_packer_db *db = (struct memory_packer_db *)backend;
struct memobject *obj = NULL; struct memobject *obj = NULL;
khiter_t pos; size_t pos;
pos = git_oidmap_lookup_index(db->objects, oid); pos = git_oidmap_lookup_index(db->objects, oid);
if (!git_oidmap_valid_index(db->objects, pos)) if (!git_oidmap_valid_index(db->objects, pos))
......
...@@ -7,6 +7,15 @@ ...@@ -7,6 +7,15 @@
#include "offmap.h" #include "offmap.h"
#define kmalloc git__malloc
#define kcalloc git__calloc
#define krealloc git__realloc
#define kreallocarray git__reallocarray
#define kfree git__free
#include "khash.h"
__KHASH_TYPE(off, git_off_t, void *)
__KHASH_IMPL(off, static kh_inline, git_off_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal) __KHASH_IMPL(off, static kh_inline, git_off_t, void *, 1, kh_int64_hash_func, kh_int64_hash_equal)
git_offmap *git_offmap_alloc(void) git_offmap *git_offmap_alloc(void)
...@@ -44,6 +53,16 @@ int git_offmap_exists(git_offmap *map, const git_off_t key) ...@@ -44,6 +53,16 @@ int git_offmap_exists(git_offmap *map, const git_off_t key)
return kh_get(off, map, key) != kh_end(map); return kh_get(off, map, key) != kh_end(map);
} }
int git_offmap_has_data(git_offmap *map, size_t idx)
{
return kh_exist(map, idx);
}
git_off_t git_offmap_key_at(git_offmap *map, size_t idx)
{
return kh_key(map, idx);
}
void *git_offmap_value_at(git_offmap *map, size_t idx) void *git_offmap_value_at(git_offmap *map, size_t idx)
{ {
return kh_val(map, idx); return kh_val(map, idx);
...@@ -81,3 +100,14 @@ void git_offmap_delete(git_offmap *map, const git_off_t key) ...@@ -81,3 +100,14 @@ void git_offmap_delete(git_offmap *map, const git_off_t key)
if (git_offmap_valid_index(map, idx)) if (git_offmap_valid_index(map, idx))
git_offmap_delete_at(map, idx); git_offmap_delete_at(map, idx);
} }
size_t git_offmap_begin(git_offmap *map)
{
GIT_UNUSED(map);
return 0;
}
size_t git_offmap_end(git_offmap *map)
{
return map->n_buckets;
}
...@@ -11,15 +11,7 @@ ...@@ -11,15 +11,7 @@
#include "git2/types.h" #include "git2/types.h"
#define kmalloc git__malloc typedef struct kh_off_s git_offmap;
#define kcalloc git__calloc
#define krealloc git__realloc
#define kreallocarray git__reallocarray
#define kfree git__free
#include "khash.h"
__KHASH_TYPE(off, git_off_t, void *)
typedef khash_t(off) git_offmap;
git_offmap *git_offmap_alloc(void); git_offmap *git_offmap_alloc(void);
void git_offmap_free(git_offmap *map); void git_offmap_free(git_offmap *map);
...@@ -31,7 +23,9 @@ size_t git_offmap_lookup_index(git_offmap *map, const git_off_t key); ...@@ -31,7 +23,9 @@ size_t git_offmap_lookup_index(git_offmap *map, const git_off_t key);
int git_offmap_valid_index(git_offmap *map, size_t idx); int git_offmap_valid_index(git_offmap *map, size_t idx);
int git_offmap_exists(git_offmap *map, const git_off_t key); int git_offmap_exists(git_offmap *map, const git_off_t key);
int git_offmap_has_data(git_offmap *map, size_t idx);
git_off_t git_offmap_key_at(git_offmap *map, size_t idx);
void *git_offmap_value_at(git_offmap *map, size_t idx); void *git_offmap_value_at(git_offmap *map, size_t idx);
void git_offmap_set_value_at(git_offmap *map, size_t idx, void *value); void git_offmap_set_value_at(git_offmap *map, size_t idx, void *value);
void git_offmap_delete_at(git_offmap *map, size_t idx); void git_offmap_delete_at(git_offmap *map, size_t idx);
...@@ -40,7 +34,22 @@ int git_offmap_put(git_offmap *map, const git_off_t key, int *err); ...@@ -40,7 +34,22 @@ int git_offmap_put(git_offmap *map, const git_off_t key, int *err);
void git_offmap_insert(git_offmap *map, const git_off_t key, void *value, int *rval); void git_offmap_insert(git_offmap *map, const git_off_t key, void *value, int *rval);
void git_offmap_delete(git_offmap *map, const git_off_t key); void git_offmap_delete(git_offmap *map, const git_off_t key);
#define git_offmap_foreach kh_foreach size_t git_offmap_begin(git_offmap *map);
#define git_offmap_foreach_value kh_foreach_value size_t git_offmap_end(git_offmap *map);
#define git_offmap_foreach(h, kvar, vvar, code) { size_t __i; \
for (__i = git_offmap_begin(h); __i != git_offmap_end(h); ++__i) { \
if (!git_offmap_has_data(h,__i)) continue; \
(kvar) = git_offmap_key_at(h,__i); \
(vvar) = git_offmap_value_at(h,__i); \
code; \
} }
#define git_offmap_foreach_value(h, vvar, code) { size_t __i; \
for (__i = git_offmap_begin(h); __i != git_offmap_end(h); ++__i) { \
if (!git_offmap_has_data(h,__i)) continue; \
(vvar) = git_offmap_value_at(h,__i); \
code; \
} }
#endif #endif
...@@ -7,6 +7,15 @@ ...@@ -7,6 +7,15 @@
#include "oidmap.h" #include "oidmap.h"
#define kmalloc git__malloc
#define kcalloc git__calloc
#define krealloc git__realloc
#define kreallocarray git__reallocarray
#define kfree git__free
#include "khash.h"
__KHASH_TYPE(oid, const git_oid *, void *)
GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid) GIT_INLINE(khint_t) git_oidmap_hash(const git_oid *oid)
{ {
khint_t h; khint_t h;
...@@ -103,3 +112,14 @@ void git_oidmap_delete(git_oidmap *map, const git_oid *key) ...@@ -103,3 +112,14 @@ void git_oidmap_delete(git_oidmap *map, const git_oid *key)
if (git_oidmap_valid_index(map, idx)) if (git_oidmap_valid_index(map, idx))
git_oidmap_delete_at(map, idx); git_oidmap_delete_at(map, idx);
} }
size_t git_oidmap_begin(git_oidmap *map)
{
GIT_UNUSED(map);
return 0;
}
size_t git_oidmap_end(git_oidmap *map)
{
return map->n_buckets;
}
...@@ -11,15 +11,7 @@ ...@@ -11,15 +11,7 @@
#include "git2/oid.h" #include "git2/oid.h"
#define kmalloc git__malloc typedef struct kh_oid_s git_oidmap;
#define kcalloc git__calloc
#define krealloc git__realloc
#define kreallocarray git__reallocarray
#define kfree git__free
#include "khash.h"
__KHASH_TYPE(oid, const git_oid *, void *)
typedef khash_t(oid) git_oidmap;
git_oidmap *git_oidmap_alloc(void); git_oidmap *git_oidmap_alloc(void);
void git_oidmap_free(git_oidmap *map); void git_oidmap_free(git_oidmap *map);
...@@ -43,9 +35,14 @@ int git_oidmap_put(git_oidmap *map, const git_oid *key, int *err); ...@@ -43,9 +35,14 @@ int git_oidmap_put(git_oidmap *map, const git_oid *key, int *err);
void git_oidmap_insert(git_oidmap *map, const git_oid *key, void *value, int *rval); void git_oidmap_insert(git_oidmap *map, const git_oid *key, void *value, int *rval);
void git_oidmap_delete(git_oidmap *map, const git_oid *key); void git_oidmap_delete(git_oidmap *map, const git_oid *key);
#define git_oidmap_foreach_value kh_foreach_value size_t git_oidmap_begin(git_oidmap *map);
size_t git_oidmap_end(git_oidmap *map);
#define git_oidmap_begin kh_begin #define git_oidmap_foreach_value(h, vvar, code) { size_t __i; \
#define git_oidmap_end kh_end for (__i = git_oidmap_begin(h); __i != git_oidmap_end(h); ++__i) { \
if (!git_oidmap_has_data(h,__i)) continue; \
(vvar) = git_oidmap_value_at(h,__i); \
code; \
} }
#endif #endif
...@@ -197,8 +197,7 @@ unsigned int git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n) ...@@ -197,8 +197,7 @@ unsigned int git_packbuilder_set_threads(git_packbuilder *pb, unsigned int n)
static void rehash(git_packbuilder *pb) static void rehash(git_packbuilder *pb)
{ {
git_pobject *po; git_pobject *po;
khiter_t pos; size_t pos, i;
size_t i;
int ret; int ret;
git_oidmap_clear(pb->object_ix); git_oidmap_clear(pb->object_ix);
...@@ -212,8 +211,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid, ...@@ -212,8 +211,7 @@ int git_packbuilder_insert(git_packbuilder *pb, const git_oid *oid,
const char *name) const char *name)
{ {
git_pobject *po; git_pobject *po;
khiter_t pos; size_t newsize, pos;
size_t newsize;
int ret; int ret;
assert(pb && oid); assert(pb && oid);
...@@ -516,7 +514,7 @@ static int cb_tag_foreach(const char *name, git_oid *oid, void *data) ...@@ -516,7 +514,7 @@ static int cb_tag_foreach(const char *name, git_oid *oid, void *data)
{ {
git_packbuilder *pb = data; git_packbuilder *pb = data;
git_pobject *po; git_pobject *po;
khiter_t pos; size_t pos;
GIT_UNUSED(name); GIT_UNUSED(name);
...@@ -1542,7 +1540,7 @@ static int lookup_walk_object(struct walk_object **out, git_packbuilder *pb, con ...@@ -1542,7 +1540,7 @@ static int lookup_walk_object(struct walk_object **out, git_packbuilder *pb, con
static int retrieve_object(struct walk_object **out, git_packbuilder *pb, const git_oid *id) static int retrieve_object(struct walk_object **out, git_packbuilder *pb, const git_oid *id)
{ {
int error; int error;
khiter_t pos; size_t pos;
struct walk_object *obj; struct walk_object *obj;
pos = git_oidmap_lookup_index(pb->walk_objects, id); pos = git_oidmap_lookup_index(pb->walk_objects, id);
......
...@@ -108,8 +108,8 @@ static int cache_init(git_pack_cache *cache) ...@@ -108,8 +108,8 @@ static int cache_init(git_pack_cache *cache)
static git_pack_cache_entry *cache_get(git_pack_cache *cache, git_off_t offset) static git_pack_cache_entry *cache_get(git_pack_cache *cache, git_off_t offset)
{ {
khiter_t k;
git_pack_cache_entry *entry = NULL; git_pack_cache_entry *entry = NULL;
size_t k;
if (git_mutex_lock(&cache->lock) < 0) if (git_mutex_lock(&cache->lock) < 0)
return NULL; return NULL;
...@@ -148,7 +148,7 @@ static int cache_add( ...@@ -148,7 +148,7 @@ static int cache_add(
{ {
git_pack_cache_entry *entry; git_pack_cache_entry *entry;
int error, exists = 0; int error, exists = 0;
khiter_t k; size_t k;
if (base->len > GIT_PACK_CACHE_SIZE_LIMIT) if (base->len > GIT_PACK_CACHE_SIZE_LIMIT)
return -1; return -1;
...@@ -954,8 +954,8 @@ git_off_t get_delta_base( ...@@ -954,8 +954,8 @@ git_off_t get_delta_base(
} else if (type == GIT_OBJ_REF_DELTA) { } else if (type == GIT_OBJ_REF_DELTA) {
/* If we have the cooperative cache, search in it first */ /* If we have the cooperative cache, search in it first */
if (p->has_cache) { if (p->has_cache) {
khiter_t k;
git_oid oid; git_oid oid;
size_t k;
git_oid_fromraw(&oid, base_info); git_oid_fromraw(&oid, base_info);
k = git_oidmap_lookup_index(p->idx_cache, &oid); k = git_oidmap_lookup_index(p->idx_cache, &oid);
......
...@@ -21,7 +21,7 @@ git_commit_list_node *git_revwalk__commit_lookup( ...@@ -21,7 +21,7 @@ git_commit_list_node *git_revwalk__commit_lookup(
git_revwalk *walk, const git_oid *oid) git_revwalk *walk, const git_oid *oid)
{ {
git_commit_list_node *commit; git_commit_list_node *commit;
khiter_t pos; size_t pos;
int ret; int ret;
/* lookup and reserve space if not already present */ /* lookup and reserve space if not already present */
......
...@@ -270,8 +270,8 @@ int git_sortedcache_clear(git_sortedcache *sc, bool wlock) ...@@ -270,8 +270,8 @@ int git_sortedcache_clear(git_sortedcache *sc, bool wlock)
/* find and/or insert item, returning pointer to item data */ /* find and/or insert item, returning pointer to item data */
int git_sortedcache_upsert(void **out, git_sortedcache *sc, const char *key) int git_sortedcache_upsert(void **out, git_sortedcache *sc, const char *key)
{ {
size_t pos;
int error = 0; int error = 0;
khiter_t pos;
void *item; void *item;
size_t keylen, itemlen; size_t keylen, itemlen;
char *item_key; char *item_key;
...@@ -320,7 +320,7 @@ done: ...@@ -320,7 +320,7 @@ done:
/* lookup item by key */ /* lookup item by key */
void *git_sortedcache_lookup(const git_sortedcache *sc, const char *key) void *git_sortedcache_lookup(const git_sortedcache *sc, const char *key)
{ {
khiter_t pos = git_strmap_lookup_index(sc->map, key); size_t pos = git_strmap_lookup_index(sc->map, key);
if (git_strmap_valid_index(sc->map, pos)) if (git_strmap_valid_index(sc->map, pos))
return git_strmap_value_at(sc->map, pos); return git_strmap_value_at(sc->map, pos);
return NULL; return NULL;
...@@ -371,7 +371,7 @@ int git_sortedcache_lookup_index( ...@@ -371,7 +371,7 @@ int git_sortedcache_lookup_index(
int git_sortedcache_remove(git_sortedcache *sc, size_t pos) int git_sortedcache_remove(git_sortedcache *sc, size_t pos)
{ {
char *item; char *item;
khiter_t mappos; size_t mappos;
/* because of pool allocation, this can't actually remove the item, /* because of pool allocation, this can't actually remove the item,
* but we can remove it from the items vector and the hash table. * but we can remove it from the items vector and the hash table.
......
...@@ -7,6 +7,15 @@ ...@@ -7,6 +7,15 @@
#include "strmap.h" #include "strmap.h"
#define kmalloc git__malloc
#define kcalloc git__calloc
#define krealloc git__realloc
#define kreallocarray git__reallocarray
#define kfree git__free
#include "khash.h"
__KHASH_TYPE(str, const char *, void *)
__KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal) __KHASH_IMPL(str, static kh_inline, const char *, void *, 1, kh_str_hash_func, kh_str_hash_equal)
int git_strmap_alloc(git_strmap **map) int git_strmap_alloc(git_strmap **map)
...@@ -102,9 +111,20 @@ void git_strmap_delete(git_strmap *map, const char *key) ...@@ -102,9 +111,20 @@ void git_strmap_delete(git_strmap *map, const char *key)
git_strmap_delete_at(map, idx); git_strmap_delete_at(map, idx);
} }
size_t git_strmap_begin(git_strmap *map)
{
GIT_UNUSED(map);
return 0;
}
size_t git_strmap_end(git_strmap *map)
{
return map->n_buckets;
}
int git_strmap_next( int git_strmap_next(
void **data, void **data,
git_strmap_iter* iter, size_t* iter,
git_strmap *map) git_strmap *map)
{ {
if (!map) if (!map)
......
...@@ -9,16 +9,7 @@ ...@@ -9,16 +9,7 @@
#include "common.h" #include "common.h"
#define kmalloc git__malloc typedef struct kh_str_s git_strmap;
#define kcalloc git__calloc
#define krealloc git__realloc
#define kreallocarray git__reallocarray
#define kfree git__free
#include "khash.h"
__KHASH_TYPE(str, const char *, void *)
typedef khash_t(str) git_strmap;
typedef khiter_t git_strmap_iter;
int git_strmap_alloc(git_strmap **map); int git_strmap_alloc(git_strmap **map);
void git_strmap_free(git_strmap *map); void git_strmap_free(git_strmap *map);
...@@ -42,15 +33,27 @@ int git_strmap_put(git_strmap *map, const char *key, int *err); ...@@ -42,15 +33,27 @@ int git_strmap_put(git_strmap *map, const char *key, int *err);
void git_strmap_insert(git_strmap *map, const char *key, void *value, int *rval); void git_strmap_insert(git_strmap *map, const char *key, void *value, int *rval);
void git_strmap_delete(git_strmap *map, const char *key); void git_strmap_delete(git_strmap *map, const char *key);
#define git_strmap_foreach kh_foreach #define git_strmap_foreach(h, kvar, vvar, code) { size_t __i; \
#define git_strmap_foreach_value kh_foreach_value for (__i = git_strmap_begin(h); __i != git_strmap_end(h); ++__i) { \
if (!git_strmap_has_data(h,__i)) continue; \
(kvar) = git_strmap_key(h,__i); \
(vvar) = git_strmap_value_at(h,__i); \
code; \
} }
#define git_strmap_foreach_value(h, vvar, code) { size_t __i; \
for (__i = git_strmap_begin(h); __i != git_strmap_end(h); ++__i) { \
if (!git_strmap_has_data(h,__i)) continue; \
(vvar) = git_strmap_value_at(h,__i); \
code; \
} }
#define git_strmap_begin kh_begin size_t git_strmap_begin(git_strmap *map);
#define git_strmap_end kh_end size_t git_strmap_end(git_strmap *map);
int git_strmap_next( int git_strmap_next(
void **data, void **data,
git_strmap_iter* iter, size_t *iter,
git_strmap *map); git_strmap *map);
#endif #endif
...@@ -60,35 +60,6 @@ enum { ...@@ -60,35 +60,6 @@ enum {
GITMODULES_CREATE = 1, GITMODULES_CREATE = 1,
}; };
static kh_inline khint_t str_hash_no_trailing_slash(const char *s)
{
khint_t h;
for (h = 0; *s; ++s)
if (s[1] != '\0' || *s != '/')
h = (h << 5) - h + *s;
return h;
}
static kh_inline int str_equal_no_trailing_slash(const char *a, const char *b)
{
size_t alen = a ? strlen(a) : 0;
size_t blen = b ? strlen(b) : 0;
if (alen > 0 && a[alen - 1] == '/')
alen--;
if (blen > 0 && b[blen - 1] == '/')
blen--;
return (alen == 0 && blen == 0) ||
(alen == blen && strncmp(a, b, alen) == 0);
}
__KHASH_IMPL(
str, static kh_inline, const char *, void *, 1,
str_hash_no_trailing_slash, str_equal_no_trailing_slash)
static int submodule_alloc(git_submodule **out, git_repository *repo, const char *name); static int submodule_alloc(git_submodule **out, git_repository *repo, const char *name);
static git_config_backend *open_gitmodules(git_repository *repo, int gitmod); static git_config_backend *open_gitmodules(git_repository *repo, int gitmod);
static int gitmodules_snapshot(git_config **snap, git_repository *repo); static int gitmodules_snapshot(git_config **snap, git_repository *repo);
...@@ -296,7 +267,7 @@ int git_submodule_lookup( ...@@ -296,7 +267,7 @@ int git_submodule_lookup(
} }
if (repo->submodule_cache != NULL) { if (repo->submodule_cache != NULL) {
khiter_t pos = git_strmap_lookup_index(repo->submodule_cache, name); size_t pos = git_strmap_lookup_index(repo->submodule_cache, name);
if (git_strmap_valid_index(repo->submodule_cache, pos)) { if (git_strmap_valid_index(repo->submodule_cache, pos)) {
if (out) { if (out) {
*out = git_strmap_value_at(repo->submodule_cache, pos); *out = git_strmap_value_at(repo->submodule_cache, pos);
...@@ -425,7 +396,7 @@ static void submodule_free_dup(void *sm) ...@@ -425,7 +396,7 @@ static void submodule_free_dup(void *sm)
static int submodule_get_or_create(git_submodule **out, git_repository *repo, git_strmap *map, const char *name) static int submodule_get_or_create(git_submodule **out, git_repository *repo, git_strmap *map, const char *name)
{ {
int error = 0; int error = 0;
khiter_t pos; size_t pos;
git_submodule *sm = NULL; git_submodule *sm = NULL;
pos = git_strmap_lookup_index(map, name); pos = git_strmap_lookup_index(map, name);
...@@ -468,7 +439,7 @@ static int submodules_from_index(git_strmap *map, git_index *idx, git_config *cf ...@@ -468,7 +439,7 @@ static int submodules_from_index(git_strmap *map, git_index *idx, git_config *cf
goto done; goto done;
while (!(error = git_iterator_advance(&entry, i))) { while (!(error = git_iterator_advance(&entry, i))) {
khiter_t pos = git_strmap_lookup_index(map, entry->path); size_t pos = git_strmap_lookup_index(map, entry->path);
git_submodule *sm; git_submodule *sm;
if (git_strmap_valid_index(map, pos)) { if (git_strmap_valid_index(map, pos)) {
...@@ -479,7 +450,7 @@ static int submodules_from_index(git_strmap *map, git_index *idx, git_config *cf ...@@ -479,7 +450,7 @@ static int submodules_from_index(git_strmap *map, git_index *idx, git_config *cf
else else
sm->flags |= GIT_SUBMODULE_STATUS__INDEX_NOT_SUBMODULE; sm->flags |= GIT_SUBMODULE_STATUS__INDEX_NOT_SUBMODULE;
} else if (S_ISGITLINK(entry->mode)) { } else if (S_ISGITLINK(entry->mode)) {
khiter_t name_pos; size_t name_pos;
const char *name; const char *name;
name_pos = git_strmap_lookup_index(names, entry->path); name_pos = git_strmap_lookup_index(names, entry->path);
...@@ -520,7 +491,7 @@ static int submodules_from_head(git_strmap *map, git_tree *head, git_config *cfg ...@@ -520,7 +491,7 @@ static int submodules_from_head(git_strmap *map, git_tree *head, git_config *cfg
goto done; goto done;
while (!(error = git_iterator_advance(&entry, i))) { while (!(error = git_iterator_advance(&entry, i))) {
khiter_t pos = git_strmap_lookup_index(map, entry->path); size_t pos = git_strmap_lookup_index(map, entry->path);
git_submodule *sm; git_submodule *sm;
if (git_strmap_valid_index(map, pos)) { if (git_strmap_valid_index(map, pos)) {
...@@ -531,7 +502,7 @@ static int submodules_from_head(git_strmap *map, git_tree *head, git_config *cfg ...@@ -531,7 +502,7 @@ static int submodules_from_head(git_strmap *map, git_tree *head, git_config *cfg
else else
sm->flags |= GIT_SUBMODULE_STATUS__HEAD_NOT_SUBMODULE; sm->flags |= GIT_SUBMODULE_STATUS__HEAD_NOT_SUBMODULE;
} else if (S_ISGITLINK(entry->mode)) { } else if (S_ISGITLINK(entry->mode)) {
khiter_t name_pos; size_t name_pos;
const char *name; const char *name;
name_pos = git_strmap_lookup_index(names, entry->path); name_pos = git_strmap_lookup_index(names, entry->path);
...@@ -1964,7 +1935,7 @@ static int submodule_load_each(const git_config_entry *entry, void *payload) ...@@ -1964,7 +1935,7 @@ static int submodule_load_each(const git_config_entry *entry, void *payload)
{ {
lfc_data *data = payload; lfc_data *data = payload;
const char *namestart, *property; const char *namestart, *property;
git_strmap_iter pos; size_t pos;
git_strmap *map = data->map; git_strmap *map = data->map;
git_buf name = GIT_BUF_INIT; git_buf name = GIT_BUF_INIT;
git_submodule *sm; git_submodule *sm;
......
...@@ -133,8 +133,8 @@ cleanup: ...@@ -133,8 +133,8 @@ cleanup:
static int find_locked(transaction_node **out, git_transaction *tx, const char *refname) static int find_locked(transaction_node **out, git_transaction *tx, const char *refname)
{ {
git_strmap_iter pos;
transaction_node *node; transaction_node *node;
size_t pos;
pos = git_strmap_lookup_index(tx->locks, refname); pos = git_strmap_lookup_index(tx->locks, refname);
if (!git_strmap_valid_index(tx->locks, pos)) { if (!git_strmap_valid_index(tx->locks, pos)) {
......
...@@ -723,7 +723,7 @@ int git_treebuilder_insert( ...@@ -723,7 +723,7 @@ int git_treebuilder_insert(
{ {
git_tree_entry *entry; git_tree_entry *entry;
int error; int error;
git_strmap_iter pos; size_t pos;
assert(bld && id && filename); assert(bld && id && filename);
...@@ -758,7 +758,7 @@ int git_treebuilder_insert( ...@@ -758,7 +758,7 @@ int git_treebuilder_insert(
static git_tree_entry *treebuilder_get(git_treebuilder *bld, const char *filename) static git_tree_entry *treebuilder_get(git_treebuilder *bld, const char *filename)
{ {
git_tree_entry *entry = NULL; git_tree_entry *entry = NULL;
git_strmap_iter pos; size_t pos;
assert(bld && filename); assert(bld && filename);
......
#include "clar_libgit2.h"
#include "apply_helpers.h"
struct iterator_compare_data {
struct merge_index_entry *expected;
size_t cnt;
size_t idx;
};
static int iterator_compare(const git_index_entry *entry, void *_data)
{
git_oid expected_id;
struct iterator_compare_data *data = (struct iterator_compare_data *)_data;
cl_assert_equal_i(GIT_IDXENTRY_STAGE(entry), data->expected[data->idx].stage);
cl_git_pass(git_oid_fromstr(&expected_id, data->expected[data->idx].oid_str));
cl_assert_equal_oid(&entry->id, &expected_id);
cl_assert_equal_i(entry->mode, data->expected[data->idx].mode);
cl_assert_equal_s(entry->path, data->expected[data->idx].path);
if (data->idx >= data->cnt)
return -1;
data->idx++;
return 0;
}
void validate_apply_workdir(
git_repository *repo,
struct merge_index_entry *workdir_entries,
size_t workdir_cnt)
{
git_index *index;
git_iterator *iterator;
git_iterator_options opts = GIT_ITERATOR_OPTIONS_INIT;
struct iterator_compare_data data = { workdir_entries, workdir_cnt };
opts.flags |= GIT_ITERATOR_INCLUDE_HASH;
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_iterator_for_workdir(&iterator, repo, index, NULL, &opts));
cl_git_pass(git_iterator_foreach(iterator, iterator_compare, &data));
cl_assert_equal_i(data.idx, data.cnt);
git_iterator_free(iterator);
git_index_free(index);
}
void validate_apply_index(
git_repository *repo,
struct merge_index_entry *index_entries,
size_t index_cnt)
{
git_index *index;
git_iterator *iterator;
struct iterator_compare_data data = { index_entries, index_cnt };
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_iterator_for_index(&iterator, repo, index, NULL));
cl_git_pass(git_iterator_foreach(iterator, iterator_compare, &data));
cl_assert_equal_i(data.idx, data.cnt);
git_iterator_free(iterator);
git_index_free(index);
}
static int iterator_eq(const git_index_entry **entry, void *_data)
{
GIT_UNUSED(_data);
if (!entry[0] || !entry[1])
return -1;
cl_assert_equal_i(GIT_IDXENTRY_STAGE(entry[0]), GIT_IDXENTRY_STAGE(entry[1]));
cl_assert_equal_oid(&entry[0]->id, &entry[1]->id);
cl_assert_equal_i(entry[0]->mode, entry[1]->mode);
cl_assert_equal_s(entry[0]->path, entry[1]->path);
return 0;
}
void validate_index_unchanged(git_repository *repo)
{
git_tree *head;
git_index *index;
git_iterator *head_iterator, *index_iterator, *iterators[2];
cl_git_pass(git_repository_head_tree(&head, repo));
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_iterator_for_tree(&head_iterator, head, NULL));
cl_git_pass(git_iterator_for_index(&index_iterator, repo, index, NULL));
iterators[0] = head_iterator;
iterators[1] = index_iterator;
cl_git_pass(git_iterator_walk(iterators, 2, iterator_eq, NULL));
git_iterator_free(head_iterator);
git_iterator_free(index_iterator);
git_tree_free(head);
git_index_free(index);
}
void validate_workdir_unchanged(git_repository *repo)
{
git_tree *head;
git_index *index;
git_iterator *head_iterator, *workdir_iterator, *iterators[2];
git_iterator_options workdir_opts = GIT_ITERATOR_OPTIONS_INIT;
cl_git_pass(git_repository_head_tree(&head, repo));
cl_git_pass(git_repository_index(&index, repo));
workdir_opts.flags |= GIT_ITERATOR_INCLUDE_HASH;
cl_git_pass(git_iterator_for_tree(&head_iterator, head, NULL));
cl_git_pass(git_iterator_for_workdir(&workdir_iterator, repo, index, NULL, &workdir_opts));
iterators[0] = head_iterator;
iterators[1] = workdir_iterator;
cl_git_pass(git_iterator_walk(iterators, 2, iterator_eq, NULL));
git_iterator_free(head_iterator);
git_iterator_free(workdir_iterator);
git_tree_free(head);
git_index_free(index);
}
...@@ -453,135 +453,15 @@ ...@@ -453,135 +453,15 @@
"-asparagus which had been laid by, boil it until these last articles are\n" \ "-asparagus which had been laid by, boil it until these last articles are\n" \
"-sufficiently done, thicken with flour, butter and milk, and serve it up.\n" "-sufficiently done, thicken with flour, butter and milk, and serve it up.\n"
struct iterator_compare_data { void validate_apply_workdir(
struct merge_index_entry *expected;
size_t cnt;
size_t idx;
};
static int iterator_compare(const git_index_entry *entry, void *_data)
{
git_oid expected_id;
struct iterator_compare_data *data = (struct iterator_compare_data *)_data;
cl_assert_equal_i(GIT_IDXENTRY_STAGE(entry), data->expected[data->idx].stage);
cl_git_pass(git_oid_fromstr(&expected_id, data->expected[data->idx].oid_str));
cl_assert_equal_oid(&entry->id, &expected_id);
cl_assert_equal_i(entry->mode, data->expected[data->idx].mode);
cl_assert_equal_s(entry->path, data->expected[data->idx].path);
if (data->idx >= data->cnt)
return -1;
data->idx++;
return 0;
}
static void validate_apply_workdir(
git_repository *repo, git_repository *repo,
struct merge_index_entry *workdir_entries, struct merge_index_entry *workdir_entries,
size_t workdir_cnt) size_t workdir_cnt);
{
git_index *index;
git_iterator *iterator;
git_iterator_options opts = GIT_ITERATOR_OPTIONS_INIT;
struct iterator_compare_data data = { workdir_entries, workdir_cnt };
opts.flags |= GIT_ITERATOR_INCLUDE_HASH;
cl_git_pass(git_repository_index(&index, repo)); void validate_apply_index(
cl_git_pass(git_iterator_for_workdir(&iterator, repo, index, NULL, &opts));
cl_git_pass(git_iterator_foreach(iterator, iterator_compare, &data));
cl_assert_equal_i(data.idx, data.cnt);
git_iterator_free(iterator);
git_index_free(index);
}
static void validate_apply_index(
git_repository *repo, git_repository *repo,
struct merge_index_entry *index_entries, struct merge_index_entry *index_entries,
size_t index_cnt) size_t index_cnt);
{
git_index *index;
git_iterator *iterator;
struct iterator_compare_data data = { index_entries, index_cnt };
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_iterator_for_index(&iterator, repo, index, NULL));
cl_git_pass(git_iterator_foreach(iterator, iterator_compare, &data));
cl_assert_equal_i(data.idx, data.cnt);
git_iterator_free(iterator);
git_index_free(index);
}
static int iterator_eq(const git_index_entry **entry, void *_data)
{
GIT_UNUSED(_data);
if (!entry[0] || !entry[1])
return -1;
cl_assert_equal_i(GIT_IDXENTRY_STAGE(entry[0]), GIT_IDXENTRY_STAGE(entry[1]));
cl_assert_equal_oid(&entry[0]->id, &entry[1]->id);
cl_assert_equal_i(entry[0]->mode, entry[1]->mode);
cl_assert_equal_s(entry[0]->path, entry[1]->path);
return 0;
}
static void validate_index_unchanged(git_repository *repo)
{
git_tree *head;
git_index *index;
git_iterator *head_iterator, *index_iterator, *iterators[2];
cl_git_pass(git_repository_head_tree(&head, repo));
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_iterator_for_tree(&head_iterator, head, NULL));
cl_git_pass(git_iterator_for_index(&index_iterator, repo, index, NULL));
iterators[0] = head_iterator;
iterators[1] = index_iterator;
cl_git_pass(git_iterator_walk(iterators, 2, iterator_eq, NULL));
git_iterator_free(head_iterator);
git_iterator_free(index_iterator);
git_tree_free(head);
git_index_free(index);
}
static void validate_workdir_unchanged(git_repository *repo)
{
git_tree *head;
git_index *index;
git_iterator *head_iterator, *workdir_iterator, *iterators[2];
git_iterator_options workdir_opts = GIT_ITERATOR_OPTIONS_INIT;
cl_git_pass(git_repository_head_tree(&head, repo));
cl_git_pass(git_repository_index(&index, repo));
workdir_opts.flags |= GIT_ITERATOR_INCLUDE_HASH;
cl_git_pass(git_iterator_for_tree(&head_iterator, head, NULL));
cl_git_pass(git_iterator_for_workdir(&workdir_iterator, repo, index, NULL, &workdir_opts));
iterators[0] = head_iterator;
iterators[1] = workdir_iterator;
cl_git_pass(git_iterator_walk(iterators, 2, iterator_eq, NULL));
git_iterator_free(head_iterator);
git_iterator_free(workdir_iterator);
git_tree_free(head); void validate_index_unchanged(git_repository *repo);
git_index_free(index); void validate_workdir_unchanged(git_repository *repo);
}
...@@ -28,7 +28,7 @@ void test_core_oidmap__basic(void) ...@@ -28,7 +28,7 @@ void test_core_oidmap__basic(void)
cl_assert(map != NULL); cl_assert(map != NULL);
for (i = 0; i < NITEMS; ++i) { for (i = 0; i < NITEMS; ++i) {
khiter_t pos; size_t pos;
int ret; int ret;
pos = git_oidmap_lookup_index(map, &items[i].oid); pos = git_oidmap_lookup_index(map, &items[i].oid);
...@@ -42,7 +42,7 @@ void test_core_oidmap__basic(void) ...@@ -42,7 +42,7 @@ void test_core_oidmap__basic(void)
for (i = 0; i < NITEMS; ++i) { for (i = 0; i < NITEMS; ++i) {
khiter_t pos; size_t pos;
pos = git_oidmap_lookup_index(map, &items[i].oid); pos = git_oidmap_lookup_index(map, &items[i].oid);
cl_assert(git_oidmap_valid_index(map, pos)); cl_assert(git_oidmap_valid_index(map, pos));
...@@ -82,7 +82,7 @@ void test_core_oidmap__hash_collision(void) ...@@ -82,7 +82,7 @@ void test_core_oidmap__hash_collision(void)
cl_assert(map != NULL); cl_assert(map != NULL);
for (i = 0; i < NITEMS; ++i) { for (i = 0; i < NITEMS; ++i) {
khiter_t pos; size_t pos;
int ret; int ret;
pos = git_oidmap_lookup_index(map, &items[i].oid); pos = git_oidmap_lookup_index(map, &items[i].oid);
...@@ -96,7 +96,7 @@ void test_core_oidmap__hash_collision(void) ...@@ -96,7 +96,7 @@ void test_core_oidmap__hash_collision(void)
for (i = 0; i < NITEMS; ++i) { for (i = 0; i < NITEMS; ++i) {
khiter_t pos; size_t pos;
pos = git_oidmap_lookup_index(map, &items[i].oid); pos = git_oidmap_lookup_index(map, &items[i].oid);
cl_assert(git_oidmap_valid_index(map, pos)); cl_assert(git_oidmap_valid_index(map, pos));
......
...@@ -60,7 +60,7 @@ void test_core_strmap__1(void) ...@@ -60,7 +60,7 @@ void test_core_strmap__1(void)
void test_core_strmap__2(void) void test_core_strmap__2(void)
{ {
khiter_t pos; size_t pos;
int i; int i;
char *str; char *str;
......
...@@ -7,29 +7,6 @@ typedef struct mailmap_entry { ...@@ -7,29 +7,6 @@ typedef struct mailmap_entry {
const char *replace_email; const char *replace_email;
} mailmap_entry; } mailmap_entry;
static const char string_mailmap[] =
"# Simple Comment line\n"
"<cto@company.xx> <cto@coompany.xx>\n"
"Some Dude <some@dude.xx> nick1 <bugs@company.xx>\n"
"Other Author <other@author.xx> nick2 <bugs@company.xx>\n"
"Other Author <other@author.xx> <nick2@company.xx>\n"
"Phil Hill <phil@company.xx> # Comment at end of line\n"
"<joseph@company.xx> Joseph <bugs@company.xx>\n"
"Santa Claus <santa.claus@northpole.xx> <me@company.xx>\n"
"Untracked <untracked@company.xx>";
static const mailmap_entry entries[] = {
{ NULL, "cto@company.xx", NULL, "cto@coompany.xx" },
{ "Some Dude", "some@dude.xx", "nick1", "bugs@company.xx" },
{ "Other Author", "other@author.xx", "nick2", "bugs@company.xx" },
{ "Other Author", "other@author.xx", NULL, "nick2@company.xx" },
{ "Phil Hill", NULL, NULL, "phil@company.xx" },
{ NULL, "joseph@company.xx", "Joseph", "bugs@company.xx" },
{ "Santa Claus", "santa.claus@northpole.xx", NULL, "me@company.xx" },
/* This entry isn't in the bare repository */
{ "Untracked", NULL, NULL, "untracked@company.xx" }
};
static const mailmap_entry resolved[] = { static const mailmap_entry resolved[] = {
{ "Brad", "cto@company.xx", "Brad", "cto@coompany.xx" }, { "Brad", "cto@company.xx", "Brad", "cto@coompany.xx" },
{ "Brad L", "cto@company.xx", "Brad L", "cto@coompany.xx" }, { "Brad L", "cto@company.xx", "Brad L", "cto@coompany.xx" },
......
...@@ -8,6 +8,29 @@ static git_repository *g_repo; ...@@ -8,6 +8,29 @@ static git_repository *g_repo;
static git_mailmap *g_mailmap; static git_mailmap *g_mailmap;
static git_config *g_config; static git_config *g_config;
static const char string_mailmap[] =
"# Simple Comment line\n"
"<cto@company.xx> <cto@coompany.xx>\n"
"Some Dude <some@dude.xx> nick1 <bugs@company.xx>\n"
"Other Author <other@author.xx> nick2 <bugs@company.xx>\n"
"Other Author <other@author.xx> <nick2@company.xx>\n"
"Phil Hill <phil@company.xx> # Comment at end of line\n"
"<joseph@company.xx> Joseph <bugs@company.xx>\n"
"Santa Claus <santa.claus@northpole.xx> <me@company.xx>\n"
"Untracked <untracked@company.xx>";
static const mailmap_entry entries[] = {
{ NULL, "cto@company.xx", NULL, "cto@coompany.xx" },
{ "Some Dude", "some@dude.xx", "nick1", "bugs@company.xx" },
{ "Other Author", "other@author.xx", "nick2", "bugs@company.xx" },
{ "Other Author", "other@author.xx", NULL, "nick2@company.xx" },
{ "Phil Hill", NULL, NULL, "phil@company.xx" },
{ NULL, "joseph@company.xx", "Joseph", "bugs@company.xx" },
{ "Santa Claus", "santa.claus@northpole.xx", NULL, "me@company.xx" },
/* This entry isn't in the bare repository */
{ "Untracked", NULL, NULL, "untracked@company.xx" }
};
void test_mailmap_parsing__initialize(void) void test_mailmap_parsing__initialize(void)
{ {
g_repo = NULL; g_repo = NULL;
......
...@@ -11,7 +11,7 @@ void test_pack_sharing__open_two_repos(void) ...@@ -11,7 +11,7 @@ void test_pack_sharing__open_two_repos(void)
git_repository *repo1, *repo2; git_repository *repo1, *repo2;
git_object *obj1, *obj2; git_object *obj1, *obj2;
git_oid id; git_oid id;
git_strmap_iter pos; size_t pos;
void *data; void *data;
int error; int error;
......
...@@ -129,9 +129,9 @@ void test_path_win32__absolute_from_relative(void) ...@@ -129,9 +129,9 @@ void test_path_win32__absolute_from_relative(void)
#endif #endif
} }
#ifdef GIT_WIN32
static void test_canonicalize(const wchar_t *in, const wchar_t *expected) static void test_canonicalize(const wchar_t *in, const wchar_t *expected)
{ {
#ifdef GIT_WIN32
git_win32_path canonical; git_win32_path canonical;
cl_assert(wcslen(in) < MAX_PATH); cl_assert(wcslen(in) < MAX_PATH);
...@@ -139,11 +139,8 @@ static void test_canonicalize(const wchar_t *in, const wchar_t *expected) ...@@ -139,11 +139,8 @@ static void test_canonicalize(const wchar_t *in, const wchar_t *expected)
cl_must_pass(git_win32_path_canonicalize(canonical)); cl_must_pass(git_win32_path_canonicalize(canonical));
cl_assert_equal_wcs(expected, canonical); cl_assert_equal_wcs(expected, canonical);
#else
GIT_UNUSED(in);
GIT_UNUSED(expected);
#endif
} }
#endif
static void test_remove_namespace(const wchar_t *in, const wchar_t *expected) static void test_remove_namespace(const wchar_t *in, const wchar_t *expected)
{ {
......
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