Author: artagnon
Date: Thu Jul 29 19:30:39 2010
New Revision: 980547
URL: http://svn.apache.org/viewvc?rev=980547&view=rev
Log:
svnrdump: Redesign the API and workflow to use for loading
Get a generalized commit editor along with related data, and then
drive it with using the callback parser functions that get fired while
parsing the diff using svn_repos_parse_dumpstream.
* subversion/svnrdump/dumpfile_parser.c
(new_revision_record, uuid_record, new_node_record,
set_revision_property, set_node_property, delete_node_property,
remove_node_props, set_fulltext, apply_textdelta, close_node,
close_revision): Add new no-op functions to set in the
svn_repos_parse_fns2_t.
(new_revision_record, new_node_record): Add a small debugging aid:
when these functions are called, print a message to stderr to
indicate parsing progress.
(apply_txdelta): Do just enough to perform like a no-op without
crashing: set the handler/ handler_baton,
(apply_window): Add some WIP code inside an #if 0 block and another
no-op one outside. This is used by apply_textdelta to set the
svn_txdelta_window_handler_t.
(build_dumpfile_parser): Fill in information about the new callback
functions into the svn_repos_parse_fns2_t. Do some memory
allocations for various batons. This is still a heavy WIP, as most
of the information in the batons isn't used. Also, don't actually
call svn_repos_parse_dumpstream2; this function only builds the
parser to use. Related to this, change the API to exclude the stream
argument.
* subversion/svnrdump/load_editor.c
(drive_load_editor): Change API to take the editor/ edit_baton (to
be fetched from get_load_editor) and stream to use with the
dumpstream parser. Also add calls to build_dumpfile_parser and
svn_repos_parse_dumpstream2 appropriately.
(get_load_editor): Change the API to remove stream. The commit
editor needs to know nothing about the stream from which the
dumpfile will be parsed. Setup necessary batons and do the
appropriate memory allocations to actually make a successful call to
svn_ra_get_commit_editor3. Set the various arguments to return
appropriately.
* subversion/svnrdump/load_editor.h
(apply_baton): New baton to be used by txdelta applier.
(parse_baton): New baton to be used by some of the parse functions,
mainly to fetch data to put into other more specific batons.
(node_baton, revision_baton): Two new batons to be used by various
parse functions.
(commit_dir_baton): The directory baton to be used by the load
editor; taken from commit.c. ### It looks very similar to the
directory baton we use in dump_editor: can we use the same baton?
(build_dumpfile_parser, drive_load_editor, get_load_editor): Track
API changes.
* subversion/svnrdump/svnrdump.c
(load_revisions): Track the API and workflow changes.
Modified:
subversion/trunk/subversion/svnrdump/dumpfile_parser.c
subversion/trunk/subversion/svnrdump/load_editor.c
subversion/trunk/subversion/svnrdump/load_editor.h
subversion/trunk/subversion/svnrdump/svnrdump.c
Modified: subversion/trunk/subversion/svnrdump/dumpfile_parser.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/svnrdump/dumpfile_parser.c?rev=980547&r1=980546&r2=980547&view=diff
==============================================================================
--- subversion/trunk/subversion/svnrdump/dumpfile_parser.c (original)
+++ subversion/trunk/subversion/svnrdump/dumpfile_parser.c Thu Jul 29 19:30:39
2010
@@ -6,21 +6,160 @@
#include "load_editor.h"
+static svn_error_t *
+new_revision_record(void **revision_baton,
+ apr_hash_t *headers,
+ void *parse_baton,
+ apr_pool_t *pool)
+{
+ struct revision_baton *rb;
+ rb = apr_pcalloc(pool, sizeof(*rb));
+ rb->pb = parse_baton;
+
+ fprintf(stderr, "new_revision_record called\n");
+
+ *revision_baton = rb;
+ return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+uuid_record(const char *uuid,
+ void *parse_baton,
+ apr_pool_t *pool)
+{
+ return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+new_node_record(void **node_baton,
+ apr_hash_t *headers,
+ void *revision_baton,
+ apr_pool_t *pool)
+{
+ struct node_baton *nb;
+ nb = apr_pcalloc(pool, sizeof(*nb));
+ nb->rb = revision_baton;
+
+ fprintf(stderr, "new_node_record called\n");
+
+ *node_baton = nb;
+ return SVN_NO_ERROR;
+}
+
+
+static svn_error_t *
+set_revision_property(void *baton,
+ const char *name,
+ const svn_string_t *value)
+{
+ return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+set_node_property(void *baton,
+ const char *name,
+ const svn_string_t *value)
+{
+ return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+delete_node_property(void *baton,
+ const char *name)
+{
+ return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+remove_node_props(void *baton)
+{
+ return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+set_fulltext(svn_stream_t **stream,
+ void *node_baton)
+{
+ return SVN_NO_ERROR;
+}
+
+#if 0
+static svn_error_t *
+apply_window(svn_txdelta_window_t *window, void *baton)
+{
+ struct apply_baton *apply_baton;
+ apr_size_t tlen;
+ apply_baton = baton;
+ if (window == NULL)
+ return SVN_NO_ERROR;
+
+ tlen = window->tview_len;
+ apply_baton->target = apr_pcalloc(apply_baton->pool, tlen);
+ svn_txdelta_apply_instructions(window, apply_baton->source,
+ apply_baton->target, &tlen);
+ return SVN_NO_ERROR;
+}
+#endif
+
+static svn_error_t *
+apply_window(svn_txdelta_window_t *window, void *baton)
+{
+ return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+apply_textdelta(svn_txdelta_window_handler_t *handler,
+ void **handler_baton,
+ void *node_baton)
+{
+ struct node_baton *nb;
+ nb = node_baton;
+ *handler = apply_window;
+ *handler_baton = nb->rb->pb->ab;
+ return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+close_node(void *baton)
+{
+ return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+close_revision(void *baton)
+{
+ return SVN_NO_ERROR;
+}
+
svn_error_t *
build_dumpfile_parser(const svn_repos_parse_fns2_t **parser,
void **parse_baton,
- svn_stream_t *stream,
apr_pool_t *pool)
{
svn_repos_parse_fns2_t *pf;
+ struct parse_baton *pb;
+ struct apply_baton *ab;
pf = apr_pcalloc(pool, sizeof(*pf));
-
- SVN_ERR(svn_repos_parse_dumpstream2(stream, pf, NULL,
- NULL, NULL, pool));
+ pf->new_revision_record = new_revision_record;
+ pf->uuid_record = uuid_record;
+ pf->new_node_record = new_node_record;
+ pf->set_revision_property = set_revision_property;
+ pf->set_node_property = set_node_property;
+ pf->delete_node_property = delete_node_property;
+ pf->remove_node_props = remove_node_props;
+ pf->set_fulltext = set_fulltext;
+ pf->apply_textdelta = apply_textdelta;
+ pf->close_node = close_node;
+ pf->close_revision = close_revision;
+
+ pb = apr_pcalloc(pool, sizeof(*pb));
+ ab = apr_pcalloc(pool, sizeof(struct apply_baton));
+ ab->source = apr_pstrmemdup(pool, " ", sizeof(" "));
+ pb->ab = ab;
*parser = pf;
- *parse_baton = NULL;
+ *parse_baton = pb;
return SVN_NO_ERROR;
}
Modified: subversion/trunk/subversion/svnrdump/load_editor.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/svnrdump/load_editor.c?rev=980547&r1=980546&r2=980547&view=diff
==============================================================================
--- subversion/trunk/subversion/svnrdump/load_editor.c (original)
+++ subversion/trunk/subversion/svnrdump/load_editor.c Thu Jul 29 19:30:39 2010
@@ -44,10 +44,18 @@ commit_callback(const svn_commit_info_t
}
svn_error_t *
-drive_load_editor(struct operation *operation,
- const svn_delta_editor_t *editor,
+drive_load_editor(const svn_delta_editor_t *editor,
+ void *edit_baton,
+ struct operation *operation,
+ svn_stream_t *stream,
apr_pool_t *pool)
{
+ const svn_repos_parse_fns2_t *parser;
+ void *pb;
+ SVN_ERR(build_dumpfile_parser(&parser, &pb, pool));
+ SVN_ERR(svn_repos_parse_dumpstream2(stream, parser, pb,
+ NULL, NULL, pool));
+
return SVN_NO_ERROR;
}
@@ -57,25 +65,30 @@ svn_error_t *
get_load_editor(const svn_delta_editor_t **editor,
void **edit_baton,
struct operation **root_operation,
- svn_stream_t *stream,
svn_ra_session_t *session,
apr_pool_t *pool)
{
- const svn_repos_parse_fns2_t *parser;
- void *pb = NULL;
const svn_delta_editor_t *de;
struct operation *root;
+ struct commit_dir_baton *db;
+ apr_hash_t *revprop_table;
+ void *cb;
root = apr_pcalloc(pool, sizeof(*root));
+ db = apr_pcalloc(pool, sizeof(*db));
+ root->baton = db;
+ revprop_table = apr_hash_make(pool);
SVN_ERR(svn_ra_get_latest_revnum(session, &(root->revision), pool));
- SVN_ERR(build_dumpfile_parser(&parser, &pb, stream, pool));
- SVN_ERR(svn_ra_get_commit_editor3(session, &de, NULL, NULL,
+
+ /* Call the commit editor and get back a delta_editor and
+ commit_baton to use for performing the actual commit */
+ SVN_ERR(svn_ra_get_commit_editor3(session, &de, &cb, revprop_table,
commit_callback, NULL, NULL, FALSE, pool));
- SVN_ERR(de->open_root(NULL, root->revision, pool, root->baton));
+ SVN_ERR(de->open_root(cb, root->revision, pool, root->baton));
*editor = de;
- *edit_baton = NULL;
+ *edit_baton = cb;
*root_operation = root;
return SVN_NO_ERROR;
Modified: subversion/trunk/subversion/svnrdump/load_editor.h
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/svnrdump/load_editor.h?rev=980547&r1=980546&r2=980547&view=diff
==============================================================================
--- subversion/trunk/subversion/svnrdump/load_editor.h (original)
+++ subversion/trunk/subversion/svnrdump/load_editor.h Thu Jul 29 19:30:39 2010
@@ -29,6 +29,60 @@
#define LOAD_EDITOR_H_
/**
+ * Baton used by the txdelta applier.
+ */
+struct apply_baton
+{
+ const char *source;
+ char *target;
+ apr_pool_t *pool;
+};
+
+/**
+ * General baton used by the parser functions. Contains a link to
+ * apply baton.
+ */
+struct parse_baton
+{
+ struct apply_baton *ab;
+};
+
+/**
+ * Baton used to represent a node; to be used by the parser
+ * functions. Contains a link to the revision baton.
+ */
+struct node_baton
+{
+ const char *path;
+ svn_node_kind_t kind;
+
+ svn_revnum_t copyfrom_rev;
+ const char *copyfrom_path;
+
+ struct revision_baton *rb;
+ apr_pool_t *pool;
+};
+
+/**
+ * Baton used to represet a revision; used by the parser
+ * functions. Contains a link to the parser baton.
+ */
+struct revision_baton
+{
+ svn_revnum_t rev;
+
+ svn_fs_txn_t *txn;
+ svn_fs_root_t *txn_root;
+
+ const svn_string_t *datestamp;
+
+ apr_int32_t rev_offset;
+
+ struct parse_baton *pb;
+ apr_pool_t *pool;
+};
+
+/**
* Used to represent an operation to perform while driving the load
* editor.
*/
@@ -41,10 +95,22 @@ struct operation {
OP_PROPSET
} operation;
- svn_revnum_t revision; /* The revision on which the operation is being
performed */
- void *baton; /* as returned by the commit editor */
+ svn_revnum_t revision; /* The revision on which the operation is
being performed */
+ void *baton; /* Represents a commit_dir_baton object */
};
+/**
+ * A directory baton from commit.c.
+ */
+struct commit_dir_baton
+{
+ struct commit_baton *edit_baton;
+ struct commit_dir_baton *parent;
+ const char *path; /* the -absolute- path to this dir in the fs */
+ svn_revnum_t base_rev; /* the revision I'm based on */
+ svn_boolean_t was_copied; /* was this directory added with history? */
+ apr_pool_t *pool; /* my personal pool, in which I am allocated. */
+};
/**
* Build up a @a parser for parsing a dumpfile stream from @a stream
@@ -54,30 +120,29 @@ struct operation {
svn_error_t *
build_dumpfile_parser(const svn_repos_parse_fns2_t **parser,
void **parse_baton,
- svn_stream_t *stream,
apr_pool_t *pool);
/**
- * Drive the load editor @a editor to perform the @a operation on
- * @a revison using @a pool for all memory allocations.
+ * Drive the load editor @a editor using the data in @a stream using
+ * @a pool for all memory allocations.
*/
svn_error_t *
-drive_load_editor(struct operation *operation,
- const svn_delta_editor_t *editor,
+drive_load_editor(const svn_delta_editor_t *editor,
+ void *edit_baton,
+ struct operation *operation,
+ svn_stream_t *stream,
apr_pool_t *pool);
/**
* Get a load editor @a editor along with an @a edit_baton and an
* operation @a root_operation corresponding to open_root, all
- * allocated in @a pool. The editor will read a dumpstream from @a
- * stream and load it into @a session when driven using
- * drive_load_editor().
+ * allocated in @a pool. The load editor will commit revisions to @a
+ * session when driven using drive_load_editor().
*/
svn_error_t *
get_load_editor(const svn_delta_editor_t **editor,
void **edit_baton,
struct operation **root_operation,
- svn_stream_t *stream,
svn_ra_session_t *session,
apr_pool_t *pool);
Modified: subversion/trunk/subversion/svnrdump/svnrdump.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/svnrdump/svnrdump.c?rev=980547&r1=980546&r2=980547&view=diff
==============================================================================
--- subversion/trunk/subversion/svnrdump/svnrdump.c (original)
+++ subversion/trunk/subversion/svnrdump/svnrdump.c Thu Jul 29 19:30:39 2010
@@ -299,8 +299,9 @@ load_revisions(svn_ra_session_t *session
stdin_stream = svn_stream_from_aprfile2(stdin_file, FALSE, pool);
SVN_ERR(get_load_editor(&load_editor, &load_baton, &root_operation,
- stdin_stream, session, pool));
- SVN_ERR(drive_load_editor(root_operation, load_editor, pool));
+ session, pool));
+ SVN_ERR(drive_load_editor(load_editor, load_baton, root_operation,
+ stdin_stream, pool));
svn_stream_close(stdin_stream);