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

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

From: Alexis Huxley <ahuxley_at_gmx.net>
Date: 2002-08-26 18:37:43 CEST

Ok, here it is again with Philip's suggested corrections, and
a s/tab/spaces/ indent change, applied. Log message repeated
for convenience.

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

Out of curiousity, why?

Bug description:

        svn invokes editor in a different directory from that in
        which it itself is invoked, which means prepared log
        messages cannot intuitively be loaded into editor.

Reproduction recipe:

        svnadmin create repos
        svn co file://`pwd`/repos wc
        touch wc/newfile
        svn add wc/newfile
        EDITOR=pwd svn commit wc

Patch description:

        The patch tries to open the temp file for the log message
        in the current directory, and only if it gets 'access denied'
        does it fall back to cd'ing to the WC base in order to
        open the temp file there.

Log entry:

* subversion/clients/cmdline/util.c:
  (svn_cl__edit_externally): Added attempt to open temp file for log
  message in current directory, and only on 'access denied' error
  fall back to old behaviour of cd'ing to top of working copy.

Patch:

Index: subversion/clients/cmdline/util.c
===================================================================
--- subversion/clients/cmdline/util.c
+++ subversion/clients/cmdline/util.c 2002-08-26 18:29:09.000000000 +0200
@@ -182,7 +182,7 @@
 svn_error_t *
 svn_cl__args_to_target_array (apr_array_header_t **targets_p,
                               apr_getopt_t *os,
- svn_cl__opt_state_t *opt_state,
+ svn_cl__opt_state_t *opt_state,
                               svn_boolean_t extract_revisions,
                               apr_pool_t *pool)
 {
@@ -390,31 +390,51 @@
   /* 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 need 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, if problems occur cd back unconditionally ***/
 
- /* 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 && !APR_STATUS_IS_EACCES(err->apr_err))
+ goto cleanup2;
+
+ /*** New cd+open's for new places go here (clone '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);
+ if (!err)
+ break;
+ else if (err && !APR_STATUS_IS_EACCES(err->apr_err))
+ goto cleanup2;
+
+ /* finally: give up and generate an error using last EACCESS error */
     goto cleanup2;
+
+ } while (0); /* facilitate goto without goto */
+
 
   /*** From here on, any problems that occur require us to cleanup
        the file we just created!! ***/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Mon Aug 26 18:38:32 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.