Author: julianfoad
Date: Fri Jun 24 16:12:24 2011
New Revision: 1139367

URL: http://svn.apache.org/viewvc?rev=1139367&view=rev
Log:
Factor out a function, small though it is.

* subversion/svn/cl.h,
  subversion/svn/util.c
  (svn_cl__check_target_is_local_path): New function.

* subversion/svn/export-cmd.c
  (svn_cl__export): Use it instead of in-line code.

* subversion/svn/import-cmd.c
  (svn_cl__import): Same.

* subversion/svn/patch-cmd.c
  (svn_cl__patch): Same.

* subversion/svn/relocate-cmd.c
  (svn_cl__relocate): Same.

* subversion/svn/switch-cmd.c
  (svn_cl__switch): Same.

Modified:
    subversion/trunk/subversion/svn/cl.h
    subversion/trunk/subversion/svn/export-cmd.c
    subversion/trunk/subversion/svn/import-cmd.c
    subversion/trunk/subversion/svn/patch-cmd.c
    subversion/trunk/subversion/svn/relocate-cmd.c
    subversion/trunk/subversion/svn/switch-cmd.c
    subversion/trunk/subversion/svn/util.c

Modified: subversion/trunk/subversion/svn/cl.h
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/cl.h?rev=1139367&r1=1139366&r2=1139367&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/cl.h (original)
+++ subversion/trunk/subversion/svn/cl.h Fri Jun 24 16:12:24 2011
@@ -827,6 +827,10 @@ svn_cl__assert_homogeneous_target_type(c
 svn_error_t *
 svn_cl__check_targets_are_local_paths(const apr_array_header_t *targets);
 
+/* Return an error if TARGET is a URL; otherwise return SVN_NO_ERROR. */
+svn_error_t *
+svn_cl__check_target_is_local_path(const char *target);
+
 /* Return a copy of PATH, converted to the local path style, skipping
  * PARENT_PATH if it is non-null and is a parent of or equal to PATH.
  *

Modified: subversion/trunk/subversion/svn/export-cmd.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/export-cmd.c?rev=1139367&r1=1139366&r2=1139367&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/export-cmd.c (original)
+++ subversion/trunk/subversion/svn/export-cmd.c Fri Jun 24 16:12:24 2011
@@ -88,9 +88,7 @@ svn_cl__export(apr_getopt_t *os,
         SVN_ERR(svn_opt__split_arg_at_peg_revision(&to, NULL, to, pool));
     }
 
-  if (svn_path_is_url(to))
-    return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-                             _("'%s' is not a local path"), to);
+  SVN_ERR(svn_cl__check_target_is_local_path(to));
 
   if (! opt_state->quiet)
     SVN_ERR(svn_cl__notifier_mark_export(ctx->notify_baton2));

Modified: subversion/trunk/subversion/svn/import-cmd.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/import-cmd.c?rev=1139367&r1=1139366&r2=1139367&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/import-cmd.c (original)
+++ subversion/trunk/subversion/svn/import-cmd.c Fri Jun 24 16:12:24 2011
@@ -100,14 +100,11 @@ svn_cl__import(apr_getopt_t *os,
       url = APR_ARRAY_IDX(targets, 1, const char *);
     }
 
-  if (svn_path_is_url(path))
-    return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-                             _("'%s' is not a local path"), path);
+  SVN_ERR(svn_cl__check_target_is_local_path(path));
 
   if (! svn_path_is_url(url))
-    return svn_error_createf
-      (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-       _("Invalid URL '%s'"), url);
+    return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                             _("Invalid URL '%s'"), url);
 
   if (opt_state->depth == svn_depth_unknown)
     opt_state->depth = svn_depth_infinity;

Modified: subversion/trunk/subversion/svn/patch-cmd.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/patch-cmd.c?rev=1139367&r1=1139366&r2=1139367&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/patch-cmd.c (original)
+++ subversion/trunk/subversion/svn/patch-cmd.c Fri Jun 24 16:12:24 2011
@@ -70,9 +70,7 @@ svn_cl__patch(apr_getopt_t *os,
 
   patch_path = APR_ARRAY_IDX(targets, 0, const char *);
 
-  if (svn_path_is_url(patch_path))
-    return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-                             _("'%s' is not a local path"), patch_path);
+  SVN_ERR(svn_cl__check_target_is_local_path(patch_path));
 
   SVN_ERR(svn_dirent_get_absolute(&abs_patch_path, patch_path, pool));
 
@@ -82,9 +80,7 @@ svn_cl__patch(apr_getopt_t *os,
     {
       target_path = APR_ARRAY_IDX(targets, 1, const char *);
 
-      if (svn_path_is_url(target_path))
-        return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-                                 _("'%s' is not a local path"), target_path);
+      SVN_ERR(svn_cl__check_target_is_local_path(target_path));
     }
   SVN_ERR(svn_dirent_get_absolute(&abs_target_path, target_path, pool));
 

Modified: subversion/trunk/subversion/svn/relocate-cmd.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/relocate-cmd.c?rev=1139367&r1=1139366&r2=1139367&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/relocate-cmd.c (original)
+++ subversion/trunk/subversion/svn/relocate-cmd.c Fri Jun 24 16:12:24 2011
@@ -102,10 +102,7 @@ svn_cl__relocate(apr_getopt_t *os,
           for (i = 2; i < targets->nelts; i++)
             {
               path = APR_ARRAY_IDX(targets, i, const char *);
-              if (svn_path_is_url(path))
-                return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-                                         _("'%s' is not a local path"),
-                                         path);
+              SVN_ERR(svn_cl__check_target_is_local_path(path));
             }
 
           for (i = 2; i < targets->nelts; i++)

Modified: subversion/trunk/subversion/svn/switch-cmd.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/switch-cmd.c?rev=1139367&r1=1139366&r2=1139367&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/switch-cmd.c (original)
+++ subversion/trunk/subversion/svn/switch-cmd.c Fri Jun 24 16:12:24 2011
@@ -142,17 +142,11 @@ svn_cl__switch(apr_getopt_t *os,
 
   /* Validate the switch_url */
   if (! svn_path_is_url(switch_url))
-    return svn_error_createf
-      (SVN_ERR_BAD_URL, NULL,
-       _("'%s' does not appear to be a URL"), switch_url);
-
-  /* Target path cannot be URL */
-  if (svn_path_is_url(target))
-    return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-                             _("'%s' is not a local path"),
-                             target);
+    return svn_error_createf(SVN_ERR_BAD_URL, NULL,
+                             _("'%s' does not appear to be a URL"), 
switch_url);
+
+  SVN_ERR(svn_cl__check_target_is_local_path(target));
 
