subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1436335 - /subversion/trunk/subversion/libsvn_client/patch.c
Date Mon, 21 Jan 2013 13:28:03 GMT
Author: stsp
Date: Mon Jan 21 13:28:03 2013
New Revision: 1436335

URL: http://svn.apache.org/viewvc?rev=1436335&view=rev
Log:
In the patch code, allow readline() callback implementations to return a
NULL line, rather than forcing them to return an empty stringbuf if no
line could be read.

* subversion/libsvn_client/patch.c
  (readline_prop, readline_file, readline_symlink): Return a NULL line
   if nothing was read, instead of allocating an empty stringbuf.
  (readline): If a NULL line was read, return the static string "".

Modified:
    subversion/trunk/subversion/libsvn_client/patch.c

Modified: subversion/trunk/subversion/libsvn_client/patch.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/patch.c?rev=1436335&r1=1436334&r2=1436335&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/patch.c (original)
+++ subversion/trunk/subversion/libsvn_client/patch.c Mon Jan 21 13:28:03 2013
@@ -517,6 +517,8 @@ typedef struct prop_read_baton_t {
  * the property value runs out in which case *EOF is set to TRUE.
  * The line-terminator is not stored in *STRINGBUF.
  *
+ * If the line is empty or could not be read, *line is set to NULL.
+ *
  * The line-terminator is detected automatically and stored in *EOL
  * if EOL is not NULL. If the end of the property value is reached
  * and does not end with a newline character, and EOL is not NULL,
@@ -530,17 +532,15 @@ readline_prop(void *baton, svn_stringbuf
               apr_pool_t *scratch_pool)
 {
   prop_read_baton_t *b = (prop_read_baton_t *)baton;
-  svn_stringbuf_t *str;
+  svn_stringbuf_t *str = NULL;
   const char *c;
   svn_boolean_t found_eof;
 
-  str = svn_stringbuf_create_ensure(80, result_pool);
-
   if ((apr_uint64_t)b->offset >= (apr_uint64_t)b->value->len)
     {
       *eol_str = NULL;
       *eof = TRUE;
-      *line = str;
+      *line = NULL;
       return SVN_NO_ERROR;
     }
 
@@ -572,7 +572,11 @@ readline_prop(void *baton, svn_stringbuf
             }
         }
       else
-        svn_stringbuf_appendbyte(str, *c);
+        {
+          if (str == NULL)
+            str = svn_stringbuf_create_ensure(80, result_pool);
+          svn_stringbuf_appendbyte(str, *c);
+        }
 
       if (*eol_str)
         break;
@@ -690,6 +694,8 @@ init_prop_target(prop_patch_target_t **p
  * or if EOF is reached in which case *EOF is set to TRUE.
  * The line-terminator is not stored in *STRINGBUF.
  *
+ * If the line is empty or could not be read, *line is set to NULL.
+ *
  * The line-terminator is detected automatically and stored in *EOL
  * if EOL is not NULL. If EOF is reached and FILE does not end
  * with a newline character, and EOL is not NULL, *EOL is set to NULL.
@@ -702,13 +708,11 @@ readline_file(void *baton, svn_stringbuf
               apr_pool_t *scratch_pool)
 {
   apr_file_t *file = (apr_file_t *)baton;
-  svn_stringbuf_t *str;
+  svn_stringbuf_t *str = NULL;
   apr_size_t numbytes;
   char c;
   svn_boolean_t found_eof;
 
-  str = svn_stringbuf_create_ensure(80, result_pool);
-
   /* Read bytes into STR up to and including, but not storing,
    * the next EOL sequence. */
   *eol_str = NULL;
@@ -755,7 +759,11 @@ readline_file(void *baton, svn_stringbuf
             }
         }
       else
-        svn_stringbuf_appendbyte(str, c);
+        {
+          if (str == NULL)
+            str = svn_stringbuf_create_ensure(80, result_pool);
+          svn_stringbuf_appendbyte(str, c);
+        }
 
       if (*eol_str)
         break;
@@ -848,7 +856,7 @@ readline_symlink(void *baton, svn_string
 
   if (sb->at_eof)
     {
-      *line = svn_stringbuf_create("", result_pool); /* Result required :( */
+      *line = NULL;
     }
   else
     {
@@ -1182,13 +1190,18 @@ readline(target_content_t *content,
   if (content->eol_style == svn_subst_eol_style_none)
     content->eol_str = eol_str;
 
-  /* Contract keywords. */
-  SVN_ERR(svn_subst_translate_cstring2(line_raw->data, line,
-                                       NULL, FALSE,
-                                       content->keywords, FALSE,
-                                       result_pool));
+  if (line_raw)
+    {
+      /* Contract keywords. */
+      SVN_ERR(svn_subst_translate_cstring2(line_raw->data, line,
+                                           NULL, FALSE,
+                                           content->keywords, FALSE,
+                                           result_pool));
+    }
+  else
+    *line = "";
 
-  if (line_raw->len > 0 || eol_str)
+  if ((line_raw && line_raw->len > 0) || eol_str)
     content->current_line++;
 
   return SVN_NO_ERROR;



Mime
View raw message