You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by plasma <pl...@pchome.com.tw> on 2003/05/19 02:30:22 UTC

[PATCH] Issue #1296: --force option for svn export

LOG:

Fix issue #1296: --force option for svn export

  * clients/cmdline/main.c: Add svn_cl__force_opt for export in
    svn_cl__options.

  * clients/cmdline/export-cmd.c, include/svn_client.h:
    Interface of svn_client_export() is changed.  A new argument named force.

  * libsvn_clients/export.c
    (svn_client_export, svn_client__get_export_editor):
    Interface is changed.  A new argument named force.
    (struct edit_baton): A new force field is added.
    (open_root, add_directory): If a --force option is specified, an
    existing directory is no longer an error.

PATCH:

--- subversion/clients/cmdline/main.c.orig	Sat May 10 09:02:58 2003
+++ subversion/clients/cmdline/main.c	Sun May 18 00:49:40 2003
@@ -226,7 +226,7 @@
     "  2. Exports a clean directory tree from the working copy specified by\n"
     "     PATH1 into PATH2.  all local changes will be preserved, but files\n"
     "     not under revision control will not be copied.\n",
-    {'r', 'q', SVN_CL__AUTH_OPTIONS} },
+    {'r', 'q', svn_cl__force_opt, SVN_CL__AUTH_OPTIONS} },
 
   { "help", svn_cl__help, {"?", "h"},
     "Display this usage message.\n"
--- subversion/clients/cmdline/export-cmd.c.orig	Sat May 10 09:03:00 2003
+++ subversion/clients/cmdline/export-cmd.c	Sun May 18 00:51:56 2003
@@ -71,6 +71,7 @@
   SVN_ERR (svn_client_export (from,
                               to,
                               &(opt_state->start_revision),
+                              opt_state->force,
                               ctx,
                               pool));
   return SVN_NO_ERROR;
--- subversion/include/svn_client.h.orig	Sun May 18 00:43:58 2003
+++ subversion/include/svn_client.h	Sun May 18 00:44:18 2003
@@ -1186,6 +1186,7 @@
 svn_client_export (const char *from,
                    const char *to,
                    svn_opt_revision_t *revision,
+                   svn_boolean_t force, 
                    svn_client_ctx_t *ctx,
                    apr_pool_t *pool);
 
--- subversion/libsvn_client/export.c.orig	Sat May 10 09:05:54 2003
+++ subversion/libsvn_client/export.c	Mon May 19 10:08:18 2003
@@ -140,6 +140,7 @@
 svn_client_export (const char *from,
                    const char *to,
                    svn_opt_revision_t *revision,
+                   svn_boolean_t force, 
                    svn_client_ctx_t *ctx,
                    apr_pool_t *pool)
 {
@@ -155,7 +156,7 @@
       URL = svn_path_canonicalize (from, pool);
       
       SVN_ERR (svn_client__get_export_editor (&export_editor, &edit_baton,
-                                              to, URL, ctx, pool));
+                                              to, URL, force, ctx, pool));
       
       if (revision->kind == svn_opt_revision_number)
         revnum = revision->value.number;
