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/12/03 17:31:07 UTC

svn commit: r1717799 - in /subversion/branches/ra-git/subversion/libsvn_fs_git: fs_git.h git-revroot.c svn_git.c svn_git.h

Author: rhuijben
Date: Thu Dec  3 16:31:07 2015
New Revision: 1717799

URL: http://svn.apache.org/viewvc?rev=1717799&view=rev
Log:
On the ra-git branch: Extract a few fs-git helper methods to a header file
to allow reusing in other parts.

* subversion/libsvn_fs_git/fs_git.h
  (includes): Include svn_git.h instead of git2.h.

* subversion/libsvn_fs_git/git-revroot.c
  (cleanup_git_object,
   cleanup_git_commit,
   cleanup_git_tree): Remove functions.
  (get_entry_object,
   get_commit_tree): Remove here.
  (find_commit): Reimplement using svn_git__commit_lookup.

* subversion/libsvn_fs_git/svn_git.c
  New file. Use some macros to avoid duplicating common patterns.

* subversion/libsvn_fs_git/svn_git.h
  New file.

Added:
    subversion/branches/ra-git/subversion/libsvn_fs_git/svn_git.c   (with props)
    subversion/branches/ra-git/subversion/libsvn_fs_git/svn_git.h   (with props)
Modified:
    subversion/branches/ra-git/subversion/libsvn_fs_git/fs_git.h
    subversion/branches/ra-git/subversion/libsvn_fs_git/git-revroot.c

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=1717799&r1=1717798&r2=1717799&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 Thu Dec  3 16:31:07 2015
@@ -20,14 +20,11 @@
 * ====================================================================
 */
 
-/* We compile in C89 mode, so the 'inline' keyword used by libgit2 isn't supported. */
-#define inline APR_INLINE
-#include <git2.h>
-#undef inline
-
 #include "svn_fs.h"
 #include "private/svn_sqlite.h"
 
+#include "svn_git.h"
+
 #ifndef SVN_LIBSVN_FS__FS_GIT_H
 #define SVN_LIBSVN_FS__FS_GIT_H
 

Modified: subversion/branches/ra-git/subversion/libsvn_fs_git/git-revroot.c
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/libsvn_fs_git/git-revroot.c?rev=1717799&r1=1717798&r2=1717799&view=diff
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/git-revroot.c (original)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/git-revroot.c Thu Dec  3 16:31:07 2015
@@ -55,57 +55,6 @@ typedef struct svn_fs_git_fs_id_t
   svn_fs_root_t *root;
 } svn_fs_git_fs_id_t;
 
-/* Helper for get_entry_object */
-static apr_status_t
-cleanup_git_object(void *baton)
-{
-  git_object_free(baton);
-  return APR_SUCCESS;
-}
-
-static apr_status_t
-cleanup_git_commit(void *baton)
-{
-  git_commit_free(baton);
-  return APR_SUCCESS;
-}
-
-static apr_status_t
-cleanup_git_tree(void *baton)
-{
-  git_tree_free(baton);
-  return APR_SUCCESS;
-}
-
-/* Gets the raw git object behind an entry. Takes care of the 'will free'
-   promise via the pool */
-static svn_error_t *
-get_entry_object(git_object **obj,
-                 const git_tree *tree,
-                 const git_tree_entry *entry,
-                 apr_pool_t *result_pool)
-{
-  GIT2_ERR(git_tree_entry_to_object(obj, git_tree_owner(tree), entry));
-
-  apr_pool_cleanup_register(result_pool, *obj, cleanup_git_object,
-                            apr_pool_cleanup_null);
-
-  return SVN_NO_ERROR;
-}
-
-static svn_error_t *
-get_commit_tree(git_tree **tree,
-                const git_commit *commit,
-                apr_pool_t *result_pool)
-{
-  GIT2_ERR(git_commit_tree(tree, commit));
-
-  apr_pool_cleanup_register(result_pool, *tree, cleanup_git_tree,
-                            apr_pool_cleanup_null);
-
-  return SVN_NO_ERROR;
-}
-
 /* We don't have real ids (yet) */
 static svn_string_t *fs_git_id_unparse(const svn_fs_id_t *id,
                                        apr_pool_t *pool)
