You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by iv...@apache.org on 2016/01/08 23:14:31 UTC

svn commit: r1723809 - in /subversion/branches/fs-node-api/subversion: include/svn_fs.h libsvn_fs/fs-loader.c libsvn_fs/fs-loader.h libsvn_fs/node_compat.c libsvn_fs/node_compat.h tests/svn_test_fs.c

Author: ivan
Date: Fri Jan  8 22:14:31 2016
New Revision: 1723809

URL: http://svn.apache.org/viewvc?rev=1723809&view=rev
Log:
On 'fs-node-api' branch: Add function to obtain svn_fs_node_t object by
ROOT + PATH and function to obtain kind of node referenced by svn_fs_node_t.

* subversion/include/svn_fs.h
  (svn_fs_open_node): New.
  (svn_fs_node_kind): New.

* subversion/libsvn_fs/fs-loader.h
  (node_vtable_t): New.
  (struct svn_fs_node_t): Declare svn_fs_node_t struct.

* subversion/libsvn_fs/fs-loader.c
  (): Include node_compat.h.
  (svn_fs_open_node, svn_fs_node_kind): New.

* subversion/libsvn_fs/node_compat.h
* subversion/libsvn_fs/node_compat.c
  (svn_fs__create_node_shim, compat_node_data_t, get_root,
   compat_fs_node_kind): New.

* subversion/tests/svn_test_fs.c
  (validate_tree_entry, svn_test__validate_tree): Validate tree using FS node
   API also.

Added:
    subversion/branches/fs-node-api/subversion/libsvn_fs/node_compat.c   (with props)
    subversion/branches/fs-node-api/subversion/libsvn_fs/node_compat.h   (with props)
Modified:
    subversion/branches/fs-node-api/subversion/include/svn_fs.h
    subversion/branches/fs-node-api/subversion/libsvn_fs/fs-loader.c
    subversion/branches/fs-node-api/subversion/libsvn_fs/fs-loader.h
    subversion/branches/fs-node-api/subversion/tests/svn_test_fs.c

Modified: subversion/branches/fs-node-api/subversion/include/svn_fs.h
URL: http://svn.apache.org/viewvc/subversion/branches/fs-node-api/subversion/include/svn_fs.h?rev=1723809&r1=1723808&r2=1723809&view=diff
==============================================================================
--- subversion/branches/fs-node-api/subversion/include/svn_fs.h (original)
+++ subversion/branches/fs-node-api/subversion/include/svn_fs.h Fri Jan  8 22:14:31 2016
@@ -1633,6 +1633,23 @@ svn_fs_paths_changed(apr_hash_t **change
  */
 typedef struct svn_fs_node_t svn_fs_node_t;
 
+/** Open the transaction named @a name in the filesystem @a fs.  Set @a *txn
+ * to the transaction.
+
+/** Open the node present at @a path under @a root. Set @a *node_p to the node
+ * Sets @a *node_p to NULL if @a path does not exist under @a root
+ * and @a ignore_enoent is non-zero. Returns error otherwise.
+ * Allocats @a *node_p in @a result_pool. Use @a scratch_pool for temporary
+ * allocation.
+ */
+svn_error_t *
+svn_fs_open_node(svn_fs_node_t **node_p,
+                 svn_fs_root_t *root,
+                 const char *path,
+                 svn_boolean_t ignore_enoent,
+                 apr_pool_t *result_pool,
+                 apr_pool_t *scratch_pool);
+
 /* Operations appropriate to all kinds of nodes.  */
 
 /** Set @a *kind_p to the type of node present at @a path under @a
@@ -1645,6 +1662,13 @@ svn_fs_check_path(svn_node_kind_t *kind_
                   const char *path,
                   apr_pool_t *pool);
 
+/** Set @a *kind_p to the type of node @a node.
+ * Use @a scratch_pool for temporary allocation.
+ */
+svn_error_t *
+svn_fs_node_kind(svn_node_kind_t *kind_p,
+                 svn_fs_node_t *node,
+                 apr_pool_t *scratch_pool);
 
 /** An opaque node history object. */
 typedef struct svn_fs_history_t svn_fs_history_t;

Modified: subversion/branches/fs-node-api/subversion/libsvn_fs/fs-loader.c
URL: http://svn.apache.org/viewvc/subversion/branches/fs-node-api/subversion/libsvn_fs/fs-loader.c?rev=1723809&r1=1723808&r2=1723809&view=diff
==============================================================================
--- subversion/branches/fs-node-api/subversion/libsvn_fs/fs-loader.c (original)
+++ subversion/branches/fs-node-api/subversion/libsvn_fs/fs-loader.c Fri Jan  8 22:14:31 2016
@@ -50,6 +50,7 @@
 #include "private/svn_subr_private.h"
 
 #include "fs-loader.h"
+#include "node_compat.h"
 
 /* This is defined by configure on platforms which use configure, but
    we need to define a fallback for Windows. */
@@ -1054,6 +1055,47 @@ svn_fs_check_path(svn_node_kind_t *kind_
 }
 
 svn_error_t *
+svn_fs_open_node(svn_fs_node_t **node_p,
+                 svn_fs_root_t *root,
+                 const char *path,
+                 svn_boolean_t ignore_enoent,
+                 apr_pool_t *result_pool,
+                 apr_pool_t *scratch_pool)
+{
+#if 0
+  if (root->vtable->open_node)
+    {
+      return svn_error_trace(root->vtable->open_node(...));
+    }
+  else
+#endif
+    {
+      svn_node_kind_t kind;
+      SVN_ERR(svn_fs_check_path(&kind, root, path, scratch_pool));
+      if (kind == svn_node_none && ignore_enoent)
+        {
+          *node_p = NULL;
+          return SVN_NO_ERROR;
+        }
+      else if (kind == svn_node_none && !ignore_enoent)
+        return SVN_FS__NOT_FOUND(root, path);
+      else
+        {
+          *node_p = svn_fs__create_node_shim(root, path, kind, result_pool);
+          return SVN_NO_ERROR;
+        }
+    }
+}
+
+svn_error_t *
+svn_fs_node_kind(svn_node_kind_t *kind_p,
+                 svn_fs_node_t *node,
+                 apr_pool_t *scratch_pool)
+{
+  return svn_error_trace(node->vtable->node_kind(kind_p, node, scratch_pool));
+}
+
+svn_error_t *
 svn_fs_node_history2(svn_fs_history_t **history_p, svn_fs_root_t *root,
                      const char *path, apr_pool_t *result_pool,
                      apr_pool_t *scratch_pool)

Modified: subversion/branches/fs-node-api/subversion/libsvn_fs/fs-loader.h
URL: http://svn.apache.org/viewvc/subversion/branches/fs-node-api/subversion/libsvn_fs/fs-loader.h?rev=1723809&r1=1723808&r2=1723809&view=diff
==============================================================================
--- subversion/branches/fs-node-api/subversion/libsvn_fs/fs-loader.h (original)
+++ subversion/branches/fs-node-api/subversion/libsvn_fs/fs-loader.h Fri Jan  8 22:14:31 2016
@@ -444,6 +444,12 @@ typedef struct id_vtable_t
                                     const svn_fs_id_t *b);
 } id_vtable_t;
 
