This just stores pairs of sha1s mapped to their similarity scores.
Signed-off-by: Jeff King <[email protected]>
---
Makefile | 5 +++++
cache.h | 5 +++++
map-sha1pair-uint32-params.h | 12 ++++++++++++
map-sha1pair-uint32.c | 8 ++++++++
map-sha1pair-uint32.h | 8 ++++++++
map-sha1pair.h | 22 ++++++++++++++++++++++
map-uint32.h | 16 ++++++++++++++++
metadata-cache.c | 3 +++
metadata-cache.h | 2 ++
9 files changed, 81 insertions(+)
create mode 100644 map-sha1pair-uint32-params.h
create mode 100644 map-sha1pair-uint32.c
create mode 100644 map-sha1pair-uint32.h
create mode 100644 map-sha1pair.h
create mode 100644 map-uint32.h
diff --git a/Makefile b/Makefile
index 08ddfa7..f020994 100644
--- a/Makefile
+++ b/Makefile
@@ -637,6 +637,10 @@ LIB_H += map-init.h
LIB_H += map-object-void-params.h
LIB_H += map-object-void.h
LIB_H += map-object.h
+LIB_H += map-sha1pair-uint32-params.h
+LIB_H += map-sha1pair-uint32.h
+LIB_H += map-sha1pair.h
+LIB_H += map-uint32.h
LIB_H += merge-file.h
LIB_H += merge-recursive.h
LIB_H += mergesort.h
@@ -752,6 +756,7 @@ LIB_OBJS += lockfile.o
LIB_OBJS += log-tree.o
LIB_OBJS += mailmap.o
LIB_OBJS += map-object-void.o
+LIB_OBJS += map-sha1pair-uint32.o
LIB_OBJS += match-trees.o
LIB_OBJS += merge-file.o
LIB_OBJS += merge-recursive.o
diff --git a/cache.h b/cache.h
index 67f28b4..23a2f93 100644
--- a/cache.h
+++ b/cache.h
@@ -677,6 +677,11 @@ static inline int is_empty_blob_sha1(const unsigned char
*sha1)
return !hashcmp(sha1, EMPTY_BLOB_SHA1_BIN);
}
+struct sha1pair {
+ unsigned char one[20];
+ unsigned char two[20];
+};
+
int git_mkstemp(char *path, size_t n, const char *template);
int git_mkstemps(char *path, size_t n, const char *template, int suffix_len);
diff --git a/map-sha1pair-uint32-params.h b/map-sha1pair-uint32-params.h
new file mode 100644
index 0000000..74c6506
--- /dev/null
+++ b/map-sha1pair-uint32-params.h
@@ -0,0 +1,12 @@
+#define NAME sha1pair_uint32
+#define PERSIST
+#define KEY_TYPE struct sha1pair
+#define PASS_KEY_BY_REF
+#define KEY_EQUAL sha1pair_equal
+#define KEY_SIZE 40
+#define KEY_TO_DISK sha1pair_to_disk
+#define HASH hash_sha1pair
+#define VALUE_TYPE uint32_t
+#define VALUE_SIZE 4
+#define VALUE_TO_DISK uint32_to_disk
+#define DISK_TO_VALUE disk_to_uint32
diff --git a/map-sha1pair-uint32.c b/map-sha1pair-uint32.c
new file mode 100644
index 0000000..93b3c16
--- /dev/null
+++ b/map-sha1pair-uint32.c
@@ -0,0 +1,8 @@
+#include "cache.h"
+#include "map-sha1pair-uint32.h"
+
+#include "map-sha1pair.h"
+#include "map-uint32.h"
+#include "map-sha1pair-uint32-params.h"
+#include "map-impl.h"
+#include "map-done.h"
diff --git a/map-sha1pair-uint32.h b/map-sha1pair-uint32.h
new file mode 100644
index 0000000..6e022fb
--- /dev/null
+++ b/map-sha1pair-uint32.h
@@ -0,0 +1,8 @@
+#ifndef MAP_SHA1PAIR_UINT32_H
+#define MAP_SHA1PAIR_UINT32_H
+
+#include "map-sha1pair-uint32-params.h"
+#include "map-decl.h"
+#include "map-done.h"
+
+#endif /* MAP_SHA1PAIR_UINT32_H */
diff --git a/map-sha1pair.h b/map-sha1pair.h
new file mode 100644
index 0000000..ea7ead8
--- /dev/null
+++ b/map-sha1pair.h
@@ -0,0 +1,22 @@
+#ifndef MAP_SHA1PAIR_H
+#define MAP_SHA1PAIR_H
+
+static inline unsigned int hash_sha1pair(const struct sha1pair *k, unsigned
int n)
+{
+ unsigned int hash;
+ memcpy(&hash, k, sizeof(unsigned int));
+ return hash % n;
+}
+
+static inline int sha1pair_equal(const struct sha1pair *a, const struct
sha1pair *b)
+{
+ return !hashcmp(a->one, b->one) && !hashcmp(a->two, b->two);
+}
+
+static inline void sha1pair_to_disk(const struct sha1pair *v, unsigned char
*out)
+{
+ hashcpy(out, v->one);
+ hashcpy(out+20, v->two);
+}
+
+#endif /* MAP_SHA1PAIR_H */
diff --git a/map-uint32.h b/map-uint32.h
new file mode 100644
index 0000000..ce63dac
--- /dev/null
+++ b/map-uint32.h
@@ -0,0 +1,16 @@
+#ifndef MAP_UINT32_H
+#define MAP_UINT32_H
+
+static inline void uint32_to_disk(uint32_t v, unsigned char *out)
+{
+ v = htonl(v);
+ memcpy(out, &v, 4);
+}
+
+static inline void disk_to_uint32(const unsigned char *in, uint32_t *v)
+{
+ memcpy(v, in, 4);
+ *v = ntohl(*v);
+}
+
+#endif /* MAP_UINT32_H */
diff --git a/metadata-cache.c b/metadata-cache.c
index 94eabfb..d70d116 100644
--- a/metadata-cache.c
+++ b/metadata-cache.c
@@ -1,5 +1,6 @@
#include "cache.h"
#include "metadata-cache.h"
+#include "map-sha1pair-uint32.h"
struct metadata_cache {
const char *name;
@@ -167,3 +168,5 @@ void name##_cache_set(ktype key, vtype value) \
metadata_cache_init(&name##_cache); \
map_persist_set_##maptype(&name##_map, key, value); \
}
+
+IMPLEMENT_CACHE(rename, sha1pair_uint32, const struct sha1pair *, uint32_t)
diff --git a/metadata-cache.h b/metadata-cache.h
index 4354023..f3e6f51 100644
--- a/metadata-cache.h
+++ b/metadata-cache.h
@@ -5,4 +5,6 @@
int name##_cache_get(ktype, vtype *); \
void name##_cache_set(ktype, vtype);
+DECLARE_CACHE(rename, const struct sha1pair *, uint32_t)
+
#endif /* METADATA_CACHE_H */
--
1.7.12.rc1.7.g7a223a6
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html