subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmpil...@apache.org
Subject svn commit: r1335639 - /subversion/trunk/subversion/libsvn_wc/adm_ops.c
Date Tue, 08 May 2012 16:56:43 GMT
Author: cmpilato
Date: Tue May  8 16:56:42 2012
New Revision: 1335639

URL: http://svn.apache.org/viewvc?rev=1335639&view=rev
Log:
Avoid opening pristine store file handles until they are actually
required.

* subversion/libsvn_wc/adm_ops.c
  (get_pristine_lazyopen_baton_t): New private callback baton type.
  (get_pristine_lazyopen_func): Callback implementation.
  (svn_wc__get_pristine_contents_by_checksum): Use the new lazyopen
    stream mechanics to avoid opening a file handle to the pristine
    contents until it's first really needed.

Suggested by: gstein

Modified:
    subversion/trunk/subversion/libsvn_wc/adm_ops.c

Modified: subversion/trunk/subversion/libsvn_wc/adm_ops.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/adm_ops.c?rev=1335639&r1=1335638&r2=1335639&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/adm_ops.c (original)
+++ subversion/trunk/subversion/libsvn_wc/adm_ops.c Tue May  8 16:56:42 2012
@@ -2250,6 +2250,31 @@ svn_wc_get_pristine_contents2(svn_stream
                                                        scratch_pool));
 }
 
+
+typedef struct get_pristine_lazyopen_baton_t
+{
+  svn_wc_context_t *wc_ctx;
+  const char *wri_abspath;
+  const svn_checksum_t *sha1_checksum;
+
+} get_pristine_lazyopen_baton_t;
+
+
+/* Implements svn_stream_lazyopen_func_t */
+static svn_error_t *
+get_pristine_lazyopen_func(svn_stream_t **stream,
+                           void *baton,
+                           apr_pool_t *result_pool,
+                           apr_pool_t *scratch_pool)
+{
+  get_pristine_lazyopen_baton_t *b = baton;
+
+  SVN_ERR(svn_wc__db_pristine_read(stream, NULL, b->wc_ctx->db,
+                                   b->wri_abspath, b->sha1_checksum,
+                                   result_pool, scratch_pool));
+  return SVN_NO_ERROR;
+}
+
 svn_error_t *
 svn_wc__get_pristine_contents_by_checksum(svn_stream_t **contents,
                                           svn_wc_context_t *wc_ctx,
@@ -2258,9 +2283,27 @@ svn_wc__get_pristine_contents_by_checksu
                                           apr_pool_t *result_pool,
                                           apr_pool_t *scratch_pool)
 {
-  return svn_error_trace(svn_wc__db_pristine_read(contents, NULL, wc_ctx->db,
-                                                  wri_abspath, sha1_checksum,
-                                                  result_pool, scratch_pool));
+  svn_boolean_t present;
+  
+  *contents = NULL;
+
+  SVN_ERR(svn_wc__db_pristine_check(&present, wc_ctx->db, wri_abspath,
+                                    sha1_checksum, scratch_pool));
+
+  if (present)
+    {
+      get_pristine_lazyopen_baton_t *gpl_baton;
+
+      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;
+      
+      SVN_ERR(svn_stream_lazyopen_create(contents, get_pristine_lazyopen_func,
+                                         gpl_baton, result_pool));
+    }
+
+  return SVN_NO_ERROR;
 }
 
 svn_error_t *



Mime
View raw message