mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
hashmap_oid: introduce hashmap_oid
A hashmap that uses git_oid's as keys. Move the hashcode function out of git_oid.
This commit is contained in:
@@ -14,9 +14,9 @@
|
||||
#include "odb.h"
|
||||
#include "object.h"
|
||||
#include "git2/oid.h"
|
||||
#include "hashmap.h"
|
||||
#include "hashmap_oid.h"
|
||||
|
||||
GIT_HASHMAP_FUNCTIONS(git_cache_oidmap, GIT_HASHMAP_INLINE, const git_oid *, git_cached_obj *, git_oid_hash32, git_oid_equal);
|
||||
GIT_HASHMAP_OID_FUNCTIONS(git_cache_oidmap, GIT_HASHMAP_INLINE, git_cached_obj *);
|
||||
|
||||
bool git_cache__enabled = true;
|
||||
ssize_t git_cache__max_storage = (256 * 1024 * 1024);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#include "git2/odb.h"
|
||||
|
||||
#include "thread.h"
|
||||
#include "hashmap.h"
|
||||
#include "hashmap_oid.h"
|
||||
|
||||
enum {
|
||||
GIT_CACHE_STORE_ANY = 0,
|
||||
@@ -30,7 +30,7 @@ typedef struct {
|
||||
git_atomic32 refcount;
|
||||
} git_cached_obj;
|
||||
|
||||
GIT_HASHMAP_STRUCT(git_cache_oidmap, const git_oid *, git_cached_obj *);
|
||||
GIT_HASHMAP_OID_STRUCT(git_cache_oidmap, git_cached_obj *);
|
||||
|
||||
typedef struct {
|
||||
git_cache_oidmap map;
|
||||
|
||||
@@ -839,7 +839,7 @@ enum generation_number_commit_state {
|
||||
GENERATION_NUMBER_COMMIT_STATE_VISITED = 3
|
||||
};
|
||||
|
||||
GIT_HASHMAP_SETUP(git_commit_graph_oidmap, const git_oid *, struct packed_commit *, git_oid_hash32, git_oid_equal);
|
||||
GIT_HASHMAP_OID_SETUP(git_commit_graph_oidmap, struct packed_commit *);
|
||||
|
||||
static int compute_generation_numbers(git_vector *commits)
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "tag.h"
|
||||
#include "vector.h"
|
||||
#include "wildmatch.h"
|
||||
#include "hashmap.h"
|
||||
#include "hashmap_oid.h"
|
||||
|
||||
/* Ported from https://github.com/git/git/blob/89dde7882f71f846ccd0359756d27bebc31108de/builtin/describe.c */
|
||||
|
||||
@@ -36,7 +36,7 @@ struct commit_name {
|
||||
git_oid peeled;
|
||||
};
|
||||
|
||||
GIT_HASHMAP_SETUP(git_describe_oidmap, const git_oid *, struct commit_name *, git_oid_hash32, git_oid_equal);
|
||||
GIT_HASHMAP_OID_SETUP(git_describe_oidmap, struct commit_name *);
|
||||
|
||||
static struct commit_name *find_commit_name(
|
||||
git_describe_oidmap *names,
|
||||
|
||||
@@ -11,9 +11,9 @@
|
||||
#include "oid.h"
|
||||
#include "oidarray.h"
|
||||
#include "parse.h"
|
||||
#include "hashmap.h"
|
||||
#include "hashmap_oid.h"
|
||||
|
||||
GIT_HASHMAP_SETUP(git_grafts_oidmap, const git_oid *, git_commit_graft *, git_oid_hash32, git_oid_equal);
|
||||
GIT_HASHMAP_OID_SETUP(git_grafts_oidmap, git_commit_graft *);
|
||||
|
||||
struct git_grafts {
|
||||
/* Map of `git_commit_graft`s */
|
||||
|
||||
30
src/libgit2/hashmap_oid.h
Normal file
30
src/libgit2/hashmap_oid.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) the libgit2 contributors. All rights reserved.
|
||||
*
|
||||
* This file is part of libgit2, distributed under the GNU GPL v2 with
|
||||
* a Linking Exception. For full terms see the included COPYING file.
|
||||
*/
|
||||
#ifndef INCLUDE_hashmap_oid_h__
|
||||
#define INCLUDE_hashmap_oid_h__
|
||||
|
||||
#include "hashmap.h"
|
||||
|
||||
GIT_INLINE(uint32_t) git_hashmap_oid_hashcode(const git_oid *oid)
|
||||
{
|
||||
uint32_t hash;
|
||||
memcpy(&hash, oid->id, sizeof(uint32_t));
|
||||
return hash;
|
||||
}
|
||||
|
||||
#define GIT_HASHMAP_OID_STRUCT(name, val_t) \
|
||||
GIT_HASHMAP_STRUCT(name, const git_oid *, val_t)
|
||||
#define GIT_HASHMAP_OID_PROTOTYPES(name, val_t) \
|
||||
GIT_HASHMAP_PROTOTYPES(name, const git_oid *, val_t)
|
||||
#define GIT_HASHMAP_OID_FUNCTIONS(name, scope, val_t) \
|
||||
GIT_HASHMAP_FUNCTIONS(name, scope, const git_oid *, val_t, git_hashmap_oid_hashcode, git_oid_equal)
|
||||
|
||||
#define GIT_HASHMAP_OID_SETUP(name, val_t) \
|
||||
GIT_HASHMAP_OID_STRUCT(name, val_t) \
|
||||
GIT_HASHMAP_OID_FUNCTIONS(name, GIT_HASHMAP_INLINE, val_t)
|
||||
|
||||
#endif
|
||||
@@ -22,13 +22,13 @@
|
||||
#include "oidarray.h"
|
||||
#include "zstream.h"
|
||||
#include "object.h"
|
||||
#include "hashmap.h"
|
||||
#include "hashmap_oid.h"
|
||||
|
||||
size_t git_indexer__max_objects = UINT32_MAX;
|
||||
|
||||
#define UINT31_MAX (0x7FFFFFFF)
|
||||
|
||||
GIT_HASHMAP_SETUP(git_indexer_oidmap, const git_oid *, git_oid *, git_oid_hash32, git_oid_equal);
|
||||
GIT_HASHMAP_OID_SETUP(git_indexer_oidmap, git_oid *);
|
||||
|
||||
struct entry {
|
||||
git_oid oid;
|
||||
|
||||
@@ -1143,7 +1143,7 @@ typedef struct {
|
||||
size_t first_entry;
|
||||
} deletes_by_oid_queue;
|
||||
|
||||
GIT_HASHMAP_SETUP(git_merge_deletes_oidmap, const git_oid *, deletes_by_oid_queue *, git_oid_hash32, git_oid_equal);
|
||||
GIT_HASHMAP_OID_SETUP(git_merge_deletes_oidmap, deletes_by_oid_queue *);
|
||||
|
||||
static void deletes_by_oid_dispose(git_merge_deletes_oidmap *map)
|
||||
{
|
||||
|
||||
@@ -28,7 +28,7 @@ struct memobject {
|
||||
char data[GIT_FLEX_ARRAY];
|
||||
};
|
||||
|
||||
GIT_HASHMAP_SETUP(git_odb_mempack_oidmap, const git_oid *, struct memobject *, git_oid_hash32, git_oid_equal);
|
||||
GIT_HASHMAP_OID_SETUP(git_odb_mempack_oidmap, struct memobject *);
|
||||
|
||||
struct memory_packer_db {
|
||||
git_odb_backend parent;
|
||||
|
||||
@@ -256,22 +256,6 @@ GIT_INLINE(void) git_oid_clear(git_oid *out, git_oid_t type)
|
||||
#endif
|
||||
}
|
||||
|
||||
/* A 32 bit representation suitable for a hashmap key */
|
||||
GIT_INLINE(uint32_t) git_oid_hash32(const git_oid *oid)
|
||||
{
|
||||
uint32_t hash;
|
||||
memcpy(&hash, oid->id, sizeof(uint32_t));
|
||||
return hash;
|
||||
}
|
||||
|
||||
/* A 64 bit representation suitable for a hashmap key */
|
||||
GIT_INLINE(uint64_t) git_oid_hash64(const git_oid *oid)
|
||||
{
|
||||
uint64_t hash;
|
||||
memcpy(&hash, oid->id, sizeof(uint64_t));
|
||||
return hash;
|
||||
}
|
||||
|
||||
/* SHA256 support */
|
||||
|
||||
int git_oid__fromstr(git_oid *out, const char *str, git_oid_t type);
|
||||
|
||||
@@ -64,8 +64,8 @@ struct walk_object {
|
||||
/* Size of the buffer to feed to zlib */
|
||||
#define COMPRESS_BUFLEN (1024 * 1024)
|
||||
|
||||
GIT_HASHMAP_FUNCTIONS(git_packbuilder_pobjectmap, GIT_HASHMAP_INLINE, const git_oid *, git_pobject *, git_oid_hash32, git_oid_equal);
|
||||
GIT_HASHMAP_FUNCTIONS(git_packbuilder_walk_objectmap, GIT_HASHMAP_INLINE, const git_oid *, struct walk_object *, git_oid_hash32, git_oid_equal);
|
||||
GIT_HASHMAP_OID_FUNCTIONS(git_packbuilder_pobjectmap, GIT_HASHMAP_INLINE, git_pobject *);
|
||||
GIT_HASHMAP_OID_FUNCTIONS(git_packbuilder_walk_objectmap, GIT_HASHMAP_INLINE, struct walk_object *);
|
||||
|
||||
static unsigned name_hash(const char *name)
|
||||
{
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#include "zstream.h"
|
||||
#include "pool.h"
|
||||
#include "indexer.h"
|
||||
#include "hashmap.h"
|
||||
#include "hashmap_oid.h"
|
||||
|
||||
#include "git2/oid.h"
|
||||
#include "git2/pack.h"
|
||||
@@ -53,8 +53,8 @@ typedef struct git_pobject {
|
||||
|
||||
typedef struct walk_object walk_object;
|
||||
|
||||
GIT_HASHMAP_STRUCT(git_packbuilder_pobjectmap, const git_oid *, git_pobject *);
|
||||
GIT_HASHMAP_STRUCT(git_packbuilder_walk_objectmap, const git_oid *, walk_object *);
|
||||
GIT_HASHMAP_OID_STRUCT(git_packbuilder_pobjectmap, git_pobject *);
|
||||
GIT_HASHMAP_OID_STRUCT(git_packbuilder_walk_objectmap, walk_object *);
|
||||
|
||||
struct git_packbuilder {
|
||||
git_repository *repo; /* associated repository */
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "odb.h"
|
||||
#include "oid.h"
|
||||
#include "oidarray.h"
|
||||
#include "hashmap_oid.h"
|
||||
|
||||
/* Option to bypass checking existence of '.keep' files */
|
||||
bool git_disable_pack_keep_file_checks = false;
|
||||
@@ -45,7 +46,7 @@ static int pack_entry_find_offset(
|
||||
#define off64_equal(a, b) ((a) == (b))
|
||||
|
||||
GIT_HASHMAP_FUNCTIONS(git_pack_offsetmap, GIT_HASHMAP_INLINE, off64_t, git_pack_cache_entry *, off64_hash, off64_equal);
|
||||
GIT_HASHMAP_FUNCTIONS(git_pack_oidmap, , const git_oid *, struct git_pack_entry *, git_oid_hash32, git_oid_equal);
|
||||
GIT_HASHMAP_OID_FUNCTIONS(git_pack_oidmap, , struct git_pack_entry *);
|
||||
|
||||
static int packfile_error(const char *message)
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include "odb.h"
|
||||
#include "zstream.h"
|
||||
#include "oid.h"
|
||||
#include "hashmap_oid.h"
|
||||
|
||||
/**
|
||||
* Function type for callbacks from git_pack_foreach_entry_offset.
|
||||
@@ -89,8 +90,8 @@ struct git_pack_entry {
|
||||
|
||||
GIT_HASHMAP_STRUCT(git_pack_offsetmap, off64_t, git_pack_cache_entry *);
|
||||
|
||||
GIT_HASHMAP_STRUCT(git_pack_oidmap, const git_oid *, struct git_pack_entry *);
|
||||
GIT_HASHMAP_PROTOTYPES(git_pack_oidmap, const git_oid *, struct git_pack_entry *);
|
||||
GIT_HASHMAP_OID_STRUCT(git_pack_oidmap, struct git_pack_entry *);
|
||||
GIT_HASHMAP_OID_PROTOTYPES(git_pack_oidmap, struct git_pack_entry *);
|
||||
|
||||
typedef struct {
|
||||
size_t memory_used;
|
||||
|
||||
@@ -14,8 +14,9 @@
|
||||
#include "git2/revparse.h"
|
||||
#include "merge.h"
|
||||
#include "vector.h"
|
||||
#include "hashmap_oid.h"
|
||||
|
||||
GIT_HASHMAP_FUNCTIONS(git_revwalk_oidmap, GIT_HASHMAP_INLINE, const git_oid *, git_commit_list_node *, git_oid_hash32, git_oid_equal);
|
||||
GIT_HASHMAP_OID_FUNCTIONS(git_revwalk_oidmap, GIT_HASHMAP_INLINE, git_commit_list_node *);
|
||||
|
||||
static int get_revision(git_commit_list_node **out, git_revwalk *walk, git_commit_list **list);
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@
|
||||
#include "pqueue.h"
|
||||
#include "pool.h"
|
||||
#include "vector.h"
|
||||
#include "hashmap.h"
|
||||
#include "hashmap_oid.h"
|
||||
|
||||
GIT_HASHMAP_STRUCT(git_revwalk_oidmap, const git_oid *, git_commit_list_node *);
|
||||
GIT_HASHMAP_OID_STRUCT(git_revwalk_oidmap, git_commit_list_node *);
|
||||
|
||||
struct git_revwalk {
|
||||
git_repository *repo;
|
||||
|
||||
Reference in New Issue
Block a user