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

Re: svn commit: rev 490 - trunk/subversion/include trunk/subversion/libsvn_wc trunk/subversion/libsvn_subr

From: Karl Fogel <kfogel_at_newton.ch.collab.net>
Date: 2001-11-22 00:32:43 CET

kevin@tigris.org writes:
> New Revision: 490
>
> Modified:
> trunk/subversion/include/svn_io.h
> trunk/subversion/libsvn_subr/io.c
> trunk/subversion/libsvn_wc/adm_ops.c
> Log:
> Avoid some duplication. This makes it so that the only one who opens an
> auth file is svn_wc__open_auth_file.

Just wanted to say thanks for the cleanups (this and others), Kevin.
There will be more such happening, especially in the WC, over the next
week or so, and the more eyes the better.

-K

> * subversion/include/svn_io.h:(svn_string_from_aprfile): New func.
>
> * subversion/libsvn_subr/io.c:(svn_string_from_aprfile): Implemented with
> body of svn_string_from_file.
> (svn_string_from_file): Move body to svn_string_from_file, call that
> function.
>
> * subversion/libsvn_wc/adm_ops.c:(svn_wc_get_auth_file) Change to use
> svn_wc__open_auth_file, instead of manually constructing the path.
>
>
> Modified: trunk/subversion/include/svn_io.h
> ==============================================================================
> --- OLD/trunk/subversion/include/svn_io.h Wed Nov 21 11:44:34 2001
> +++ NEW/trunk/subversion/include/svn_io.h Wed Nov 21 11:44:34 2001
> @@ -261,6 +261,13 @@
> const char *filename,
> apr_pool_t *pool);
>
> +/* Sets *RESULT to a string containing the contents of the already opened
> + FILE. Reads from the current position in file to the end. Does not
> + close the file or reset the cursor position.*/
> +svn_error_t *svn_string_from_aprfile (svn_stringbuf_t **result,
> + apr_file_t *file,
> + apr_pool_t *pool);
> +
> /* Recursively remove directory PATH. */
> apr_status_t apr_dir_remove_recursively (const char *path, apr_pool_t *pool);
>
>
> Modified: trunk/subversion/libsvn_wc/adm_ops.c
> ==============================================================================
> --- OLD/trunk/subversion/libsvn_wc/adm_ops.c Wed Nov 21 11:44:35 2001
> +++ NEW/trunk/subversion/libsvn_wc/adm_ops.c Wed Nov 21 11:44:35 2001
> @@ -1339,19 +1339,15 @@
> svn_stringbuf_t **contents,
> apr_pool_t *pool)
> {
> - svn_stringbuf_t *full_path_to_file =
> - svn_wc__adm_path (path, 0, pool, SVN_WC__ADM_AUTH_DIR, filename, NULL);
> -
> - /* Sanity check */
> - if (! svn_wc__adm_path_exists (path, 0, pool,
> - SVN_WC__ADM_AUTH_DIR, filename, NULL))
> - return
> - svn_error_createf (SVN_ERR_WC_PATH_NOT_FOUND, 0, NULL, pool,
> - "auth file '%s' not found in adm area of '%s'",
> - filename, path->data);
> + apr_file_t *file;
> + svn_stringbuf_t *fname = svn_stringbuf_create(filename, pool);
> + SVN_ERR (svn_wc__open_auth_file (&file, path, fname, APR_READ, pool));
>
> /* Read the file's contents into a stringbuf, allocated in POOL. */
> - SVN_ERR (svn_string_from_file (contents, full_path_to_file->data, pool));
> + SVN_ERR (svn_string_from_aprfile (contents, file, pool));
> +
> + SVN_ERR (svn_wc__close_auth_file (file, path, fname,
> + 0 /* Don't sync */, pool));
>
> return SVN_NO_ERROR;
> }
>
> Modified: trunk/subversion/libsvn_subr/io.c
> ==============================================================================
> --- OLD/trunk/subversion/libsvn_subr/io.c Wed Nov 21 11:44:35 2001
> +++ NEW/trunk/subversion/libsvn_subr/io.c Wed Nov 21 11:44:35 2001
> @@ -702,51 +702,65 @@
> }
>
>
> -/* TODO write test for this, then refactor. */
> +/* TODO write test for these two functions, then refactor. */
> +
> svn_error_t *
> -svn_string_from_file (svn_stringbuf_t **result, const char *filename, apr_pool_t *pool)
> +svn_string_from_file (svn_stringbuf_t **result,
> + const char *filename,
> + apr_pool_t *pool)
> {
> - /* ### this function must be fixed to do an apr_stat() for SIZE,
> - ### alloc the buffer, then read the file into the buffer. Using
> - ### an svn_stringbuf_t means quadratic memory usage: start with
> - ### BUFSIZE, allocate 2*BUFSIZE, then alloc 4*BUFSIZE, etc.
> - ### The pools keep each of those allocs around. */
> -
> - svn_stringbuf_t *res;
> apr_status_t apr_err;
> - char buf[BUFSIZ];
> - apr_size_t len;
> apr_file_t *f = NULL;
>
> - res = svn_stringbuf_create ("", pool);
> -
> apr_err = apr_file_open (&f, filename, APR_READ, APR_OS_DEFAULT, pool);
> if (apr_err)
> return svn_error_createf (apr_err, 0, NULL, pool,
> "read_from_file: failed to open '%s'",
> filename);
> -
> - do {
> - apr_err = apr_file_read_full (f, buf, sizeof(buf), &len);
> - if (apr_err && !APR_STATUS_IS_EOF (apr_err))
> - return svn_error_createf (apr_err, 0, NULL, pool,
> - "read_from_file: failed to read '%s'",
> - filename);
> -
> - svn_stringbuf_appendbytes (res, buf, len);
> - } while (len != 0);
> +
> + SVN_ERR (svn_string_from_aprfile (result, f, pool));
>
> apr_err = apr_file_close (f);
> if (apr_err)
> return svn_error_createf (apr_err, 0, NULL, pool,
> - "read_from_file: failed to close '%s'",
> + "svn_string_from_file: failed to close '%s'",
> filename);
> -
> - *result = res;
> return SVN_NO_ERROR;
> }
>
>
> +svn_error_t *
> +svn_string_from_aprfile(svn_stringbuf_t **result,
> + apr_file_t *file,
> + apr_pool_t *pool)
> +{
> + /* ### this function must be fixed to do an apr_stat() for SIZE,
> + ### alloc the buffer, then read the file into the buffer. Using
> + ### an svn_stringbuf_t means quadratic memory usage: start with
> + ### BUFSIZE, allocate 2*BUFSIZE, then alloc 4*BUFSIZE, etc.
> + ### The pools keep each of those allocs around. */
> + char buf[BUFSIZ];
> + apr_size_t len;
> + apr_status_t apr_err;
> + svn_stringbuf_t *res = svn_stringbuf_create("", pool);
> +
> + do {
> + apr_err = apr_file_read_full (file, buf, sizeof(buf), &len);
> + if (apr_err && !APR_STATUS_IS_EOF (apr_err))
> + {
> + const char * filename;
> + apr_file_name_get (&filename, file);
> + return svn_error_createf (apr_err, 0, NULL, pool,
> + "svn_string_from_aprfile: failed to read '%s'",
> + filename);
> + }
> +
> + svn_stringbuf_appendbytes (res, buf, len);
> + } while (len != 0);
> +
> + *result = res;
> + return SVN_NO_ERROR;
> +}
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: svn-unsubscribe@subversion.tigris.org
> For additional commands, e-mail: svn-help@subversion.tigris.org

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Oct 21 14:36:49 2006

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.