Author: brane
Date: Fri May 16 22:50:22 2025
New Revision: 1925598

URL: http://svn.apache.org/viewvc?rev=1925598&view=rev
Log:
Convert public functions for handling patches to use streams
instead of APR files.

* subversion/include/svn_client.h: Include svn_io.h for svn_stream_t.
  (svn_client_patch_stream): Read the patch from a stream instead of a file.
* subversion/include/svn_diff.h
  (svn_diff_patch_parser_create): Likewise, read the patch from a stream.

* subversion/libsvn_client/patch.c: Do not include svn_io.h.
  (svn_client_patch): Forward to svn_client_patch_stream() and remove
   the parameter checks that are repeated there.
  (svn_client_patch_stream): Read the patch from a stream instead of a file.

* subversion/libsvn_diff/parse-diff.c: Include svn_io_private.h (temporary).
  (svn_diff_patch_parser_create): Read the patch from a stream, etc.
   For now, just unwrap the underlying APR file from the stream.
  (svn_patch_file_t): Replace the apr_file member with a stream.
  (svn_diff_open_patch_file): Read the patch from a stream, yet again.
  (svn_diff_close_patch_file): Close the stream.

* subversion/tests/libsvn_client/client-test.c
  (test_patch): Open a stream for svn_client_patch_stream.

Modified:
    subversion/branches/patch-from-stream/subversion/include/svn_client.h
    subversion/branches/patch-from-stream/subversion/include/svn_diff.h
    subversion/branches/patch-from-stream/subversion/libsvn_client/patch.c
    subversion/branches/patch-from-stream/subversion/libsvn_diff/parse-diff.c
    
subversion/branches/patch-from-stream/subversion/tests/libsvn_client/client-test.c

Modified: subversion/branches/patch-from-stream/subversion/include/svn_client.h
URL: 
http://svn.apache.org/viewvc/subversion/branches/patch-from-stream/subversion/include/svn_client.h?rev=1925598&r1=1925597&r2=1925598&view=diff
==============================================================================
--- subversion/branches/patch-from-stream/subversion/include/svn_client.h 
(original)
+++ subversion/branches/patch-from-stream/subversion/include/svn_client.h Fri 
May 16 22:50:22 2025
@@ -39,6 +39,7 @@
 #include <apr_file_io.h>
 #include <apr_time.h>
 
+#include "svn_io.h"
 #include "svn_types.h"
 #include "svn_string.h"
 #include "svn_wc.h"
