You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by gs...@apache.org on 2012/05/10 05:20:50 UTC

svn commit: r1336473 - in /subversion/trunk/subversion/libsvn_ra_serf: commit.c options.c property.c ra_serf.h

Author: gstein
Date: Thu May 10 03:20:50 2012
New Revision: 1336473

URL: http://svn.apache.org/viewvc?rev=1336473&view=rev
Log:
Simplify the OPTIONS processing by encapsulating the the code to run
it, with just two functions for getting the requested information.

* subversion/libsvn_ra_serf/ra_serf.h:
  (svn_ra_serf__options_context_t, svn_ra_serf__get_options_done_ptr,
      svn_ra_serf__options_get_activity_collection,
      svn_ra_serf__options_get_youngest_rev,
      svn_ra_serf__create_options_req): obsolete. removed.
  (svn_ra_serf__v2_get_youngest_revnum): new declaration
  (svn_ra_serf__v1_get_activity_collection): new declaration

* subversion/libsvn_ra_serf/options.c:
  (struct svn_ra_serf__options_context_t): renamed and typedef'd to ...
  (options_context_t): ... this. PATH member removed; unused.
  (push_state, pop_state, end_options, cdata_options,
      optons_response_handler): track typedef rename
  (svn_ra_serf__get_options_done_ptr,
      svn_ra_serf__options_get_activity_collection,
      svn_ra_serf__options_get_youngest_rev): obsolete. removed.
  (capabilities_headers_iterator_callback): track typedef rename. we
    already have OPT_CTX, so no need to fetch from parser user_data.
  (svn_ra_serf__create_optoins_req): made static and renamed to ...
  (create_options_req): ... this. track typedef rename. drop the PATH
    parameter since it is always the session root. remove
    initialization of the unused PATH member.
  (svn_ra_serf__v2_get_youngest_revnum): new implementation
  (svn_ra_serf__v1_get_activity_collection): new implementation
  (svn_ra_serf__exchange_capabilities): track rename of typedef and
    create_options_req. adjust params to latter. directly access
    CTX->DONE rather than use the obsolete function.

* subversion/libsvn_ra_serf/property.c:
  (svn_ra_serf__get_baseline_info): use v2_get_youngest_revnum

* subversion/libsvn_ra_serf/commit.c:
  (open_root): use v1_get_activity_collection

Modified:
    subversion/trunk/subversion/libsvn_ra_serf/commit.c
    subversion/trunk/subversion/libsvn_ra_serf/options.c
    subversion/trunk/subversion/libsvn_ra_serf/property.c
    subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h

