2626#include <assert.h>
2727#include <string.h>
2828#include <git2.h>
29- #include <git2/odb_backend.h>
29+ #include <git2/sys/ odb_backend.h>
3030#include <sqlite3.h>
3131
3232#define GIT2_TABLE_NAME "git2_odb"
@@ -54,7 +54,7 @@ int sqlite_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_backen
5454 * type_p = (git_otype )sqlite3_column_int (backend -> st_read_header , 0 );
5555 * len_p = (size_t )sqlite3_column_int (backend -> st_read_header , 1 );
5656 assert (sqlite3_step (backend -> st_read_header ) == SQLITE_DONE );
57- error = GIT_SUCCESS ;
57+ error = GIT_OK ;
5858 } else {
5959 error = GIT_ENOTFOUND ;
6060 }
@@ -81,10 +81,11 @@ int sqlite_backend__read(void **data_p, size_t *len_p, git_otype *type_p, git_od
8181 * data_p = malloc (* len_p );
8282
8383 if (* data_p == NULL ) {
84- error = GIT_ENOMEM ;
84+ giterr_set_oom ();
85+ error = GIT_ERROR ;
8586 } else {
8687 memcpy (* data_p , sqlite3_column_blob (backend -> st_read , 2 ), * len_p );
87- error = GIT_SUCCESS ;
88+ error = GIT_OK ;
8889 }
8990
9091 assert (sqlite3_step (backend -> st_read ) == SQLITE_DONE );
@@ -98,17 +99,17 @@ int sqlite_backend__read(void **data_p, size_t *len_p, git_otype *type_p, git_od
9899}
99100
100101int sqlite_backend__read_prefix (git_oid * out_oid , void * * data_p , size_t * len_p , git_otype * type_p , git_odb_backend * _backend ,
101- const git_oid * short_oid , unsigned int len ) {
102+ const git_oid * short_oid , size_t len ) {
102103 if (len >= GIT_OID_HEXSZ ) {
103104 /* Just match the full identifier */
104105 int error = sqlite_backend__read (data_p , len_p , type_p , _backend , short_oid );
105- if (error == GIT_SUCCESS )
106+ if (error == GIT_OK )
106107 git_oid_cpy (out_oid , short_oid );
107108
108109 return error ;
109- } else if (len < GIT_OID_HEXSZ ) {
110- return GIT_ENOTIMPLEMENTED ;
111110 }
111+ /* not implemented (yet) */
112+ return GIT_ERROR ;
112113}
113114
114115int sqlite_backend__exists (git_odb_backend * _backend , const git_oid * oid )
@@ -133,7 +134,7 @@ int sqlite_backend__exists(git_odb_backend *_backend, const git_oid *oid)
133134}
134135
135136
136- int sqlite_backend__write (git_oid * id , git_odb_backend * _backend , const void * data , size_t len , git_otype type )
137+ int sqlite_backend__write (git_odb_backend * _backend , const git_oid * id , const void * data , size_t len , git_otype type )
137138{
138139 int error ;
139140 sqlite_backend * backend ;
@@ -142,9 +143,6 @@ int sqlite_backend__write(git_oid *id, git_odb_backend *_backend, const void *da
142143
143144 backend = (sqlite_backend * )_backend ;
144145
145- if ((error = git_odb_hash (id , data , len , type )) < 0 )
146- return error ;
147-
148146 error = SQLITE_ERROR ;
149147
150148 if (sqlite3_bind_text (backend -> st_write , 1 , (char * )id -> id , 20 , SQLITE_TRANSIENT ) == SQLITE_OK &&
@@ -155,7 +153,7 @@ int sqlite_backend__write(git_oid *id, git_odb_backend *_backend, const void *da
155153 }
156154
157155 sqlite3_reset (backend -> st_write );
158- return (error == SQLITE_DONE ) ? GIT_SUCCESS : GIT_ERROR ;
156+ return (error == SQLITE_DONE ) ? GIT_OK : GIT_ERROR ;
159157}
160158
161159
@@ -185,7 +183,7 @@ static int create_table(sqlite3 *db)
185183 if (sqlite3_exec (db , sql_creat , NULL , NULL , NULL ) != SQLITE_OK )
186184 return GIT_ERROR ;
187185
188- return GIT_SUCCESS ;
186+ return GIT_OK ;
189187}
190188
191189static int init_db (sqlite3 * db )
@@ -207,7 +205,7 @@ static int init_db(sqlite3 *db)
207205
208206 case SQLITE_ROW :
209207 /* the table was found */
210- error = GIT_SUCCESS ;
208+ error = GIT_OK ;
211209 break ;
212210
213211 default :
@@ -239,7 +237,7 @@ static int init_statements(sqlite_backend *backend)
239237 if (sqlite3_prepare_v2 (backend -> db , sql_write , -1 , & backend -> st_write , NULL ) != SQLITE_OK )
240238 return GIT_ERROR ;
241239
242- return GIT_SUCCESS ;
240+ return GIT_OK ;
243241}
244242
245243int git_odb_backend_sqlite (git_odb_backend * * backend_out , const char * sqlite_db )
@@ -248,8 +246,10 @@ int git_odb_backend_sqlite(git_odb_backend **backend_out, const char *sqlite_db)
248246 int error ;
249247
250248 backend = calloc (1 , sizeof (sqlite_backend ));
251- if (backend == NULL )
252- return GIT_ENOMEM ;
249+ if (backend == NULL ) {
250+ giterr_set_oom ();
251+ return GIT_ERROR ;
252+ }
253253
254254 if (sqlite3_open (sqlite_db , & backend -> db ) != SQLITE_OK )
255255 goto cleanup ;
@@ -262,6 +262,7 @@ int git_odb_backend_sqlite(git_odb_backend **backend_out, const char *sqlite_db)
262262 if (error < 0 )
263263 goto cleanup ;
264264
265+ backend -> parent .version = GIT_ODB_BACKEND_VERSION ;
265266 backend -> parent .read = & sqlite_backend__read ;
266267 backend -> parent .read_prefix = & sqlite_backend__read_prefix ;
267268 backend -> parent .read_header = & sqlite_backend__read_header ;
@@ -270,7 +271,7 @@ int git_odb_backend_sqlite(git_odb_backend **backend_out, const char *sqlite_db)
270271 backend -> parent .free = & sqlite_backend__free ;
271272
272273 * backend_out = (git_odb_backend * )backend ;
273- return GIT_SUCCESS ;
274+ return GIT_OK ;
274275
275276cleanup :
276277 sqlite_backend__free ((git_odb_backend * )backend );
0 commit comments