From 7d7cd8857a451ff50b126e452bcbdc0fb397db35 Mon Sep 17 00:00:00 2001 From: Vicent Marti Date: Fri, 3 Dec 2010 18:01:30 +0200 Subject: Decouple storage from ODB logic Comes with two default backends: loose object and packfiles. Signed-off-by: Vicent Marti --- src/odb.h | 61 ++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 17 deletions(-) (limited to 'src/odb.h') diff --git a/src/odb.h b/src/odb.h index a45b803b8..2726cbb46 100644 --- a/src/odb.h +++ b/src/odb.h @@ -1,22 +1,49 @@ #ifndef INCLUDE_odb_h__ #define INCLUDE_odb_h__ -/** First 4 bytes of a pack-*.idx file header. - * - * Note this header exists only in idx v2 and later. The idx v1 - * file format does not have a magic sequence at the front, and - * must be detected by the first four bytes *not* being this value - * and the first 8 bytes matching the following expression: - * - * uint32_t *fanout = ... the file data at offset 0 ... - * ntohl(fanout[0]) < ntohl(fanout[1]) - * - * The value chosen here for PACK_TOC is such that the above - * cannot be true for an idx v1 file. - */ -#define PACK_TOC 0xff744f63 /* -1tOc */ - -/** First 4 bytes of a pack-*.pack file header. */ -#define PACK_SIG 0x5041434b /* PACK */ +#include +#include + +#include "vector.h" + +struct git_odb { + void *_internal; + git_vector backends; +}; + +struct git_odb_backend { + git_odb *odb; + + int priority; + + int (* read)( + git_rawobj *, + struct git_odb_backend *, + const git_oid *); + + int (* read_header)( + git_rawobj *, + struct git_odb_backend *, + const git_oid *); + + int (* write)( + git_oid *id, + struct git_odb_backend *, + git_rawobj *obj); + + int (* exists)( + struct git_odb_backend *, + const git_oid *); + + void (* free)(struct git_odb_backend *); + +}; + +int git_odb__hash_obj(git_oid *id, char *hdr, size_t n, int *len, git_rawobj *obj); +int git_odb__inflate_buffer(void *in, size_t inlen, void *out, size_t outlen); + + +int git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir); +int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir); #endif -- cgit v1.2.3