Author: rhuijben
Date: Thu Apr 28 22:01:39 2011
New Revision: 1097635

URL: http://svn.apache.org/viewvc?rev=1097635&view=rev
Log:
Avoid one or (depending on status) 2 database read transactions in
svn_wc__internal_file_modified_p by doing a bit of work inside
svn_wc__get_pristine_contents ourselves.

* subversion/libsvn_wc/questions.c
  (compare_and_verify): Fix old typo in commented code.
  (svn_wc__internal_file_modified_p): Retrieve more info from _read_info()
    and use it go directly to the svn_wc__db_pristine api.

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

Modified: subversion/trunk/subversion/libsvn_wc/questions.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/questions.c?rev=1097635&r1=1097634&r2=1097635&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_wc/questions.c (original)
+++ subversion/trunk/subversion/libsvn_wc/questions.c Thu Apr 28 22:01:39 2011
@@ -164,7 +164,7 @@ compare_and_verify(svn_boolean_t *modifi
       && !special
       && !props_mod
       && (keywords == NULL)
-      && (versioned_file_size < versioned_file_size))
+      && (versioned_file_size < pristine_file_size))
     {
       *modified_p = TRUE; /* The file is < its repository normal form
                              and the properties didn't change.
@@ -276,11 +276,15 @@ svn_wc__internal_file_modified_p(svn_boo
 {
   svn_stream_t *pristine_stream;
   svn_filesize_t pristine_size;
+  svn_wc__db_status_t status;
+  svn_wc__db_kind_t kind;
+  const svn_checksum_t *checksum;
+  svn_filesize_t recorded_size;
+  apr_time_t recorded_mod_time;
   svn_boolean_t has_props;
   svn_boolean_t props_mod;
   svn_error_t *err;
   apr_finfo_t finfo;
-  const svn_checksum_t *verify_checksum = NULL;
   apr_int32_t wanted
     = APR_FINFO_SIZE | APR_FINFO_MTIME | APR_FINFO_TYPE | APR_FINFO_LINK;
 
@@ -314,15 +318,32 @@ svn_wc__internal_file_modified_p(svn_boo
   if (read_only_p)
     SVN_ERR(svn_io__is_finfo_read_only(read_only_p, &finfo, scratch_pool));
 
-  if (! force_comparison)
+  /* Read the relevant info */
+  SVN_ERR(svn_wc__db_read_info(&status, &kind, NULL, NULL, NULL, NULL, NULL,
+                               NULL, NULL, NULL, &checksum, NULL, NULL, NULL,
+                               NULL, NULL, NULL,
+                               &recorded_size, &recorded_mod_time,
+                               NULL, NULL, NULL, &has_props, &props_mod,
+                               NULL, NULL, NULL,
+                               db, local_abspath,
+                               scratch_pool, scratch_pool));
+
+  /* If we don't have a pristine or the node has a status that allows a
+     pristine, just say that the node is modified */
+  if (!checksum
+      || (kind != svn_wc__db_kind_file)
+      || ((status != svn_wc__db_status_normal)
+          && (status != svn_wc__db_status_added)))
     {
-      svn_filesize_t recorded_size;
-      apr_time_t recorded_mod_time;
+      *modified_p = TRUE;
+      return SVN_NO_ERROR;
+    }
 
+  if (! force_comparison)
+    {
       /* We're allowed to use a heuristic to determine whether files may
          have changed.  The heuristic has these steps:
 
-
          1. Compare the working file's size
             with the size cached in the entries file
          2. If they differ, do a full file compare
@@ -347,16 +368,6 @@ svn_wc__internal_file_modified_p(svn_boo
 
       */
 
-      /* Read the relevant info */
-      SVN_ERR(svn_wc__db_read_info(NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-                                   NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-                                   NULL, NULL, NULL,
-                                   &recorded_size, &recorded_mod_time,
-                                   NULL, NULL, NULL, &has_props, &props_mod,
-                                   NULL, NULL, NULL,
-                                   db, local_abspath,
-                                   scratch_pool, scratch_pool));
-
       /* Compare the sizes, if applicable */
       if (recorded_size != SVN_INVALID_FILESIZE
           && finfo.size != recorded_size)
@@ -373,40 +384,11 @@ svn_wc__internal_file_modified_p(svn_boo
       *modified_p = FALSE;
       return SVN_NO_ERROR;
     }
-  else
-    {
-      SVN_ERR(svn_wc__db_read_info(NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-                                   NULL, NULL, NULL, &verify_checksum, NULL,
-                                   NULL, NULL, NULL, NULL, NULL, NULL, NULL,
-                                   NULL, NULL, NULL, &has_props, &props_mod,
-                                   NULL, NULL, NULL,
-                                   db, local_abspath,
-                                   scratch_pool, scratch_pool));
-    }
 
  compare_them:
-  /* If there's no text-base file, we have to assume the working file
-     is modified.  For example, a file scheduled for addition but not
-     yet committed. */
-  /* We used to stat for the working base here, but we just give
-     compare_and_verify a try; we'll check for errors afterwards */
-  err = svn_wc__get_pristine_contents(&pristine_stream, &pristine_size,
-                                      db, local_abspath,
-                                      scratch_pool, scratch_pool);
-  if (err && APR_STATUS_IS_ENOENT(err->apr_err))
-    {
-      svn_error_clear(err);
-      *modified_p = TRUE;
-      return SVN_NO_ERROR;
-    }
-
-  SVN_ERR(err);
-
-  if (pristine_stream == NULL)
-    {
-      *modified_p = TRUE;
-      return SVN_NO_ERROR;
-    }
+  SVN_ERR(svn_wc__db_pristine_read(&pristine_stream, &pristine_size,
+                                   db, local_abspath, checksum,
+                                   scratch_pool, scratch_pool));
 
   /* Check all bytes, and verify checksum if requested. */
   SVN_ERR(compare_and_verify(modified_p, db,
@@ -414,7 +396,7 @@ svn_wc__internal_file_modified_p(svn_boo
                              pristine_stream, pristine_size,
                              has_props, props_mod,
                              compare_textbases,
-                             verify_checksum,
+                             force_comparison ? checksum : NULL,
                              scratch_pool));
 
   if (!*modified_p)


Reply via email to