[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH v2] New dumpstream parser to check version number

From: Ramkumar Ramachandra <artagnon_at_gmail.com>
Date: Thu, 19 Aug 2010 11:17:55 +0530

[[[
* subversion/libsvn_repos/load.c
  (svn_repos_parse_dumpstream2, svn_repos_parse_dumpstream3): Rename
  the older function and add a version_number argument; error out if
  there's a version mismatch.

* subversion/include/svn_repos.h
  (svn_repos_parse_dumpstream2, svn_repos_parse_dumpstream3): Add new
  function and mark svn_repos_parse_dumpstream2 as deprecated.

* subversion/svnrdump/load_editor.c
  (drive_dumpstream_loader): Update to use the new API, and call it
  with version_number 3.
]]]

Index: subversion/include/svn_repos.h
===================================================================
--- subversion/include/svn_repos.h (revision 986884)
+++ subversion/include/svn_repos.h (working copy)
@@ -2286,6 +2286,7 @@ svn_repos_node_from_baton(void *edit_baton);
 /* The RFC822-style headers in our dumpfile format. */
 #define SVN_REPOS_DUMPFILE_MAGIC_HEADER "SVN-fs-dump-format-version"
 #define SVN_REPOS_DUMPFILE_FORMAT_VERSION 3
+#define SVN_REPOS_DUMPFILE_FORMAT_UNKNOWN_VERSION -1
 #define SVN_REPOS_DUMPFILE_UUID "UUID"
 #define SVN_REPOS_DUMPFILE_CONTENT_LENGTH "Content-length"
 
@@ -2646,6 +2647,11 @@ typedef svn_repos_parse_fns2_t svn_repos_parser_fn
  * @a cancel_baton as argument to see if the client wishes to cancel
  * the dump.
  *
+ * If @a exact_version is SVN_REPOS_DUMPFILE_FORMAT_UNKNOWN_VERSION,
+ * it is ignored and the dumpstream is parsed without this
+ * information. Else, the function checks the dumpstream's version
+ * number, and errors out if there's a mismatch.
+ *
  * This parser has built-in knowledge of the dumpfile format, but only
  * in a general sense:
  *
@@ -2661,17 +2667,33 @@ typedef svn_repos_parse_fns2_t svn_repos_parser_fn
  * This is enough knowledge to make it easy on vtable implementors,
  * but still allow expansion of the format: most headers are ignored.
  *
- * @since New in 1.1.
+ * @since New in 1.7.
  */
 svn_error_t *
-svn_repos_parse_dumpstream2(svn_stream_t *stream,
+svn_repos_parse_dumpstream3(svn_stream_t *stream,
                             const svn_repos_parse_fns2_t *parse_fns,
                             void *parse_baton,
                             svn_cancel_func_t cancel_func,
                             void *cancel_baton,
+ int exact_version,
                             apr_pool_t *pool);
 
+/**
+ * Similar to svn_repos_parse_dumpstream3(), but with @a exact_version
+ * always set to SVN_REPOS_DUMPFILE_FORMAT_UNKNOWN_VERSION.
+ *
+ * @since New in 1.1.
+ * @deprecated Provided for backward compatibility with the 1.6 API.
+ */
+SVN_DEPRECATED
+svn_error_t *svn_repos_parse_dumpstream2(svn_stream_t *stream,
+ const svn_repos_parse_fns2_t *parse_fns,
+ void *parse_baton,
+ svn_cancel_func_t cancel_func,
+ void *cancel_baton,
+ apr_pool_t *pool);
 
+
 /**
  * Set @a *parser and @a *parse_baton to a vtable parser which commits new
  * revisions to the fs in @a repos. The constructed parser will treat
Index: subversion/libsvn_repos/load.c
===================================================================
--- subversion/libsvn_repos/load.c (revision 986884)
+++ subversion/libsvn_repos/load.c (working copy)
@@ -654,14 +654,29 @@ parse_format_version(const char *versionstring, in
 }
 
 
+svn_error_t *
+svn_repos_parse_dumpstream2(svn_stream_t *stream,
+ const svn_repos_parse_fns2_t *parse_fns,
+ void *parse_baton,
+ svn_cancel_func_t cancel_func,
+ void *cancel_baton,
+ apr_pool_t *pool)
+{
+ return svn_repos_parse_dumpstream3(stream, parse_fns, parse_baton,
+ cancel_func, cancel_baton,
+ SVN_REPOS_DUMPFILE_FORMAT_UNKNOWN_VERSION,
+ pool);
+}
 
+
 /* The Main Parser Logic */
 svn_error_t *
-svn_repos_parse_dumpstream2(svn_stream_t *stream,
+svn_repos_parse_dumpstream3(svn_stream_t *stream,
                             const svn_repos_parse_fns2_t *parse_fns,
                             void *parse_baton,
                             svn_cancel_func_t cancel_func,
                             void *cancel_baton,
+ int exact_version,
                             apr_pool_t *pool)
 {
   svn_boolean_t eof;
@@ -690,6 +705,15 @@ svn_error_t *
     return svn_error_createf(SVN_ERR_STREAM_MALFORMED_DATA, NULL,
                              _("Unsupported dumpfile version: %d"), version);
 
+ /* Error out if exact_version doesn't match version exactly */
+ /* ### TODO: Extend svn_parse_fns2_t to provide another callback for
+ ### version number; that way we can impose arbitrary constraints
+ ### on it, not just check for exact version */
+ if (exact_version != SVN_REPOS_DUMPFILE_FORMAT_UNKNOWN_VERSION
+ && exact_version != version)
+ return svn_error_createf(SVN_ERR_STREAM_MALFORMED_DATA, NULL,
+ _("Unsupported dumpfile version: %d"), version);
+
   /* A dumpfile "record" is defined to be a header-block of
      rfc822-style headers, possibly followed by a content-block.
 
Index: subversion/svnrdump/load_editor.c
===================================================================
--- subversion/svnrdump/load_editor.c (revision 986884)
+++ subversion/svnrdump/load_editor.c (working copy)
@@ -540,8 +540,10 @@ drive_dumpstream_loader(svn_stream_t *stream,
   pb = parse_baton;
 
   SVN_ERR(svn_ra_get_repos_root2(session, &(pb->root_url), pool));
- SVN_ERR(svn_repos_parse_dumpstream2(stream, parser, parse_baton,
- NULL, NULL, pool));
+ SVN_ERR(svn_repos_parse_dumpstream3(stream, parser, parse_baton,
+ NULL, NULL,
+ SVN_REPOS_DUMPFILE_FORMAT_VERSION,
+ pool));
 
   return SVN_NO_ERROR;
 }

-- Ram
Received on 2010-08-19 07:50:49 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.