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 20:51:37 UTC

svn commit: r1717312 - in /subversion/branches/ra-git/subversion/libsvn_fs_git: ./ fs_git.h fsgit-queries.sql git-fs.c git-lib.c gitdb.c revmap.c util.c

Author: rhuijben
Date: Mon Nov 30 19:51:36 2015
New Revision: 1717312

URL: http://svn.apache.org/viewvc?rev=1717312&view=rev
Log:
On the ra-git branch: Start populating the revision map in the sqlite
database. Temporarily use the fs recover api for this.

* subversion/libsvn_fs_git
  (svn:ignore): Add fsgit-queries.h

* subversion/libsvn_fs_git/fsgit-queries.sql
  (STMT_SELECT_REV_BY_COMMITID,
   STMT_INSERT_COMMIT): New statements.

* subversion/libsvn_fs_git/fs_git.h
  (svn_fs_git__wrap_git_error): Remove unused argument.
  (svn_fs_git__wrap_git_error): By default wrap with tracing.
  (GIT2_ERR): Update caller.
  (svn_fs_git_fs_t): Add revwalk.
  (svn_fs_git__db_ensure_commit,
   svn_fs_git__revmap_update): New function.

* subversion/libsvn_fs_git/git-fs.c
  (fs_git_refresh_revprops,
   fs_git_revision_proplist): Stub with a success result.
  (fs_git_cleanup): Free revwalk, if used.

* subversion/libsvn_fs_git/git-lib.c
  (fs_git_recover): Update the revision map.

* subversion/libsvn_fs_git/gitdb.c
  (svn_fs_git__db_ensure_commit): New function.

* subversion/libsvn_fs_git/revmap.c
  New file.
  (revmap_update_branch
   revmap_update,
   svn_fs_git__revmap_update): New function.

* subversion/libsvn_fs_git/util.c
  (svn_fs_git__wrap_git_error): Undefine macro. Remove argument.

Modified:
    subversion/branches/ra-git/subversion/libsvn_fs_git/   (props changed)
    subversion/branches/ra-git/subversion/libsvn_fs_git/fs_git.h
    subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-queries.sql
    subversion/branches/ra-git/subversion/libsvn_fs_git/git-fs.c
    subversion/branches/ra-git/subversion/libsvn_fs_git/git-lib.c
    subversion/branches/ra-git/subversion/libsvn_fs_git/gitdb.c
    subversion/branches/ra-git/subversion/libsvn_fs_git/revmap.c
    subversion/branches/ra-git/subversion/libsvn_fs_git/util.c

Propchange: subversion/branches/ra-git/subversion/libsvn_fs_git/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Mon Nov 30 19:51:36 2015
@@ -0,0 +1 @@
+fsgit-queries.h

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=1717312&r1=1717311&r2=1717312&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 19:51:36 2015
@@ -27,14 +27,16 @@
 #define SVN_LIBSVN_FS__FS_GIT_H
 
 svn_error_t *
-svn_fs_git__wrap_git_error(int err);
+svn_fs_git__wrap_git_error(void);
 
-#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));   \
+#define svn_fs_git__wrap_git_error() \
+          svn_error_trace(svn_fs_git__wrap_git_error())
+
+#define GIT2_ERR(expr)                        \
+  do {                                        \
+    int svn_err__git_temp = (expr);           \
+    if (svn_err__git_temp)                    \
+      return svn_fs_git__wrap_git_error();    \
   } while (0)
 
 typedef struct svn_fs_git_fs_t
@@ -42,6 +44,8 @@ typedef struct svn_fs_git_fs_t
   git_repository *repos;
   svn_sqlite__db_t *sdb;
 