-  /* Canonicalize the URL. */
   switch_url = svn_uri_canonicalize(switch_url, scratch_pool);
 
   /* Deal with depthstuffs. */

Modified: subversion/trunk/subversion/svn/util.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/util.c?rev=1139367&r1=1139366&r2=1139367&view=diff
==============================================================================
--- subversion/trunk/subversion/svn/util.c (original)
+++ subversion/trunk/subversion/svn/util.c Fri Jun 24 16:12:24 2011
@@ -1390,6 +1390,15 @@ svn_cl__assert_homogeneous_target_type(c
 }
 
 svn_error_t *
+svn_cl__check_target_is_local_path(const char *target)
+{
+  if (svn_path_is_url(target))
+    return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                             _("'%s' is not a local path"), target);
+  return SVN_NO_ERROR;
+}
+
+svn_error_t *
 svn_cl__check_targets_are_local_paths(const apr_array_header_t *targets)
 {
   int i;
@@ -1398,9 +1407,7 @@ svn_cl__check_targets_are_local_paths(co
     {
       const char *target = APR_ARRAY_IDX(targets, i, const char *);
 
-      if (svn_path_is_url(target))
-        return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-                                 _("'%s' is not a local path"), target);
+      SVN_ERR(svn_cl__check_target_is_local_path(target));
     }
   return SVN_NO_ERROR;
 }


Reply via email to