subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gst...@apache.org
Subject svn commit: r929758 - in /subversion/trunk/subversion: include/svn_io.h libsvn_subr/deprecated.c libsvn_subr/stream.c
Date Thu, 01 Apr 2010 00:40:49 GMT
Author: gstein
Date: Thu Apr  1 00:40:49 2010
New Revision: 929758

URL: http://svn.apache.org/viewvc?rev=929758&view=rev
Log:
Update svn_stream_contents_same() to close the streams before exit. If a
stream is read to the end, then it may as well be closed (and, thus,
simplifying the work for the caller).

* subversion/include/svn_io.h:
  (svn_stream_contents_same2): new function
  (svn_stream_contents_same): deprecated

* subversion/libsvn_subr/stream.c:
  (svn_stream_contents_same): renamed to ...
  (svn_stream_contents_same2): ... this. the streams are now closed before
    exit (regardless or result or error).

* subversion/libsvn_subr/deprecated.c:
  (svn_stream_contents_same): new function. the two streams are disowned
    before passing to same2() so they won't be closed

Modified:
    subversion/trunk/subversion/include/svn_io.h
    subversion/trunk/subversion/libsvn_subr/deprecated.c
    subversion/trunk/subversion/libsvn_subr/stream.c

Modified: subversion/trunk/subversion/include/svn_io.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_io.h?rev=929758&r1=929757&r2=929758&view=diff
==============================================================================
--- subversion/trunk/subversion/include/svn_io.h (original)
+++ subversion/trunk/subversion/include/svn_io.h Thu Apr  1 00:40:49 2010
@@ -1235,10 +1235,29 @@ svn_stream_copy(svn_stream_t *from,
 
 
 /** Set @a *same to TRUE if @a stream1 and @a stream2 have the same
- * contents, else set it to FALSE.  Use @a pool for temporary allocations.
+ * contents, else set it to FALSE.
+ *
+ * Both streams will be closed before this function returns (regardless of
+ * the result, or any possible error).
+ *
+ * Use @a scratch_pool for temporary allocations.
+ *
+ * @since New in 1.7.
+ */
+svn_error_t *
+svn_stream_contents_same2(svn_boolean_t *same,
+                          svn_stream_t *stream1,
+                          svn_stream_t *stream2,
+                          apr_pool_t *pool);
+
+
+/**
+ * Same as svn_stream_contents_same2(), but the streams will not be closed.
  *
  * @since New in 1.4.
+ * @deprecated Provided for backward compatibility with the 1.6 API.
  */
+SVN_DEPRECATED
 svn_error_t *
 svn_stream_contents_same(svn_boolean_t *same,
                          svn_stream_t *stream1,

Modified: subversion/trunk/subversion/libsvn_subr/deprecated.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/deprecated.c?rev=929758&r1=929757&r2=929758&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/deprecated.c (original)
+++ subversion/trunk/subversion/libsvn_subr/deprecated.c Thu Apr  1 00:40:49 2010
@@ -856,6 +856,19 @@ svn_stream_from_aprfile(apr_file_t *file
   return svn_stream_from_aprfile2(file, TRUE, pool);
 }
 
+svn_error_t *
+svn_stream_contents_same(svn_boolean_t *same,
+                         svn_stream_t *stream1,
+                         svn_stream_t *stream2,
+                         apr_pool_t *pool)
+{
+  return svn_error_return(svn_stream_contents_same2(
+                            same,
+                            svn_stream_disown(stream1, pool),
+                            svn_stream_disown(stream2, pool),
+                            pool));
+}
+
 /*** From path.c ***/
 
 const char *

Modified: subversion/trunk/subversion/libsvn_subr/stream.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/stream.c?rev=929758&r1=929757&r2=929758&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/stream.c (original)
+++ subversion/trunk/subversion/libsvn_subr/stream.c Thu Apr  1 00:40:49 2010
@@ -472,22 +472,27 @@ svn_error_t *svn_stream_copy3(svn_stream
 }
 
 svn_error_t *
-svn_stream_contents_same(svn_boolean_t *same,
-                         svn_stream_t *stream1,
-                         svn_stream_t *stream2,
-                         apr_pool_t *pool)
+svn_stream_contents_same2(svn_boolean_t *same,
+                          svn_stream_t *stream1,
+                          svn_stream_t *stream2,
+                          apr_pool_t *pool)
 {
   char *buf1 = apr_palloc(pool, SVN__STREAM_CHUNK_SIZE);
   char *buf2 = apr_palloc(pool, SVN__STREAM_CHUNK_SIZE);
   apr_size_t bytes_read1 = SVN__STREAM_CHUNK_SIZE;
   apr_size_t bytes_read2 = SVN__STREAM_CHUNK_SIZE;
+  svn_error_t *err = NULL;
 
   *same = TRUE;  /* assume TRUE, until disproved below */
   while (bytes_read1 == SVN__STREAM_CHUNK_SIZE
          && bytes_read2 == SVN__STREAM_CHUNK_SIZE)
     {
-      SVN_ERR(svn_stream_read(stream1, buf1, &bytes_read1));
-      SVN_ERR(svn_stream_read(stream2, buf2, &bytes_read2));
+      err = svn_stream_read(stream1, buf1, &bytes_read1);
+      if (err)
+        break;
+      err = svn_stream_read(stream2, buf2, &bytes_read2);
+      if (err)
+        break;
 
       if ((bytes_read1 != bytes_read2)
           || (memcmp(buf1, buf2, bytes_read1)))
@@ -497,7 +502,10 @@ svn_stream_contents_same(svn_boolean_t *
         }
     }
 
-  return SVN_NO_ERROR;
+  return svn_error_compose_create(err,
+                                  svn_error_compose_create(
+                                    svn_stream_close(stream1),
+                                    svn_stream_close(stream2)));
 }
 
 



Mime
View raw message