Author: cmpilato
Date: Mon Jun 25 17:32:26 2012
New Revision: 1353676

URL: http://svn.apache.org/viewvc?rev=1353676&view=rev
Log:
Teach the get_wc_content() RA callback and supporting code to handle
MD5 checksums as content indexes, too.  This *should* result in the
benefits of this enhancement extending to users of all 1.8 clients
irrespective of the server's pedigree, as MD5s have been in the server
streams since ... like ... forever.

* subversion/include/svn_ra.h
  (svn_ra_get_wc_contents_func_t): Rename 'sha1_checksum' to merely
    'checksum', and relax the requirement that SHA1 be the checksum
    algorithm used to call up cached pristine contents.

* subversion/libsvn_client/ra.c
  (get_wc_contents): Rename 'sha1_checksum' to 'checksum'.

* subversion/libsvn_ra_serf/update.c
  (fetch_file): If we don't have a SHA1 checksum to use, that's okay
    -- try the MD5 instead (which we definitely should have for all
    extant servers).

* subversion/include/private/svn_wc_private.h
  (svn_wc__get_pristine_contents_by_checksum): Rename 'sha1_checksum'
    to 'checksum'.

* subversion/libsvn_wc/adm_ops.c
  (get_pristine_lazyopen_baton_t): Rename 'sha1_checksum' to 'checksum'.
  (get_pristine_lazyopen_func): If the reference checksum isn't a
    SHA1, try to lookup the SHA1 based on what we have.
  (svn_wc__get_pristine_contents_by_checksum): Rename 'sha1_checksum'
    to 'checksum'.

Suggested by: gstein

Modified:
    subversion/trunk/subversion/include/private/svn_wc_private.h
    subversion/trunk/subversion/include/svn_ra.h
    subversion/trunk/subversion/libsvn_client/ra.c
    subversion/trunk/subversion/libsvn_ra_serf/update.c
    subversion/trunk/subversion/libsvn_wc/adm_ops.c

Modified: subversion/trunk/subversion/include/private/svn_wc_private.h
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/include/private/svn_wc_private.h?rev=1353676&r1=1353675&r2=1353676&view=diff
==============================================================================
--- subversion/trunk/subversion/include/private/svn_wc_private.h (original)
+++ subversion/trunk/subversion/include/private/svn_wc_private.h Mon Jun 25 
17:32:26 2012
@@ -1085,15 +1085,15 @@ svn_wc__node_get_md5_from_sha1(const svn
                                apr_pool_t *result_pool,
                                apr_pool_t *scratch_pool);
 
-/* Like svn_wc_get_pristine_contents2(), but keyed on the
-   SHA1_CHECKSUM rather than on the local absolute path of the working
-   file.  WRI_ABSPATH is any versioned path of the working copy in
-   whose pristine database we'll be looking for these contents.  */
+/* Like svn_wc_get_pristine_contents2(), but keyed on the CHECKSUM
+   rather than on the local absolute path of the working file.
+   WRI_ABSPATH is any versioned path of the working copy in whose
+   pristine database we'll be looking for these contents.  */
 svn_error_t *
 svn_wc__get_pristine_contents_by_checksum(svn_stream_t **contents,
                                           svn_wc_context_t *wc_ctx,
                                           const char *wri_abspath,
-                                          const svn_checksum_t *sha1_checksum,
+                                          const svn_checksum_t *checksum,
                                           apr_pool_t *result_pool,
                                           apr_pool_t *scratch_pool);
 

