You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by rh...@apache.org on 2015/09/24 18:40:33 UTC

svn commit: r1705102 - /subversion/trunk/subversion/libsvn_diff/parse-diff.c

Author: rhuijben
Date: Thu Sep 24 16:40:33 2015
New Revision: 1705102

URL: http://svn.apache.org/viewvc?rev=1705102&view=rev
Log:
Following up on r1705038, r1705080 avoid an unneeded seek when the caller
doesn't need the EOL value. And apply the same behavior to the function that
is used for creating reject files.

* subversion/libsvn_diff/parse-diff.c
  (hunk_readline_original_or_modified): Avoid unneeded work. Don't duplicate
    EOL type as that is a static value anyway.
  (svn_diff_hunk_readline_diff_text): Add final EOL unless we explicitly don't
    want one, just like the other similar functions.

Modified:
    subversion/trunk/subversion/libsvn_diff/parse-diff.c

Modified: subversion/trunk/subversion/libsvn_diff/parse-diff.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_diff/parse-diff.c?rev=1705102&r1=1705101&r2=1705102&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_diff/parse-diff.c (original)
+++ subversion/trunk/subversion/libsvn_diff/parse-diff.c Thu Sep 24 16:40:33 2015
@@ -581,17 +581,16 @@ hunk_readline_original_or_modified(apr_f
       *stringbuf = svn_stringbuf_dup(str, result_pool);
     }
 
-  if (!filtered)
+  if (!filtered && *eof && !*eol && !no_final_eol && *str->data)
     {
-      if (*eof && !*eol && !no_final_eol && *str->data)
-        {
-          /* Ok, we miss a final EOL in the patch file, but didn't see a
-             no eol marker line.
+      /* Ok, we miss a final EOL in the patch file, but didn't see a
+         no eol marker line.
 
-             We should report that we had an EOL or the patch code will
-             misbehave (and it knows nothing about no eol markers)
+         We should report that we had an EOL or the patch code will
+         misbehave (and it knows nothing about no eol markers) */
 
-             Lets pick the first eol we find in our patch file */
+      if (eol != &eol_p)
+        {
           apr_off_t start = 0;
 
           SVN_ERR(svn_io_file_seek(file, APR_SET, &start, scratch_pool));
@@ -601,11 +600,10 @@ hunk_readline_original_or_modified(apr_f
 
           /* Every patch file that has hunks has at least one EOL*/
           SVN_ERR_ASSERT(*eol != NULL);
-          *eol = apr_pstrdup(result_pool, *eol);
-          *eof = FALSE;
-
-          /* Fall through to seek back to the right location */
         }
+
+      *eof = FALSE;
+      /* Fall through to seek back to the right location */
     }
   SVN_ERR(svn_io_file_seek(file, APR_SET, &pos, scratch_pool));
 
@@ -661,13 +659,16 @@ svn_diff_hunk_readline_diff_text(svn_dif
   svn_stringbuf_t *line;
   apr_size_t max_len;
   apr_off_t pos;
+  const char *eol_p;
+
+  if (!eol)
+    eol = &eol_p;
 
   if (hunk->diff_text_range.current >= hunk->diff_text_range.end)
     {
       /* We're past the range. Indicate that no bytes can be read. */
       *eof = TRUE;
-      if (eol)
-        *eol = NULL;
+      *eol = NULL;
       *stringbuf = svn_stringbuf_create_empty(result_pool);
       return SVN_NO_ERROR;
     }
@@ -683,6 +684,37 @@ svn_diff_hunk_readline_diff_text(svn_dif
   hunk->diff_text_range.current = 0;
   SVN_ERR(svn_io_file_seek(hunk->apr_file, APR_CUR,
                            &hunk->diff_text_range.current, scratch_pool));
+
+  if (*eof && !*eol && !hunk->no_final_eol && *line->data)
+    {
+      /* Ok, we miss a final EOL in the patch file, but didn't see a
+          no eol marker line.
+
+          We should report that we had an EOL or the patch code will
+          misbehave (and it knows nothing about no eol markers) */
+
+      if (eol != &eol_p)
+        {
+          /* Lets pick the first eol we find in our patch file */
+          apr_off_t start = 0;
+          svn_stringbuf_t *str;
+
+          SVN_ERR(svn_io_file_seek(hunk->apr_file, APR_SET, &start,
+                                   scratch_pool));
+
+          SVN_ERR(svn_io_file_readline(hunk->apr_file, &str, eol, NULL,
+                                       APR_SIZE_MAX,
+                                       scratch_pool, scratch_pool));
+
+          /* Every patch file that has hunks has at least one EOL*/
+          SVN_ERR_ASSERT(*eol != NULL);
+        }
+
+      *eof = FALSE;
+
+      /* Fall through to seek back to the right location */
+    }
+
   SVN_ERR(svn_io_file_seek(hunk->apr_file, APR_SET, &pos, scratch_pool));
 
   if (hunk->patch->reverse)