+typedef struct node_vtable_t
+{
+  svn_error_t *(*node_kind)(svn_node_kind_t *kind_p,
+                            svn_fs_node_t *node,
+                            apr_pool_t *scratch_pool);
+} node_vtable_t;
 
 
 /*** Definitions of the abstract FS object types ***/
@@ -564,6 +570,12 @@ struct svn_fs_lock_target_t
   svn_revnum_t current_rev;
 };
 
+struct svn_fs_node_t
+{
+  /* FSAP-specific vtable and private data */
+  const node_vtable_t *vtable;
+  void *fsap_data;
+};
 
 #ifdef __cplusplus
 }

Added: subversion/branches/fs-node-api/subversion/libsvn_fs/node_compat.c
URL: http://svn.apache.org/viewvc/subversion/branches/fs-node-api/subversion/libsvn_fs/node_compat.c?rev=1723809&view=auto
==============================================================================
--- subversion/branches/fs-node-api/subversion/libsvn_fs/node_compat.c (added)
+++ subversion/branches/fs-node-api/subversion/libsvn_fs/node_compat.c Fri Jan  8 22:14:31 2016
@@ -0,0 +1,99 @@
+/*
+ * node_compat.c:  Compatibility shims implementation of svn_fs_node_t
+ *
+ * ====================================================================
+ *    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-loader.h"
+#include "node_compat.h"
+
+typedef struct compat_node_data_t
+{
+  svn_fs_t *fs;
+  const char *path;
+  svn_node_kind_t node_kind;
+  const char *txn_name;
+  svn_revnum_t rev;
+} compat_node_data_t;
+
+/* Sets *ROOT_P to temporary FS root object referenced by node with
+ * node private data FND. */
+static svn_error_t *
+get_root(svn_fs_root_t **root_p,
+         compat_node_data_t *fnd,
+         apr_pool_t *pool)
+{
+  if (fnd->txn_name)
+    {
+      svn_fs_txn_t *txn;
+      SVN_ERR(svn_fs_open_txn(&txn, fnd->fs, fnd->txn_name, pool));
+      SVN_ERR(svn_fs_txn_root(root_p, txn, pool));
+      return SVN_NO_ERROR;
+    }
+  else
+    {
+      SVN_ERR(svn_fs_revision_root(root_p, fnd->fs, fnd->rev, pool));
+      return SVN_NO_ERROR;
+    }
+}
+
+static svn_error_t *
+compat_fs_node_kind(svn_node_kind_t *kind_p,
+                    svn_fs_node_t *node,
+                    apr_pool_t *scratch_pool)
+{
+  compat_node_data_t *fnd = node->fsap_data;
+  *kind_p = fnd->node_kind;
+  return SVN_NO_ERROR;
+}
+
+static const node_vtable_t compat_node_vtable = 
+{
+  compat_fs_node_kind,
+};
+
+svn_fs_node_t *
+svn_fs__create_node_shim(svn_fs_root_t *root,
+                         const char *path,
+                         svn_node_kind_t kind,
+                         apr_pool_t *result_pool)
+{
+  compat_node_data_t *fnd = apr_palloc(result_pool,
+      sizeof(*fnd));
+  svn_fs_node_t *node = apr_palloc(result_pool, sizeof(*node));
+  fnd->fs = root->fs;
+  if (root->is_txn_root)
+    {
+      fnd->txn_name = apr_pstrdup(result_pool, root->txn);
+      fnd->rev = SVN_INVALID_REVNUM;
+    }
+  else
+    {
+      fnd->txn_name = NULL;
+      fnd->rev = root->rev;
+    }
+
+  fnd->path = apr_pstrdup(result_pool, path);
+  fnd->node_kind = kind;
+
+  node->vtable = &compat_node_vtable;
+  node->fsap_data = fnd;
+
+  return node;
+}

