subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hwri...@apache.org
Subject svn commit: r1165787 - in /subversion/trunk: build.conf subversion/include/svn_delta.h subversion/libsvn_delta/compat.c subversion/tests/libsvn_delta/ subversion/tests/libsvn_delta/editor-test.c
Date Tue, 06 Sep 2011 19:06:38 GMT
Author: hwright
Date: Tue Sep  6 19:06:38 2011
New Revision: 1165787

URL: http://svn.apache.org/viewvc?rev=1165787&view=rev
Log:
Add some rough skeleton code for wrapping a delta editor in an svn_editor_t.

* subversion/include/svn_delta.h
  (svn_delta_from_editor): New.

* subversion/tests/libsvn_delta:
  (svn:ignore): Ignore the new tests and binary.

* subversion/tests/libsvn_delta/editor-test.c:
  New.

* subversion/libsvn_delta/compat.c
  (ev2_edit_baton, ev2_dir_baton, ev2_file_baton,
   ev2_set_target_revision,
   ev2_open_root,
   ev2_delete_entry,
   ev2_add_directory,
   ev2_open_directory,
   ev2_change_dir_prop,
   ev2_close_directory,
   ev2_absent_directory,
   ev2_add_file,
   ev2_open_file,
   ev2_apply_textdelta,
   ev2_change_file_prop,
   ev2_close_file,
   ev2_absent_file,
   ev2_close_edit,
   ev2_abort_edit,
   svn_delta_from_editor):
    New.

* build.conf
  (editor-test): New.

Added:
    subversion/trunk/subversion/tests/libsvn_delta/editor-test.c
Modified:
    subversion/trunk/build.conf
    subversion/trunk/subversion/include/svn_delta.h
    subversion/trunk/subversion/libsvn_delta/compat.c
    subversion/trunk/subversion/tests/libsvn_delta/   (props changed)

Modified: subversion/trunk/build.conf
URL: http://svn.apache.org/viewvc/subversion/trunk/build.conf?rev=1165787&r1=1165786&r2=1165787&view=diff
==============================================================================
--- subversion/trunk/build.conf (original)
+++ subversion/trunk/build.conf Tue Sep  6 19:06:38 2011
@@ -865,6 +865,14 @@ sources = random-test.c
 install = test
 libs = libsvn_test libsvn_delta libsvn_subr apriconv apr
 
+[editor-test]
+description = Test the editor v2 interface
+type = exe
+path = subversion/tests/libsvn_delta
+sources = editor-test.c
+install = test
+libs = libsvn_test libsvn_delta libsvn_subr apriconv apr
+
 [window-test]
 description = Test delta window generation
 type = exe

Modified: subversion/trunk/subversion/include/svn_delta.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_delta.h?rev=1165787&r1=1165786&r2=1165787&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_delta.h (original)
+++ subversion/trunk/subversion/include/svn_delta.h Tue Sep  6 19:06:38 2011
@@ -42,6 +42,8 @@
 #include "svn_io.h"
 #include "svn_checksum.h"
 
+#include "private/svn_editor.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif /* __cplusplus */
@@ -1085,6 +1087,22 @@ typedef struct svn_delta_editor_t
 svn_delta_editor_t *
 svn_delta_default_editor(apr_pool_t *pool);
 