@@ -209,17 +158,9 @@ find_commit(const git_commit **commit, s
             const git_oid *oid, apr_pool_t *result_pool)
 {
   svn_fs_git_fs_t *fgf = root->fs->fsap_data;
-  git_commit *cmt;
-
-  GIT2_ERR(git_commit_lookup(&cmt, fgf->repos, oid));
 
-  if (cmt)
-    {
-      apr_pool_cleanup_register(result_pool, cmt, cleanup_git_commit,
-                                apr_pool_cleanup_null);
-    }
-  *commit = cmt;
-  return SVN_NO_ERROR;
+  return svn_error_trace(
+    svn_git__commit_lookup(commit, fgf->repos, oid, result_pool));
 }
 
 static svn_error_t *
@@ -251,7 +192,7 @@ find_tree_entry(const git_tree_entry **e
           git_object *obj;
           git_tree *sub_tree;
 
-          SVN_ERR(get_entry_object(&obj, tree, e, result_pool));
+          SVN_ERR(svn_git__tree_entry_to_object(&obj, tree, e, result_pool));
 
           sub_tree = (git_tree*)obj;
 
@@ -373,10 +314,10 @@ walk_tree_for_changes(apr_hash_t *change
         {
           git_object *e_new_tree, *e_old_tree;
 
-          SVN_ERR(get_entry_object(&e_new_tree, new_tree, entry,
-                                    iterpool));
-          SVN_ERR(get_entry_object(&e_old_tree, old_tree, old_entry,
-                                    iterpool));
+          SVN_ERR(svn_git__tree_entry_to_object(&e_new_tree, new_tree,
+                                                entry, iterpool));
+          SVN_ERR(svn_git__tree_entry_to_object(&e_old_tree, old_tree,
+                                                old_entry, iterpool));
 
           SVN_ERR(walk_tree_for_changes(
                       changed_paths,
@@ -429,8 +370,8 @@ walk_tree_for_changes(apr_hash_t *change
           svn_hash_sets(changed_paths, make_fspath(epath, result_pool),
                         ch);
 
-          SVN_ERR(get_entry_object(&e_new_tree, new_tree, entry,
-                                    iterpool));
+          SVN_ERR(svn_git__tree_entry_to_object(&e_new_tree, new_tree, entry,
+                                                iterpool));
 
           SVN_ERR(walk_tree_for_changes(
                           changed_paths, epath, root,
@@ -523,13 +464,13 @@ fs_git_paths_changed(apr_hash_t **change
     return SVN_NO_ERROR; /* No actual changes in this revision*/
 
   SVN_ERR(find_commit(&commit, root, cmt_oid, pool));
-  SVN_ERR(get_commit_tree(&tree, commit, pool));
+  SVN_ERR(svn_git__commit_tree(&tree, commit, pool));
   parent_oid = git_commit_parent_id(commit, 0);
 
   if (parent_oid)
     {
       SVN_ERR(find_commit(&parent_commit, root, parent_oid, pool));
-      SVN_ERR(get_commit_tree(&parent_tree, parent_commit, pool));
+      SVN_ERR(svn_git__commit_tree(&parent_tree, parent_commit, pool));
     }
   else
     {
@@ -581,7 +522,7 @@ fs_git_check_path(svn_node_kind_t *kind_
       return SVN_NO_ERROR;
     }
 
-  SVN_ERR(get_commit_tree(&tree, commit, pool));
+  SVN_ERR(svn_git__commit_tree(&tree, commit, pool));
   SVN_ERR(find_tree_entry(&entry, tree, relpath, pool, pool));
 
   if (!entry)
@@ -650,7 +591,7 @@ fs_git_node_history(svn_fs_history_t **h
       return SVN_NO_ERROR;
     }
 
-  SVN_ERR(get_commit_tree(&tree, commit, scratch_pool));
+  SVN_ERR(svn_git__commit_tree(&tree, commit, scratch_pool));
   SVN_ERR(find_tree_entry(&entry, tree, relpath, scratch_pool, scratch_pool));
 
   if (!entry)
@@ -737,8 +678,8 @@ fs_git_node_relation(svn_fs_node_relatio
       return SVN_NO_ERROR;
     }
 
-  SVN_ERR(get_commit_tree(&tree_a, commit_a, scratch_pool));
-  SVN_ERR(get_commit_tree(&tree_b, commit_b, scratch_pool));
+  SVN_ERR(svn_git__commit_tree(&tree_a, commit_a, scratch_pool));
+  SVN_ERR(svn_git__commit_tree(&tree_b, commit_b, scratch_pool));
 
   SVN_ERR(find_tree_entry(&entry_a, tree_a, relpath_a,
                           scratch_pool, scratch_pool));
@@ -802,7 +743,7 @@ fs_git_node_created_rev(svn_revnum_t *re
     }
   iterpool = svn_pool_create(pool);
 
-  SVN_ERR(get_commit_tree(&rev_tree, rev_commit, iterpool));
+  SVN_ERR(svn_git__commit_tree(&rev_tree, rev_commit, iterpool));
   SVN_ERR(find_tree_entry(&rev_entry, rev_tree, relpath, pool, iterpool));
 
   last_oid = *git_commit_id(rev_commit);
@@ -819,7 +760,7 @@ fs_git_node_created_rev(svn_revnum_t *re
 
       SVN_ERR(find_commit(&cmt, root, oid_p, iterpool));
 
-      SVN_ERR(get_commit_tree(&cmt_tree, cmt, iterpool));
+      SVN_ERR(svn_git__commit_tree(&cmt_tree, cmt, iterpool));
 
       SVN_ERR(find_tree_entry(&cmt_entry, cmt_tree, relpath,
                               iterpool, iterpool));
@@ -1046,7 +987,7 @@ fs_git_dir_entries(apr_hash_t **entries_
       return SVN_NO_ERROR;
     }
 
-  SVN_ERR(get_commit_tree(&tree, commit, pool));
+  SVN_ERR(svn_git__commit_tree(&tree, commit, pool));
 
   if (*relpath)
     {
@@ -1058,7 +999,7 @@ fs_git_dir_entries(apr_hash_t **entries_
       if (!entry || git_tree_entry_type(entry) != GIT_OBJ_TREE)
         return SVN_FS__ERR_NOT_DIRECTORY(root->fs, path);
 
-      SVN_ERR(get_entry_object(&obj, tree, entry, pool));
+      SVN_ERR(svn_git__tree_entry_to_object(&obj, tree, entry, pool));
 
       tree = (git_tree*)obj;
     }
@@ -1128,7 +1069,7 @@ fs_git_file_length(svn_filesize_t *lengt
   if (!commit)
     return SVN_FS__ERR_NOT_FILE(root->fs, path);
 
-  SVN_ERR(get_commit_tree(&tree, commit, pool));
+  SVN_ERR(svn_git__commit_tree(&tree, commit, pool));
 
   SVN_ERR(find_tree_entry(&entry, tree, relpath, pool, pool));
 
@@ -1141,7 +1082,7 @@ fs_git_file_length(svn_filesize_t *lengt
       /* ### TODO */
     }
 
-  SVN_ERR(get_entry_object(&obj, tree, entry, pool));
+  SVN_ERR(svn_git__tree_entry_to_object(&obj, tree, entry, pool));
 
   blob = (git_blob*)obj;
 
@@ -1164,7 +1105,7 @@ fs_git_file_checksum(svn_checksum_t **ch
   if (!commit)
     return SVN_FS__ERR_NOT_FILE(root->fs, path);
 
-  SVN_ERR(get_commit_tree(&tree, commit, pool));
+  SVN_ERR(svn_git__commit_tree(&tree, commit, pool));
 
   SVN_ERR(find_tree_entry(&entry, tree, relpath, pool, pool));
 
@@ -1198,7 +1139,7 @@ fs_git_file_contents(svn_stream_t **cont
   if (!commit)
     return SVN_FS__ERR_NOT_FILE(root->fs, path);
 
-  SVN_ERR(get_commit_tree(&tree, commit, pool));
+  SVN_ERR(svn_git__commit_tree(&tree, commit, pool));
 
   SVN_ERR(find_tree_entry(&entry, tree, relpath, pool, pool));
 
@@ -1277,8 +1218,8 @@ fs_git_contents_changed(int *changed_p,
   else if (!commit_b)
     return SVN_FS__ERR_NOT_FILE(root_b->fs, path_b);
 
-  SVN_ERR(get_commit_tree(&tree_a, commit_a, scratch_pool));
-  SVN_ERR(get_commit_tree(&tree_b, commit_b, scratch_pool));
+  SVN_ERR(svn_git__commit_tree(&tree_a, commit_a, scratch_pool));
+  SVN_ERR(svn_git__commit_tree(&tree_b, commit_b, scratch_pool));
 
   SVN_ERR(find_tree_entry(&entry_a, tree_a, relpath_a,
                           scratch_pool, scratch_pool));

Added: subversion/branches/ra-git/subversion/libsvn_fs_git/svn_git.c
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/libsvn_fs_git/svn_git.c?rev=1717799&view=auto
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/svn_git.c (added)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/svn_git.c Thu Dec  3 16:31:07 2015
@@ -0,0 +1,130 @@
+/* svn-git.c --- Some helper functions to ease working with libgit2
+ *
+ * ====================================================================
+ *    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 "fs_git.h"
+#include "svn_git.h"
+
+#define DECLARE_GIT_CLEANUP(type,func)              \
+  static apr_status_t cleanup_##type(void *baton)   \
+  {                                                 \
+      type *item = baton;                           \
+      func(item);                                   \
+      return APR_SUCCESS;                           \
+  }
+
+#define GIT_RELEASE_AT_CLEANUP(type, item, result_pool)       \
+  do                                                          \
+  {                                                           \
+      type *val_for_cleanup = item;                           \
+      apr_pool_cleanup_register(result_pool, val_for_cleanup, \
+                                cleanup_##type,               \
+                                apr_pool_cleanup_null);       \
+  } while (0)
+
+DECLARE_GIT_CLEANUP(git_repository, git_repository_free)
+DECLARE_GIT_CLEANUP(git_commit, git_commit_free)
+DECLARE_GIT_CLEANUP(git_object, git_object_free)
+DECLARE_GIT_CLEANUP(git_tree, git_tree_free)
+
+svn_error_t *
+svn_git__repository_open(const git_repository **repo_p,
+                         const char *local_abspath,
+                         apr_pool_t *result_pool)
+{
+  git_repository *repo;
+
+  GIT2_ERR(git_repository_open(&repo, local_abspath));
+
+  GIT_RELEASE_AT_CLEANUP(git_repository, repo, result_pool);
+
+  *repo_p = repo;
+  return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_git__repository_init(const git_repository **repo_p,
+                         const char *local_abspath,
+                         svn_boolean_t is_bare,
+                         apr_pool_t *result_pool)
+{
+  git_repository *repo;
+
+  GIT2_ERR(git_repository_init(&repo, local_abspath, is_bare));
+
+  GIT_RELEASE_AT_CLEANUP(git_repository, repo, result_pool);
+
+  *repo_p = repo;
+  return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_git__commit_lookup(const git_commit **commit_p,
+                       git_repository *repo,
+                       const git_oid *id,
+                       apr_pool_t *result_pool)
+{
+  git_commit *commit;
+
+  GIT2_ERR(git_commit_lookup(&commit, repo, id));
+
+  if (commit)
+    GIT_RELEASE_AT_CLEANUP(git_commit, commit, result_pool);
+
+  *commit_p = commit;
+  return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_git__commit_tree(const git_tree **tree_p,
+                     const git_commit *commit,
+                     apr_pool_t *result_pool)
+{
+  git_tree *tree;
+
+  GIT2_ERR(git_commit_tree(&tree, commit));
+
+  if (tree)
+    GIT_RELEASE_AT_CLEANUP(git_tree, tree, result_pool);
+
+  *tree_p = tree;
+  return SVN_NO_ERROR;
+}
+
+svn_error_t *
+svn_git__tree_entry_to_object(const git_object **object_p,
+                              const git_tree *tree,
+                              const git_tree_entry *entry,
+                              apr_pool_t *result_pool)
+{
+  git_object *object;
+
+  GIT2_ERR(git_tree_entry_to_object(&object,
+                                    git_tree_owner(tree),
+                                    entry));
+
+  if (object)
+    GIT_RELEASE_AT_CLEANUP(git_object, object, result_pool);
+
+  *object_p = object;
+
+  return SVN_NO_ERROR;
+}

Propchange: subversion/branches/ra-git/subversion/libsvn_fs_git/svn_git.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: subversion/branches/ra-git/subversion/libsvn_fs_git/svn_git.h
URL: http://svn.apache.org/viewvc/subversion/branches/ra-git/subversion/libsvn_fs_git/svn_git.h?rev=1717799&view=auto
==============================================================================
--- subversion/branches/ra-git/subversion/libsvn_fs_git/svn_git.h (added)
+++ subversion/branches/ra-git/subversion/libsvn_fs_git/svn_git.h Thu Dec  3 16:31:07 2015
@@ -0,0 +1,68 @@
+/* svn-git.c --- Some helper functions to ease working with libgit2
+ *
+ * ====================================================================
+ *    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.
+ * ====================================================================
+ */
+
+/* We compile in C89 mode, so the 'inline' keyword used by libgit2 isn't supported. */
+#define inline APR_INLINE
+#include <git2.h>
+#undef inline
+
+#include "svn_types.h"
+
+#ifndef SVN_LIBSVN_FS__SVN_GIT_H
+#define SVN_LIBSVN_FS__SVN_GIT_H
+
+
+/* Like git_repository_open() but lifetime limited by pool */
+svn_error_t *
+svn_git__repository_open(const git_repository **repo_p,
+                         const char *local_abspath,
+                         apr_pool_t *result_pool);
+
+/* Like git_repository_open() but lifetime limited by pool */
+svn_error_t *
+svn_git__repository_init(const git_repository **repo_p,
+                         const char *local_abspath,
+                         svn_boolean_t bare,
+                         apr_pool_t *result_pool);
+
+/* Like git_commit_lookup() but lifetime limited by pool */
+svn_error_t *
+svn_git__commit_lookup(const git_commit **commit,
+                       git_repository *repo,
+                       const git_oid *id,
+                       apr_pool_t *result_pool);
+
+/* Like git_commit_tree() but lifetime limited by pool */
+svn_error_t *
+svn_git__commit_tree(const git_tree **tree_p,
+                     const git_commit *commit,
+                     apr_pool_t *result_pool);
+
+/* Like git_tree_entry_to_object() but lifetime limited by pool */
+svn_error_t *
+svn_git__tree_entry_to_object(const git_object **object_p,
+                              const git_tree *tree,
+                              const git_tree_entry *entry,
+                              apr_pool_t *result_pool);
+
+
+#endif /* SVN_LIBSVN_FS__SVN_GIT_H*/

Propchange: subversion/branches/ra-git/subversion/libsvn_fs_git/svn_git.h
------------------------------------------------------------------------------
    svn:eol-style = native