@@ -7773,7 +7774,7 @@ svn_client_patch(const char *patch_abspa
 
 /**
  * Similar to svn_client_patch(), but the patch is read from a file handle,
- * described in @a patch_file.
+ * described in @a patch_stream.
  *
  * In future versions, this function may be used to apply a patch directly
  * from an svn_stream_t.
@@ -7781,7 +7782,7 @@ svn_client_patch(const char *patch_abspa
  * @since New in 1.15.
  */
 svn_error_t *
-svn_client_patch_stream(apr_file_t *patch_file,
+svn_client_patch_stream(svn_stream_t *patch_stream,
                         const char *wc_dir_abspath,
                         svn_boolean_t dry_run,
                         int strip_count,

Modified: subversion/branches/patch-from-stream/subversion/include/svn_diff.h
URL: 
http://svn.apache.org/viewvc/subversion/branches/patch-from-stream/subversion/include/svn_diff.h?rev=1925598&r1=1925597&r2=1925598&view=diff
==============================================================================
--- subversion/branches/patch-from-stream/subversion/include/svn_diff.h 
(original)
+++ subversion/branches/patch-from-stream/subversion/include/svn_diff.h Fri May 
16 22:50:22 2025
@@ -1385,7 +1385,7 @@ typedef struct svn_diff_patch_parser_t s
  * @since New in 1.15
  */
 svn_diff_patch_parser_t *
-svn_diff_patch_parser_create(apr_file_t *patch_file,
+svn_diff_patch_parser_create(svn_stream_t *patch_file,
                              apr_pool_t *result_pool);
 
 /**

Modified: subversion/branches/patch-from-stream/subversion/libsvn_client/patch.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/patch-from-stream/subversion/libsvn_client/patch.c?rev=1925598&r1=1925597&r2=1925598&view=diff
==============================================================================
--- subversion/branches/patch-from-stream/subversion/libsvn_client/patch.c 
(original)
+++ subversion/branches/patch-from-stream/subversion/libsvn_client/patch.c Fri 
May 16 22:50:22 2025
@@ -33,7 +33,6 @@
 #include "svn_dirent_uri.h"
 #include "svn_diff.h"
 #include "svn_hash.h"
-#include "svn_io.h"
 #include "svn_path.h"
 #include "svn_pools.h"
 #include "svn_props.h"
@@ -3735,18 +3734,10 @@ svn_client_patch(const char *patch_abspa
                  apr_pool_t *scratch_pool)
 {
   svn_node_kind_t kind;
-  apr_file_t *patch_file;
-  svn_diff_patch_parser_t *patch_parser;
+  svn_stream_t *patch_stream;
 
-  if (strip_count < 0)
-    return svn_error_create(SVN_ERR_INCORRECT_PARAMS, NULL,
-                            _("strip count must be positive"));
-
-  if (svn_path_is_url(wc_dir_abspath))
-    return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
-                             _("'%s' is not a local path"),
-                             svn_dirent_local_style(wc_dir_abspath,
-                                                    scratch_pool));
+  /* NOTE: There are some parameter checks we could do here before opening
+           the file, but they're duplicated in svn_client_patch_stream. */
 
   SVN_ERR(svn_io_check_path(patch_abspath, &kind, scratch_pool));
   if (kind == svn_node_none)
@@ -3760,35 +3751,21 @@ svn_client_patch(const char *patch_abspa
                              svn_dirent_local_style(patch_abspath,
                                                     scratch_pool));
 
-  SVN_ERR(svn_io_check_path(wc_dir_abspath, &kind, scratch_pool));
-  if (kind == svn_node_none)
-    return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
-                             _("'%s' does not exist"),
-                             svn_dirent_local_style(wc_dir_abspath,
-                                                    scratch_pool));
-  if (kind != svn_node_dir)
-    return svn_error_createf(SVN_ERR_ILLEGAL_TARGET, NULL,
-                             _("'%s' is not a directory"),
-                             svn_dirent_local_style(wc_dir_abspath,
-                                                    scratch_pool));
-
-  SVN_ERR(svn_io_file_open(&patch_file, patch_abspath, APR_READ | APR_BUFFERED,
-                           APR_OS_DEFAULT, scratch_pool));
-  patch_parser = svn_diff_patch_parser_create(patch_file, scratch_pool);
-
-  SVN_WC__CALL_WITH_WRITE_LOCK(
-    apply_patches(patch_parser, wc_dir_abspath, dry_run, strip_count,
-                  reverse, ignore_whitespace, remove_tempfiles,
-                  patch_func, patch_baton, ctx, scratch_pool),
-    ctx->wc_ctx, wc_dir_abspath, FALSE /* lock_anchor */, scratch_pool);
+  SVN_ERR(svn_stream_open_readonly(&patch_stream, patch_abspath,
+                                   scratch_pool, scratch_pool));
+  SVN_ERR(svn_client_patch_stream(patch_stream, wc_dir_abspath,
+                                  dry_run, strip_count, reverse,
+                                  ignore_whitespace, remove_tempfiles,
+                                  patch_func, patch_baton, ctx,
+                                  scratch_pool));
 
-  SVN_ERR(svn_io_file_close(patch_file, scratch_pool));
+  SVN_ERR(svn_stream_close(patch_stream));
 
   return SVN_NO_ERROR;
 }
 
 svn_error_t *
-svn_client_patch_stream(apr_file_t *patch_file,
+svn_client_patch_stream(svn_stream_t *patch_stream,
                         const char *wc_dir_abspath,
                         svn_boolean_t dry_run,
                         int strip_count,
@@ -3825,7 +3802,7 @@ svn_client_patch_stream(apr_file_t *patc
                              svn_dirent_local_style(wc_dir_abspath,
                                                     scratch_pool));
 
-  patch_parser = svn_diff_patch_parser_create(patch_file, scratch_pool);
+  patch_parser = svn_diff_patch_parser_create(patch_stream, scratch_pool);
 
   SVN_WC__CALL_WITH_WRITE_LOCK(
     apply_patches(patch_parser, wc_dir_abspath, dry_run, strip_count,

Modified: 
subversion/branches/patch-from-stream/subversion/libsvn_diff/parse-diff.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/patch-from-stream/subversion/libsvn_diff/parse-diff.c?rev=1925598&r1=1925597&r2=1925598&view=diff
==============================================================================
--- subversion/branches/patch-from-stream/subversion/libsvn_diff/parse-diff.c 
(original)
+++ subversion/branches/patch-from-stream/subversion/libsvn_diff/parse-diff.c 
Fri May 16 22:50:22 2025
@@ -43,6 +43,8 @@
 #include "private/svn_diff_private.h"
 #include "private/svn_sorts_private.h"
 
+#include "private/svn_io_private.h" /* FIXME: svn_stream__aprfile */
+
 #include "diff.h"
 
 #include "svn_private_config.h"
@@ -2179,13 +2181,19 @@ struct svn_diff_patch_parser_t
 };
 
 svn_diff_patch_parser_t *
-svn_diff_patch_parser_create(apr_file_t *patch_file,
+svn_diff_patch_parser_create(svn_stream_t *patch_stream,
                              apr_pool_t *result_pool)
 {
   svn_diff_patch_parser_t *result;
 
+  /* FIXME: Temporary hack on the patch-from-stream branch: Assume that
+            patch_stream was created by svn_stream_open_readonly and it
+            therefore has an underlying apr_file_t, which we'll unwrap.
+            here This is just to make it easier to convert the actual patch
+            parsing code in smaller chunks. */
+
   result = apr_palloc(result_pool, sizeof(*result));
-  result->apr_file = patch_file;
+  result->apr_file = svn_stream__aprfile(patch_stream); /* FIXME: <-remove */
   result->next_patch_offset = 0;
 
   return result;
@@ -2375,26 +2383,26 @@ svn_diff_patch_parser_next(svn_patch_t *
 struct svn_patch_file_t
 {
   /* The APR file handle to the patch file. */
-  apr_file_t *apr_file;
+  svn_stream_t *stream;
 
   /* Inner parser for svn_diff_patch_parser_next() */
   svn_diff_patch_parser_t *parser;
 };
 
+/* TODO: Revise this function to also take a scratch_pool. */
 svn_error_t *
 svn_diff_open_patch_file(svn_patch_file_t **patch_file,
                          const char *local_abspath,
                          apr_pool_t *result_pool)
 {
-  svn_patch_file_t *p;
+  svn_patch_file_t *p = apr_palloc(result_pool, sizeof(*p));
+  apr_pool_t *scratch_pool = svn_pool_create(result_pool);
 
-  p = apr_palloc(result_pool, sizeof(*p));
-  SVN_ERR(svn_io_file_open(&p->apr_file, local_abspath,
-                           APR_READ | APR_BUFFERED, APR_OS_DEFAULT,
-                           result_pool));
-
-  p->parser = svn_diff_patch_parser_create(p->apr_file, result_pool);
+  SVN_ERR(svn_stream_open_readonly(&p->stream, local_abspath,
+                                   result_pool, scratch_pool));
+  p->parser = svn_diff_patch_parser_create(p->stream, result_pool);
 
+  svn_pool_destroy(scratch_pool);
   *patch_file = p;
 
   return SVN_NO_ERROR;
@@ -2417,6 +2425,6 @@ svn_error_t *
 svn_diff_close_patch_file(svn_patch_file_t *patch_file,
                           apr_pool_t *scratch_pool)
 {
-  return svn_error_trace(svn_io_file_close(patch_file->apr_file,
-                                           scratch_pool));
+  SVN_UNUSED(scratch_pool);
+  return svn_error_trace(svn_stream_close(patch_file->stream));
 }

Modified: 
subversion/branches/patch-from-stream/subversion/tests/libsvn_client/client-test.c
URL: 
http://svn.apache.org/viewvc/subversion/branches/patch-from-stream/subversion/tests/libsvn_client/client-test.c?rev=1925598&r1=1925597&r2=1925598&view=diff
==============================================================================
--- 
subversion/branches/patch-from-stream/subversion/tests/libsvn_client/client-test.c
 (original)
+++ 
subversion/branches/patch-from-stream/subversion/tests/libsvn_client/client-test.c
 Fri May 16 22:50:22 2025
@@ -342,6 +342,7 @@ test_patch(const svn_test_opts_t *opts,
   svn_opt_revision_t peg_rev;
   svn_client_ctx_t *ctx;
   apr_file_t *patch_file;
+  svn_stream_t *patch_stream;
   struct patch_collection_baton pcb;
   const char *patch_file_path;
   const char *patched_tempfile_path;
@@ -436,7 +437,9 @@ test_patch(const svn_test_opts_t *opts,
   apr_hash_clear(pcb.patched_tempfiles);
   apr_hash_clear(pcb.reject_tempfiles);
 
-  SVN_ERR(svn_client_patch_stream(patch_file, wc_path, FALSE, 0, FALSE,
+  patch_stream = svn_stream_from_aprfile2(patch_file, FALSE, pool);
+  SVN_ERR(svn_stream_reset(patch_stream));
+  SVN_ERR(svn_client_patch_stream(patch_stream, wc_path, FALSE, 0, FALSE,
                                   FALSE, FALSE, patch_collection_func, &pcb,
                                   ctx, pool));
 
@@ -451,7 +454,7 @@ test_patch(const svn_test_opts_t *opts,
   SVN_ERR(check_patch_result(reject_tempfile_path, expected_gamma_reject,
                              APR_EOL_STR, EXPECTED_GAMMA_REJECT_LINES, pool));
 
-  SVN_ERR(svn_io_file_close(patch_file, pool));
+  SVN_ERR(svn_stream_close(patch_stream));
 
   return SVN_NO_ERROR;
 }


Reply via email to