+/* Return a delta editor and baton which will forward calls to @a editor,
+ * allocated in @a pool.
+ *
+ * @note: Since the semantics behind the two editors are different, calls
+ * the timing of calls forwarded to @a editor may be imprecise.  That is,
+ * the memory and computational overhead in using this forwarding
+ * mechanism may be large.
+ *
+ * @since New in 1.8.
+ */
+svn_error_t *
+svn_delta_from_editor(svn_delta_editor_t **deditor,
+                      void **dedit_baton,
+                      svn_editor_t *editor,
+                      apr_pool_t *pool);
+
 /** A text-delta window handler which does nothing.
  *
  * Editors can return this handler from @c apply_textdelta if they don't

Modified: subversion/trunk/subversion/libsvn_delta/compat.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_delta/compat.c?rev=1165787&r1=1165786&r2=1165787&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_delta/compat.c (original)
+++ subversion/trunk/subversion/libsvn_delta/compat.c Tue Sep  6 19:06:38 2011
@@ -76,3 +76,250 @@ svn_compat_wrap_file_rev_handler(svn_fil
   *handler2_baton = fwb;
   *handler2 = file_rev_handler_wrapper;
 }
+
+
+/* The following code maps the calls to a traditional delta editor to an
+ * Editorv2 editor.  It does this by keeping track of a lot of state, and
+ * then communicating that state to Ev2 upon closure of the file or dir (or
+ * edit).  Note that Ev2 calls add_symlink() and set_target() are not present
+ * in the delta editor paradigm, so we never call them.
+ *
+ * The general idea here is that we have to see *all* the actions on a node's
+ * parent before we can process that node, which means we need to buffer a
+ * large amount of information in the dir batons, and then process it in the
+ * close_directory() handler. */
+
+struct ev2_edit_baton
+{
+  svn_editor_t *editor;
+};
+
+struct ev2_dir_baton
+{
+  struct ev2_edit_baton *eb;
+};
+
+struct ev2_file_baton
+{
+  struct ev2_edit_baton *eb;
+};
+
+static svn_error_t *
+ev2_set_target_revision(void *edit_baton,
+                        svn_revnum_t target_revision,
+                        apr_pool_t *scratch_pool)
+{
+  struct ev2_edit_baton *eb = edit_baton;
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+ev2_open_root(void *edit_baton,
+              svn_revnum_t base_revision,
+              apr_pool_t *result_pool,
+              void **root_baton)
+{
+  struct ev2_dir_baton *db = apr_palloc(result_pool, sizeof(*db));
+  struct ev2_edit_baton *eb = edit_baton;
+
+  db->eb = eb;
+
+  *root_baton = db;
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+ev2_delete_entry(const char *path,
+                 svn_revnum_t revision,
+                 void *parent_baton,
+                 apr_pool_t *scratch_pool)
+{
+  struct ev2_dir_baton *pb = parent_baton;
+
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+ev2_add_directory(const char *path,
+                  void *parent_baton,
+                  const char *copyfrom_path,
+                  svn_revnum_t copyfrom_revision,
+                  apr_pool_t *result_pool,
+                  void **child_baton)
+{
+  struct ev2_dir_baton *pb = parent_baton;
+
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+ev2_open_directory(const char *path,
+                   void *parent_baton,
+                   svn_revnum_t base_revision,
+                   apr_pool_t *result_pool,
+                   void **child_baton)
+{
+  struct ev2_dir_baton *pb = parent_baton;
+  struct ev2_dir_baton *db = apr_palloc(result_pool, sizeof(*db));
+
+  db->eb = pb->eb;
+
+  *child_baton = db;
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+ev2_change_dir_prop(void *dir_baton,
+                    const char *name,
+                    const svn_string_t *value,
+                    apr_pool_t *scratch_pool)
+{
+  struct ev2_dir_baton *db = dir_baton;
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+ev2_close_directory(void *dir_baton,
+                    apr_pool_t *scratch_pool)
+{
+  struct ev2_dir_baton *db = dir_baton;
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+ev2_absent_directory(const char *path,
+                     void *parent_baton,
+                     apr_pool_t *scratch_pool)
+{
+  struct ev2_dir_baton *pb = parent_baton;
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+ev2_add_file(const char *path,
+             void *parent_baton,
+             const char *copyfrom_path,
+             svn_revnum_t copyfrom_revision,
+             apr_pool_t *result_pool,
+             void **file_baton)
+{
+  struct ev2_file_baton *fb = apr_palloc(result_pool, sizeof(*fb));
+  struct ev2_dir_baton *pb = parent_baton;
+
+  fb->eb = pb->eb;
+
+  *file_baton = fb;
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+ev2_open_file(const char *path,
+              void *parent_baton,
+              svn_revnum_t base_revision,
+              apr_pool_t *result_pool,
+              void **file_baton)
+{
+  struct ev2_file_baton *fb = apr_palloc(result_pool, sizeof(*fb));
+  struct ev2_dir_baton *pb = parent_baton;
+
+  fb->eb = pb->eb;
+
+  *file_baton = fb;
+  return SVN_NO_ERROR;
+}
+
+
+static svn_error_t *
+ev2_apply_textdelta(void *file_baton,
+                    const char *base_checksum,
+                    apr_pool_t *result_pool,
+                    svn_txdelta_window_handler_t *handler,
+                    void **handler_baton)
+{
+  struct ev2_file_baton *fb = file_baton;
+
+  *handler_baton = NULL;
+  *handler = svn_delta_noop_window_handler;
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+ev2_change_file_prop(void *file_baton,
+                     const char *name,
+                     const svn_string_t *value,
+                     apr_pool_t *scratch_pool)
+{
+  struct ev2_file_baton *fb = file_baton;
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+ev2_close_file(void *file_baton,
+               const char *text_checksum,
+               apr_pool_t *scratch_pool)
+{
+  struct ev2_file_baton *fb = file_baton;
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+ev2_absent_file(const char *path,
+                void *parent_baton,
+                apr_pool_t *scratch_pool)
+{
+  struct ev2_dir_baton *pb = parent_baton;
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+ev2_close_edit(void *edit_baton,
+               apr_pool_t *scratch_pool)
+{
+  struct ev2_edit_baton *eb = edit_baton;
+
+  return svn_error_trace(svn_editor_complete(eb->editor));
+}
+
+static svn_error_t *
+ev2_abort_edit(void *edit_baton,
+               apr_pool_t *scratch_pool)
+{
+  struct ev2_edit_baton *eb = edit_baton;
+
+  return svn_error_trace(svn_editor_abort(eb->editor));
+}
+
+svn_error_t *
+svn_delta_from_editor(svn_delta_editor_t **deditor,
+                      void **dedit_baton,
+                      svn_editor_t *editor,
+                      apr_pool_t *pool)
+{
+  /* Static 'cause we don't want it to be on the stack. */
+  static svn_delta_editor_t delta_editor = {
+      ev2_set_target_revision,
+      ev2_open_root,
+      ev2_delete_entry,
+      ev2_add_directory,
+      ev2_open_directory,
+      ev2_change_dir_prop,
+      ev2_close_directory,
+      ev2_absent_directory,
+      ev2_add_file,
+      ev2_open_file,
+      ev2_apply_textdelta,
+      ev2_change_file_prop,
+      ev2_close_file,
+      ev2_absent_file,
+      ev2_close_edit,
+      ev2_abort_edit
+    };
+  struct ev2_edit_baton *eb = apr_palloc(pool, sizeof(*eb));
+
+  eb->editor = editor;
+
+  *dedit_baton = eb;
+  *deditor = &delta_editor;
+
+  return SVN_NO_ERROR;
+}

Propchange: subversion/trunk/subversion/tests/libsvn_delta/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Sep  6 19:06:38 2011
@@ -1,6 +1,7 @@
 Debug
 Release
 .libs
+ev2-from-delta-editor-test
 deltaparse-test
 delta-combine-test
 vdelta-test
@@ -8,6 +9,7 @@ random-test
 xml-output-test
 svndiff-test
 window-test
+editor-test
 combined
 *.o
 *.lo

Added: subversion/trunk/subversion/tests/libsvn_delta/editor-test.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_delta/editor-test.c?rev=1165787&view=auto
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_delta/editor-test.c (added)
+++ subversion/trunk/subversion/tests/libsvn_delta/editor-test.c Tue Sep  6 19:06:38 2011
@@ -0,0 +1,250 @@
+/*
+ * editor-test.c:  Test editor APIs
+ *
+ * ====================================================================
+ *    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 <apr_pools.h>
+
+#include "../svn_test.h"
+
+#include "svn_types.h"
+#include "svn_error.h"
+#include "private/svn_editor.h"
+
+#include "../svn_test_fs.h"
+
+/* We use svn_repos APIs in some of these tests simply for convenience. */
+
+/* This implements svn_editor_cb_add_directory_t */
+static svn_error_t *
+add_directory_noop_cb(void *baton,
+                      const char *relpath,
+                      const apr_array_header_t *children,
+                      apr_hash_t *props,
+                      svn_revnum_t replaces_rev,
+                      apr_pool_t *scratch_pool)
+{
+  return SVN_NO_ERROR;
+}
+
+/* This implements svn_editor_cb_add_file_t */
+static svn_error_t *
+add_file_noop_cb(void *baton,
+                 const char *relpath,
+                 apr_hash_t *props,
+                 svn_revnum_t replaces_rev,
+                 apr_pool_t *scratch_pool)
+{
+  return SVN_NO_ERROR;
+}
+
+/* This implements svn_editor_cb_add_symlink_t */
+static svn_error_t *
+add_symlink_noop_cb(void *baton,
+                    const char *relpath,
+                    const char *target,
+                    apr_hash_t *props,
+                    svn_revnum_t replaces_rev,
+                    apr_pool_t *scratch_pool)
+{
+  return SVN_NO_ERROR;
+}
+
+/* This implements svn_editor_cb_add_absent_t */
+static svn_error_t *
+add_absent_noop_cb(void *baton,
+                   const char *relpath,
+                   svn_node_kind_t kind,
+                   svn_revnum_t replaces_rev,
+                   apr_pool_t *scratch_pool)
+{
+  return SVN_NO_ERROR;
+}
+
+/* This implements svn_editor_cb_set_props_t */
+static svn_error_t *
+set_props_noop_cb(void *baton,
+                  const char *relpath,
+                  svn_revnum_t revision,
+                  apr_hash_t *props,
+                  svn_boolean_t complete,
+                  apr_pool_t *scratch_pool)
+{
+  return SVN_NO_ERROR;
+}
+
+/* This implements svn_editor_cb_set_text_t */
+static svn_error_t *
+set_text_noop_cb(void *baton,
+                 const char *relpath,
+                 svn_revnum_t revision,
+                 const svn_checksum_t *checksum,
+                 svn_stream_t *contents,
+                 apr_pool_t *scratch_pool)
+{
+  return SVN_NO_ERROR;
+}
+
+/* This implements svn_editor_cb_set_target_t */
+static svn_error_t *
+set_target_noop_cb(void *baton,
+                   const char *relpath,
+                   svn_revnum_t revision,
+                   const char *target,
+                   apr_pool_t *scratch_pool)
+{
+  return SVN_NO_ERROR;
+}
+
+/* This implements svn_editor_cb_delete_t */
+static svn_error_t *
+delete_noop_cb(void *baton,
+               const char *relpath,
+               svn_revnum_t revision,
+               apr_pool_t *scratch_pool)
+{
+  return SVN_NO_ERROR;
+}
+
+/* This implements svn_editor_cb_copy_t */
+static svn_error_t *
+copy_noop_cb(void *baton,
+             const char *src_relpath,
+             svn_revnum_t src_revision,
+             const char *dst_relpath,
+             svn_revnum_t replaces_rev,
+             apr_pool_t *scratch_pool)
+{
+  return SVN_NO_ERROR;
+}
+
+/* This implements svn_editor_cb_move_t */
+static svn_error_t *
+move_noop_cb(void *baton,
+             const char *src_relpath,
+             svn_revnum_t src_revision,
+             const char *dst_relpath,
+             svn_revnum_t replaces_rev,
+             apr_pool_t *scratch_pool)
+{
+  return SVN_NO_ERROR;
+}
+
+/* This implements svn_editor_cb_complete_t */
+static svn_error_t *
+complete_noop_cb(void *baton,
+                 apr_pool_t *scratch_pool)
+{
+  return SVN_NO_ERROR;
+}
+
+/* This implements svn_editor_cb_abort_t */
+static svn_error_t *
+abort_noop_cb(void *baton,
+              apr_pool_t *scratch_pool)
+{
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+get_noop_editor(svn_editor_t **editor,
+                void *editor_baton,
+                svn_cancel_func_t cancel_func,
+                void *cancel_baton,
+                apr_pool_t *result_pool,
+                apr_pool_t *scratch_pool)
+{
+  svn_editor_cb_many_t editor_cbs = {
+      add_directory_noop_cb,
+      add_file_noop_cb,
+      add_symlink_noop_cb,
+      add_absent_noop_cb,
+      set_props_noop_cb,
+      set_text_noop_cb,
+      set_target_noop_cb,
+      delete_noop_cb,
+      copy_noop_cb,
+      move_noop_cb,
+      complete_noop_cb,
+      abort_noop_cb
+    };
+
+  SVN_ERR(svn_editor_create(editor, editor_baton, cancel_func, cancel_baton,
+                            result_pool, scratch_pool));
+  SVN_ERR(svn_editor_setcb_many(*editor, &editor_cbs, scratch_pool));
+
+  return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+editor_from_delta_editor_test(const svn_test_opts_t *opts,
+                              apr_pool_t *pool)
+{
+  svn_repos_t *repos;
+  svn_fs_t *fs;
+  svn_fs_txn_t *txn;
+  svn_fs_root_t *revision_root, *txn_root, *base_root;
+  svn_revnum_t youngest_rev;
+  void *dedit_baton;
+  svn_delta_editor_t *deditor;
+  svn_editor_t *editor;
+
+  /* Create a filesystem and repository. */
+  SVN_ERR(svn_test__create_repos(&repos, "ev2-from-delta-editor-test",
+                                 opts, pool));
+  fs = svn_repos_fs(repos);
+
+  /* Prepare a txn to receive the greek tree. */
+  SVN_ERR(svn_fs_begin_txn(&txn, fs, 0, pool));
+  SVN_ERR(svn_fs_txn_root(&txn_root, txn, pool));
+
+  /* Create and commit the greek tree. */
+  SVN_ERR(svn_test__create_greek_tree(txn_root, pool));
+  SVN_ERR(svn_repos_fs_commit_txn(NULL, repos, &youngest_rev, txn, pool));
+  SVN_TEST_ASSERT(SVN_IS_VALID_REVNUM(youngest_rev));
+
+  SVN_ERR(svn_fs_revision_root(&revision_root, fs, youngest_rev, pool));
+  SVN_ERR(svn_fs_revision_root(&base_root, fs, 0, pool));
+
+  /* Construct our editor, and from it a delta editor. */
+  SVN_ERR(get_noop_editor(&editor, NULL, NULL, NULL, pool, pool));
+  SVN_ERR(svn_delta_from_editor(&deditor, &dedit_baton, editor, pool));
+
+  SVN_ERR(svn_repos_replay2(revision_root, "", SVN_INVALID_REVNUM, TRUE,
+                            deditor, dedit_baton, NULL, NULL, pool));
+
+  /* Close the edit. */
+  SVN_ERR(deditor->close_edit(dedit_baton, pool));
+
+  return SVN_NO_ERROR;
+}
+
+
+
+/* The test table.  */
+
+struct svn_test_descriptor_t test_funcs[] =
+  {
+    SVN_TEST_NULL,
+    SVN_TEST_OPTS_PASS(editor_from_delta_editor_test,
+                       "editor creation from delta editor"),
+    SVN_TEST_NULL
+  };



Mime
View raw message