[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-23 17:37:14 CEST

Hi,

I submitted this patch at the beginning of the week, but I
think it got ignored - presumably 'cos I hadn't read 'HACKING'
all the way to the end ;-)

Also, a couple of questions regarding automated tests:

sbox.build creates a working copy, right? If I want to create a
directory *in which* to call sbox.build, then where should I be
doing it? Presumably I need to do this under the test directory,
but then what variables/interface does the test harness offer me?

(I want to create a writable and unwritable directory to run the
commit from.)

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

(Rather than looking at how to integrate a pseudo-editor into the
test directories/PATH/etc, I thought I might invoke

        EDITOR="python -c 'import os; print os.getcwd()'" svn commit

but perhaps that only works on Unix-like OSs.)

Can anyone advise? Thanks! Anyway, here's the patch ... be gentle ;-)

Alexis

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-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)
+ 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);
+ if (!err)
+ break;
+ else if (err && err->apr_err != APR_EACCES)
+ 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 Fri Aug 23 17:38:03 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.