+  git_revwalk *revwalk;
+
   svn_error_t *(*svn_fs_open)(svn_fs_t **,
                               const char *,
                               apr_hash_t *,
@@ -79,4 +83,20 @@ svn_fs_git__db_youngest_rev(svn_revnum_t
                             svn_fs_t *fs,
                             apr_pool_t *pool);
 
+svn_error_t *
+svn_fs_git__db_ensure_commit(svn_fs_t *fs,
+                             git_oid *oid,
+                             svn_revnum_t *latest_rev,
+                             git_reference *ref);
+
+/* From revmap.c */
+/* Until there is a formal api, this will synchronize the revisions */
+svn_error_t *
+svn_fs_git__revmap_update(svn_fs_t *fs,
+                          svn_fs_git_fs_t *fgf,
+                          svn_cancel_func_t cancel_func,
+                          void *cancel_baton,
+                          apr_pool_t *scratch_pool);
+
+
 #endif

Modified: 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=1717312&r1=1717311&r2=1717312&view=diff
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-queries.sql (original)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/fsgit-queries.sql Mon Nov 30 19:51:36 2015
@@ -38,6 +38,12 @@ SELECT MAX(
    IFNULL((SELECT MAX(revnum) FROM TAGMAP), 0),
    IFNULL((SELECT MAX(from_rev) FROM BRANCHMAP), 0))
 
+-- STMT_SELECT_REV_BY_COMMITID
+SELECT revnum FROM REVMAP WHERE commit_id = ?1
+
+-- STMT_INSERT_COMMIT
+INSERT INTO REVMAP (revnum, commit_id, relpath) VALUES (?1, ?2, ?3)
+
 
 /* Grab all the statements related to the schema.  */
 

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=1717312&r1=1717311&r2=1717312&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 19:51:36 2015
@@ -50,7 +50,7 @@ fs_git_youngest_rev(svn_revnum_t *younge
 static svn_error_t *
 fs_git_refresh_revprops(svn_fs_t *fs, apr_pool_t *scratch_pool)
 {
-  return svn_error_create(APR_ENOTIMPL, NULL, NULL);
+  return SVN_NO_ERROR;
 }
 
 static svn_error_t *
@@ -62,7 +62,8 @@ fs_git_revision_prop(svn_string_t **valu
 static svn_error_t *
 fs_git_revision_proplist(apr_hash_t **table_p, svn_fs_t *fs, svn_revnum_t rev, svn_boolean_t refresh, apr_pool_t *result_pool, apr_pool_t *scratch_pool)
 {
-  return svn_error_create(APR_ENOTIMPL, NULL, NULL);
+  *table_p = apr_hash_make(result_pool);
+  return SVN_NO_ERROR;
 }
 
 static svn_error_t *fs_git_change_rev_prop(svn_fs_t *fs, svn_revnum_t rev, const char *name, const svn_string_t *const *old_value_p, const svn_string_t *value, apr_pool_t *pool)
@@ -219,6 +220,12 @@ fs_git_cleanup(void *baton)
   svn_fs_t *fs = baton;
   svn_fs_git_fs_t *fgf = fs->fsap_data;
 
+  if (fgf->revwalk)
+    {
+      git_revwalk_free(fgf->revwalk);
+      fgf->revwalk = NULL;
+    }
+
   if (fgf->repos)
     {
       git_repository_free(fgf->repos);

Modified: subversion/branches/ra-git/subversion/libsvn_fs_git/git-lib.c
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/libsvn_fs_git/git-lib.c?rev=1717312&r1=1717311&r2=1717312&view=diff
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/git-lib.c (original)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/git-lib.c Mon Nov 30 19:51:36 2015
@@ -174,8 +174,14 @@ fs_git_recover(svn_fs_t *fs,
                svn_cancel_func_t cancel_func, void *cancel_baton,
                apr_pool_t *pool)
 {
+  svn_fs_git_fs_t *fgf = fs->fsap_data;
+
   SVN_ERR(svn_fs__check_fs(fs, TRUE));
 
+  SVN_ERR(svn_fs_git__revmap_update(fs, fgf,
+                                    cancel_func, cancel_baton,
+                                    pool));
+
   return SVN_NO_ERROR;
 }
 

Modified: 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=1717312&r1=1717311&r2=1717312&view=diff
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/gitdb.c (original)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/gitdb.c Mon Nov 30 19:51:36 2015
@@ -62,7 +62,36 @@ svn_fs_git__db_youngest_rev(svn_revnum_t
   return SVN_NO_ERROR;
 }
 
+svn_error_t *
+svn_fs_git__db_ensure_commit(svn_fs_t *fs,
+                             git_oid *oid,
+                             svn_revnum_t *latest_rev,
+                             git_reference *ref)
+{
+  svn_fs_git_fs_t *fgf = fs->fsap_data;
+  svn_sqlite__stmt_t *stmt;
+  svn_boolean_t got_row;
+  svn_revnum_t new_rev;
+
+  SVN_ERR(svn_sqlite__get_statement(&stmt, fgf->sdb, STMT_SELECT_REV_BY_COMMITID));
+  SVN_ERR(svn_sqlite__bind_blob(stmt, 1, oid, sizeof(*oid)));
+  SVN_ERR(svn_sqlite__step(&got_row, stmt));
+  SVN_ERR(svn_sqlite__reset(stmt));
+
+  if (got_row)
+    return SVN_NO_ERROR;
+
+  new_rev = *latest_rev + 1;
+  SVN_ERR(svn_sqlite__get_statement(&stmt, fgf->sdb, STMT_INSERT_COMMIT));
+  SVN_ERR(svn_sqlite__bind_revnum(stmt, 1, new_rev));
+  SVN_ERR(svn_sqlite__bind_blob(stmt, 2, oid, sizeof(*oid)));
+  SVN_ERR(svn_sqlite__bind_text(stmt, 3, "trunk"));
+  SVN_ERR(svn_sqlite__update(NULL, stmt));
 
+  *latest_rev = new_rev;
+
+  return SVN_NO_ERROR;
+}
 
 svn_error_t *
 svn_fs_git__db_open(svn_fs_t *fs,

Modified: 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=1717312&r1=1717311&r2=1717312&view=diff
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/revmap.c (original)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/revmap.c Mon Nov 30 19:51:36 2015
@@ -1 +1,119 @@
+/* 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 "svn_pools.h"
+#include "svn_fs.h"
+
+#include "private/svn_fs_private.h"
+#include "private/svn_sqlite.h"
+
+#include "fs_git.h"
+
+static svn_error_t *
+revmap_update_branch(svn_fs_t *fs,
+                     svn_fs_git_fs_t *fgf,
+                     git_reference *ref,
+                     svn_revnum_t *latest_rev,
+                     svn_cancel_func_t cancel_func,
+                     void *cancel_baton,
+                     apr_pool_t *scratch_pool)
+{
+  const char *name = git_reference_name(ref);
+  git_revwalk *revwalk = fgf->revwalk;
+  int git_err;
+  git_oid oid;
+
+  git_revwalk_reset(revwalk);
+  git_revwalk_push_ref(revwalk, name);
+  git_revwalk_simplify_first_parent(revwalk);
+  git_revwalk_sorting(revwalk, GIT_SORT_REVERSE);
+
+  while (!(git_err = git_revwalk_next(&oid, revwalk)))
+    {
+      SVN_ERR(svn_fs_git__db_ensure_commit(fs, &oid, latest_rev, ref));
+    }
+
+  if (git_err != GIT_ITEROVER)
+    return svn_fs_git__wrap_git_error();
+
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+revmap_update(svn_fs_t *fs,
+              svn_fs_git_fs_t *fgf,
+              svn_cancel_func_t cancel_func,
+              void *cancel_baton,
+              apr_pool_t *scratch_pool)
+{
+  git_branch_iterator *iter;
+  git_reference *ref;
+  git_branch_t branch_t;
+  apr_pool_t *iterpool = svn_pool_create(scratch_pool);
+  svn_error_t *err = NULL;
+  svn_revnum_t latest_rev, youngest;
+
+  SVN_ERR(svn_fs_git__db_youngest_rev(&youngest, fs, scratch_pool));
+  latest_rev = youngest;
+
+  GIT2_ERR(git_branch_iterator_new(&iter, fgf->repos, GIT_BRANCH_ALL));
+
+  while (!git_branch_next(&ref, &branch_t, iter) && !err)
+    {
+      svn_pool_clear(iterpool);
+      err = revmap_update_branch(fs, fgf, ref, &latest_rev,
+                                 cancel_func, cancel_baton,
+                                 iterpool);
+    }
+
+  git_branch_iterator_free(iter);
+
+  if (youngest < latest_rev) {
+    /* TODO: Make sqlite optimize the order a bit */
+  }
+
+  svn_pool_destroy(iterpool);
+
+  return svn_error_trace(err);
+}
+
+svn_error_t *
+svn_fs_git__revmap_update(svn_fs_t *fs,
+                          svn_fs_git_fs_t *fgf,
+                          svn_cancel_func_t cancel_func,
+                          void *cancel_baton,
+                          apr_pool_t *scratch_pool)
+{
+  if (!fgf->revwalk)
+    GIT2_ERR(git_revwalk_new(&fgf->revwalk, fgf->repos));
+
+  SVN_SQLITE__WITH_LOCK(revmap_update(fs, fgf,
+                                      cancel_func, cancel_baton,
+                                      scratch_pool),
+                        fgf->sdb);
+
+  return SVN_NO_ERROR;
+}

Modified: 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=1717312&r1=1717311&r2=1717312&view=diff
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/util.c (original)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/util.c Mon Nov 30 19:51:36 2015
@@ -27,8 +27,10 @@
 #include "svn_private_config.h"
 #include "fs_git.h"
 
+
+#undef svn_fs_git__wrap_git_error
 svn_error_t *
-svn_fs_git__wrap_git_error(int err)
+svn_fs_git__wrap_git_error(void)
 {
   git_error git_err;
 
@@ -39,4 +41,3 @@ svn_fs_git__wrap_git_error(int err)
   return svn_error_createf(SVN_ERR_FS_GIT_LIBGIT2_ERROR, NULL,
                            _("git: %s"), git_err.message);
 }
-