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

Re: [PATCH] fixes svn's chdir before invoking $EDITOR for commit log message

From: Philip Martin <philip_at_codematters.co.uk>
Date: 2002-08-23 18:19:57 CEST

Alexis Huxley <ahuxley@gmx.net> writes:

> Is '<envvar>=<value> <command>' portable?

No.

$ csh
debian2:~> XXX=yyy vi
XXX=yyy: Command not found.

It may not work in old Bourne shells either, it's so long since I used
one I can't remember.

> Index: subversion/clients/cmdline/util.c
> ===================================================================
> --- subversion/clients/cmdline/util.c
> +++ subversion/clients/cmdline/util.c 2002-08-20 21:02:20.000000000 +0200
> @@ -382,31 +382,49 @@
> /* Convert file contents from UTF-8 */
> SVN_ERR (svn_utf_cstring_from_utf8 (&contents_native, contents, pool));
>
> - /* Move to BASE_DIR to avoid getting characters that need quoting
> - into tmpfile_name */
> + /* Get cwd - will be needed later if we cd anywhere searching for writable dir */
> apr_err = apr_filepath_get (&old_cwd, APR_FILEPATH_NATIVE, pool);
> if (apr_err)
> {
> return svn_error_create
> - (apr_err, 0, NULL, pool, "failed to get current working directory");
> - }
> - SVN_ERR (svn_utf_cstring_from_utf8 (&base_dir_native, base_dir, pool));
> - apr_err = apr_filepath_set (base_dir_native, pool);
> - if (apr_err)
> - {
> - return svn_error_createf
> - (apr_err, 0, NULL, pool,
> - "failed to change working directory to '%s'", base_dir);
> + (apr_err, 0, NULL, pool, "failed to get current working directory");
> }
>
> - /*** From here on, any problems that occur require us to cd back!! ***/
> + /*** From here on, if problems occur we cd back unconditionally, even if superfluous ***/
>
> - /* Ask the working copy for a temporary file */
> - err = svn_io_open_unique_file
> - (&tmp_file, &tmpfile_name,
> - "msg", ".tmp", FALSE, pool);
> - if (err)
> + do { /* 1 loop only; 'do' facilitates 'break' */
> +
> + /* first attempt: stay in cwd, and try opening here */
> + err = svn_io_open_unique_file (&tmp_file, &tmpfile_name, "msg", ".tmp", FALSE, pool);
> + if (!err)
> + break;
> + else if (err && err->apr_err != APR_EACCES)

Don't test against APR errors explicitly. Use APR_STATUS_IS_EACCES.

> + goto cleanup2;
> +
> + /*** Additional cd+open's go here (copy and edit the 'last attempt' block) ***/
> +
> + /* last attempt: go to base of WC, and try opening there */
> + err = svn_utf_cstring_from_utf8 (&base_dir_native, base_dir, pool);
> + if (err)
> + goto cleanup2;
> + apr_err = apr_filepath_set (base_dir_native, pool);
> + if (apr_err)
> + {
> + err = svn_error_createf (apr_err, 0, NULL, pool,
> + "failed to change working directory to '%s'", base_dir);
> + goto cleanup2;
> + }
> + err = svn_io_open_unique_file (&tmp_file, &tmpfile_name, "msg", ".tmp", FALSE, pool);

HACKING limits lines to 80 characters.

> + if (!err)
> + break;
> + else if (err && err->apr_err != APR_EACCES)

APR_STATUS_IS_EACCES again.

> + goto cleanup2;
> +
> + /* finally: give up and generate an error using last EACCESS error */
> goto cleanup2;
> +
> + } while (0); /* facilitate goto without goto */

Interesting idea (although given the number of other gotos I'm not
sure it's much of a benefit).

> +
>
> /*** From here on, any problems that occur require us to cleanup
> the file we just created!! ***/

-- 
Philip Martin
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Fri Aug 23 18:20:34 2002

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.