Commit b0233216 by Vicent Marti

Remove custom backends

All the custom backend code will be moved to a separate project,
	together with the new MySQL backend.
parent 0f49a589
......@@ -32,28 +32,6 @@ ELSEIF ()
SET(SHA1_TYPE "builtin" CACHE STRING "Which SHA1 implementation to use: builtin, ppc")
ENDIF ()
INCLUDE(FindPkgConfig)
# Show SQLite3 settings in GUI (if they won't be found out)
SET(SQLITE3_INCLUDE_DIRS "" CACHE PATH "SQLite include directory")
SET(SQLITE3_LIBRARIES "" CACHE FILEPATH "SQLite library")
# Are SQLite3 variables already set up? (poor Windows/no pkg-config/no sqlite3.pc)
IF (SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES)
SET(SQLITE3_FOUND 1)
ENDIF ()
# Try to find SQLite3 via pkg-config
IF (PKG_CONFIG_FOUND AND NOT SQLITE3_FOUND)
pkg_check_modules(SQLITE3 sqlite3)
ENDIF ()
# Compile SQLite backend if SQLite3 is available
IF (SQLITE3_FOUND)
ADD_DEFINITIONS(-DGIT2_SQLITE_BACKEND)
INCLUDE_DIRECTORIES(${SQLITE3_INCLUDE_DIRS})
ENDIF ()
# Installation paths
SET(INSTALL_BIN bin CACHE PATH "Where to install binaries to.")
SET(INSTALL_LIB lib CACHE PATH "Where to install libraries to.")
......
......@@ -110,10 +110,8 @@ typedef enum {
GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY),
} git_odb_streammode;
GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir);
GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir);
GIT_EXTERN(int) git_odb_backend_sqlite(git_odb_backend **backend_out, const char *sqlite_db);
GIT_END_DECL
......
/*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* In addition to the permissions in the GNU General Public License,
* the authors give you unlimited permission to link the compiled
* version of this file into combinations with other programs,
* and to distribute those combinations without any restriction
* coming from the use of this file. (The General Public License
* restrictions do apply in other respects; for example, they cover
* modification of the file, and distribution when not linked into
* a combined executable.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "common.h"
#include "git2/object.h"
#include "hash.h"
#include "odb.h"
#include "git2/odb_backend.h"
#ifdef GIT2_HIREDIS_BACKEND
#include <hiredis/hiredis.h>
typedef struct {
git_odb_backend parent;
redisContext *db;
} hiredis_backend;
int hiredis_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_backend *_backend, const git_oid *oid) {
hiredis_backend *backend;
int error;
redisReply *reply;
assert(len_p && type_p && _backend && oid);
backend = (hiredis_backend *) _backend;
error = GIT_ERROR;
reply = redisCommand(backend->db, "HMGET %b %s %s", oid->id, GIT_OID_RAWSZ,
"type", "size");
if (reply && reply->type == REDIS_REPLY_ARRAY) {
if (reply->element[0]->type != REDIS_REPLY_NIL &&
reply->element[0]->type != REDIS_REPLY_NIL) {
*type_p = (git_otype) atoi(reply->element[0]->str);
*len_p = (size_t) atoi(reply->element[1]->str);
error = GIT_SUCCESS;
} else {
error = GIT_ENOTFOUND;
}
} else {
error = GIT_ERROR;
}
freeReplyObject(reply);
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to read header");
}
int hiredis_backend__read(void **data_p, size_t *len_p, git_otype *type_p, git_odb_backend *_backend, const git_oid *oid) {
hiredis_backend *backend;
int error;
redisReply *reply;
assert(data_p && len_p && type_p && _backend && oid);
backend = (hiredis_backend *) _backend;
error = GIT_ERROR;
reply = redisCommand(backend->db, "HMGET %b %s %s %s", oid->id, GIT_OID_RAWSZ,
"type", "size", "data");
if (reply && reply->type == REDIS_REPLY_ARRAY) {
if (reply->element[0]->type != REDIS_REPLY_NIL &&
reply->element[1]->type != REDIS_REPLY_NIL &&
reply->element[2]->type != REDIS_REPLY_NIL) {
*type_p = (git_otype) atoi(reply->element[0]->str);
*len_p = (size_t) atoi(reply->element[1]->str);
*data_p = git__malloc(*len_p);
if (*data_p == NULL) {
error = GIT_ENOMEM;
} else {
memcpy(*data_p, reply->element[2]->str, *len_p);
error = GIT_SUCCESS;
}
} else {
error = GIT_ENOTFOUND;
}
} else {
error = GIT_ERROR;
}
freeReplyObject(reply);
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to read backend");
}
int hiredis_backend__read_prefix(git_oid *out_oid, void **data_p, size_t *len_p, git_otype *type_p, git_odb_backend *_backend,
const git_oid *short_oid, unsigned int len) {
if (len >= GIT_OID_HEXSZ) {
/* Just match the full identifier */
int error = hiredis_backend__read(data_p, len_p, type_p, backend, short_oid);
if (error == GIT_SUCCESS)
git_oid_cpy(out_oid, short_oid);
return error;
} else if (len < GIT_OID_HEXSZ) {
/* TODO */
return git__throw(GIT_ENOTIMPLEMENTED, "Hiredis backend cannot search objects from short oid");
}
}
int hiredis_backend__exists(git_odb_backend *_backend, const git_oid *oid) {
hiredis_backend *backend;
int found;
redisReply *reply;
assert(_backend && oid);
backend = (hiredis_backend *) _backend;
found = 0;
reply = redisCommand(backend->db, "exists %b", oid->id, GIT_OID_RAWSZ);
if (reply && reply->type != REDIS_REPLY_NIL && reply->type != REDIS_REPLY_ERROR)
found = 1;
freeReplyObject(reply);
return found;
}
int hiredis_backend__write(git_oid *id, git_odb_backend *_backend, const void *data, size_t len, git_otype type) {
hiredis_backend *backend;
int error;
redisReply *reply;
assert(id && _backend && data);
backend = (hiredis_backend *) _backend;
error = GIT_ERROR;
if ((error = git_odb_hash(id, data, len, type)) < 0)
return git__rethrow(error, "Failed to write backend");
reply = redisCommand(backend->db, "HMSET %b "
"type %d "
"size %d "
"data %b ", id->id, GIT_OID_RAWSZ,
(int) type, len, data, len);
error = (reply == NULL || reply->type == REDIS_REPLY_ERROR) ? GIT_ERROR : GIT_SUCCESS;
freeReplyObject(reply);
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to write backend");
}
void hiredis_backend__free(git_odb_backend *_backend) {
hiredis_backend *backend;
assert(_backend);
backend = (hiredis_backend *) _backend;
redisFree(backend->db);
free(backend);
}
int git_odb_backend_hiredis(git_odb_backend **backend_out, const char *host, int port) {
hiredis_backend *backend;
backend = git__calloc(1, sizeof (hiredis_backend));
if (backend == NULL)
return GIT_ENOMEM;
backend->db = redisConnect(host, port);
if (backend->db->err)
goto cleanup;
backend->parent.read = &hiredis_backend__read;
backend->parent.read_prefix = &hiredis_backend__read_prefix;
backend->parent.read_header = &hiredis_backend__read_header;
backend->parent.write = &hiredis_backend__write;
backend->parent.exists = &hiredis_backend__exists;
backend->parent.free = &hiredis_backend__free;
*backend_out = (git_odb_backend *) backend;
return GIT_SUCCESS;
cleanup:
free(backend);
return git__throw(GIT_ERROR, "Failed to get ODB backend");
}
#else
int git_odb_backend_hiredis(git_odb_backend ** GIT_UNUSED(backend_out),
const char *GIT_UNUSED(host), int GIT_UNUSED(port)) {
GIT_UNUSED_ARG(backend_out);
GIT_UNUSED_ARG(host);
GIT_UNUSED_ARG(port);
return git__throw(GIT_ENOTIMPLEMENTED, "Failed to get ODB backend. Feature not yet implemented");
}
#endif /* HAVE_HIREDIS */
/*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* In addition to the permissions in the GNU General Public License,
* the authors give you unlimited permission to link the compiled
* version of this file into combinations with other programs,
* and to distribute those combinations without any restriction
* coming from the use of this file. (The General Public License
* restrictions do apply in other respects; for example, they cover
* modification of the file, and distribution when not linked into
* a combined executable.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "common.h"
#include "git2/object.h"
#include "hash.h"
#include "odb.h"
#include "git2/odb_backend.h"
#ifdef GIT2_SQLITE_BACKEND
#include <sqlite3.h>
#define GIT2_TABLE_NAME "git2_odb"
typedef struct {
git_odb_backend parent;
sqlite3 *db;
sqlite3_stmt *st_read;
sqlite3_stmt *st_write;
sqlite3_stmt *st_read_header;
} sqlite_backend;
int sqlite_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_backend *_backend, const git_oid *oid)
{
sqlite_backend *backend;
int error;
assert(len_p && type_p && _backend && oid);
backend = (sqlite_backend *)_backend;
error = GIT_ERROR;
if (sqlite3_bind_text(backend->st_read_header, 1, (char *)oid->id, 20, SQLITE_TRANSIENT) == SQLITE_OK) {
if (sqlite3_step(backend->st_read_header) == SQLITE_ROW) {
*type_p = (git_otype)sqlite3_column_int(backend->st_read_header, 0);
*len_p = (size_t)sqlite3_column_int(backend->st_read_header, 1);
assert(sqlite3_step(backend->st_read_header) == SQLITE_DONE);
error = GIT_SUCCESS;
} else {
error = GIT_ENOTFOUND;
}
}
sqlite3_reset(backend->st_read_header);
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "SQLite backend: Failed to read header");
}
int sqlite_backend__read(void **data_p, size_t *len_p, git_otype *type_p, git_odb_backend *_backend, const git_oid *oid)
{
sqlite_backend *backend;
int error;
assert(data_p && len_p && type_p && _backend && oid);
backend = (sqlite_backend *)_backend;
error = GIT_ERROR;
if (sqlite3_bind_text(backend->st_read, 1, (char *)oid->id, 20, SQLITE_TRANSIENT) == SQLITE_OK) {
if (sqlite3_step(backend->st_read) == SQLITE_ROW) {
*type_p = (git_otype)sqlite3_column_int(backend->st_read, 0);
*len_p = (size_t)sqlite3_column_int(backend->st_read, 1);
*data_p = git__malloc(*len_p);
if (*data_p == NULL) {
error = GIT_ENOMEM;
} else {
memcpy(*data_p, sqlite3_column_blob(backend->st_read, 2), *len_p);
error = GIT_SUCCESS;
}
assert(sqlite3_step(backend->st_read) == SQLITE_DONE);
} else {
error = GIT_ENOTFOUND;
}
}
sqlite3_reset(backend->st_read);
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "SQLite backend: Failed to read");
}
int sqlite_backend__read_prefix(git_oid *out_oid, void **data_p, size_t *len_p, git_otype *type_p, git_odb_backend *_backend,
const git_oid *short_oid, unsigned int len) {
if (len >= GIT_OID_HEXSZ) {
/* Just match the full identifier */
int error = sqlite_backend__read(data_p, len_p, type_p, _backend, short_oid);
if (error == GIT_SUCCESS)
git_oid_cpy(out_oid, short_oid);
return error;
} else if (len < GIT_OID_HEXSZ) {
/* TODO */
return git__throw(GIT_ENOTIMPLEMENTED, "Sqlite backend cannot search objects from short oid");
}
}
int sqlite_backend__exists(git_odb_backend *_backend, const git_oid *oid)
{
sqlite_backend *backend;
int found;
assert(_backend && oid);
backend = (sqlite_backend *)_backend;
found = 0;
if (sqlite3_bind_text(backend->st_read_header, 1, (char *)oid->id, 20, SQLITE_TRANSIENT) == SQLITE_OK) {
if (sqlite3_step(backend->st_read_header) == SQLITE_ROW) {
found = 1;
assert(sqlite3_step(backend->st_read_header) == SQLITE_DONE);
}
}
sqlite3_reset(backend->st_read_header);
return found;
}
int sqlite_backend__write(git_oid *id, git_odb_backend *_backend, const void *data, size_t len, git_otype type)
{
int error;
sqlite_backend *backend;
assert(id && _backend && data);
backend = (sqlite_backend *)_backend;
if ((error = git_odb_hash(id, data, len, type)) < 0)
return git__rethrow(error, "SQLite backend: Failed to write");
error = SQLITE_ERROR;
if (sqlite3_bind_text(backend->st_write, 1, (char *)id->id, 20, SQLITE_TRANSIENT) == SQLITE_OK &&
sqlite3_bind_int(backend->st_write, 2, (int)type) == SQLITE_OK &&
sqlite3_bind_int(backend->st_write, 3, len) == SQLITE_OK &&
sqlite3_bind_blob(backend->st_write, 4, data, len, SQLITE_TRANSIENT) == SQLITE_OK) {
error = sqlite3_step(backend->st_write);
}
sqlite3_reset(backend->st_write);
return (error == SQLITE_DONE) ? GIT_SUCCESS : git__throw(GIT_ERROR, "SQLite backend: Failed to write");
}
void sqlite_backend__free(git_odb_backend *_backend)
{
sqlite_backend *backend;
assert(_backend);
backend = (sqlite_backend *)_backend;
sqlite3_finalize(backend->st_read);
sqlite3_finalize(backend->st_read_header);
sqlite3_finalize(backend->st_write);
sqlite3_close(backend->db);
free(backend);
}
static int create_table(sqlite3 *db)
{
static const char *sql_creat =
"CREATE TABLE '" GIT2_TABLE_NAME "' ("
"'oid' CHARACTER(20) PRIMARY KEY NOT NULL,"
"'type' INTEGER NOT NULL,"
"'size' INTEGER NOT NULL,"
"'data' BLOB);";
if (sqlite3_exec(db, sql_creat, NULL, NULL, NULL) != SQLITE_OK)
return git__throw(GIT_ERROR, "SQLite backend: Failed to create table");
return GIT_SUCCESS;
}
static int init_db(sqlite3 *db)
{
static const char *sql_check =
"SELECT name FROM sqlite_master WHERE type='table' AND name='" GIT2_TABLE_NAME "';";
sqlite3_stmt *st_check;
int error;
if (sqlite3_prepare_v2(db, sql_check, -1, &st_check, NULL) != SQLITE_OK)
return git__throw(GIT_ERROR, "SQLite backend: Failed to initialize database");
switch (sqlite3_step(st_check)) {
case SQLITE_DONE:
/* the table was not found */
error = create_table(db);
break;
case SQLITE_ROW:
/* the table was found */
error = GIT_SUCCESS;
break;
default:
error = GIT_ERROR;
break;
}
sqlite3_finalize(st_check);
return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "SQLite backend: Failed to initialize database");
}
static int init_statements(sqlite_backend *backend)
{
static const char *sql_read =
"SELECT type, size, data FROM '" GIT2_TABLE_NAME "' WHERE oid = ?;";
static const char *sql_read_header =
"SELECT type, size FROM '" GIT2_TABLE_NAME "' WHERE oid = ?;";
static const char *sql_write =
"INSERT OR IGNORE INTO '" GIT2_TABLE_NAME "' VALUES (?, ?, ?, ?);";
if (sqlite3_prepare_v2(backend->db, sql_read, -1, &backend->st_read, NULL) != SQLITE_OK)
return git__throw(GIT_ERROR, "SQLite backend: Failed to initialize statements");
if (sqlite3_prepare_v2(backend->db, sql_read_header, -1, &backend->st_read_header, NULL) != SQLITE_OK)
return git__throw(GIT_ERROR, "SQLite backend: Failed to initialize statements");
if (sqlite3_prepare_v2(backend->db, sql_write, -1, &backend->st_write, NULL) != SQLITE_OK)
return git__throw(GIT_ERROR, "SQLite backend: Failed to initialize statements");
return GIT_SUCCESS;
}
int git_odb_backend_sqlite(git_odb_backend **backend_out, const char *sqlite_db)
{
sqlite_backend *backend;
int error;
backend = git__calloc(1, sizeof(sqlite_backend));
if (backend == NULL)
return GIT_ENOMEM;
if (sqlite3_open(sqlite_db, &backend->db) != SQLITE_OK)
goto cleanup;
error = init_db(backend->db);
if (error < 0)
goto cleanup;
error = init_statements(backend);
if (error < 0)
goto cleanup;
backend->parent.read = &sqlite_backend__read;
backend->parent.read_prefix = &sqlite_backend__read_prefix;
backend->parent.read_header = &sqlite_backend__read_header;
backend->parent.write = &sqlite_backend__write;
backend->parent.exists = &sqlite_backend__exists;
backend->parent.free = &sqlite_backend__free;
*backend_out = (git_odb_backend *)backend;
return GIT_SUCCESS;
cleanup:
sqlite_backend__free((git_odb_backend *)backend);
return git__throw(GIT_ERROR, "SQLite backend: Failed to get ODB backend");
}
#else
int git_odb_backend_sqlite(git_odb_backend **GIT_UNUSED(backend_out), const char *GIT_UNUSED(sqlite_db))
{
GIT_UNUSED_ARG(backend_out);
GIT_UNUSED_ARG(sqlite_db);
return git__throw(GIT_ENOTIMPLEMENTED, "SQLite backend: Failed to get ODB backend. Operation not yet implemented");
}
#endif /* HAVE_SQLITE3 */
/*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* In addition to the permissions in the GNU General Public License,
* the authors give you unlimited permission to link the compiled
* version of this file into combinations with other programs,
* and to distribute those combinations without any restriction
* coming from the use of this file. (The General Public License
* restrictions do apply in other respects; for example, they cover
* modification of the file, and distribution when not linked into
* a combined executable.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "test_lib.h"
#include "odb.h"
#ifdef GIT2_SQLITE_BACKEND
#include "t03-data.h"
#include "fileops.h"
#include "git2/odb_backend.h"
static int cmp_objects(git_odb_object *odb_obj, git_rawobj *raw)
{
if (raw->type != git_odb_object_type(odb_obj))
return -1;
if (raw->len != git_odb_object_size(odb_obj))
return -1;
if ((raw->len > 0) && (memcmp(raw->data, git_odb_object_data(odb_obj), raw->len) != 0))
return -1;
return 0;
}
static git_odb *open_sqlite_odb(void)
{
git_odb *odb;
git_odb_backend *sqlite;
if (git_odb_new(&odb) < GIT_SUCCESS)
return NULL;
if (git_odb_backend_sqlite(&sqlite, ":memory:") < GIT_SUCCESS)
return NULL;
if (git_odb_add_backend(odb, sqlite, 0) < GIT_SUCCESS)
return NULL;
return odb;
}
#define TEST_WRITE(PTR) {\
git_odb *db; \
git_oid id1, id2; \
git_odb_object *obj; \
db = open_sqlite_odb(); \
must_be_true(db != NULL); \
must_pass(git_oid_mkstr(&id1, PTR.id)); \
must_pass(git_odb_write(&id2, db, PTR##_obj.data, PTR##_obj.len, PTR##_obj.type)); \
must_be_true(git_oid_cmp(&id1, &id2) == 0); \
must_pass(git_odb_read(&obj, db, &id1)); \
must_pass(cmp_objects(obj, &PTR##_obj)); \
git_odb_object_close(obj); \
git_odb_close(db); \
}
BEGIN_TEST(sqlite0, "write a commit, read it back (sqlite backend)")
TEST_WRITE(commit);
END_TEST
BEGIN_TEST(sqlite1, "write a tree, read it back (sqlite backend)")
TEST_WRITE(tree);
END_TEST
BEGIN_TEST(sqlite2, "write a tag, read it back (sqlite backend)")
TEST_WRITE(tag);
END_TEST
BEGIN_TEST(sqlite3, "write a zero-byte entry, read it back (sqlite backend)")
TEST_WRITE(zero);
END_TEST
BEGIN_TEST(sqlite4, "write a one-byte entry, read it back (sqlite backend)")
TEST_WRITE(one);
END_TEST
BEGIN_TEST(sqlite5, "write a two-byte entry, read it back (sqlite backend)")
TEST_WRITE(two);
END_TEST
BEGIN_TEST(sqlite6, "write some bytes in an entry, read it back (sqlite backend)")
TEST_WRITE(some);
END_TEST
BEGIN_SUITE(sqlite)
ADD_TEST(sqlite0);
ADD_TEST(sqlite1);
ADD_TEST(sqlite2);
ADD_TEST(sqlite3);
ADD_TEST(sqlite4);
ADD_TEST(sqlite5);
ADD_TEST(sqlite6);
END_SUITE
#else /* no sqlite builtin */
BEGIN_SUITE(sqlite)
/* empty */
END_SUITE
#endif
/*
* This file is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2,
* as published by the Free Software Foundation.
*
* In addition to the permissions in the GNU General Public License,
* the authors give you unlimited permission to link the compiled
* version of this file into combinations with other programs,
* and to distribute those combinations without any restriction
* coming from the use of this file. (The General Public License
* restrictions do apply in other respects; for example, they cover
* modification of the file, and distribution when not linked into
* a combined executable.)
*
* This file is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "test_lib.h"
#include "odb.h"
#ifdef GIT2_HIREDIS_BACKEND
#include "t03-data.h"
#include "fileops.h"
#include "git2/odb_backend.h"
static int cmp_objects(git_odb_object *odb_obj, git_rawobj *raw)
{
if (raw->type != git_odb_object_type(odb_obj))
return -1;
if (raw->len != git_odb_object_size(odb_obj))
return -1;
if ((raw->len > 0) && (memcmp(raw->data, git_odb_object_data(odb_obj), raw->len) != 0))
return -1;
return 0;
}
static git_odb *open_hiredis_odb(void)
{
git_odb *odb;
git_odb_backend *hiredis;
if (git_odb_new(&odb) < GIT_SUCCESS)
return NULL;
if (git_odb_backend_hiredis(&hiredis, "127.0.0.1", 6379) < GIT_SUCCESS)
return NULL;
if (git_odb_add_backend(odb, hiredis, 0) < GIT_SUCCESS)
return NULL;
return odb;
}
#define TEST_WRITE(PTR) {\
git_odb *db; \
git_oid id1, id2; \
git_odb_object *obj; \
db = open_hiredis_odb(); \
must_be_true(db != NULL); \
must_pass(git_oid_mkstr(&id1, PTR.id)); \
must_pass(git_odb_write(&id2, db, PTR##_obj.data, PTR##_obj.len, PTR##_obj.type)); \
must_be_true(git_oid_cmp(&id1, &id2) == 0); \
must_pass(git_odb_read(&obj, db, &id1)); \
must_pass(cmp_objects(obj, &PTR##_obj)); \
git_odb_object_close(obj); \
git_odb_close(db); \
}
BEGIN_TEST(hiredis0, "write a commit, read it back (hiredis backend)")
TEST_WRITE(commit);
END_TEST
BEGIN_TEST(hiredis1, "write a tree, read it back (hiredis backend)")
TEST_WRITE(tree);
END_TEST
BEGIN_TEST(hiredis2, "write a tag, read it back (hiredis backend)")
TEST_WRITE(tag);
END_TEST
BEGIN_TEST(hiredis3, "write a zero-byte entry, read it back (hiredis backend)")
TEST_WRITE(zero);
END_TEST
BEGIN_TEST(hiredis4, "write a one-byte entry, read it back (hiredis backend)")
TEST_WRITE(one);
END_TEST
BEGIN_TEST(hiredis5, "write a two-byte entry, read it back (hiredis backend)")
TEST_WRITE(two);
END_TEST
BEGIN_TEST(hiredis6, "write some bytes in an entry, read it back (hiredis backend)")
TEST_WRITE(some);
END_TEST
BEGIN_SUITE(hiredis)
ADD_TEST(hiredis0);
ADD_TEST(hiredis1);
ADD_TEST(hiredis2);
ADD_TEST(hiredis3);
ADD_TEST(hiredis4);
ADD_TEST(hiredis5);
ADD_TEST(hiredis6);
END_SUITE
#else /* no hiredis builtin */
BEGIN_SUITE(hiredis)
/* empty */
END_SUITE
#endif
......@@ -40,8 +40,6 @@ DECLARE_SUITE(hashtable);
DECLARE_SUITE(tag);
DECLARE_SUITE(tree);
DECLARE_SUITE(refs);
DECLARE_SUITE(sqlite);
DECLARE_SUITE(hiredis);
DECLARE_SUITE(repository);
DECLARE_SUITE(threads);
DECLARE_SUITE(config);
......@@ -58,10 +56,8 @@ static libgit2_suite suite_methods[]= {
SUITE_NAME(tag),
SUITE_NAME(tree),
SUITE_NAME(refs),
SUITE_NAME(sqlite),
SUITE_NAME(repository),
SUITE_NAME(threads),
SUITE_NAME(hiredis),
SUITE_NAME(config),
};
......
......@@ -17,7 +17,7 @@ CFLAGS_WIN32_L = ['/RELEASE'] # used for /both/ debug and release builds.
# sets the module's checksum in the header.
CFLAGS_WIN32_L_DBG = ['/DEBUG']
ALL_LIBS = ['crypto', 'pthread', 'sqlite3', 'hiredis']
ALL_LIBS = ['crypto', 'pthread']
def options(opt):
opt.load('compiler_c')
......@@ -30,10 +30,6 @@ PPC optimized version (ppc) or the SHA1 functions from OpenSSL (openssl)")
help='Force a specific MSVC++ version (7.1, 8.0, 9.0, 10.0), if more than one is installed')
opt.add_option('--arch', action='store', default='x86',
help='Select target architecture (ia64, x64, x86, x86_amd64, x86_ia64)')
opt.add_option('--with-sqlite', action='store_true', default=False,
dest='use_sqlite', help='Enable sqlite support')
opt.add_option('--with-hiredis', action='store_true', default=False,
dest='use_hiredis', help='Enable redis support using hiredis')
opt.add_option('--threadsafe', action='store_true', default=False,
help='Make libgit2 thread-safe (requires pthreads)')
......@@ -73,17 +69,6 @@ def configure(conf):
conf.check_cc(lib='pthread', uselib_store='pthread')
conf.env.DEFINES += ['GIT_THREADS']
# check for sqlite3
if conf.options.use_sqlite and conf.check_cc(
lib='sqlite3', uselib_store='sqlite3', install_path=None, mandatory=False):
conf.env.DEFINES += ['GIT2_SQLITE_BACKEND']
# check for hiredis
if conf.options.use_hiredis and conf.check_cc(
lib='hiredis', uselib_store='hiredis', install_path=None, mandatory=False):
conf.env.DEFINES += ['GIT2_HIREDIS_BACKEND']
if conf.options.sha1 not in ['openssl', 'ppc', 'builtin']:
conf.fatal('Invalid SHA1 option')
......@@ -149,7 +134,6 @@ def build_library(bld, build_type):
# E.g. src/unix/*.c
# src/win32/*.c
sources = sources + directory.ant_glob('src/%s/*.c' % bld.env.PLATFORM)
sources = sources + directory.ant_glob('src/backends/*.c')
sources = sources + directory.ant_glob('deps/zlib/*.c')
# SHA1 methods source
......
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