26
26
#include <assert.h>
27
27
#include <string.h>
28
28
#include <git2.h>
29
- #include <git2/odb_backend.h>
29
+ #include <git2/sys/ odb_backend.h>
30
30
31
31
/* MySQL C Api docs:
32
32
* http://dev.mysql.com/doc/refman/5.1/en/c-api-function-overview.html
@@ -82,13 +82,13 @@ int mysql_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_backend
82
82
if (mysql_stmt_num_rows (backend -> st_read_header ) == 1 ) {
83
83
result_buffers [0 ].buffer_type = MYSQL_TYPE_TINY ;
84
84
result_buffers [0 ].buffer = type_p ;
85
- result_buffers [0 ].buffer_length = sizeof (type_p );
86
- memset (type_p , 0 , sizeof (type_p ));
85
+ result_buffers [0 ].buffer_length = sizeof (* type_p );
86
+ memset (type_p , 0 , sizeof (* type_p ));
87
87
88
88
result_buffers [1 ].buffer_type = MYSQL_TYPE_LONGLONG ;
89
89
result_buffers [1 ].buffer = len_p ;
90
- result_buffers [1 ].buffer_length = sizeof (len_p );
91
- memset (len_p , 0 , sizeof (len_p ));
90
+ result_buffers [1 ].buffer_length = sizeof (* len_p );
91
+ memset (len_p , 0 , sizeof (* len_p ));
92
92
93
93
if (mysql_stmt_bind_result (backend -> st_read_header , result_buffers ) != 0 )
94
94
return GIT_ERROR ;
@@ -97,7 +97,7 @@ int mysql_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_backend
97
97
if (mysql_stmt_fetch (backend -> st_read_header ) != 0 )
98
98
return GIT_ERROR ;
99
99
100
- error = GIT_SUCCESS ;
100
+ error = GIT_OK ;
101
101
} else {
102
102
error = GIT_ENOTFOUND ;
103
103
}
@@ -145,13 +145,13 @@ int mysql_backend__read(void **data_p, size_t *len_p, git_otype *type_p, git_odb
145
145
if (mysql_stmt_num_rows (backend -> st_read ) == 1 ) {
146
146
result_buffers [0 ].buffer_type = MYSQL_TYPE_TINY ;
147
147
result_buffers [0 ].buffer = type_p ;
148
- result_buffers [0 ].buffer_length = sizeof (type_p );
149
- memset (type_p , 0 , sizeof (type_p ));
148
+ result_buffers [0 ].buffer_length = sizeof (* type_p );
149
+ memset (type_p , 0 , sizeof (* type_p ));
150
150
151
151
result_buffers [1 ].buffer_type = MYSQL_TYPE_LONGLONG ;
152
152
result_buffers [1 ].buffer = len_p ;
153
- result_buffers [1 ].buffer_length = sizeof (len_p );
154
- memset (len_p , 0 , sizeof (len_p ));
153
+ result_buffers [1 ].buffer_length = sizeof (* len_p );
154
+ memset (len_p , 0 , sizeof (* len_p ));
155
155
156
156
// by setting buffer and buffer_length to 0, this tells libmysql
157
157
// we want it to set data_len to the *actual* length of that field
@@ -181,7 +181,7 @@ int mysql_backend__read(void **data_p, size_t *len_p, git_otype *type_p, git_odb
181
181
return GIT_ERROR ;
182
182
}
183
183
184
- error = GIT_SUCCESS ;
184
+ error = GIT_OK ;
185
185
} else {
186
186
error = GIT_ENOTFOUND ;
187
187
}
@@ -235,7 +235,7 @@ int mysql_backend__exists(git_odb_backend *_backend, const git_oid *oid)
235
235
return found ;
236
236
}
237
237
238
- int mysql_backend__write (git_oid * oid , git_odb_backend * _backend , const void * data , size_t len , git_otype type )
238
+ int mysql_backend__write (git_odb_backend * _backend , const git_oid * oid , const void * data , size_t len , git_otype type )
239
239
{
240
240
int error ;
241
241
mysql_backend * backend ;
@@ -246,9 +246,6 @@ int mysql_backend__write(git_oid *oid, git_odb_backend *_backend, const void *da
246
246
247
247
backend = (mysql_backend * )_backend ;
248
248
249
- if ((error = git_odb_hash (oid , data , len , type )) < 0 )
250
- return error ;
251
-
252
249
memset (bind_buffers , 0 , sizeof (bind_buffers ));
253
250
254
251
// bind the oid
@@ -292,7 +289,7 @@ int mysql_backend__write(git_oid *oid, git_odb_backend *_backend, const void *da
292
289
if (mysql_stmt_reset (backend -> st_read_header ) != 0 )
293
290
return GIT_ERROR ;
294
291
295
- return GIT_SUCCESS ;
292
+ return GIT_OK ;
296
293
}
297
294
298
295
void mysql_backend__free (git_odb_backend * _backend )
@@ -329,7 +326,7 @@ static int create_table(MYSQL *db)
329
326
if (mysql_real_query (db , sql_create , strlen (sql_create )) != 0 )
330
327
return GIT_ERROR ;
331
328
332
- return GIT_SUCCESS ;
329
+ return GIT_OK ;
333
330
}
334
331
335
332
static int init_db (MYSQL * db )
@@ -354,7 +351,7 @@ static int init_db(MYSQL *db)
354
351
error = create_table (db );
355
352
} else if (num_rows > 0 ) {
356
353
/* the table was found */
357
- error = GIT_SUCCESS ;
354
+ error = GIT_OK ;
358
355
} else {
359
356
error = GIT_ERROR ;
360
357
}
@@ -410,7 +407,7 @@ static int init_statements(mysql_backend *backend)
410
407
return GIT_ERROR ;
411
408
412
409
413
- return GIT_SUCCESS ;
410
+ return GIT_OK ;
414
411
}
415
412
416
413
int git_odb_backend_mysql (git_odb_backend * * backend_out , const char * mysql_host ,
@@ -422,8 +419,10 @@ int git_odb_backend_mysql(git_odb_backend **backend_out, const char *mysql_host,
422
419
my_bool reconnect ;
423
420
424
421
backend = calloc (1 , sizeof (mysql_backend ));
425
- if (backend == NULL )
426
- return GIT_ENOMEM ;
422
+ if (backend == NULL ) {
423
+ giterr_set_oom ();
424
+ return GIT_ERROR ;
425
+ }
427
426
428
427
backend -> db = mysql_init (backend -> db );
429
428
@@ -445,14 +444,15 @@ int git_odb_backend_mysql(git_odb_backend **backend_out, const char *mysql_host,
445
444
if (error < 0 )
446
445
goto cleanup ;
447
446
447
+ backend -> parent .version = GIT_ODB_BACKEND_VERSION ;
448
448
backend -> parent .read = & mysql_backend__read ;
449
449
backend -> parent .read_header = & mysql_backend__read_header ;
450
450
backend -> parent .write = & mysql_backend__write ;
451
451
backend -> parent .exists = & mysql_backend__exists ;
452
452
backend -> parent .free = & mysql_backend__free ;
453
453
454
454
* backend_out = (git_odb_backend * )backend ;
455
- return GIT_SUCCESS ;
455
+ return GIT_OK ;
456
456
457
457
cleanup :
458
458
mysql_backend__free ((git_odb_backend * )backend );
0 commit comments