Modified: subversion/trunk/subversion/libsvn_ra_serf/commit.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/commit.c?rev=1336473&r1=1336472&r2=1336473&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/commit.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/commit.c Thu May 10 03:20:50 2012
@@ -1356,19 +1356,12 @@ open_root(void *edit_baton,
     }
   else
     {
-      svn_ra_serf__options_context_t *opt_ctx;
       const char *activity_str;
 
-      SVN_ERR(svn_ra_serf__create_options_req(&opt_ctx, ctx->session,
-                                              ctx->session->conns[0],
-                                              ctx->session->session_url.path,
-                                              ctx->pool));
-
-      SVN_ERR(svn_ra_serf__context_run_wait(
-        svn_ra_serf__get_options_done_ptr(opt_ctx),
-        ctx->session, ctx->pool));
-
-      activity_str = svn_ra_serf__options_get_activity_collection(opt_ctx);
+      SVN_ERR(svn_ra_serf__v1_get_activity_collection(&activity_str,
+                                                      ctx->session->conns[0],
+                                                      ctx->pool,
+                                                      ctx->pool));
       if (!activity_str)
         return svn_error_create(SVN_ERR_RA_DAV_OPTIONS_REQ_FAILED, NULL,
                                 _("The OPTIONS response did not include the "

Modified: subversion/trunk/subversion/libsvn_ra_serf/options.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/options.c?rev=1336473&r1=1336472&r2=1336473&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/options.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/options.c Thu May 10 03:20:50 2012
@@ -62,7 +62,7 @@ typedef struct options_state_list_t {
   struct options_state_list_t *prev;
 } options_state_list_t;
 
-struct svn_ra_serf__options_context_t {
+typedef struct options_context_t {
   /* pool to allocate memory from */
   apr_pool_t *pool;
 
@@ -85,14 +85,14 @@ struct svn_ra_serf__options_context_t {
   svn_ra_serf__handler_t *handler;
   svn_ra_serf__xml_parser_t *parser_ctx;
 
-  const char *path;
-
   const char *activity_collection;
   svn_revnum_t youngest_rev;
-};
+
+} options_context_t;
+
 
 static void
-push_state(svn_ra_serf__options_context_t *options_ctx, options_state_e state)
+push_state(options_context_t *options_ctx, options_state_e state)
 {
   options_state_list_t *new_state;
 
@@ -112,7 +112,7 @@ push_state(svn_ra_serf__options_context_
   options_ctx->state = new_state;
 }
 
-static void pop_state(svn_ra_serf__options_context_t *options_ctx)
+static void pop_state(options_context_t *options_ctx)
 {
   options_state_list_t *free_state;
   free_state = options_ctx->state;
@@ -128,7 +128,7 @@ start_options(svn_ra_serf__xml_parser_t 
               const char **attrs,
               apr_pool_t *scratch_pool)
 {
-  svn_ra_serf__options_context_t *options_ctx = parser->user_data;
+  options_context_t *options_ctx = parser->user_data;
 
   if (!options_ctx->state && strcmp(name.name, "options-response") == 0)
     {
@@ -159,7 +159,7 @@ end_options(svn_ra_serf__xml_parser_t *p
             svn_ra_serf__dav_props_t name,
             apr_pool_t *scratch_pool)
 {
-  svn_ra_serf__options_context_t *options_ctx = parser->user_data;
+  options_context_t *options_ctx = parser->user_data;
   options_state_list_t *cur_state;
 
   if (!options_ctx->state)
@@ -197,7 +197,7 @@ cdata_options(svn_ra_serf__xml_parser_t 
               apr_size_t len,
               apr_pool_t *scratch_pool)
 {
-  svn_ra_serf__options_context_t *ctx = parser->user_data;
+  options_context_t *ctx = parser->user_data;
 
   if (ctx->collect_cdata)
     svn_stringbuf_appendbytes(ctx->acbuf, data, len);
@@ -224,24 +224,6 @@ create_options_body(serf_bucket_t **body
   return SVN_NO_ERROR;
 }
 
-svn_boolean_t*
-svn_ra_serf__get_options_done_ptr(svn_ra_serf__options_context_t *ctx)
-{
-  return &ctx->done;
-}
-
-const char *
-svn_ra_serf__options_get_activity_collection(svn_ra_serf__options_context_t *ctx)
-{
-  return ctx->activity_collection;
-}
-
-svn_revnum_t
-svn_ra_serf__options_get_youngest_rev(svn_ra_serf__options_context_t *ctx)
-{
-  return ctx->youngest_rev;
-}
-
 
 /* We use these static pointers so we can employ pointer comparison
  * of our capabilities hash members instead of strcmp()ing all over
@@ -262,7 +244,7 @@ capabilities_headers_iterator_callback(v
                                        const char *key,
                                        const char *val)
 {
-  svn_ra_serf__options_context_t *opt_ctx = baton;
+  options_context_t *opt_ctx = baton;
   svn_ra_serf__session_t *session = opt_ctx->session;
 
   if (svn_cstring_casecmp(key, "dav") == 0)
@@ -367,10 +349,7 @@ capabilities_headers_iterator_callback(v
         }
       else if (svn_cstring_casecmp(key, SVN_DAV_YOUNGEST_REV_HEADER) == 0)
         {
-          struct svn_ra_serf__options_context_t *user_data;
-
-          user_data = opt_ctx->parser_ctx->user_data;
-          user_data->youngest_rev = SVN_STR_TO_REV(val);
+          opt_ctx->youngest_rev = SVN_STR_TO_REV(val);
         }
     }
 
@@ -388,7 +367,7 @@ options_response_handler(serf_request_t 
                          void *baton,
                          apr_pool_t *pool)
 {
-  svn_ra_serf__options_context_t *opt_ctx = baton;
+  options_context_t *opt_ctx = baton;
 
   if (!opt_ctx->headers_processed)
     {
@@ -420,14 +399,13 @@ options_response_handler(serf_request_t 
 }
 
 
-svn_error_t *
-svn_ra_serf__create_options_req(svn_ra_serf__options_context_t **opt_ctx,
-                                svn_ra_serf__session_t *session,
-                                svn_ra_serf__connection_t *conn,
-                                const char *path,
-                                apr_pool_t *pool)
+static svn_error_t *
+create_options_req(options_context_t **opt_ctx,
+                   svn_ra_serf__session_t *session,
+                   svn_ra_serf__connection_t *conn,
+                   apr_pool_t *pool)
 {
-  svn_ra_serf__options_context_t *new_ctx;
+  options_context_t *new_ctx;
   svn_ra_serf__handler_t *handler;
   svn_ra_serf__xml_parser_t *parser_ctx;
 
@@ -436,8 +414,6 @@ svn_ra_serf__create_options_req(svn_ra_s
   new_ctx->pool = pool;
 
   new_ctx->acbuf = svn_stringbuf_create_empty(pool);
-
-  new_ctx->path = path;
   new_ctx->youngest_rev = SVN_INVALID_REVNUM;
 
   new_ctx->session = session;
@@ -447,7 +423,7 @@ svn_ra_serf__create_options_req(svn_ra_s
 
   handler->handler_pool = pool;
   handler->method = "OPTIONS";
-  handler->path = path;
+  handler->path = session->session_url.path;
   handler->body_delegate = create_options_body;
   handler->body_type = "text/xml";
   handler->conn = conn;
@@ -476,6 +452,48 @@ svn_ra_serf__create_options_req(svn_ra_s
 }
 
 
+svn_error_t *
+svn_ra_serf__v2_get_youngest_revnum(svn_revnum_t *youngest,
+                                    svn_ra_serf__connection_t *conn,
+                                    apr_pool_t *scratch_pool)
+{
+  svn_ra_serf__session_t *session = conn->session;
+  options_context_t *opt_ctx;
+
+  SVN_ERR_ASSERT(SVN_RA_SERF__HAVE_HTTPV2_SUPPORT(session));
+
+  SVN_ERR(create_options_req(&opt_ctx, session, conn, scratch_pool));
+  SVN_ERR(svn_ra_serf__context_run_wait(&opt_ctx->done, session,
+                                        scratch_pool));
+
+  *youngest = opt_ctx->youngest_rev;
+
+  return SVN_NO_ERROR;
+}
+
+
+svn_error_t *
+svn_ra_serf__v1_get_activity_collection(const char **activity_url,
+                                        svn_ra_serf__connection_t *conn,
+                                        apr_pool_t *result_pool,
+                                        apr_pool_t *scratch_pool)
+{
+  svn_ra_serf__session_t *session = conn->session;
+  options_context_t *opt_ctx;
+
+  SVN_ERR_ASSERT(!SVN_RA_SERF__HAVE_HTTPV2_SUPPORT(session));
+
+  SVN_ERR(create_options_req(&opt_ctx, session, conn, scratch_pool));
+  SVN_ERR(svn_ra_serf__context_run_wait(&opt_ctx->done, session,
+                                        scratch_pool));
+
+  *activity_url = apr_pstrdup(result_pool, opt_ctx->activity_collection);
+
+  return SVN_NO_ERROR;
+
+}
+
+
 
 /** Capabilities exchange. */
 
@@ -484,16 +502,13 @@ svn_ra_serf__exchange_capabilities(svn_r
                                    const char **corrected_url,
                                    apr_pool_t *pool)
 {
-  svn_ra_serf__options_context_t *opt_ctx;
+  options_context_t *opt_ctx;
   svn_error_t *err;
 
   /* This routine automatically fills in serf_sess->capabilities */
-  SVN_ERR(svn_ra_serf__create_options_req(&opt_ctx, serf_sess,
-                                          serf_sess->conns[0],
-                                          serf_sess->session_url.path, pool));
+  SVN_ERR(create_options_req(&opt_ctx, serf_sess, serf_sess->conns[0], pool));
 
-  err = svn_ra_serf__context_run_wait(
-            svn_ra_serf__get_options_done_ptr(opt_ctx), serf_sess, pool);
+  err = svn_ra_serf__context_run_wait(&opt_ctx->done, serf_sess, pool);
 
   /* If our caller cares about server redirections, and our response
      carries such a thing, report as much.  We'll disregard ERR --

Modified: subversion/trunk/subversion/libsvn_ra_serf/property.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/property.c?rev=1336473&r1=1336472&r2=1336473&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/property.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/property.c Thu May 10 03:20:50 2012
@@ -980,15 +980,8 @@ svn_ra_serf__get_baseline_info(const cha
         }
       else
         {
-          svn_ra_serf__options_context_t *opt_ctx;
-
-          SVN_ERR(svn_ra_serf__create_options_req(&opt_ctx, session, conn,
-                                                  session->session_url.path,
-                                                  pool));
-          SVN_ERR(svn_ra_serf__context_run_wait(
-                svn_ra_serf__get_options_done_ptr(opt_ctx), session, pool));
-
-          actual_revision = svn_ra_serf__options_get_youngest_rev(opt_ctx);
+          SVN_ERR(svn_ra_serf__v2_get_youngest_revnum(
+                    &actual_revision, conn, pool));
           if (! SVN_IS_VALID_REVNUM(actual_revision))
             return svn_error_create(SVN_ERR_RA_DAV_OPTIONS_REQ_FAILED, NULL,
                                     _("The OPTIONS response did not include "

Modified: subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h?rev=1336473&r1=1336472&r2=1336473&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/ra_serf.h Thu May 10 03:20:50 2012
@@ -1082,28 +1082,35 @@ svn_ra_serf__merge_create_req(svn_ra_ser
 
 /** OPTIONS-related functions **/
 
-typedef struct svn_ra_serf__options_context_t svn_ra_serf__options_context_t;
+/* On HTTPv2 connections, run an OPTIONS request over CONN to fetch the
+   current youngest revnum, returning it in *YOUNGEST.
+
+   (the revnum is headers of the OPTIONS response)
+
+   This function performs the request synchronously.
+
+   All temporary allocations will be made in SCRATCH_POOL.  */
+svn_error_t *
+svn_ra_serf__v2_get_youngest_revnum(svn_revnum_t *youngest,
+                                    svn_ra_serf__connection_t *conn,
+                                    apr_pool_t *scratch_pool);
+
+
+/* On HTTPv1 connections, run an OPTIONS request over CONN to fetch the
+   activity collection set and return it in *ACTIVITY_URL, allocated
+   from RESULT_POOL.
+
+   (the activity-collection-set is in the body of the OPTIONS response)
+
+   This function performs the request synchronously.
+
+   All temporary allocations will be made in SCRATCH_POOL.  */
+svn_error_t *
+svn_ra_serf__v1_get_activity_collection(const char **activity_url,
+                                        svn_ra_serf__connection_t *conn,
+                                        apr_pool_t *result_pool,
+                                        apr_pool_t *scratch_pool);
 
-/* Is this OPTIONS-request done yet? */
-svn_boolean_t*
-svn_ra_serf__get_options_done_ptr(svn_ra_serf__options_context_t *ctx);
-
-const char *
-svn_ra_serf__options_get_activity_collection(svn_ra_serf__options_context_t *ctx);
-
-svn_revnum_t
-svn_ra_serf__options_get_youngest_rev(svn_ra_serf__options_context_t *ctx);
-
-/* Create an OPTIONS request.  When run, ask for an
-   activity-collection-set in the request body (retrievable via
-   accessor above) and also parse the server's capability headers into
-   the SESSION->capabilites hash. */
-svn_error_t *
-svn_ra_serf__create_options_req(svn_ra_serf__options_context_t **opt_ctx,
-                                svn_ra_serf__session_t *session,
-                                svn_ra_serf__connection_t *conn,
-                                const char *path,
-                                apr_pool_t *pool);
 
 /* Set @a VCC_URL to the default VCC for our repository based on @a
  * ORIG_PATH for the session @a SESSION, ensuring that the VCC URL and