You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by rh...@apache.org on 2015/11/30 17:57:24 UTC
svn commit: r1717294 - in /subversion/branches/ra-git: ./
subversion/include/ subversion/libsvn_fs_git/
Author: rhuijben
Date: Mon Nov 30 16:57:24 2015
New Revision: 1717294
URL: http://svn.apache.org/viewvc?rev=1717294&view=rev
Log:
On the ra-git branch: Allow creating an empty git-fs to allow other layers
to apply some changes there.
* build.conf
(fsgit_queries): Add sqlite header.
* subversion/include/svn_error_codes.h
(SVN_ERR_FS_GIT_CATEGORY_START): Declare git range.
(SVN_ERR_FS_GIT_LIBGIT2_ERROR): New error.
* subversion/libsvn_fs_git/fs_git.h
(includes): Add git2.h.
(svn_fs_git__wrap_git_error): New function.
(GIT2_ERR): New define.
(svn_fs_git_fs_t): Add repos.
(svn_fs_git__db_open,
svn_fs_git__db_create,
svn_fs_git__db_youngest_rev): New functions.
* subversion/libsvn_fs_git/fsgit-metadata.sql
* subversion/libsvn_fs_git/fsgit-queries.sql
New files.
* subversion/libsvn_fs_git/git-fs.c
(includes): Remove some unused includes.
(fs_git_youngest_rev): Add implementation.
* subversion/libsvn_fs_git/gitdb.c
New file for sqlite handling.
* subversion/libsvn_fs_git/revmap.c
New file for revision mapping.
* subversion/libsvn_fs_git/util.c
New file for some utils.
Added:
subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-metadata.sql (with props)
subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-queries.sql (with props)
subversion/branches/ra-git/subversion/libsvn_fs_git/gitdb.c (with props)
subversion/branches/ra-git/subversion/libsvn_fs_git/revmap.c (with props)
subversion/branches/ra-git/subversion/libsvn_fs_git/util.c (with props)
Modified:
subversion/branches/ra-git/build.conf
subversion/branches/ra-git/subversion/include/svn_error_codes.h
subversion/branches/ra-git/subversion/libsvn_fs_git/fs_git.h
subversion/branches/ra-git/subversion/libsvn_fs_git/git-fs.c
Modified: subversion/branches/ra-git/build.conf
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/build.conf?rev=1717294&r1=1717293&r2=1717294&view=diff
==============================================================================
--- subversion/branches/ra-git/build.conf (original)
+++ subversion/branches/ra-git/build.conf Mon Nov 30 16:57:24 2015
@@ -480,6 +480,12 @@ type = sql-header
path = subversion/libsvn_wc
sources = wc-queries.sql
+[fsgit_queries]
+description = Queries on the FS-GIT database
+type = sql-header
+path = subversion/libsvn_fs_git
+sources = fsgit-queries.sql
+
[subr_sqlite]
description = Internal statements for SQLite interface
type = sql-header
Modified: subversion/branches/ra-git/subversion/include/svn_error_codes.h
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/include/svn_error_codes.h?rev=1717294&r1=1717293&r2=1717294&view=diff
==============================================================================
--- subversion/branches/ra-git/subversion/include/svn_error_codes.h (original)
+++ subversion/branches/ra-git/subversion/include/svn_error_codes.h Mon Nov 30 16:57:24 2015
@@ -152,6 +152,9 @@ extern "C" {
+ (23 * SVN_ERR_CATEGORY_SIZE))
#define SVN_ERR_X509_CATEGORY_START (APR_OS_START_USERERR \
+ (24 * SVN_ERR_CATEGORY_SIZE))
+/** @since New in 1.1.0 */
+#define SVN_ERR_FS_GIT_CATEGORY_START (APR_OS_START_USERERR \
+ + (25 * SVN_ERR_CATEGORY_SIZE))
#endif /* DOXYGEN_SHOULD_SKIP_THIS */
@@ -1731,6 +1734,11 @@ SVN_ERROR_START
SVN_ERR_X509_CATEGORY_START + 19,
"Certficate verification failed")
+ /** @since New in 1.10 */
+ SVN_ERRDEF(SVN_ERR_FS_GIT_LIBGIT2_ERROR,
+ SVN_ERR_FS_GIT_CATEGORY_START + 0,
+ "Libgit2 reported some error")
+
SVN_ERROR_END
Modified: subversion/branches/ra-git/subversion/libsvn_fs_git/fs_git.h
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/libsvn_fs_git/fs_git.h?rev=1717294&r1=1717293&r2=1717294&view=diff
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/fs_git.h (original)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/fs_git.h Mon Nov 30 16:57:24 2015
@@ -20,11 +20,27 @@
* ====================================================================
*/
+#include <git2.h>
+#include "private/svn_sqlite.h"
+
#ifndef SVN_LIBSVN_FS__FS_GIT_H
#define SVN_LIBSVN_FS__FS_GIT_H
+svn_error_t *
+svn_fs_git__wrap_git_error(int err);
+
+#define GIT2_ERR(expr) \
+ do { \
+ int svn_err__git_temp = (expr); \
+ if (svn_err__git_temp) \
+ return svn_error_trace( \
+ svn_fs_git__wrap_git_error(svn_err__git_temp)); \
+ } while (0)
+
typedef struct svn_fs_git_fs_t
{
+ git_repository *repos;
+ svn_sqlite__db_t *sdb;
svn_error_t *(*svn_fs_open)(svn_fs_t **,
const char *,
@@ -49,4 +65,18 @@ svn_fs_git__open(svn_fs_t *fs,
apr_pool_t *scratch_pool);
+/* From gitdb.c */
+svn_error_t *
+svn_fs_git__db_open(svn_fs_t *fs,
+ apr_pool_t *scratch_pool);
+
+svn_error_t *
+svn_fs_git__db_create(svn_fs_t *fs,
+ apr_pool_t *scratch_pool);
+
+svn_error_t *
+svn_fs_git__db_youngest_rev(svn_revnum_t *youngest_p,
+ svn_fs_t *fs,
+ apr_pool_t *pool);
+
#endif
Added: subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-metadata.sql
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-metadata.sql?rev=1717294&view=auto
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-metadata.sql (added)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-metadata.sql Mon Nov 30 16:57:24 2015
@@ -0,0 +1,72 @@
+/* wc-metadata.sql -- schema used in the wc-metadata SQLite database
+ * This is intended for use with SQLite 3
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ */
+
+/* One big list of statements to create our (current) schema. */
+-- STMT_CREATE_SCHEMA
+
+CREATE TABLE REPOSITORY (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+
+ /* the UUID of the repository */
+ uuid TEXT NOT NULL
+);
+
+CREATE TABLE REVMAP (
+ /* The Subversion revision number */
+ revnum INTEGER PRIMARY KEY AUTOINCREMENT,
+
+ /* The git commit mapped to the revision */
+ commit_id TEXT NOT NULL,
+
+ /* The relpath below which we express this commit (E.g. 'trunk') */
+ relpath TEXT NOT NULL
+);
+
+CREATE UNIQUE INDEX I_REVMAP_COMMIT_ID ON REVMAP (commit_id);
+CREATE UNIQUE INDEX I_REVMAP_RELPATH_ID ON REVMAP (relpath, revnum);
+
+CREATE TABLE TAGMAP (
+ /* The revision in which the tag was created */
+ revnum INTEGER PRIMARY KEY AUTOINCREMENT,
+
+ name TEXT NOT NULL
+);
+
+CREATE UNIQUE INDEX I_TAGMAP_NAME ON TAGMAP (name);
+
+CREATE TABLE BRANCHMAP (
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
+
+ relpath TEXT NOT NULL,
+
+ from_rev INTEGER NOT NULL,
+
+ to_rev INTEGER NULL
+);
+
+CREATE UNIQUE INDEX I_BRANCHMAP_RELPATH ON BRANCHMAP (relpath, from_rev);
+CREATE UNIQUE INDEX I_BRANCHMAP_FROM_REV ON BRANCHMAP (from_rev, relpath);
+
+PRAGMA user_version =
+-- define: SVN_FS_GIT__VERSION
+;
Propchange: subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-metadata.sql
------------------------------------------------------------------------------
svn:eol-style = native
Added: subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-queries.sql
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-queries.sql?rev=1717294&view=auto
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-queries.sql (added)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-queries.sql Mon Nov 30 16:57:24 2015
@@ -0,0 +1,44 @@
+/* fsgit-queries.sql -- queries used to interact with the git-metadata
+ * SQLite database
+ * This is intended for use with SQLite 3
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ */
+
+/* ------------------------------------------------------------------------- */
+
+/* these are used in wc_db.c */
+
+-- STMT_SELECT_UUID
+SELECT uuid from REPOSITORY
+
+-- STMT_INSERT_UUID
+INSERT INTO REPOSITORY(uuid) VALUES (?1)
+
+-- STMT_SELECT_HEADREV
+SELECT MAX(
+ IFNULL((SELECT MAX(revnum) FROM REVMAP), 0),
+ IFNULL((SELECT MAX(revnum) FROM TAGMAP), 0),
+ IFNULL((SELECT MAX(from_rev) FROM BRANCHMAP), 0))
+
+
+/* Grab all the statements related to the schema. */
+
+-- include: fsgit-metadata
Propchange: subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-queries.sql
------------------------------------------------------------------------------
svn:eol-style = native
Modified: subversion/branches/ra-git/subversion/libsvn_fs_git/git-fs.c
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/libsvn_fs_git/git-fs.c?rev=1717294&r1=1717293&r2=1717294&view=diff
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/git-fs.c (original)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/git-fs.c Mon Nov 30 16:57:24 2015
@@ -26,10 +26,8 @@
#include <apr_general.h>
#include <apr_pools.h>
-#include <apr_file_io.h>
#include "svn_fs.h"
-#include "svn_delta.h"
#include "svn_version.h"
#include "svn_pools.h"
@@ -44,7 +42,9 @@
static svn_error_t *
fs_git_youngest_rev(svn_revnum_t *youngest_p, svn_fs_t *fs, apr_pool_t *pool)
{
- return svn_error_create(APR_ENOTIMPL, NULL, NULL);
+ SVN_ERR(svn_fs_git__db_youngest_rev(youngest_p, fs, pool));
+
+ return SVN_NO_ERROR;
}
static svn_error_t *
@@ -145,7 +145,15 @@ fs_git_get_locks(svn_fs_t *fs, const cha
static svn_error_t *
fs_git_info_format(int *fs_format, svn_version_t **supports_version, svn_fs_t *fs, apr_pool_t *result_pool, apr_pool_t *scratch_pool)
{
- return svn_error_create(APR_ENOTIMPL, NULL, NULL);
+ *fs_format = 0;
+ *supports_version = apr_palloc(result_pool, sizeof(svn_version_t));
+
+ (*supports_version)->major = SVN_VER_MAJOR;
+ (*supports_version)->minor = 10;
+ (*supports_version)->patch = 0;
+ (*supports_version)->tag = "";
+
+ return SVN_NO_ERROR;
}
static svn_error_t *
@@ -205,6 +213,21 @@ static fs_vtable_t fs_vtable =
fs_git_bdb_set_errcall
};
+static apr_status_t
+fs_git_cleanup(void *baton)
+{
+ svn_fs_t *fs = baton;
+ svn_fs_git_fs_t *fgf = fs->fsap_data;
+
+ if (fgf->repos)
+ {
+ git_repository_free(fgf->repos);
+ fgf->repos = NULL;
+ }
+
+ return APR_SUCCESS;
+}
+
svn_error_t *
svn_fs_git__initialize_fs_struct(svn_fs_t *fs,
apr_pool_t *scratch_pool)
@@ -213,6 +236,10 @@ svn_fs_git__initialize_fs_struct(svn_fs_
fs->vtable = &fs_vtable;
fs->fsap_data = fgf;
+
+ apr_pool_cleanup_register(fs->pool, fs, fs_git_cleanup,
+ apr_pool_cleanup_null);
+
return SVN_NO_ERROR;
}
@@ -221,7 +248,15 @@ svn_fs_git__create(svn_fs_t *fs,
const char *path,
apr_pool_t *scratch_pool)
{
- return svn_error_create(APR_ENOTIMPL, NULL, NULL);
+ svn_fs_git_fs_t *fgf = fs->fsap_data;
+
+ fs->path = apr_pstrdup(fs->pool, path);
+
+ GIT2_ERR(git_repository_init(&fgf->repos, path, TRUE /* is_bare */));
+
+ SVN_ERR(svn_fs_git__db_create(fs, scratch_pool));
+
+ return APR_SUCCESS;
}
svn_error_t *
@@ -229,5 +264,14 @@ svn_fs_git__open(svn_fs_t *fs,
const char *path,
apr_pool_t *scratch_pool)
{
- return svn_error_create(APR_ENOTIMPL, NULL, NULL);
+ svn_fs_git_fs_t *fgf = fs->fsap_data;
+
+ fs->path = apr_pstrdup(fs->pool, path);
+
+ GIT2_ERR(git_repository_open(&fgf->repos, path));
+
+ SVN_ERR(svn_fs_git__db_open(fs, scratch_pool));
+
+ return APR_SUCCESS;
}
+
Added: subversion/branches/ra-git/subversion/libsvn_fs_git/gitdb.c
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/libsvn_fs_git/gitdb.c?rev=1717294&view=auto
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/gitdb.c (added)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/gitdb.c Mon Nov 30 16:57:24 2015
@@ -0,0 +1,126 @@
+/* gitdb.c --- manage the mapping db of the git filesystem
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <apr_general.h>
+#include <apr_pools.h>
+
+#include "svn_fs.h"
+#include "svn_version.h"
+#include "svn_pools.h"
+#include "svn_dirent_uri.h"
+
+#include "svn_private_config.h"
+
+#include "private/svn_fs_util.h"
+
+#include "../libsvn_fs/fs-loader.h"
+#include "fs_git.h"
+
+#include "fsgit-queries.h"
+
+#define SVN_FS_GIT__VERSION 1
+FSGIT_QUERIES_SQL_DECLARE_STATEMENTS(statements);
+
+
+svn_error_t *
+svn_fs_git__db_youngest_rev(svn_revnum_t *youngest_p,
+ svn_fs_t *fs,
+ apr_pool_t *pool)
+{
+ svn_fs_git_fs_t *fgf = fs->fsap_data;
+ svn_sqlite__stmt_t *stmt;
+
+ SVN_ERR(svn_sqlite__get_statement(&stmt, fgf->sdb, STMT_SELECT_HEADREV));
+ SVN_ERR(svn_sqlite__step_row(stmt));
+
+ *youngest_p = svn_sqlite__column_revnum(stmt, 0);
+ SVN_ERR(svn_sqlite__reset(stmt));
+
+ return SVN_NO_ERROR;
+}
+
+
+
+svn_error_t *
+svn_fs_git__db_open(svn_fs_t *fs,
+ apr_pool_t *scratch_pool)
+{
+ svn_fs_git_fs_t *fgf = fs->fsap_data;
+ svn_sqlite__stmt_t *stmt;
+ const char *db_path = svn_dirent_join(fs->path, ".svn-git-fs.db",
+ scratch_pool);
+
+ SVN_ERR(svn_sqlite__open(&fgf->sdb, db_path, svn_sqlite__mode_readwrite,
+ statements, 0, NULL, 0,
+ fs->pool, scratch_pool));
+
+ SVN_ERR(svn_sqlite__get_statement(&stmt, fgf->sdb, STMT_SELECT_UUID));
+ SVN_ERR(svn_sqlite__step_row(stmt));
+
+ fs->uuid = svn_sqlite__column_text(stmt, 0, fs->pool);
+ SVN_ERR(svn_sqlite__reset(stmt));
+
+ return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+create_schema(svn_fs_t *fs,
+ apr_pool_t *scratch_pool)
+{
+ svn_fs_git_fs_t *fgf = fs->fsap_data;
+ svn_sqlite__stmt_t *stmt;
+ const char *uuid;
+
+ SVN_ERR(svn_sqlite__exec_statements(fgf->sdb,
+ STMT_CREATE_SCHEMA));
+
+ uuid = svn_uuid_generate(fs->pool);
+
+ SVN_ERR(svn_sqlite__get_statement(&stmt, fgf->sdb, STMT_INSERT_UUID));
+ SVN_ERR(svn_sqlite__bind_text(stmt, 1, uuid));
+ SVN_ERR(svn_sqlite__update(NULL, stmt));
+
+ fs->uuid = uuid;
+
+ return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_fs_git__db_create(svn_fs_t *fs,
+ apr_pool_t *scratch_pool)
+{
+ svn_fs_git_fs_t *fgf = fs->fsap_data;
+ const char *db_path = svn_dirent_join(fs->path, ".svn-git-fs.db",
+ scratch_pool);
+
+ SVN_ERR(svn_sqlite__open(&fgf->sdb, db_path, svn_sqlite__mode_rwcreate,
+ statements, 0, NULL, 0,
+ scratch_pool, scratch_pool));
+
+ SVN_SQLITE__WITH_LOCK(create_schema(fs, scratch_pool), fgf->sdb);
+
+ return SVN_NO_ERROR;
+}
Propchange: subversion/branches/ra-git/subversion/libsvn_fs_git/gitdb.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: subversion/branches/ra-git/subversion/libsvn_fs_git/revmap.c
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/libsvn_fs_git/revmap.c?rev=1717294&view=auto
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/revmap.c (added)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/revmap.c Mon Nov 30 16:57:24 2015
@@ -0,0 +1 @@
+
Propchange: subversion/branches/ra-git/subversion/libsvn_fs_git/revmap.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: subversion/branches/ra-git/subversion/libsvn_fs_git/util.c
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/libsvn_fs_git/util.c?rev=1717294&view=auto
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/util.c (added)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/util.c Mon Nov 30 16:57:24 2015
@@ -0,0 +1,42 @@
+/* util.c --- git filesystem utilities
+ *
+ * ====================================================================
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ */
+
+#include "svn_fs.h"
+#include "svn_version.h"
+#include "svn_pools.h"
+
+#include "svn_private_config.h"
+#include "fs_git.h"
+
+svn_error_t *
+svn_fs_git__wrap_git_error(int err)
+{
+ git_error git_err;
+
+ if (giterr_detach(&git_err) == -1)
+ SVN_ERR_MALFUNCTION();
+
+ /* ### TODO: map error code */
+ return svn_error_createf(SVN_ERR_FS_GIT_LIBGIT2_ERROR, NULL,
+ _("git: %s"), git_err.message);
+}
+
Propchange: subversion/branches/ra-git/subversion/libsvn_fs_git/util.c
------------------------------------------------------------------------------
svn:eol-style = native