[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Consolidate EOL functions to new libsvn_subr/eol.c

From: Edmund Wong <ed_at_kdtc.net>
Date: Tue, 18 Aug 2009 09:57:39 +0800

Hi,

This is my first attempt at a 'large' patch
(in terms of # of files affected).

Edmund

Log:

[[[

Moved the EOL functions from the libsvn_subr/subst.c library to
libsvn_subr/eol.c and from include/svn_subst.h to
include/private/svn_eol_private.h. This is to allow future
consolidation of EOL functions to be placed in the new files
instead of being all over the place.

Changed patch.c, subst-tests.c and diff-file.c to reflect the change
in libraries for svn_subst_find_eol_start(), svn_subst_detect_eol(),
and svn_subst_detect_file_eol(), which have all been renamed to
svn_eol_find_eol_start(), svn_eol_detect_eol() and
svn_eol_detect_file_eol() respectively.

Updated the build.conf to include the new private header
(svn_eol_private.h).

* build.conf:
  (msvc-export): Added private\svn_eol_private.h to end of list.

* subversion/libsvn_diff/diff-file.c:
   Include private/svn_eol_private.h

* subversion/libsvn_subr/eol.c: New.

* subversion/include/private/svn_eol_private.h: New.

* subversion/libsvn_subr/subst.c,
   subversion/include/svn_subst.h:
  (svn_subst_find_eol_start, svn_subst_detect_eol,
   svn_subst_detect_file_eol): Moved from here ...

* subversion/libsvn_subr/eol.c,
   subversion/include/private/svn_eol_private.h
  (svn_eol_find_eol_start, svn_eol_detect_eol,
   svn_eol_detect_file_eol): ...to here.

* subversion/libsvn_subr/eol.c,
   subversion/include/private/svn_eol_private.h,
   subversion/libsvn_client/patch.c,
   subversion/libsvn_diff/diff-file.c:
   Included private/svn_eol_private.h,
   Renamed svn_subst_find_eol_start() to svn_eol_find_eol_start(),
   and svn_subst_detect_eol() to svn_eol_detect_eol().

* subversion/tests/libsvn_subr/subst-test.c
   Included private/svn_eol_private.h.

Patch by Edmund Wong <ed {at} kdtc.net>
Suggested by: stsp

]]]

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=2384594

Index: build.conf
===================================================================
--- build.conf (revision 38767)
+++ build.conf (working copy)
@@ -320,7 +320,7 @@
 path = subversion/libsvn_subr
 libs = aprutil apriconv apr xml zlib apr_memcache sqlite
 msvc-libs = advapi32.lib shfolder.lib ole32.lib crypt32.lib version.lib
-msvc-export = svn_auth.h svn_base64.h svn_checksum.h svn_cmdline.h svn_compat.h svn_config.h svn_ctype.h svn_dirent_uri.h svn_dso.h svn_error.h svn_hash.h svn_io.h svn_iter.h svn_md5.h svn_mergeinfo.h svn_nls.h svn_opt.h svn_path.h svn_pools.h svn_props.h svn_quoprint.h svn_sorts.h svn_string.h svn_subst.h svn_time.h svn_types.h svn_user.h svn_utf.h svn_version.h svn_xml.h private\svn_atomic.h private\svn_cache.h private\svn_cmdline_private.h private\svn_log.h private\svn_mergeinfo_private.h private\svn_opt_private.h private\svn_patch.h private\svn_skel.h private\svn_sqlite.h private\svn_utf_private.h
+msvc-export = svn_auth.h svn_base64.h svn_checksum.h svn_cmdline.h svn_compat.h svn_config.h svn_ctype.h svn_dirent_uri.h svn_dso.h svn_error.h svn_hash.h svn_io.h svn_iter.h svn_md5.h svn_mergeinfo.h svn_nls.h svn_opt.h svn_path.h svn_pools.h svn_props.h svn_quoprint.h svn_sorts.h svn_string.h svn_subst.h svn_time.h svn_types.h svn_user.h svn_utf.h svn_version.h svn_xml.h private\svn_atomic.h private\svn_cache.h private\svn_cmdline_private.h private\svn_log.h private\svn_mergeinfo_private.h private\svn_opt_private.h private\svn_patch.h private\svn_skel.h private\svn_sqlite.h private\svn_utf_private.h private\svn_eol_private.h
 
 # Working copy management lib
 [libsvn_wc]
Index: subversion/libsvn_diff/diff_file.c
===================================================================
--- subversion/libsvn_diff/diff_file.c (revision 38767)
+++ subversion/libsvn_diff/diff_file.c (working copy)
@@ -45,6 +45,7 @@
 #include "svn_ctype.h"
 
 #include "private/svn_utf_private.h"
+#include "private/svn_eol_private.h"
 
 /* A token, i.e. a line read from a file. */
 typedef struct svn_diff__file_token_t
@@ -295,7 +296,7 @@
 
   while (1)
     {
- eol = svn_subst_find_eol_start(curp, endp - curp);
+ eol = svn_eol_find_eol_start(curp, endp - curp);
       if (eol)
         {
           had_cr = (*eol == '\r');
@@ -825,7 +826,7 @@
                 }
             }
 
- eol = svn_subst_find_eol_start(curp, length);
+ eol = svn_eol_find_eol_start(curp, length);
 
           if (eol != NULL)
             {
@@ -1426,7 +1427,7 @@
   if (curp == endp)
     return SVN_NO_ERROR;
 
- eol = svn_subst_find_eol_start(curp, endp - curp);
+ eol = svn_eol_find_eol_start(curp, endp - curp);
   if (!eol)
     eol = endp;
   else
@@ -1724,7 +1725,7 @@
   /* Check what eol marker we should use for conflict markers.
      We use the eol marker of the modified file and fall back on the
      platform's eol marker if that file doesn't contain any newlines. */
- eol = svn_subst_detect_eol(baton.buffer[1], baton.endp[1]);
+ eol = svn_eol_detect_eol(baton.buffer[1], baton.endp[1]);
   if (! eol)
     eol = APR_EOL_STR;
   baton.marker_eol = eol;
Index: subversion/libsvn_subr/subst.c
===================================================================
--- subversion/libsvn_subr/subst.c (revision 38767)
+++ subversion/libsvn_subr/subst.c (working copy)
@@ -1647,94 +1647,3 @@
 
   return SVN_NO_ERROR;
 }
-
-char *
-svn_subst_find_eol_start(char *buf, apr_size_t len)
-{
- for (; len > 0; ++buf, --len)
- {
- if (*buf == '\n' || *buf == '\r')
- return buf;
- }
- return NULL;
-}
-
-const char *
-svn_subst_detect_eol(char *buf, char *endp)
-{
- const char *eol;
-
- SVN_ERR_ASSERT_NO_RETURN(buf <= endp);
- eol = svn_subst_find_eol_start(buf, endp - buf);
- if (eol)
- {
- if (*eol == '\n')
- return "\n";
-
- /* We found a CR. */
- ++eol;
- if (eol == endp || *eol != '\n')
- return "\r";
- return "\r\n";
- }
-
- return NULL;
-}
-
-svn_error_t *
-svn_subst_detect_file_eol(const char **eol, apr_file_t *file, apr_pool_t *pool)
-{
- char buf[512];
- apr_size_t nbytes;
- svn_error_t *err;
- apr_off_t orig_pos;
- apr_off_t pos;
-
- /* Remember original file offset. */
- orig_pos = 0;
- SVN_ERR(svn_io_file_seek(file, APR_CUR, &orig_pos, pool));
-
- do
- {
- memset(buf, '\0', sizeof(buf));
-
- /* Read a chunk. */
- nbytes = sizeof(buf);
- err = svn_io_file_read(file, buf, &nbytes, pool);
- if (err)
- {
- /* An error occured. We're going to return in any case,
- * so reset the file cursor right now. */
- pos = orig_pos;
- SVN_ERR(svn_io_file_seek(file, APR_SET, &pos, pool));
- SVN_ERR_ASSERT(orig_pos == pos);
-
- /* If we reached the end of the file, the file has no
- * EOL markers at all... */
- if (APR_STATUS_IS_EOF(err->apr_err))
- {
- svn_error_clear(err);
- return SVN_NO_ERROR;
- }
- else
- {
- /* Whatever happened, it's something we don't know how
- * to deal with. Just return the error. */
- return svn_error_return(err);
- }
- }
-
- /* Try to detect the EOL style of the file by searching the
- * current chunk. */
- SVN_ERR_ASSERT(nbytes <= sizeof(buf));
- *eol = svn_subst_detect_eol(buf, buf + nbytes);
- }
- while (*eol == NULL);
-
- /* We're done, reset the file cursor to the original offset. */
- pos = orig_pos;
- SVN_ERR(svn_io_file_seek(file, APR_SET, &pos, pool));
- SVN_ERR_ASSERT(orig_pos == pos);
-
- return SVN_NO_ERROR;
-}
Index: subversion/libsvn_subr/eol.c
===================================================================
--- subversion/libsvn_subr/eol.c (revision 0)
+++ subversion/libsvn_subr/eol.c (revision 0)
@@ -0,0 +1,140 @@
+/*
+ * eol.c : generic eol/keyword routines
+ *
+ * ====================================================================
+ * Licensed to the Subversion Corporation (SVN Corp.) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SVN Corp. licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ */
+
+
+
+#define APR_WANT_STRFUNC
+#include <apr_want.h>
+
+#include <stdlib.h>
+#include <assert.h>
+#include <apr_pools.h>
+#include <apr_tables.h>
+#include <apr_file_io.h>
+#include <apr_strings.h>
+
+#include "svn_cmdline.h"
+#include "svn_types.h"
+#include "svn_string.h"
+#include "svn_time.h"
+#include "svn_dirent_uri.h"
+#include "svn_path.h"
+#include "svn_error.h"
+#include "svn_utf.h"
+#include "svn_io.h"
+#include "svn_subst.h"
+#include "svn_pools.h"
+
+#include "svn_private_config.h"
+#include "private/svn_eol_private.h"
+
+char *
+svn_eol_find_eol_start(char *buf, apr_size_t len)
+{
+ for (; len > 0; ++buf, --len)
+ {
+ if (*buf == '\n' || *buf == '\r')
+ return buf;
+ }
+ return NULL;
+}
+
+const char *
+svn_eol_detect_eol(char *buf, char *endp)
+{
+ const char *eol;
+
+ SVN_ERR_ASSERT_NO_RETURN(buf <= endp);
+ eol = svn_eol_find_eol_start(buf, endp - buf);
+ if (eol)
+ {
+ if (*eol == '\n')
+ return "\n";
+
+ /* We found a CR. */
+ ++eol;
+ if (eol == endp || *eol != '\n')
+ return "\r";
+ return "\r\n";
+ }
+
+ return NULL;
+}
+
+svn_error_t *
+svn_eol_detect_file_eol(const char **eol, apr_file_t *file, apr_pool_t *pool)
+{
+ char buf[512];
+ apr_size_t nbytes;
+ svn_error_t *err;
+ apr_off_t orig_pos;
+ apr_off_t pos;
+
+ /* Remember original file offset. */
+ orig_pos = 0;
+ SVN_ERR(svn_io_file_seek(file, APR_CUR, &orig_pos, pool));
+
+ do
+ {
+ memset(buf, '\0', sizeof(buf));
+
+ /* Read a chunk. */
+ nbytes = sizeof(buf);
+ err = svn_io_file_read(file, buf, &nbytes, pool);
+ if (err)
+ {
+ /* An error occured. We're going to return in any case,
+ * so reset the file cursor right now. */
+ pos = orig_pos;
+ SVN_ERR(svn_io_file_seek(file, APR_SET, &pos, pool));
+ SVN_ERR_ASSERT(orig_pos == pos);
+
+ /* If we reached the end of the file, the file has no
+ * EOL markers at all... */
+ if (APR_STATUS_IS_EOF(err->apr_err))
+ {
+ svn_error_clear(err);
+ return SVN_NO_ERROR;
+ }
+ else
+ {
+ /* Whatever happened, it's something we don't know how
+ * to deal with. Just return the error. */
+ return svn_error_return(err);
+ }
+ }
+
+ /* Try to detect the EOL style of the file by searching the
+ * current chunk. */
+ SVN_ERR_ASSERT(nbytes <= sizeof(buf));
+ *eol = svn_eol_detect_eol(buf, buf + nbytes);
+ }
+ while (*eol == NULL);
+
+ /* We're done, reset the file cursor to the original offset. */
+ pos = orig_pos;
+ SVN_ERR(svn_io_file_seek(file, APR_SET, &pos, pool));
+ SVN_ERR_ASSERT(orig_pos == pos);
+
+ return SVN_NO_ERROR;
+}
Index: subversion/tests/libsvn_subr/subst-test.c
===================================================================
--- subversion/tests/libsvn_subr/subst-test.c (revision 38767)
+++ subversion/tests/libsvn_subr/subst-test.c (working copy)
@@ -28,6 +28,7 @@
 #include "svn_subst.h"
 
 #include "../svn_test.h"
+#include "private/svn_eol_private.h"
 
 
 
Index: subversion/include/svn_subst.h
===================================================================
--- subversion/include/svn_subst.h (revision 38767)
+++ subversion/include/svn_subst.h (working copy)
@@ -570,48 +570,6 @@
                                           svn_boolean_t for_output,
                                           apr_pool_t *pool);
 
-/* Generic EOL character helper routines */
-
-/* Look for the start of an end-of-line sequence (i.e. CR or LF)
- * in the array pointed to by @a buf , of length @a len.
- * If such a byte is found, return the pointer to it, else return NULL.
- *
- * @since New in 1.7
- */
-char *
-svn_subst_find_eol_start(char *buf, apr_size_t len);
-
-/* Return the first eol marker found in [@a buf, @a endp) as a
- * NUL-terminated string, or NULL if no eol marker is found.
- *
- * If the last valid character of @a buf is the first byte of a
- * potentially two-byte eol sequence, just return that single-character
- * sequence, that is, assume @a buf represents a CR-only or LF-only file.
- * This is correct for callers that pass an entire file at once, and is
- * no more likely to be incorrect than correct for any caller that
- * doesn't.
- *
- * @since New in 1.7
- */
-const char *
-svn_subst_detect_eol(char *buf, char *endp);
-
-/* Detect the EOL marker used in @a file and return it in @a *eol.
- * If it cannot be detected, set @a *eol to NULL.
- *
- * The file is searched starting at the current file cursor position.
- * The first EOL marker found will be returnd. So if the file has
- * inconsistent EOL markers, this won't be detected.
- *
- * Upon return, the original file cursor position is always preserved,
- * even if an error is thrown.
- *
- * Do temporary allocations in @a pool.
- *
- * @since New in 1.7 */
-svn_error_t *
-svn_subst_detect_file_eol(const char **eol, apr_file_t *file, apr_pool_t *pool);
-
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
Index: subversion/include/private/svn_eol_private.h
===================================================================
--- subversion/include/private/svn_eol_private.h (revision 0)
+++ subversion/include/private/svn_eol_private.h (revision 0)
@@ -0,0 +1,86 @@
+/**
+ * @copyright
+ * ====================================================================
+ * Licensed to the Subversion Corporation (SVN Corp.) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The SVN Corp. licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ * ====================================================================
+ * @endcopyright
+ *
+ * @file svn_auth_private.h
+ * @brief Subversion's authentication system - Internal routines
+ */
+
+#ifndef SVN_EOL_PRIVATE_H
+#define SVN_EOL_PRIVATE_H
+
+#include <apr_pools.h>
+#include <apr_hash.h>
+
+#include "svn_types.h"
+#include "svn_error.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+/* Generic EOL character helper routines */
+
+/* Look for the start of an end-of-line sequence (i.e. CR or LF)
+ * in the array pointed to by @a buf , of length @a len.
+ * If such a byte is found, return the pointer to it, else return NULL.
+ *
+ * @since New in 1.7
+ */
+char *
+svn_eol_find_eol_start(char *buf, apr_size_t len);
+
+/* Return the first eol marker found in [@a buf, @a endp) as a
+ * NUL-terminated string, or NULL if no eol marker is found.
+ *
+ * If the last valid character of @a buf is the first byte of a
+ * potentially two-byte eol sequence, just return that single-character
+ * sequence, that is, assume @a buf represents a CR-only or LF-only file.
+ * This is correct for callers that pass an entire file at once, and is
+ * no more likely to be incorrect than correct for any caller that
+ * doesn't.
+ *
+ * @since New in 1.7
+ */
+const char *
+svn_eol_detect_eol(char *buf, char *endp);
+
+/* Detect the EOL marker used in @a file and return it in @a *eol.
+ * If it cannot be detected, set @a *eol to NULL.
+ *
+ * The file is searched starting at the current file cursor position.
+ * The first EOL marker found will be returnd. So if the file has
+ * inconsistent EOL markers, this won't be detected.
+ *
+ * Upon return, the original file cursor position is always preserved,
+ * even if an error is thrown.
+ *
+ * Do temporary allocations in @a pool.
+ *
+ * @since New in 1.7 */
+svn_error_t *
+svn_eol_detect_file_eol(const char **eol, apr_file_t *file, apr_pool_t *pool);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* SVN_EOL_PRIVATE_H */
Index: subversion/libsvn_client/patch.c
===================================================================
--- subversion/libsvn_client/patch.c (revision 38767)
+++ subversion/libsvn_client/patch.c (working copy)
@@ -45,6 +45,7 @@
 
 #include "svn_private_config.h"
 #include "private/svn_diff_private.h"
+#include "private/svn_eol_private.h"
 
 
 /*** Code. ***/
@@ -2033,7 +2034,7 @@
       SVN_ERR(svn_io_file_open(&new_target->file, new_target->abs_path,
                                APR_READ | APR_BINARY | APR_BUFFERED,
                                APR_OS_DEFAULT, result_pool));
- SVN_ERR(svn_subst_detect_file_eol(&new_target->eol_str, new_target->file,
+ SVN_ERR(svn_eol_detect_file_eol(&new_target->eol_str, new_target->file,
                                         scratch_pool));
       new_target->stream = svn_stream_from_aprfile2(new_target->file, FALSE,
                                                     result_pool);
@@ -2795,7 +2796,7 @@
   SVN_ERR(svn_io_file_open(&patch_file, patch_path,
                            APR_READ | APR_BINARY, 0, pool));
 
- SVN_ERR(svn_subst_detect_file_eol(&patch_eol_str, patch_file, pool));
+ SVN_ERR(svn_eol_detect_file_eol(&patch_eol_str, patch_file, pool));
   if (patch_eol_str == NULL)
     {
       /* If we can't figure out the EOL scheme, just assume native.
Received on 2009-08-18 04:21:04 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.