Modified: subversion/trunk/subversion/include/svn_ra.h
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_ra.h?rev=1353676&r1=1353675&r2=1353676&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_ra.h (original)
+++ subversion/trunk/subversion/include/svn_ra.h Mon Jun 25 17:32:26 2012
@@ -121,16 +121,16 @@ typedef svn_error_t *(*svn_ra_invalidate
                                                           apr_pool_t *pool);
 
 /** This is a function type which allows the RA layer to fetch the
- * cached pristine file contents whose SHA1 checksum is @a
- * sha1_checksum, if any.  @a *contents will be a read stream
- * containing those contents if they are found; NULL otherwise.
+ * cached pristine file contents whose checksum is @a checksum, if
+ * any.  @a *contents will be a read stream containing those contents
+ * if they are found; NULL otherwise.
  *
  * @since New in 1.8.
  */
 typedef svn_error_t *
 (*svn_ra_get_wc_contents_func_t)(void *baton,
                                  svn_stream_t **contents,
-                                 const svn_checksum_t *sha1_checksum,
+                                 const svn_checksum_t *checksum,
                                  apr_pool_t *pool);
 
 

Modified: subversion/trunk/subversion/libsvn_client/ra.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/ra.c?rev=1353676&r1=1353675&r2=1353676&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/ra.c (original)
+++ subversion/trunk/subversion/libsvn_client/ra.c Mon Jun 25 17:32:26 2012
@@ -245,7 +245,7 @@ invalidate_wc_props(void *baton,
 static svn_error_t *
 get_wc_contents(void *baton,
                 svn_stream_t **contents,
-                const svn_checksum_t *sha1_checksum,
+                const svn_checksum_t *checksum,
                 apr_pool_t *pool)
 {
   callback_baton_t *cb = baton;
@@ -260,7 +260,7 @@ get_wc_contents(void *baton,
              svn_wc__get_pristine_contents_by_checksum(contents,
                                                        cb->ctx->wc_ctx,
                                                        cb->base_dir_abspath,
-                                                       sha1_checksum,
+                                                       checksum,
                                                        pool, pool));
 }
 

Modified: subversion/trunk/subversion/libsvn_ra_serf/update.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/update.c?rev=1353676&r1=1353675&r2=1353676&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_ra_serf/update.c (original)
+++ subversion/trunk/subversion/libsvn_ra_serf/update.c Mon Jun 25 17:32:26 2012
@@ -464,10 +464,6 @@ set_file_props(void *baton,
   const svn_delta_editor_t *editor = info->dir->report_context->update_editor;
   const char *prop_name;
 
-  if (strcmp(name, "md5-checksum") == 0
-      && strcmp(ns, SVN_DAV_PROP_NS_DAV) == 0)
-    info->final_checksum = apr_pstrdup(info->pool, val->data);
-
   prop_name = svn_ra_serf__svnname_from_wirename(ns, name, scratch_pool);
   if (prop_name != NULL)
     return svn_error_trace(editor->change_file_prop(info->file_baton,
@@ -1250,18 +1246,32 @@ fetch_file(report_context_t *ctx, report
       svn_stream_t *contents = NULL;
 
       if (ctx->sess->wc_callbacks->get_wc_contents
-          && info->final_sha1_checksum)
+          && (info->final_sha1_checksum || info->final_checksum))
         {
           svn_error_t *err;
-          svn_checksum_t *sha1_checksum;
+          svn_checksum_t *checksum;
+         
+          /* Parse our checksum, preferring SHA1 to MD5. */
+          if (info->final_sha1_checksum)
+            {
+              err = svn_checksum_parse_hex(&checksum, svn_checksum_sha1,
+                                           info->final_sha1_checksum,
+                                           info->pool);
+            }
+          else if (info->final_checksum)
+            {
+              err = svn_checksum_parse_hex(&checksum, svn_checksum_md5,
+                                           info->final_checksum,
+                                           info->pool);
+            }
 
-          err = svn_checksum_parse_hex(&sha1_checksum, svn_checksum_sha1,
-                                       info->final_sha1_checksum, info->pool);
+          /* Okay so far?  Let's try to get a stream on some readily
+             available matching content. */
           if (!err)
             {
               err = ctx->sess->wc_callbacks->get_wc_contents(
                         ctx->sess->wc_callback_baton, &contents,
-                        sha1_checksum, info->pool);
+                        checksum, info->pool);
             }
 
           if (err)
@@ -2088,6 +2098,13 @@ end_report(svn_ra_serf__xml_parser_t *pa
 
       svn_ra_serf__set_ver_prop(props, info->base_name, info->base_rev,
                                 ns->namespace, ns->url, set_val_str, pool);
+
+      /* Advance handling:  if we spotted the md5-checksum property on
+         the wire, remember it's value. */
+      if (strcmp(ns->url, "md5-checksum") == 0
+          && strcmp(ns->namespace, SVN_DAV_PROP_NS_DAV) == 0)
+        info->final_checksum = apr_pstrdup(info->pool, set_val_str->data);
+
       svn_ra_serf__xml_pop_state(parser);
     }
   else if (state == IGNORE_PROP_NAME || state == NEED_PROP_NAME)

Modified: subversion/trunk/subversion/libsvn_wc/adm_ops.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/adm_ops.c?rev=1353676&r1=1353675&r2=1353676&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/adm_ops.c (original)
+++ subversion/trunk/subversion/libsvn_wc/adm_ops.c Mon Jun 25 17:32:26 2012
@@ -2265,7 +2265,7 @@ typedef struct get_pristine_lazyopen_bat
 {
   svn_wc_context_t *wc_ctx;
   const char *wri_abspath;
-  const svn_checksum_t *sha1_checksum;
+  const svn_checksum_t *checksum;
 
 } get_pristine_lazyopen_baton_t;
 
@@ -2278,9 +2278,19 @@ get_pristine_lazyopen_func(svn_stream_t 
                            apr_pool_t *scratch_pool)
 {
   get_pristine_lazyopen_baton_t *b = baton;
+  const svn_checksum_t *sha1_checksum;
+
+  /* svn_wc__db_pristine_read() wants a SHA1, so if we have an MD5,
+     we'll use it to lookup the SHA1. */
+  if (b->checksum->kind == svn_checksum_sha1)
+    sha1_checksum = b->checksum;
+  else
+    SVN_ERR(svn_wc__db_pristine_get_sha1(&sha1_checksum, b->wc_ctx->db,
+                                         b->wri_abspath, b->checksum,
+                                         scratch_pool, scratch_pool));
 
   SVN_ERR(svn_wc__db_pristine_read(stream, NULL, b->wc_ctx->db,
-                                   b->wri_abspath, b->sha1_checksum,
+                                   b->wri_abspath, sha1_checksum,
                                    result_pool, scratch_pool));
   return SVN_NO_ERROR;
 }
@@ -2289,7 +2299,7 @@ svn_error_t *
 svn_wc__get_pristine_contents_by_checksum(svn_stream_t **contents,
                                           svn_wc_context_t *wc_ctx,
                                           const char *wri_abspath,
-                                          const svn_checksum_t *sha1_checksum,
+                                          const svn_checksum_t *checksum,
                                           apr_pool_t *result_pool,
                                           apr_pool_t *scratch_pool)
 {
@@ -2298,7 +2308,7 @@ svn_wc__get_pristine_contents_by_checksu
   *contents = NULL;
 
   SVN_ERR(svn_wc__db_pristine_check(&present, wc_ctx->db, wri_abspath,
-                                    sha1_checksum, scratch_pool));
+                                    checksum, scratch_pool));
 
   if (present)
     {
@@ -2307,7 +2317,7 @@ svn_wc__get_pristine_contents_by_checksu
       gpl_baton = apr_pcalloc(result_pool, sizeof(*gpl_baton));
       gpl_baton->wc_ctx = wc_ctx;
       gpl_baton->wri_abspath = wri_abspath;
-      gpl_baton->sha1_checksum = sha1_checksum;
+      gpl_baton->checksum = checksum;
       
       *contents = svn_stream_lazyopen_create(get_pristine_lazyopen_func,
                                              gpl_baton, result_pool);


Reply via email to