@@ -194,6 +195,7 @@
 {
   const char *root_path;
   const char *root_url;
+  svn_boolean_t force;
 
   svn_wc_notify_func_t notify_func;
   void *notify_baton;
@@ -305,11 +307,15 @@
   svn_node_kind_t kind;
   
   SVN_ERR (svn_io_check_path (eb->root_path, &kind, pool));
-  if (kind != svn_node_none)
-    return svn_error_create (SVN_ERR_WC_OBSTRUCTED_UPDATE,
-                             NULL, eb->root_path);
-
-  SVN_ERR (svn_io_dir_make (eb->root_path, APR_OS_DEFAULT, pool));
+  if ( kind == svn_node_none )
+    {
+      SVN_ERR (svn_io_dir_make (eb->root_path, APR_OS_DEFAULT, pool));
+    }
+  else if (! (kind == svn_node_dir && eb->force))
+    {
+      return svn_error_create (SVN_ERR_WC_OBSTRUCTED_UPDATE,
+                               NULL, eb->root_path);
+    }
 
   if (eb->notify_func)
     (*eb->notify_func) (eb->notify_baton,
@@ -338,8 +344,18 @@
   struct edit_baton *eb = parent_baton;
   const char *full_path = svn_path_join (eb->root_path,
                                          path, pool);
+  svn_node_kind_t kind;
 
-  SVN_ERR (svn_io_dir_make (full_path, APR_OS_DEFAULT, pool));
+  SVN_ERR (svn_io_check_path (full_path, &kind, pool));
+  if ( kind == svn_node_none )
+    {
+      SVN_ERR (svn_io_dir_make (full_path, APR_OS_DEFAULT, pool));
+    }
+  else if (! (kind == svn_node_dir && eb->force))
+    {
+      return svn_error_create (SVN_ERR_WC_OBSTRUCTED_UPDATE,
+                               NULL, eb->root_path);
+    }
 
   if (eb->notify_func)
     (*eb->notify_func) (eb->notify_baton,
@@ -545,6 +561,7 @@
                                void **edit_baton,
                                const char *root_path,
                                const char *root_url,
+                               svn_boolean_t force, 
                                svn_client_ctx_t *ctx,
                                apr_pool_t *pool)
 {
@@ -553,6 +570,7 @@
 
   eb->root_path = apr_pstrdup (pool, root_path);
   eb->root_url = apr_pstrdup (pool, root_url);
+  eb->force = force;
   eb->notify_func = ctx->notify_func;
   eb->notify_baton = ctx->notify_baton;
 

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Issue #1296: --force option for svn export

Posted by plasma <pl...@pchome.com.tw>.
On Thu, May 22, 2003 at 01:38:34PM +0100, Julian Foad wrote:
> plasma wrote:
> >
> >Sounds good.  Below is another try, and it is aginst 0.23.  In
> >addition, I throw SVN_ERR_WC_OBSTRUCTED_UPDATE if target is a file
> >instead of a directory in open_root() and add_directory().
> 
> Please could you give a short description (in the log message and/or in the 
> "--help" text) of what the "--force" option means or does.  I am asking 
> because issue 1296 says "nice to have a --overwrite or --force option to 
> tell 'svn export' to just overwrite any files that already exist", but I 
> can't see anything in this patch that overwrites files.

'svn export' barks when a directory it doesn't expect to exist exists.
For 'svn export', the first it has to do is create a directory for
destination, and it will fail if the destination directory exists in
the first place.  My patch changes the behavior that svn doesn't see
an existing directory as an error if --force is given.

You don't see my patch to overwrites files because svn already does so.
All I need to do is get it past existing directories.

> Also, your original message said that your problem was that "svn co 
> bogus-url" created the destination directory before failing because of the 
> bad URL, and the existence of that directory caused a second attempt (with 
> the correct URL) to fail.  That use case could be better fixed by changing 
> "svn co" to not leave a dangling directory when it fails in that way.

No, I don't say that.  I never metion anything about 'svn co'.  You
could find my original mails below:

http://subversion.tigris.org/servlets/ReadMsg?list=dev&msgNo=37578
http://subversion.tigris.org/servlets/ReadMsg?list=dev&msgNo=37593

And the example in the second mail is bad.  William Uther gave a
better example in

http://subversion.tigris.org/servlets/ReadMsg?list=dev&msgNo=37596

as "untarring over an already existing dir."


Regards,
plasma

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Issue #1296: --force option for svn export

Posted by Julian Foad <ju...@btopenworld.com>.
plasma wrote:
> 
> Sounds good.  Below is another try, and it is aginst 0.23.  In
> addition, I throw SVN_ERR_WC_OBSTRUCTED_UPDATE if target is a file
> instead of a directory in open_root() and add_directory().

Please could you give a short description (in the log message and/or in the "--help" text) of what the "--force" option means or does.  I am asking because issue 1296 says "nice to have a --overwrite or --force option to tell 'svn export' to just overwrite any files that already exist", but I can't see anything in this patch that overwrites files.

Also, your original message said that your problem was that "svn co bogus-url" created the destination directory before failing because of the bad URL, and the existence of that directory caused a second attempt (with the correct URL) to fail.  That use case could be better fixed by changing "svn co" to not leave a dangling directory when it fails in that way.

- Julian


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Issue #1296: --force option for svn export

Posted by plasma <pl...@pchome.com.tw>.
On Sun, May 18, 2003 at 11:14:05PM -0500, cmpilato@collab.net wrote:
> Just a suggestion (doesn't count as a patch review): if an existing
> directory is the only condition that causes SVN_ERR_WC_OBSTRUCTED_UPDATE 
> to be returned as part of an export, you might consider having the
> client code (in export-cmd.c) check for that error, and wrap it with a
> suggestion that the user either remove the directory, or use the
> --force option.

Sounds good.  Below is another try, and it is aginst 0.23.  In
addition, I throw SVN_ERR_WC_OBSTRUCTED_UPDATE if target is a file
instead of a directory in open_root() and add_directory().


plasma


LOG:

Fix issue #1296: --force option for svn export

  * clients/cmdline/main.c: Add svn_cl__force_opt for export in
    svn_cl__options.

  * clients/cmdline/export-cmd.c
    Interface of svn_client_export() is changed.  A new argument named force.
    Give suggestions if target directory exists and --force is not given.

  * include/svn_client.h:
    Interface of svn_client_export() is changed.  A new argument named force.

  * libsvn_clients/export.c
    (svn_client_export, svn_client__get_export_editor):
    Interface is changed.  A new argument named force.
    (struct edit_baton): A new force field is added.
    (open_root, add_directory): If a --force option is specified, an
    existing directory is no longer an error.


PATCH:

--- subversion/clients/cmdline/main.c.orig	Sun May 18 08:16:30 2003
+++ subversion/clients/cmdline/main.c	Mon May 19 18:01:27 2003
@@ -226,7 +226,7 @@
     "  2. Exports a clean directory tree from the working copy specified by\n"
     "     PATH1 into PATH2.  all local changes will be preserved, but files\n"
     "     not under revision control will not be copied.\n",
-    {'r', 'q', SVN_CL__AUTH_OPTIONS} },
+    {'r', 'q', svn_cl__force_opt, SVN_CL__AUTH_OPTIONS} },
 
   { "help", svn_cl__help, {"?", "h"},
     "Display this usage message.\n"
--- subversion/clients/cmdline/export-cmd.c.orig	Sun May 18 08:16:30 2003
+++ subversion/clients/cmdline/export-cmd.c	Mon May 19 23:59:46 2003
@@ -42,6 +42,7 @@
   svn_client_ctx_t *ctx = ((svn_cl__cmd_baton_t *) baton)->ctx;
   const char *from, *to;
   apr_array_header_t *targets;
+  svn_error_t *err;
 
   SVN_ERR (svn_opt_args_to_target_array (&targets, os, 
                                          opt_state->targets,
@@ -68,10 +69,18 @@
                           FALSE, pool);
 
   /* Do the export. */
-  SVN_ERR (svn_client_export (from,
-                              to,
-                              &(opt_state->start_revision),
-                              ctx,
-                              pool));
+  err = svn_client_export (from,
+                           to,
+                           &(opt_state->start_revision),
+                           opt_state->force,
+                           ctx,
+                           pool);
+  if (err && err->apr_err == SVN_ERR_WC_OBSTRUCTED_UPDATE && !opt_state->force)
+    SVN_ERR_W (err,
+               "Destination directory exists.  Please remove "
+               "the directory, or try again with --force.");
+  else
+    SVN_ERR (err);
+
   return SVN_NO_ERROR;
 }
--- subversion/libsvn_client/export.c.orig	Sun May 18 08:18:33 2003
+++ subversion/libsvn_client/export.c	Tue May 20 00:02:31 2003
@@ -141,6 +141,7 @@
 svn_client_export (const char *from,
                    const char *to,
                    svn_opt_revision_t *revision,
+                   svn_boolean_t force, 
                    svn_client_ctx_t *ctx,
                    apr_pool_t *pool)
 {
@@ -156,7 +157,7 @@
       URL = svn_path_canonicalize (from, pool);
       
       SVN_ERR (svn_client__get_export_editor (&export_editor, &edit_baton,
-                                              to, URL, ctx, pool));
+                                              to, URL, force, ctx, pool));
       
       if (revision->kind == svn_opt_revision_number)
         revnum = revision->value.number;
@@ -195,6 +196,7 @@
 {
   const char *root_path;
   const char *root_url;
+  svn_boolean_t force;
 
   svn_wc_notify_func_t notify_func;
   void *notify_baton;
@@ -250,11 +252,14 @@
   svn_node_kind_t kind;
   
   SVN_ERR (svn_io_check_path (eb->root_path, &kind, pool));
-  if (kind != svn_node_none)
-    return svn_error_create (SVN_ERR_WC_OBSTRUCTED_UPDATE,
-                             NULL, eb->root_path);
-
-  SVN_ERR (svn_io_dir_make (eb->root_path, APR_OS_DEFAULT, pool));
+  if ( kind == svn_node_none )
+      SVN_ERR (svn_io_dir_make (eb->root_path, APR_OS_DEFAULT, pool));
+  else if (kind == svn_node_file)
+      return svn_error_create (SVN_ERR_WC_NOT_DIRECTORY,
+                               NULL, eb->root_path);
+  else if ( (! (kind == svn_node_dir && eb->force)) || kind != svn_node_dir)
+      return svn_error_create (SVN_ERR_WC_OBSTRUCTED_UPDATE,
+                               NULL, eb->root_path);
 
   if (eb->notify_func)
     (*eb->notify_func) (eb->notify_baton,
@@ -283,8 +288,17 @@
   struct edit_baton *eb = parent_baton;
   const char *full_path = svn_path_join (eb->root_path,
                                          path, pool);
+  svn_node_kind_t kind;
 
-  SVN_ERR (svn_io_dir_make (full_path, APR_OS_DEFAULT, pool));
+  SVN_ERR (svn_io_check_path (full_path, &kind, pool));
+  if ( kind == svn_node_none )
+      SVN_ERR (svn_io_dir_make (full_path, APR_OS_DEFAULT, pool));
+  else if (kind == svn_node_file)
+      return svn_error_create (SVN_ERR_WC_NOT_DIRECTORY,
+                               NULL, full_path);
+  else if (! (kind == svn_node_dir && eb->force))
+      return svn_error_create (SVN_ERR_WC_OBSTRUCTED_UPDATE,
+                               NULL, full_path);
 
   if (eb->notify_func)
     (*eb->notify_func) (eb->notify_baton,
@@ -492,6 +506,7 @@
                                void **edit_baton,
                                const char *root_path,
                                const char *root_url,
+                               svn_boolean_t force, 
                                svn_client_ctx_t *ctx,
                                apr_pool_t *pool)
 {
@@ -500,6 +515,7 @@
 
   eb->root_path = apr_pstrdup (pool, root_path);
   eb->root_url = apr_pstrdup (pool, root_url);
+  eb->force = force;
   eb->notify_func = ctx->notify_func;
   eb->notify_baton = ctx->notify_baton;
 
--- subversion/libsvn_client/client.h.orig	Mon May 19 23:23:22 2003
+++ subversion/libsvn_client/client.h	Mon May 19 23:23:26 2003
@@ -224,6 +224,7 @@
                                              void **edit_baton,
                                              const char *root_path,
                                              const char *root_url,
+                                             svn_boolean_t force,
                                              svn_client_ctx_t *ctx,
                                              apr_pool_t *pool);
 
--- subversion/include/svn_client.h.orig	Sun May 18 08:21:39 2003
+++ subversion/include/svn_client.h	Mon May 19 18:01:27 2003
@@ -1181,6 +1181,7 @@
 svn_client_export (const char *from,
                    const char *to,
                    svn_opt_revision_t *revision,
+                   svn_boolean_t force, 
                    svn_client_ctx_t *ctx,
                    apr_pool_t *pool);
 
==========================================================
 �@���d�w�Ҧ��t��
 http://edm-prg.epaper.com.tw/click.php?ad_code=7762
==========================================================
 PChome�ʪ��G�x�W�Ĥ@���ʪ������I
 http://shopping.pchome.com.tw/
==========================================================

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Issue #1296: --force option for svn export

Posted by cm...@collab.net.
plasma <pl...@pchome.com.tw> writes:

> LOG:
> 
> Fix issue #1296: --force option for svn export
> 
>   * clients/cmdline/main.c: Add svn_cl__force_opt for export in
>     svn_cl__options.
> 
>   * clients/cmdline/export-cmd.c, include/svn_client.h:
>     Interface of svn_client_export() is changed.  A new argument named force.
> 
>   * libsvn_clients/export.c
>     (svn_client_export, svn_client__get_export_editor):
>     Interface is changed.  A new argument named force.
>     (struct edit_baton): A new force field is added.
>     (open_root, add_directory): If a --force option is specified, an
>     existing directory is no longer an error.

Just a suggestion (doesn't count as a patch review): if an existing
directory is the only condition that causes SVN_ERR_WC_OBSTRUCTED_UPDATE 
to be returned as part of an export, you might consider having the
client code (in export-cmd.c) check for that error, and wrap it with a
suggestion that the user either remove the directory, or use the
--force option.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org