Skip to content

Commit 9d57a7a

Browse files
committed
hashmap_oid: introduce hashmap_oid
A hashmap that uses git_oid's as keys. Move the hashcode function out of git_oid.
1 parent 7ca51a8 commit 9d57a7a

File tree

16 files changed

+57
-40
lines changed

16 files changed

+57
-40
lines changed

src/libgit2/cache.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#include "odb.h"
1515
#include "object.h"
1616
#include "git2/oid.h"
17-
#include "hashmap.h"
17+
#include "hashmap_oid.h"
1818

19-
GIT_HASHMAP_FUNCTIONS(git_cache_oidmap, GIT_HASHMAP_INLINE, const git_oid *, git_cached_obj *, git_oid_hash32, git_oid_equal);
19+
GIT_HASHMAP_OID_FUNCTIONS(git_cache_oidmap, GIT_HASHMAP_INLINE, git_cached_obj *);
2020

2121
bool git_cache__enabled = true;
2222
ssize_t git_cache__max_storage = (256 * 1024 * 1024);

src/libgit2/cache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "git2/odb.h"
1515

1616
#include "thread.h"
17-
#include "hashmap.h"
17+
#include "hashmap_oid.h"
1818

1919
enum {
2020
GIT_CACHE_STORE_ANY = 0,
@@ -30,7 +30,7 @@ typedef struct {
3030
git_atomic32 refcount;
3131
} git_cached_obj;
3232

33-
GIT_HASHMAP_STRUCT(git_cache_oidmap, const git_oid *, git_cached_obj *);
33+
GIT_HASHMAP_OID_STRUCT(git_cache_oidmap, git_cached_obj *);
3434

3535
typedef struct {
3636
git_cache_oidmap map;

src/libgit2/commit_graph.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ enum generation_number_commit_state {
839839
GENERATION_NUMBER_COMMIT_STATE_VISITED = 3
840840
};
841841

842-
GIT_HASHMAP_SETUP(git_commit_graph_oidmap, const git_oid *, struct packed_commit *, git_oid_hash32, git_oid_equal);
842+
GIT_HASHMAP_OID_SETUP(git_commit_graph_oidmap, struct packed_commit *);
843843

844844
static int compute_generation_numbers(git_vector *commits)
845845
{

src/libgit2/describe.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "tag.h"
2222
#include "vector.h"
2323
#include "wildmatch.h"
24-
#include "hashmap.h"
24+
#include "hashmap_oid.h"
2525

2626
/* Ported from https://github.com/git/git/blob/89dde7882f71f846ccd0359756d27bebc31108de/builtin/describe.c */
2727

@@ -36,7 +36,7 @@ struct commit_name {
3636
git_oid peeled;
3737
};
3838

39-
GIT_HASHMAP_SETUP(git_describe_oidmap, const git_oid *, struct commit_name *, git_oid_hash32, git_oid_equal);
39+
GIT_HASHMAP_OID_SETUP(git_describe_oidmap, struct commit_name *);
4040

4141
static struct commit_name *find_commit_name(
4242
git_describe_oidmap *names,

src/libgit2/grafts.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
#include "oid.h"
1212
#include "oidarray.h"
1313
#include "parse.h"
14-
#include "hashmap.h"
14+
#include "hashmap_oid.h"
1515

16-
GIT_HASHMAP_SETUP(git_grafts_oidmap, const git_oid *, git_commit_graft *, git_oid_hash32, git_oid_equal);
16+
GIT_HASHMAP_OID_SETUP(git_grafts_oidmap, git_commit_graft *);
1717

1818
struct git_grafts {
1919
/* Map of `git_commit_graft`s */

src/libgit2/hashmap_oid.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (C) the libgit2 contributors. All rights reserved.
3+
*
4+
* This file is part of libgit2, distributed under the GNU GPL v2 with
5+
* a Linking Exception. For full terms see the included COPYING file.
6+
*/
7+
#ifndef INCLUDE_hashmap_oid_h__
8+
#define INCLUDE_hashmap_oid_h__
9+
10+
#include "hashmap.h"
11+
12+
GIT_INLINE(uint32_t) git_hashmap_oid_hashcode(const git_oid *oid)
13+
{
14+
uint32_t hash;
15+
memcpy(&hash, oid->id, sizeof(uint32_t));
16+
return hash;
17+
}
18+
19+
#define GIT_HASHMAP_OID_STRUCT(name, val_t) \
20+
GIT_HASHMAP_STRUCT(name, const git_oid *, val_t)
21+
#define GIT_HASHMAP_OID_PROTOTYPES(name, val_t) \
22+
GIT_HASHMAP_PROTOTYPES(name, const git_oid *, val_t)
23+
#define GIT_HASHMAP_OID_FUNCTIONS(name, scope, val_t) \
24+
GIT_HASHMAP_FUNCTIONS(name, scope, const git_oid *, val_t, git_hashmap_oid_hashcode, git_oid_equal)
25+
26+
#define GIT_HASHMAP_OID_SETUP(name, val_t) \
27+
GIT_HASHMAP_OID_STRUCT(name, val_t) \
28+
GIT_HASHMAP_OID_FUNCTIONS(name, GIT_HASHMAP_INLINE, val_t)
29+
30+
#endif

src/libgit2/indexer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
#include "oidarray.h"
2323
#include "zstream.h"
2424
#include "object.h"
25-
#include "hashmap.h"
25+
#include "hashmap_oid.h"
2626

2727
size_t git_indexer__max_objects = UINT32_MAX;
2828

2929
#define UINT31_MAX (0x7FFFFFFF)
3030

31-
GIT_HASHMAP_SETUP(git_indexer_oidmap, const git_oid *, git_oid *, git_oid_hash32, git_oid_equal);
31+
GIT_HASHMAP_OID_SETUP(git_indexer_oidmap, git_oid *);
3232

3333
struct entry {
3434
git_oid oid;

src/libgit2/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ typedef struct {
11431143
size_t first_entry;
11441144
} deletes_by_oid_queue;
11451145

1146-
GIT_HASHMAP_SETUP(git_merge_deletes_oidmap, const git_oid *, deletes_by_oid_queue *, git_oid_hash32, git_oid_equal);
1146+
GIT_HASHMAP_OID_SETUP(git_merge_deletes_oidmap, deletes_by_oid_queue *);
11471147

11481148
static void deletes_by_oid_dispose(git_merge_deletes_oidmap *map)
11491149
{

src/libgit2/odb_mempack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct memobject {
2828
char data[GIT_FLEX_ARRAY];
2929
};
3030

31-
GIT_HASHMAP_SETUP(git_odb_mempack_oidmap, const git_oid *, struct memobject *, git_oid_hash32, git_oid_equal);
31+
GIT_HASHMAP_OID_SETUP(git_odb_mempack_oidmap, struct memobject *);
3232

3333
struct memory_packer_db {
3434
git_odb_backend parent;

src/libgit2/oid.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -256,22 +256,6 @@ GIT_INLINE(void) git_oid_clear(git_oid *out, git_oid_t type)
256256
#endif
257257
}
258258

259-
/* A 32 bit representation suitable for a hashmap key */
260-
GIT_INLINE(uint32_t) git_oid_hash32(const git_oid *oid)
261-
{
262-
uint32_t hash;
263-
memcpy(&hash, oid->id, sizeof(uint32_t));
264-
return hash;
265-
}
266-
267-
/* A 64 bit representation suitable for a hashmap key */
268-
GIT_INLINE(uint64_t) git_oid_hash64(const git_oid *oid)
269-
{
270-
uint64_t hash;
271-
memcpy(&hash, oid->id, sizeof(uint64_t));
272-
return hash;
273-
}
274-
275259
/* SHA256 support */
276260

277261
int git_oid__fromstr(git_oid *out, const char *str, git_oid_t type);

0 commit comments

Comments
 (0)