Skip to content

Commit

Permalink
get mysql backend compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
brianmario committed Jun 20, 2011
1 parent fd438a4 commit 60557a0
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 29 deletions.
37 changes: 37 additions & 0 deletions CMake/FindLibmysql.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# $Id$
#
# - Find libmysql
# Find libmysql
#
# LIBMYSQL_INCLUDE_DIR - where to find mysql.h, etc.
# LIBMYSQL_LIBRARY - List of libraries when using libmysql.
# LIBMYSQL_FOUND - True if libmysql found.


IF (LIBMYSQL_INCLUDE_DIR)
# Already in cache, be silent
SET(LIBMYSQL_FIND_QUIETLY TRUE)
ENDIF ()

FIND_PATH(LIBMYSQL_INCLUDE_DIR mysql.h)

FIND_LIBRARY(LIBMYSQL_LIBRARY mysqlclient)

# handle the QUIETLY and REQUIRED arguments and set Libmysql_FOUND to TRUE if
# all listed variables are TRUE
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBMYSQL DEFAULT_MSG LIBMYSQL_LIBRARY LIBMYSQL_INCLUDE_DIR)

SET(LIBMYSQL_VERSION 0)

IF(LIBMYSQL_FOUND)
if (EXISTS "${LIBMYSQL_INCLUDE_DIR}/mysql_version.h")
FILE(READ "${LIBMYSQL_INCLUDE_DIR}/mysql_version.h" _MYSQL_VERSION_CONENTS)
STRING(REGEX REPLACE ".*#define MYSQL_SERVER_VERSION\\s+\"([0-9.]+)\".*" "\\1" LIBMYSQL_VERSION "${_MYSQL_VERSION_CONENTS}")
endif()
ENDIF()

SET(LIBMYSQL_VERSION ${LIBMYSQL_VERSION} CACHE STRING "Version number of libmysql")

MARK_AS_ADVANCED(LIBMYSQL_LIBRARY LIBMYSQL_INCLUDE_DIR LIBMYSQL_VERSION)
19 changes: 19 additions & 0 deletions mysql/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
PROJECT(LIBGIT2-mysql C)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

INCLUDE(../CMake/FindLibgit2.cmake)
INCLUDE(../CMake/FindLibmysql.cmake)

# Build options
OPTION (BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON)
OPTION (BUILD_TESTS "Build Tests" ON)

# Build Release by default
IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
ENDIF ()

# Compile and link LIBGIT2
INCLUDE_DIRECTORIES(${LIBGIT2_INCLUDE_DIRS} ${LIBMYSQL_INCLUDE_DIR})
ADD_LIBRARY(git2-mysql mysql.c)
TARGET_LINK_LIBRARIES(git2-mysql ${LIBGIT2_LIBRARIES} ${LIBMYSQL_LIBRARY})
35 changes: 6 additions & 29 deletions mysql/mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,10 @@
* 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_MYSQL_BACKEND
#include <assert.h>
#include <string.h>
#include <git2.h>
#include <git2/odb_backend.h>

/* MySQL C Api docs:
* http://dev.mysql.com/doc/refman/5.1/en/c-api-function-overview.html
Expand Down Expand Up @@ -177,7 +173,7 @@ int mysql_backend__read(void **data_p, size_t *len_p, git_otype *type_p, git_odb
// return GIT_ERROR;

if (data_len > 0) {
*data_p = git__malloc(data_len);
*data_p = malloc(data_len);
result_buffers[2].buffer = *data_p;
result_buffers[2].buffer_length = data_len;

Expand Down Expand Up @@ -425,7 +421,7 @@ int git_odb_backend_mysql(git_odb_backend **backend_out, const char *mysql_host,
int error;
my_bool reconnect;

backend = git__calloc(1, sizeof(mysql_backend));
backend = calloc(1, sizeof(mysql_backend));
if (backend == NULL)
return GIT_ENOMEM;

Expand Down Expand Up @@ -462,22 +458,3 @@ int git_odb_backend_mysql(git_odb_backend **backend_out, const char *mysql_host,
mysql_backend__free((git_odb_backend *)backend);
return GIT_ERROR;
}

#else

int git_odb_backend_mysql(git_odb_backend **GIT_UNUSED(backend_out), const char *GIT_UNUSED(mysql_host),
const char *GIT_UNUSED(mysql_user), const char *GIT_UNUSED(mysql_passwd), const char *GIT_UNUSED(mysql_db),
unsigned int GIT_UNUSED(mysql_port), const char *GIT_UNUSED(mysql_unix_socket), unsigned long GIT_UNUSED(mysql_client_flag))
{
GIT_UNUSED_ARG(backend_out);
GIT_UNUSED_ARG(mysql_host);
GIT_UNUSED_ARG(mysql_user);
GIT_UNUSED_ARG(mysql_passwd);
GIT_UNUSED_ARG(mysql_db);
GIT_UNUSED_ARG(mysql_port);
GIT_UNUSED_ARG(mysql_unix_socket);
GIT_UNUSED_ARG(mysql_client_flag);
return GIT_ENOTIMPLEMENTED;
}

#endif /* HAVE_MYSQL */

1 comment on commit 60557a0

@hrushikeshgeete
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am beginner.
Please, explain how exactly to compile.

Please sign in to comment.