Propchange: subversion/branches/fs-node-api/subversion/libsvn_fs/node_compat.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: subversion/branches/fs-node-api/subversion/libsvn_fs/node_compat.h
URL: http://svn.apache.org/viewvc/subversion/branches/fs-node-api/subversion/libsvn_fs/node_compat.h?rev=1723809&view=auto
==============================================================================
--- subversion/branches/fs-node-api/subversion/libsvn_fs/node_compat.h (added)
+++ subversion/branches/fs-node-api/subversion/libsvn_fs/node_compat.h Fri Jan  8 22:14:31 2016
@@ -0,0 +1,33 @@
+/*
+ * node_compat.h:  Compatibility shims implementation of svn_fs_node_t
+ *
+ * ====================================================================
+ *    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>
+
+/* Creates svn_fs_node_t object of the node identified by ROOT + PATH
+ * of type KIND.
+ * Allocates result in RESULT_POOL.
+ */
+svn_fs_node_t *
+svn_fs__create_node_shim(svn_fs_root_t *root,
+                         const char *path,
+                         svn_node_kind_t kind,
+                         apr_pool_t *result_pool);

Propchange: subversion/branches/fs-node-api/subversion/libsvn_fs/node_compat.h
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: subversion/branches/fs-node-api/subversion/tests/svn_test_fs.c
URL: http://svn.apache.org/viewvc/subversion/branches/fs-node-api/subversion/tests/svn_test_fs.c?rev=1723809&r1=1723808&r2=1723809&view=diff
==============================================================================
--- subversion/branches/fs-node-api/subversion/tests/svn_test_fs.c (original)
+++ subversion/branches/fs-node-api/subversion/tests/svn_test_fs.c Fri Jan  8 22:14:31 2016
@@ -451,6 +451,7 @@ validate_tree_entry(svn_fs_root_t *root,
   svn_stringbuf_t *rstring;
   svn_node_kind_t kind;
   svn_boolean_t is_dir, is_file;
+  svn_fs_node_t *node;
 
   /* Verify that node types are reported consistently. */
   SVN_ERR(svn_fs_check_path(&kind, root, path, pool));
@@ -488,6 +489,16 @@ validate_tree_entry(svn_fs_root_t *root,
            path);
     }
 
+  /* Validate the same using FS node API. */
+  SVN_ERR(svn_fs_open_node(&node, root, path, FALSE, pool, pool));
+  SVN_ERR(svn_fs_node_kind(&kind, node, pool));
+  if ((kind == svn_node_file && !contents) ||
+      (kind == svn_node_dir && contents))
+    return svn_error_createf
+      (SVN_ERR_FS_GENERAL, NULL,
+       "node '%s' in tree was of unexpected node type",
+       path);
+
   return SVN_NO_ERROR;
 }
 
@@ -611,6 +622,7 @@ svn_test__validate_tree(svn_fs_root_t *r
     {
       svn_node_kind_t kind;
       svn_boolean_t is_dir, is_file;
+      svn_fs_node_t *node;
 
       /* Verify that the node is reported as "n/a". */
       SVN_ERR(svn_fs_check_path(&kind, root, na_name, subpool));
@@ -620,6 +632,15 @@ svn_test__validate_tree(svn_fs_root_t *r
       SVN_TEST_ASSERT(kind == svn_node_none);
       SVN_TEST_ASSERT(!is_file);
       SVN_TEST_ASSERT(!is_dir);
+
+      /* Verify the same using FS node API. */
+      SVN_ERR(svn_fs_open_node(&node, root, na_name, TRUE,
+                               subpool, subpool));
+      SVN_TEST_ASSERT(node == NULL);
+
+      SVN_TEST_ASSERT_ERROR(svn_fs_open_node(&node, root, na_name,
+                                             FALSE, subpool, subpool),
+                            SVN_ERR_FS_NOT_FOUND);
     }
 
   if (missing_entries || extra_entries || corrupt_entries)