subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g..@apache.org
Subject svn commit: r1549081 [13/18] - in /subversion/branches/invoke-diff-cmd-feature: ./ build/ build/ac-macros/ build/generator/ build/generator/templates/ contrib/server-side/ contrib/server-side/svncutter/ subversion/bindings/javahl/native/ subversion/bin...
Date Sun, 08 Dec 2013 17:56:53 GMT
Modified: subversion/branches/invoke-diff-cmd-feature/subversion/svnauth/svnauth.c
URL: http://svn.apache.org/viewvc/subversion/branches/invoke-diff-cmd-feature/subversion/svnauth/svnauth.c?rev=1549081&r1=1549080&r2=1549081&view=diff
==============================================================================
--- subversion/branches/invoke-diff-cmd-feature/subversion/svnauth/svnauth.c (original)
+++ subversion/branches/invoke-diff-cmd-feature/subversion/svnauth/svnauth.c Sun Dec  8 17:56:46 2013
@@ -872,24 +872,13 @@ subcommand_delete(apr_getopt_t *os, void
 }
 
 
-/* Report and clear the error ERR, and return EXIT_FAILURE. */
-#define EXIT_ERROR(err)                                                 \
-  svn_cmdline_handle_exit_error(err, NULL, "svnauth: ")
-
-/* A redefinition of the public SVN_INT_ERR macro, that suppresses the
- * error message if it is SVN_ERR_IO_PIPE_WRITE_ERROR, amd with the
- * program name 'svnauth' instead of 'svn'. */
-#undef SVN_INT_ERR
-#define SVN_INT_ERR(expr)                                        \
-  do {                                                           \
-    svn_error_t *svn_err__temp = (expr);                         \
-    if (svn_err__temp)                                           \
-      return EXIT_ERROR(svn_err__temp);                          \
-  } while (0)
-
-
-static int
-sub_main(int argc, const char *argv[], apr_pool_t *pool)
+/*
+ * On success, leave *EXIT_CODE untouched and return SVN_NO_ERROR. On error,
+ * either return an error to be displayed, or set *EXIT_CODE to non-zero and
+ * return SVN_NO_ERROR.
+ */
+static svn_error_t *
+sub_main(int *exit_code, int argc, const char *argv[], apr_pool_t *pool)
 {
   svn_error_t *err;
   const svn_opt_subcommand_desc2_t *subcommand = NULL;
@@ -898,12 +887,13 @@ sub_main(int argc, const char *argv[], a
 
   if (argc <= 1)
     {
-      SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
-      return EXIT_FAILURE;
+      SVN_ERR(subcommand_help(NULL, NULL, pool));
+      *exit_code = EXIT_FAILURE;
+      return SVN_NO_ERROR;
     }
 
   /* Parse options. */
-  SVN_INT_ERR(svn_cmdline__getopt_init(&os, argc, argv, pool));
+  SVN_ERR(svn_cmdline__getopt_init(&os, argc, argv, pool));
   os->interleave = 1;
 
   while (1)
@@ -919,8 +909,9 @@ sub_main(int argc, const char *argv[], a
         break;
       else if (apr_err)
         {
-          SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
-          return EXIT_FAILURE;
+          SVN_ERR(subcommand_help(NULL, NULL, pool));
+          *exit_code = EXIT_FAILURE;
+          return SVN_NO_ERROR;
         }
 
       switch (opt_id) {
@@ -929,7 +920,7 @@ sub_main(int argc, const char *argv[], a
         opt_state.help = TRUE;
         break;
       case opt_config_dir:
-        SVN_INT_ERR(svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool));
+        SVN_ERR(svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool));
         opt_state.config_dir = svn_dirent_internal_style(utf8_opt_arg, pool);
         break;
       case opt_show_passwords:
@@ -940,8 +931,9 @@ sub_main(int argc, const char *argv[], a
         break;
       default:
         {
-          SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
-          return EXIT_FAILURE;
+          SVN_ERR(subcommand_help(NULL, NULL, pool));
+          *exit_code = EXIT_FAILURE;
+          return SVN_NO_ERROR;
         }
       }
     }
@@ -970,8 +962,9 @@ sub_main(int argc, const char *argv[], a
             {
               svn_error_clear(svn_cmdline_fprintf(stderr, pool,
                                         _("subcommand argument required\n")));
-              SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
-              return EXIT_FAILURE;
+              SVN_ERR(subcommand_help(NULL, NULL, pool));
+              *exit_code = EXIT_FAILURE;
+              return SVN_NO_ERROR;
             }
         }
       else
@@ -981,19 +974,20 @@ sub_main(int argc, const char *argv[], a
           if (subcommand == NULL)
             {
               const char *first_arg_utf8;
-              SVN_INT_ERR(svn_utf_cstring_to_utf8(&first_arg_utf8,
-                                                  first_arg, pool));
+              SVN_ERR(svn_utf_cstring_to_utf8(&first_arg_utf8,
+                                              first_arg, pool));
               svn_error_clear(
                 svn_cmdline_fprintf(stderr, pool,
                                     _("Unknown subcommand: '%s'\n"),
                                     first_arg_utf8));
-              SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
-              return EXIT_FAILURE;
+              SVN_ERR(subcommand_help(NULL, NULL, pool));
+              *exit_code = EXIT_FAILURE;
+              return SVN_NO_ERROR;
             }
         }
     }
 
-  SVN_INT_ERR(svn_config_ensure(opt_state.config_dir, pool));
+  SVN_ERR(svn_config_ensure(opt_state.config_dir, pool));
 
   /* Run the subcommand. */
   err = (*subcommand->cmd_func)(os, &opt_state, pool);
@@ -1007,28 +1001,18 @@ sub_main(int argc, const char *argv[], a
           err = svn_error_quick_wrap(err,
                                      _("Try 'svnauth help' for more info"));
         }
-      return EXIT_ERROR(err);
-    }
-  else
-    {
-      /* Ensure that everything is written to stdout, so the user will
-         see any print errors. */
-      err = svn_cmdline_fflush(stdout);
-      if (err)
-        {
-          return EXIT_ERROR(err);
-        }
-      return EXIT_SUCCESS;
+      return err;
     }
 
-  return EXIT_SUCCESS;
+  return SVN_NO_ERROR;
 }
 
 int
 main(int argc, const char *argv[])
 {
   apr_pool_t *pool;
-  int exit_code;
+  int exit_code = EXIT_SUCCESS;
+  svn_error_t *err;
 
   /* Initialize the app. */
   if (svn_cmdline_init("svnauth", stderr) != EXIT_SUCCESS)
@@ -1039,7 +1023,17 @@ main(int argc, const char *argv[])
    */
   pool = apr_allocator_owner_get(svn_pool_create_allocator(FALSE));
 
-  exit_code = sub_main(argc, argv, pool);
+  err = sub_main(&exit_code, argc, argv, pool);
+
+  /* Flush stdout and report if it fails. It would be flushed on exit anyway
+     but this makes sure that output is not silently lost if it fails. */
+  err = svn_error_compose_create(err, svn_cmdline_fflush(stdout));
+
+  if (err)
+    {
+      exit_code = EXIT_FAILURE;
+      svn_cmdline_handle_exit_error(err, NULL, "svnauth: ");
+    }
 
   svn_pool_destroy(pool);
   return exit_code;

Modified: subversion/branches/invoke-diff-cmd-feature/subversion/svndumpfilter/svndumpfilter.c
URL: http://svn.apache.org/viewvc/subversion/branches/invoke-diff-cmd-feature/subversion/svndumpfilter/svndumpfilter.c?rev=1549081&r1=1549080&r2=1549081&view=diff
==============================================================================
--- subversion/branches/invoke-diff-cmd-feature/subversion/svndumpfilter/svndumpfilter.c (original)
+++ subversion/branches/invoke-diff-cmd-feature/subversion/svndumpfilter/svndumpfilter.c Sun Dec  8 17:56:46 2013
@@ -1355,12 +1355,16 @@ subcommand_include(apr_getopt_t *os, voi
 
 /** Main. **/
 
-int
-main(int argc, const char *argv[])
+/*
+ * On success, leave *EXIT_CODE untouched and return SVN_NO_ERROR. On error,
+ * either return an error to be displayed, or set *EXIT_CODE to non-zero and
+ * return SVN_NO_ERROR.
+ */
+static svn_error_t *
+sub_main(int *exit_code, int argc, const char *argv[], apr_pool_t *pool)
 {
   svn_error_t *err;
   apr_status_t apr_err;
-  apr_pool_t *pool;
 
   const svn_opt_subcommand_desc2_t *subcommand = NULL;
   struct svndumpfilter_opt_state opt_state;
@@ -1369,33 +1373,19 @@ main(int argc, const char *argv[])
   apr_array_header_t *received_opts;
   int i;
 
-
-  /* Initialize the app. */
-  if (svn_cmdline_init("svndumpfilter", stderr) != EXIT_SUCCESS)
-    return EXIT_FAILURE;
-
-  /* Create our top-level pool.  Use a separate mutexless allocator,
-   * given this application is single threaded.
-   */
-  pool = apr_allocator_owner_get(svn_pool_create_allocator(FALSE));
-
   /* Check library versions */
-  err = check_lib_versions();
-  if (err)
-    return svn_cmdline_handle_exit_error(err, pool, "svndumpfilter: ");
+  SVN_ERR(check_lib_versions());
 
   received_opts = apr_array_make(pool, SVN_OPT_MAX_OPTIONS, sizeof(int));
 
   /* Initialize the FS library. */
-  err = svn_fs_initialize(pool);
-  if (err)
-    return svn_cmdline_handle_exit_error(err, pool, "svndumpfilter: ");
+  SVN_ERR(svn_fs_initialize(pool));
 
   if (argc <= 1)
     {
-      SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
-      svn_pool_destroy(pool);
-      return EXIT_FAILURE;
+      SVN_ERR(subcommand_help(NULL, NULL, pool));
+      *exit_code = EXIT_FAILURE;
+      return SVN_NO_ERROR;
     }
 
   /* Initialize opt_state. */
@@ -1404,9 +1394,7 @@ main(int argc, const char *argv[])
   opt_state.end_revision.kind = svn_opt_revision_unspecified;
 
   /* Parse options. */
-  err = svn_cmdline__getopt_init(&os, argc, argv, pool);
-  if (err)
-    return svn_cmdline_handle_exit_error(err, pool, "svndumpfilter: ");
+  SVN_ERR(svn_cmdline__getopt_init(&os, argc, argv, pool));
 
   os->interleave = 1;
   while (1)
@@ -1419,9 +1407,9 @@ main(int argc, const char *argv[])
         break;
       else if (apr_err)
         {
-          SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
-          svn_pool_destroy(pool);
-          return EXIT_FAILURE;
+          SVN_ERR(subcommand_help(NULL, NULL, pool));
+          *exit_code = EXIT_FAILURE;
+          return SVN_NO_ERROR;
         }
 
       /* Stash the option code in an array before parsing it. */
@@ -1462,9 +1450,9 @@ main(int argc, const char *argv[])
           break;
         default:
           {
-            SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
-            svn_pool_destroy(pool);
-            return EXIT_FAILURE;
+            SVN_ERR(subcommand_help(NULL, NULL, pool));
+            *exit_code = EXIT_FAILURE;
+            return SVN_NO_ERROR;
           }
         }  /* close `switch' */
     }  /* close `while' */
@@ -1473,10 +1461,10 @@ main(int argc, const char *argv[])
      --drop-all-empty-revs. */
   if (opt_state.drop_empty_revs && opt_state.drop_all_empty_revs)
     {
-      err = svn_error_create(SVN_ERR_CL_MUTUALLY_EXCLUSIVE_ARGS, NULL,
-                             _("--drop-empty-revs cannot be used with "
-                               "--drop-all-empty-revs"));
-      return svn_cmdline_handle_exit_error(err, pool, "svndumpfilter: ");
+      return svn_error_create(SVN_ERR_CL_MUTUALLY_EXCLUSIVE_ARGS,
+                              NULL,
+                              _("--drop-empty-revs cannot be used with "
+                                "--drop-all-empty-revs"));
     }
 
   /* If the user asked for help, then the rest of the arguments are
@@ -1508,9 +1496,9 @@ main(int argc, const char *argv[])
               svn_error_clear(svn_cmdline_fprintf
                               (stderr, pool,
                                _("Subcommand argument required\n")));
-              SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
-              svn_pool_destroy(pool);
-              return EXIT_FAILURE;
+              SVN_ERR(subcommand_help(NULL, NULL, pool));
+              *exit_code = EXIT_FAILURE;
+              return SVN_NO_ERROR;
             }
         }
       else
@@ -1520,18 +1508,16 @@ main(int argc, const char *argv[])
           if (subcommand == NULL)
             {
               const char* first_arg_utf8;
-              if ((err = svn_utf_cstring_to_utf8(&first_arg_utf8, first_arg,
-                                                 pool)))
-                return svn_cmdline_handle_exit_error(err, pool,
-                                                     "svndumpfilter: ");
+              SVN_ERR(svn_utf_cstring_to_utf8(&first_arg_utf8, first_arg,
+                                              pool));
 
               svn_error_clear(
                 svn_cmdline_fprintf(stderr, pool,
                                     _("Unknown subcommand: '%s'\n"),
                                     first_arg_utf8));
-              SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
-              svn_pool_destroy(pool);
-              return EXIT_FAILURE;
+              SVN_ERR(subcommand_help(NULL, NULL, pool));
+              *exit_code = EXIT_FAILURE;
+              return SVN_NO_ERROR;
             }
         }
     }
@@ -1551,7 +1537,7 @@ main(int argc, const char *argv[])
 
           /* Ensure that each prefix is UTF8-encoded, in internal
              style, and absolute. */
-          SVN_INT_ERR(svn_utf_cstring_to_utf8(&prefix, os->argv[i], pool));
+          SVN_ERR(svn_utf_cstring_to_utf8(&prefix, os->argv[i], pool));
           prefix = svn_relpath__internal_style(prefix, pool);
           if (prefix[0] != '/')
             prefix = apr_pstrcat(pool, "/", prefix, SVN_VA_NULL);
@@ -1569,12 +1555,12 @@ main(int argc, const char *argv[])
              the targets into an array, because otherwise we wouldn't
              know what delimiter to use for svn_cstring_split().  */
 
-          SVN_INT_ERR(svn_utf_cstring_to_utf8(&utf8_targets_file,
-                                              opt_state.targets_file, pool));
+          SVN_ERR(svn_utf_cstring_to_utf8(&utf8_targets_file,
+                                          opt_state.targets_file, pool));
 
-          SVN_INT_ERR(svn_stringbuf_from_file2(&buffer, utf8_targets_file,
-                                               pool));
-          SVN_INT_ERR(svn_utf_stringbuf_to_utf8(&buffer_utf8, buffer, pool));
+          SVN_ERR(svn_stringbuf_from_file2(&buffer, utf8_targets_file,
+                                           pool));
+          SVN_ERR(svn_utf_stringbuf_to_utf8(&buffer_utf8, buffer, pool));
 
           targets = apr_array_append(pool,
                          svn_cstring_split(buffer_utf8->data, "\n\r",
@@ -1595,8 +1581,8 @@ main(int argc, const char *argv[])
           svn_error_clear(svn_cmdline_fprintf
                           (stderr, pool,
                            _("\nError: no prefixes supplied.\n")));
-          svn_pool_destroy(pool);
-          return EXIT_FAILURE;
+          *exit_code = EXIT_FAILURE;
+          return SVN_NO_ERROR;
         }
     }
 
@@ -1621,15 +1607,15 @@ main(int argc, const char *argv[])
                                           pool);
           svn_opt_format_option(&optstr, badopt, FALSE, pool);
           if (subcommand->name[0] == '-')
-            SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
+            SVN_ERR(subcommand_help(NULL, NULL, pool));
           else
             svn_error_clear(svn_cmdline_fprintf
                             (stderr, pool,
                              _("Subcommand '%s' doesn't accept option '%s'\n"
                                "Type 'svndumpfilter help %s' for usage.\n"),
                              subcommand->name, optstr, subcommand->name));
-          svn_pool_destroy(pool);
-          return EXIT_FAILURE;
+          *exit_code = EXIT_FAILURE;
+          return SVN_NO_ERROR;
         }
     }
 
@@ -1646,14 +1632,40 @@ main(int argc, const char *argv[])
                                      _("Try 'svndumpfilter help' for more "
                                        "info"));
         }
-      return svn_cmdline_handle_exit_error(err, pool, "svndumpfilter: ");
+      return err;
     }
-  else
-    {
-      svn_pool_destroy(pool);
 
-      /* Flush stdout, making sure the user will see any print errors. */
-      SVN_INT_ERR(svn_cmdline_fflush(stdout));
-      return EXIT_SUCCESS;
+  return SVN_NO_ERROR;
+}
+
+int
+main(int argc, const char *argv[])
+{
+  apr_pool_t *pool;
+  int exit_code = EXIT_SUCCESS;
+  svn_error_t *err;
+
+  /* Initialize the app. */
+  if (svn_cmdline_init("svndumpfilter", stderr) != EXIT_SUCCESS)
+    return EXIT_FAILURE;
+
+  /* Create our top-level pool.  Use a separate mutexless allocator,
+   * given this application is single threaded.
+   */
+  pool = apr_allocator_owner_get(svn_pool_create_allocator(FALSE));
+
+  err = sub_main(&exit_code, argc, argv, pool);
+
+  /* Flush stdout and report if it fails. It would be flushed on exit anyway
+     but this makes sure that output is not silently lost if it fails. */
+  err = svn_error_compose_create(err, svn_cmdline_fflush(stdout));
+
+  if (err)
+    {
+      exit_code = EXIT_FAILURE;
+      svn_cmdline_handle_exit_error(err, NULL, "svndumpfilter: ");
     }
+
+  svn_pool_destroy(pool);
+  return exit_code;
 }

Modified: subversion/branches/invoke-diff-cmd-feature/subversion/svnlook/svnlook.c
URL: http://svn.apache.org/viewvc/subversion/branches/invoke-diff-cmd-feature/subversion/svnlook/svnlook.c?rev=1549081&r1=1549080&r2=1549081&view=diff
==============================================================================
--- subversion/branches/invoke-diff-cmd-feature/subversion/svnlook/svnlook.c (original)
+++ subversion/branches/invoke-diff-cmd-feature/subversion/svnlook/svnlook.c Sun Dec  8 17:56:46 2013
@@ -1899,7 +1899,8 @@ do_plist(svnlook_ctxt_t *c,
       svn_xml_make_header2(&sb, "UTF-8", pool);
 
       /* "<properties>" */
-      svn_xml_make_open_tag(&sb, pool, svn_xml_normal, "properties", NULL);
+      svn_xml_make_open_tag(&sb, pool, svn_xml_normal, "properties",
+                            SVN_VA_NULL);
     }
 
   if (inherited_props)
@@ -1918,7 +1919,7 @@ do_plist(svnlook_ctxt_t *c,
               svn_xml_make_open_tag(
                 &sb, pool, svn_xml_normal, "target", "path",
                 svn_fspath__canonicalize(elt->path_or_url, pool),
-                NULL);
+                SVN_VA_NULL);
               SVN_ERR(svn_cmdline__print_xml_prop_hash(&sb, elt->prop_hash,
                                                        !verbose, TRUE,
                                                        pool));
@@ -1945,19 +1946,19 @@ do_plist(svnlook_ctxt_t *c,
               char *revstr = apr_psprintf(pool, "%ld", c->rev_id);
 
               svn_xml_make_open_tag(&sb, pool, svn_xml_normal, "revprops",
-                                    "rev", revstr, NULL);
+                                    "rev", revstr, SVN_VA_NULL);
             }
           else
             {
               svn_xml_make_open_tag(&sb, pool, svn_xml_normal, "revprops",
-                                    "txn", c->txn_name, NULL);
+                                    "txn", c->txn_name, SVN_VA_NULL);
             }
         }
       else
         {
           /* "<target ...>" */
           svn_xml_make_open_tag(&sb, pool, svn_xml_normal, "target",
-                                "path", path, NULL);
+                                "path", path, SVN_VA_NULL);
         }
     }
 
@@ -2004,7 +2005,7 @@ do_plist(svnlook_ctxt_t *c,
         }
       else if (xml)
         svn_xml_make_open_tag(&sb, pool, svn_xml_self_closing, "property",
-                              "name", pname, NULL);
+                              "name", pname, SVN_VA_NULL);
       else
         printf("  %s\n", pname);
     }
@@ -2457,12 +2458,16 @@ subcommand_uuid(apr_getopt_t *os, void *
 
 /*** Main. ***/
 
-int
-main(int argc, const char *argv[])
+/*
+ * On success, leave *EXIT_CODE untouched and return SVN_NO_ERROR. On error,
+ * either return an error to be displayed, or set *EXIT_CODE to non-zero and
+ * return SVN_NO_ERROR.
+ */
+static svn_error_t *
+sub_main(int *exit_code, int argc, const char *argv[], apr_pool_t *pool)
 {
   svn_error_t *err;
   apr_status_t apr_err;
-  apr_pool_t *pool;
 
   const svn_opt_subcommand_desc2_t *subcommand = NULL;
   struct svnlook_opt_state opt_state;
@@ -2471,32 +2476,19 @@ main(int argc, const char *argv[])
   apr_array_header_t *received_opts;
   int i;
 
-  /* Initialize the app. */
-  if (svn_cmdline_init("svnlook", stderr) != EXIT_SUCCESS)
-    return EXIT_FAILURE;
-
-  /* Create our top-level pool.  Use a separate mutexless allocator,
-   * given this application is single threaded.
-   */
-  pool = apr_allocator_owner_get(svn_pool_create_allocator(FALSE));
-
   received_opts = apr_array_make(pool, SVN_OPT_MAX_OPTIONS, sizeof(int));
 
   /* Check library versions */
-  err = check_lib_versions();
-  if (err)
-    return svn_cmdline_handle_exit_error(err, pool, "svnlook: ");
+  SVN_ERR(check_lib_versions());
 
   /* Initialize the FS library. */
-  err = svn_fs_initialize(pool);
-  if (err)
-    return svn_cmdline_handle_exit_error(err, pool, "svnlook: ");
+  SVN_ERR(svn_fs_initialize(pool));
 
   if (argc <= 1)
     {
-      SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
-      svn_pool_destroy(pool);
-      return EXIT_FAILURE;
+      SVN_ERR(subcommand_help(NULL, NULL, pool));
+      *exit_code = EXIT_FAILURE;
+      return SVN_NO_ERROR;
     }
 
   /* Initialize opt_state. */
@@ -2504,9 +2496,7 @@ main(int argc, const char *argv[])
   opt_state.rev = SVN_INVALID_REVNUM;
 
   /* Parse options. */
-  err = svn_cmdline__getopt_init(&os, argc, argv, pool);
-  if (err)
-    return svn_cmdline_handle_exit_error(err, pool, "svnlook: ");
+  SVN_ERR(svn_cmdline__getopt_init(&os, argc, argv, pool));
 
   os->interleave = 1;
   while (1)
@@ -2519,9 +2509,9 @@ main(int argc, const char *argv[])
         break;
       else if (apr_err)
         {
-          SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
-          svn_pool_destroy(pool);
-          return EXIT_FAILURE;
+          SVN_ERR(subcommand_help(NULL, NULL, pool));
+          *exit_code = EXIT_FAILURE;
+          return SVN_NO_ERROR;
         }
 
       /* Stash the option code in an array before parsing it. */
@@ -2536,9 +2526,8 @@ main(int argc, const char *argv[])
             if ((! SVN_IS_VALID_REVNUM(opt_state.rev))
                 || (! digits_end)
                 || *digits_end)
-              SVN_INT_ERR(svn_error_create
-                          (SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-                           _("Invalid revision number supplied")));
+              return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                                      _("Invalid revision number supplied"));
           }
           break;
 
@@ -2585,15 +2574,13 @@ main(int argc, const char *argv[])
             opt_state.limit = strtol(opt_arg, &end, 10);
             if (end == opt_arg || *end != '\0')
               {
-                err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-                                       _("Non-numeric limit argument given"));
-                return svn_cmdline_handle_exit_error(err, pool, "svnlook: ");
+                return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                                        _("Non-numeric limit argument given"));
               }
             if (opt_state.limit <= 0)
               {
-                err = svn_error_create(SVN_ERR_INCORRECT_PARAMS, NULL,
+                return svn_error_create(SVN_ERR_INCORRECT_PARAMS, NULL,
                                     _("Argument to --limit must be positive"));
-                return svn_cmdline_handle_exit_error(err, pool, "svnlook: ");
               }
           }
           break;
@@ -2643,26 +2630,26 @@ main(int argc, const char *argv[])
           break;
 
         default:
-          SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
-          svn_pool_destroy(pool);
-          return EXIT_FAILURE;
+          SVN_ERR(subcommand_help(NULL, NULL, pool));
+          *exit_code = EXIT_FAILURE;
+          return SVN_NO_ERROR;
 
         }
     }
 
   /* The --transaction and --revision options may not co-exist. */
   if ((opt_state.rev != SVN_INVALID_REVNUM) && opt_state.txn)
-    SVN_INT_ERR(svn_error_create
+    return svn_error_create
                 (SVN_ERR_CL_MUTUALLY_EXCLUSIVE_ARGS, NULL,
                  _("The '--transaction' (-t) and '--revision' (-r) arguments "
-                   "cannot co-exist")));
+                   "cannot co-exist"));
 
   /* The --show-inherited-props and --revprop options may not co-exist. */
   if (opt_state.show_inherited_props && opt_state.revprop)
-    SVN_INT_ERR(svn_error_create
+    return svn_error_create
                 (SVN_ERR_CL_MUTUALLY_EXCLUSIVE_ARGS, NULL,
                  _("Cannot use the '--show-inherited-props' option with the "
-                   "'--revprop' option")));
+                   "'--revprop' option"));
 
   /* The --diff-cmd and --invoke-diff-cmd options may not co-exist. */
   if (opt_state.diff_cmd && opt_state.invoke_diff_cmd)
@@ -2700,9 +2687,9 @@ main(int argc, const char *argv[])
               svn_error_clear
                 (svn_cmdline_fprintf(stderr, pool,
                                      _("Subcommand argument required\n")));
-              SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
-              svn_pool_destroy(pool);
-              return EXIT_FAILURE;
+              SVN_ERR(subcommand_help(NULL, NULL, pool));
+              *exit_code = EXIT_FAILURE;
+              return SVN_NO_ERROR;
             }
         }
       else
@@ -2712,15 +2699,13 @@ main(int argc, const char *argv[])
           if (subcommand == NULL)
             {
               const char *first_arg_utf8;
-              err = svn_utf_cstring_to_utf8(&first_arg_utf8, first_arg,
-                                            pool);
-              if (err)
-                return svn_cmdline_handle_exit_error(err, pool, "svnlook: ");
+              SVN_ERR(svn_utf_cstring_to_utf8(&first_arg_utf8, first_arg,
+                                              pool));
               svn_error_clear(
                 svn_cmdline_fprintf(stderr, pool,
                                     _("Unknown subcommand: '%s'\n"),
                                     first_arg_utf8));
-              SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
+              SVN_ERR(subcommand_help(NULL, NULL, pool));
 
               /* Be kind to people who try 'svnlook verify'. */
               if (strcmp(first_arg_utf8, "verify") == 0)
@@ -2730,9 +2715,8 @@ main(int argc, const char *argv[])
                                         _("Try 'svnadmin verify' instead.\n")));
                 }
 
-
-              svn_pool_destroy(pool);
-              return EXIT_FAILURE;
+              *exit_code = EXIT_FAILURE;
+              return SVN_NO_ERROR;
             }
         }
     }
@@ -2751,9 +2735,9 @@ main(int argc, const char *argv[])
       /* Get the repository. */
       if (os->ind < os->argc)
         {
-          SVN_INT_ERR(svn_utf_cstring_to_utf8(&repos_path,
-                                              os->argv[os->ind++],
-                                              pool));
+          SVN_ERR(svn_utf_cstring_to_utf8(&repos_path,
+                                          os->argv[os->ind++],
+                                          pool));
           repos_path = svn_dirent_internal_style(repos_path, pool);
         }
 
@@ -2762,9 +2746,9 @@ main(int argc, const char *argv[])
           svn_error_clear
             (svn_cmdline_fprintf(stderr, pool,
                                  _("Repository argument required\n")));
-          SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
-          svn_pool_destroy(pool);
-          return EXIT_FAILURE;
+          SVN_ERR(subcommand_help(NULL, NULL, pool));
+          *exit_code = EXIT_FAILURE;
+          return SVN_NO_ERROR;
         }
       else if (svn_path_is_url(repos_path))
         {
@@ -2772,8 +2756,8 @@ main(int argc, const char *argv[])
             (svn_cmdline_fprintf(stderr, pool,
                                  _("'%s' is a URL when it should be a path\n"),
                                  repos_path));
-          svn_pool_destroy(pool);
-          return EXIT_FAILURE;
+          *exit_code = EXIT_FAILURE;
+          return SVN_NO_ERROR;
         }
 
       opt_state.repos_path = repos_path;
@@ -2781,8 +2765,7 @@ main(int argc, const char *argv[])
       /* Get next arg (arg1), if any. */
       if (os->ind < os->argc)
         {
-          SVN_INT_ERR(svn_utf_cstring_to_utf8
-                      (&arg1, os->argv[os->ind++], pool));
+          SVN_ERR(svn_utf_cstring_to_utf8(&arg1, os->argv[os->ind++], pool));
           arg1 = svn_dirent_internal_style(arg1, pool);
         }
       opt_state.arg1 = arg1;
@@ -2790,8 +2773,7 @@ main(int argc, const char *argv[])
       /* Get next arg (arg2), if any. */
       if (os->ind < os->argc)
         {
-          SVN_INT_ERR(svn_utf_cstring_to_utf8
-                      (&arg2, os->argv[os->ind++], pool));
+          SVN_ERR(svn_utf_cstring_to_utf8(&arg2, os->argv[os->ind++], pool));
           arg2 = svn_dirent_internal_style(arg2, pool);
         }
       opt_state.arg2 = arg2;
@@ -2817,7 +2799,7 @@ main(int argc, const char *argv[])
                                           pool);
           svn_opt_format_option(&optstr, badopt, FALSE, pool);
           if (subcommand->name[0] == '-')
-            SVN_INT_ERR(subcommand_help(NULL, NULL, pool));
+            SVN_ERR(subcommand_help(NULL, NULL, pool));
           else
             svn_error_clear
               (svn_cmdline_fprintf
@@ -2825,8 +2807,8 @@ main(int argc, const char *argv[])
                 _("Subcommand '%s' doesn't accept option '%s'\n"
                   "Type 'svnlook help %s' for usage.\n"),
                 subcommand->name, optstr, subcommand->name));
-          svn_pool_destroy(pool);
-          return EXIT_FAILURE;
+          *exit_code = EXIT_FAILURE;
+          return SVN_NO_ERROR;
         }
     }
 
@@ -2867,14 +2849,40 @@ main(int argc, const char *argv[])
           err = svn_error_quick_wrap(err,
                                      _("Try 'svnlook help' for more info"));
         }
-      return svn_cmdline_handle_exit_error(err, pool, "svnlook: ");
+      return err;
     }
-  else
+
+  return SVN_NO_ERROR;
+}
+
+int
+main(int argc, const char *argv[])
+{
+  apr_pool_t *pool;
+  int exit_code = EXIT_SUCCESS;
+  svn_error_t *err;
+
+  /* Initialize the app. */
+  if (svn_cmdline_init("svnlook", stderr) != EXIT_SUCCESS)
+    return EXIT_FAILURE;
+
+  /* Create our top-level pool.  Use a separate mutexless allocator,
+   * given this application is single threaded.
+   */
+  pool = apr_allocator_owner_get(svn_pool_create_allocator(FALSE));
+
+  err = sub_main(&exit_code, argc, argv, pool);
+
+  /* Flush stdout and report if it fails. It would be flushed on exit anyway
+     but this makes sure that output is not silently lost if it fails. */
+  err = svn_error_compose_create(err, svn_cmdline_fflush(stdout));
+
+  if (err)
     {
-      svn_pool_destroy(pool);
-      /* Ensure everything is printed on stdout, so the user sees any
-         print errors. */
-      SVN_INT_ERR(svn_cmdline_fflush(stdout));
-      return EXIT_SUCCESS;
+      exit_code = EXIT_FAILURE;
+      svn_cmdline_handle_exit_error(err, NULL, "svnlook: ");
     }
+
+  svn_pool_destroy(pool);
+  return exit_code;
 }

Modified: subversion/branches/invoke-diff-cmd-feature/subversion/svnmucc/svnmucc.c
URL: http://svn.apache.org/viewvc/subversion/branches/invoke-diff-cmd-feature/subversion/svnmucc/svnmucc.c?rev=1549081&r1=1549080&r2=1549081&view=diff
==============================================================================
--- subversion/branches/invoke-diff-cmd-feature/subversion/svnmucc/svnmucc.c (original)
+++ subversion/branches/invoke-diff-cmd-feature/subversion/svnmucc/svnmucc.c Sun Dec  8 17:56:46 2013
@@ -59,36 +59,20 @@
 #include "private/svn_ra_private.h"
 #include "private/svn_string_private.h"
 
-static void handle_error(svn_error_t *err, apr_pool_t *pool)
-{
-  if (err)
-    svn_handle_error2(err, stderr, FALSE, "svnmucc: ");
-  svn_error_clear(err);
-  if (pool)
-    svn_pool_destroy(pool);
-  exit(EXIT_FAILURE);
-}
-
-static apr_pool_t *
-init(const char *application)
+/* Version compatibility check */
+static svn_error_t *
+check_lib_versions(void)
 {
-  svn_error_t *err;
-  const svn_version_checklist_t checklist[] = {
-    {"svn_client", svn_client_version},
-    {"svn_subr", svn_subr_version},
-    {"svn_ra", svn_ra_version},
-    {NULL, NULL}
-  };
+  static const svn_version_checklist_t checklist[] =
+    {
+      { "svn_client", svn_client_version },
+      { "svn_subr",   svn_subr_version },
+      { "svn_ra",     svn_ra_version },
+      { NULL, NULL }
+    };
   SVN_VERSION_DEFINE(my_version);
 
-  if (svn_cmdline_init(application, stderr))
-    exit(EXIT_FAILURE);
-
-  err = svn_ver_check_list2(&my_version, checklist, svn_ver_equal);
-  if (err)
-    handle_error(err, NULL);
-
-  return apr_allocator_owner_get(svn_pool_create_allocator(FALSE));
+  return svn_ver_check_list2(&my_version, checklist, svn_ver_equal);
 }
 
 static svn_error_t *
@@ -174,8 +158,8 @@ struct operation {
 };
 
 
-/* An iterator (for use via apr_table_do) which sets node properties.
-   REC is a pointer to a struct driver_state. */
+/* Set node properties.
+   ... */
 static svn_error_t *
 change_props(const svn_delta_editor_t *editor,
              void *baton,
@@ -917,10 +901,10 @@ sanitize_url(const char *url,
   return svn_uri_canonicalize(url, pool);
 }
 
+/* Print a usage message on STREAM. */
 static void
-usage(apr_pool_t *pool, int exit_val)
+usage(FILE *stream, apr_pool_t *pool)
 {
-  FILE *stream = exit_val == EXIT_SUCCESS ? stdout : stderr;
   svn_error_clear(svn_cmdline_fputs(
     _("usage: svnmucc ACTION...\n"
       "Subversion multiple URL command client.\n"
@@ -964,16 +948,13 @@ usage(apr_pool_t *pool, int exit_val)
       "  --no-auth-cache        : do not cache authentication tokens\n"
       "  --version              : print version information\n"),
                   stream, pool));
-  svn_pool_destroy(pool);
-  exit(exit_val);
 }
 
-static void
-insufficient(apr_pool_t *pool)
+static svn_error_t *
+insufficient(void)
 {
-  handle_error(svn_error_create(SVN_ERR_INCORRECT_PARAMS, NULL,
-                                "insufficient arguments"),
-               pool);
+  return svn_error_create(SVN_ERR_INCORRECT_PARAMS, NULL,
+                          "insufficient arguments");
 }
 
 static svn_error_t *
@@ -1040,10 +1021,14 @@ sanitize_log_sources(apr_hash_t *revprop
   return SVN_NO_ERROR;
 }
 
-int
-main(int argc, const char **argv)
+/*
+ * On success, leave *EXIT_CODE untouched and return SVN_NO_ERROR. On error,
+ * either return an error to be displayed, or set *EXIT_CODE to non-zero and
+ * return SVN_NO_ERROR.
+ */
+static svn_error_t *
+sub_main(int *exit_code, int argc, const char *argv[], apr_pool_t *pool)
 {
-  apr_pool_t *pool = init("svnmucc");
   apr_array_header_t *actions = apr_array_make(pool, 1,
                                                sizeof(struct action *));
   const char *anchor = NULL;
@@ -1094,6 +1079,9 @@ main(int argc, const char **argv)
   apr_hash_t *revprops = apr_hash_make(pool);
   int i;
 
+  /* Check library versions */
+  SVN_ERR(check_lib_versions());
+
   config_options = apr_array_make(pool, 0,
                                   sizeof(svn_cmdline__config_argument_t*));
 
@@ -1109,22 +1097,17 @@ main(int argc, const char **argv)
       if (APR_STATUS_IS_EOF(status))
         break;
       if (status != APR_SUCCESS)
-        handle_error(svn_error_wrap_apr(status, "getopt failure"), pool);
+        return svn_error_wrap_apr(status, "getopt failure");
       switch(opt)
         {
         case 'm':
-          err = svn_utf_cstring_to_utf8(&message, arg, pool);
-          if (err)
-            handle_error(err, pool);
+          SVN_ERR(svn_utf_cstring_to_utf8(&message, arg, pool));
           break;
         case 'F':
           {
             const char *arg_utf8;
-            err = svn_utf_cstring_to_utf8(&arg_utf8, arg, pool);
-            if (! err)
-              err = svn_stringbuf_from_file2(&filedata, arg, pool);
-            if (err)
-              handle_error(err, pool);
+            SVN_ERR(svn_utf_cstring_to_utf8(&arg_utf8, arg, pool));
+            SVN_ERR(svn_stringbuf_from_file2(&filedata, arg, pool));
           }
           break;
         case 'u':
@@ -1134,13 +1117,10 @@ main(int argc, const char **argv)
           password = apr_pstrdup(pool, arg);
           break;
         case 'U':
-          err = svn_utf_cstring_to_utf8(&root_url, arg, pool);
-          if (err)
-            handle_error(err, pool);
+          SVN_ERR(svn_utf_cstring_to_utf8(&root_url, arg, pool));
           if (! svn_path_is_url(root_url))
-            handle_error(svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
-                                           "'%s' is not a URL\n", root_url),
-                         pool);
+            return svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
+                                     "'%s' is not a URL\n", root_url);
           root_url = sanitize_url(root_url, pool);
           break;
         case 'r':
@@ -1153,17 +1133,13 @@ main(int argc, const char **argv)
             if ((! SVN_IS_VALID_REVNUM(base_revision))
                 || (! digits_end)
                 || *digits_end)
-              handle_error(svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR,
-                                             NULL,
-                                             _("Invalid revision number '%s'"),
-                                             saved_arg),
-                           pool);
+              return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                                       _("Invalid revision number '%s'"),
+                                       saved_arg);
           }
           break;
         case with_revprop_opt:
-          err = svn_opt_parse_revprop(&revprops, arg, pool);
-          if (err != SVN_NO_ERROR)
-            handle_error(err, pool);
+          SVN_ERR(svn_opt_parse_revprop(&revprops, arg, pool));
           break;
         case 'X':
           extra_args_file = apr_pstrdup(pool, arg);
@@ -1178,40 +1154,31 @@ main(int argc, const char **argv)
           trust_server_cert = TRUE;
           break;
         case config_dir_opt:
-          err = svn_utf_cstring_to_utf8(&config_dir, arg, pool);
-          if (err)
-            handle_error(err, pool);
+          SVN_ERR(svn_utf_cstring_to_utf8(&config_dir, arg, pool));
           break;
         case config_inline_opt:
-          err = svn_utf_cstring_to_utf8(&opt_arg, arg, pool);
-          if (err)
-            handle_error(err, pool);
-
-          err = svn_cmdline__parse_config_option(config_options, opt_arg,
-                                                 pool);
-          if (err)
-            handle_error(err, pool);
+          SVN_ERR(svn_utf_cstring_to_utf8(&opt_arg, arg, pool));
+          SVN_ERR(svn_cmdline__parse_config_option(config_options, opt_arg,
+                                                   pool));
           break;
         case no_auth_cache_opt:
           no_auth_cache = TRUE;
           break;
         case version_opt:
-          SVN_INT_ERR(display_version(opts, pool));
-          exit(EXIT_SUCCESS);
-          break;
+          SVN_ERR(display_version(opts, pool));
+          return SVN_NO_ERROR;
         case 'h':
         case '?':
-          usage(pool, EXIT_SUCCESS);
-          break;
+          usage(stdout, pool);
+          return SVN_NO_ERROR;
         }
     }
 
   if (non_interactive && force_interactive)
     {
-      err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-                             _("--non-interactive and --force-interactive "
-                               "are mutually exclusive"));
-      return svn_cmdline_handle_exit_error(err, pool, "svnmucc: ");
+      return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                              _("--non-interactive and --force-interactive "
+                                "are mutually exclusive"));
     }
   else
     non_interactive = !svn_cmdline__be_interactive(non_interactive,
@@ -1219,16 +1186,13 @@ main(int argc, const char **argv)
 
   if (trust_server_cert && !non_interactive)
     {
-      err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-                             _("--trust-server-cert requires "
-                               "--non-interactive"));
-      return svn_cmdline_handle_exit_error(err, pool, "svnmucc: ");
+      return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                              _("--trust-server-cert requires "
+                                "--non-interactive"));
     }
 
   /* Make sure we have a log message to use. */
-  err = sanitize_log_sources(revprops, message, filedata);
-  if (err)
-    handle_error(err, pool);
+  SVN_ERR(sanitize_log_sources(revprops, message, filedata));
 
   /* Copy the rest of our command-line arguments to an array,
      UTF-8-ing them along the way. */
@@ -1236,10 +1200,9 @@ main(int argc, const char **argv)
   while (opts->ind < opts->argc)
     {
       const char *arg = opts->argv[opts->ind++];
-      if ((err = svn_utf_cstring_to_utf8(&(APR_ARRAY_PUSH(action_args,
-                                                          const char *)),
-                                         arg, pool)))
-        handle_error(err, pool);
+      SVN_ERR(svn_utf_cstring_to_utf8(&APR_ARRAY_PUSH(action_args,
+                                                      const char *),
+                                      arg, pool));
     }
 
   /* If there are extra arguments in a supplementary file, tack those
@@ -1249,14 +1212,10 @@ main(int argc, const char **argv)
       const char *extra_args_file_utf8;
       svn_stringbuf_t *contents, *contents_utf8;
 
-      err = svn_utf_cstring_to_utf8(&extra_args_file_utf8,
-                                    extra_args_file, pool);
-      if (! err)
-        err = svn_stringbuf_from_file2(&contents, extra_args_file_utf8, pool);
-      if (! err)
-        err = svn_utf_stringbuf_to_utf8(&contents_utf8, contents, pool);
-      if (err)
-        handle_error(err, pool);
+      SVN_ERR(svn_utf_cstring_to_utf8(&extra_args_file_utf8,
+                                      extra_args_file, pool));
+      SVN_ERR(svn_stringbuf_from_file2(&contents, extra_args_file_utf8, pool));
+      SVN_ERR(svn_utf_stringbuf_to_utf8(&contents_utf8, contents, pool));
       svn_cstring_split_append(action_args, contents_utf8->data, "\n\r",
                                FALSE, pool);
     }
@@ -1287,13 +1246,16 @@ main(int argc, const char **argv)
         action->action = ACTION_PROPDEL;
       else if (! strcmp(action_string, "?") || ! strcmp(action_string, "h")
                || ! strcmp(action_string, "help"))
-        usage(pool, EXIT_SUCCESS);
+        {
+          usage(stdout, pool);
+          return SVN_NO_ERROR;
+        }
       else
-        handle_error(svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
-                                       "'%s' is not an action\n",
-                                       action_string), pool);
+        return svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
+                                 "'%s' is not an action\n",
+                                 action_string);
       if (++i == action_args->nelts)
-        insufficient(pool);
+        return insufficient();
 
       /* For copies, there should be a revision number next. */
       if (action->action == ACTION_CP)
@@ -1312,12 +1274,12 @@ main(int argc, const char **argv)
 
               action->rev = strtol(rev_str, &end, 0);
               if (*end)
-                handle_error(svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
-                                               "'%s' is not a revision\n",
-                                               rev_str), pool);
+                return svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
+                                         "'%s' is not a revision\n",
+                                         rev_str);
             }
           if (++i == action_args->nelts)
-            insufficient(pool);
+            return insufficient();
         }
       else
         {
@@ -1331,7 +1293,7 @@ main(int argc, const char **argv)
             svn_dirent_internal_style(APR_ARRAY_IDX(action_args, i,
                                                     const char *), pool);
           if (++i == action_args->nelts)
-            insufficient(pool);
+            return insufficient();
         }
 
       /* For propset, propsetf, and propdel, a property name (and
@@ -1342,7 +1304,7 @@ main(int argc, const char **argv)
         {
           action->prop_name = APR_ARRAY_IDX(action_args, i, const char *);
           if (++i == action_args->nelts)
-            insufficient(pool);
+            return insufficient();
 
           if (action->action == ACTION_PROPDEL)
             {
@@ -1354,7 +1316,7 @@ main(int argc, const char **argv)
                 svn_string_create(APR_ARRAY_IDX(action_args, i,
                                                 const char *), pool);
               if (++i == action_args->nelts)
-                insufficient(pool);
+                return insufficient();
             }
           else
             {
@@ -1363,12 +1325,10 @@ main(int argc, const char **argv)
                                                         const char *), pool);
 
               if (++i == action_args->nelts)
-                insufficient(pool);
+                return insufficient();
 
-              err = read_propvalue_file(&(action->prop_value),
-                                        propval_file, pool);
-              if (err)
-                handle_error(err, pool);
+              SVN_ERR(read_propvalue_file(&(action->prop_value),
+                                          propval_file, pool));
 
               action->action = ACTION_PROPSET;
             }
@@ -1377,14 +1337,10 @@ main(int argc, const char **argv)
               && svn_prop_needs_translation(action->prop_name))
             {
               svn_string_t *translated_value;
-              err = svn_subst_translate_string2(&translated_value, NULL,
-                                                NULL, action->prop_value, NULL,
-                                                FALSE, pool, pool);
-              if (err)
-                handle_error(
-                    svn_error_quick_wrap(err,
-                                         "Error normalizing property value"),
-                    pool);
+              SVN_ERR_W(svn_subst_translate_string2(&translated_value, NULL,
+                                                    NULL, action->prop_value,
+                                                    NULL, FALSE, pool, pool),
+                        "Error normalizing property value");
               action->prop_value = translated_value;
             }
         }
@@ -1412,10 +1368,10 @@ main(int argc, const char **argv)
           if (! svn_path_is_url(url))
             {
               if (! root_url)
-                handle_error(svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
-                                               "'%s' is not a URL, and "
-                                               "--root-url (-U) not provided\n",
-                                               url), pool);
+                return svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
+                                         "'%s' is not a URL, and "
+                                         "--root-url (-U) not provided\n",
+                                         url);
               /* ### These relpaths are already URI-encoded. */
               url = apr_pstrcat(pool, root_url, "/",
                                 svn_relpath_canonicalize(url, pool),
@@ -1437,20 +1393,23 @@ main(int argc, const char **argv)
             {
               anchor = svn_uri_get_longest_ancestor(anchor, url, pool);
               if (!anchor || !anchor[0])
-                handle_error(svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
-                                               "URLs in the action list do not "
-                                               "share a common ancestor"),
-                             pool);
+                return svn_error_createf(SVN_ERR_INCORRECT_PARAMS, NULL,
+                                         "URLs in the action list do not "
+                                         "share a common ancestor");
             }
 
           if ((++i == action_args->nelts) && (j + 1 < num_url_args))
-            insufficient(pool);
+            return insufficient();
         }
       APR_ARRAY_PUSH(actions, struct action *) = action;
     }
 
   if (! actions->nelts)
-    usage(pool, EXIT_FAILURE);
+    {
+      *exit_code = EXIT_FAILURE;
+      usage(stderr, pool);
+      return SVN_NO_ERROR;
+    }
 
   if ((err = execute(actions, anchor, revprops, username, password,
                      config_dir, config_options, non_interactive,
@@ -1461,12 +1420,40 @@ main(int argc, const char **argv)
                                    _("Authentication failed and interactive"
                                      " prompting is disabled; see the"
                                      " --force-interactive option"));
-      handle_error(err, pool);
+      return err;
     }
 
-  /* Ensure that stdout is flushed, so the user will see all results. */
-  svn_error_clear(svn_cmdline_fflush(stdout));
+  return SVN_NO_ERROR;
+}
+
+int
+main(int argc, const char *argv[])
+{
+  apr_pool_t *pool;
+  int exit_code = EXIT_SUCCESS;
+  svn_error_t *err;
+
+  /* Initialize the app. */
+  if (svn_cmdline_init("svnmucc", stderr) != EXIT_SUCCESS)
+    return EXIT_FAILURE;
+
+  /* Create our top-level pool.  Use a separate mutexless allocator,
+   * given this application is single threaded.
+   */
+  pool = apr_allocator_owner_get(svn_pool_create_allocator(FALSE));
+
+  err = sub_main(&exit_code, argc, argv, pool);
+
+  /* Flush stdout and report if it fails. It would be flushed on exit anyway
+     but this makes sure that output is not silently lost if it fails. */
+  err = svn_error_compose_create(err, svn_cmdline_fflush(stdout));
+
+  if (err)
+    {
+      exit_code = EXIT_FAILURE;
+      svn_cmdline_handle_exit_error(err, NULL, "svnmucc: ");
+    }
 
   svn_pool_destroy(pool);
-  return EXIT_SUCCESS;
+  return exit_code;
 }

Modified: subversion/branches/invoke-diff-cmd-feature/subversion/svnrdump/svnrdump.c
URL: http://svn.apache.org/viewvc/subversion/branches/invoke-diff-cmd-feature/subversion/svnrdump/svnrdump.c?rev=1549081&r1=1549080&r2=1549081&view=diff
==============================================================================
--- subversion/branches/invoke-diff-cmd-feature/subversion/svnrdump/svnrdump.c (original)
+++ subversion/branches/invoke-diff-cmd-feature/subversion/svnrdump/svnrdump.c Sun Dec  8 17:56:46 2013
@@ -666,21 +666,6 @@ version(const char *progname,
 }
 
 
-/* Report and clear the error ERR, and return EXIT_FAILURE. */
-#define EXIT_ERROR(err)                                                 \
-  svn_cmdline_handle_exit_error(err, NULL, "svnrdump: ")
-
-/* A redefinition of the public SVN_INT_ERR macro, that suppresses the
- * error message if it is SVN_ERR_IO_PIPE_WRITE_ERROR, and with the
- * program name 'svnrdump' instead of 'svn'. */
-#undef SVN_INT_ERR
-#define SVN_INT_ERR(expr)                                        \
-  do {                                                           \
-    svn_error_t *svn_err__temp = (expr);                         \
-    if (svn_err__temp)                                           \
-      return EXIT_ERROR(svn_err__temp);                          \
-  } while (0)
-
 /* Handle the "dump" subcommand.  Implements `svn_opt_subcommand_t'.  */
 static svn_error_t *
 dump_cmd(apr_getopt_t *os,
@@ -829,8 +814,13 @@ validate_and_resolve_revisions(opt_baton
   return SVN_NO_ERROR;
 }
 
-static int
-sub_main(int argc, const char *argv[], apr_pool_t *pool)
+/*
+ * On success, leave *EXIT_CODE untouched and return SVN_NO_ERROR. On error,
+ * either return an error to be displayed, or set *EXIT_CODE to non-zero and
+ * return SVN_NO_ERROR.
+ */
+static svn_error_t *
+sub_main(int *exit_code, int argc, const char *argv[], apr_pool_t *pool)
 {
   svn_error_t *err = SVN_NO_ERROR;
   const svn_opt_subcommand_desc2_t *subcommand = NULL;
@@ -854,7 +844,7 @@ sub_main(int argc, const char *argv[], a
   opt_baton->end_revision.kind = svn_opt_revision_unspecified;
   opt_baton->url = NULL;
 
-  SVN_INT_ERR(svn_cmdline__getopt_init(&os, argc, argv, pool));
+  SVN_ERR(svn_cmdline__getopt_init(&os, argc, argv, pool));
 
   os->interleave = TRUE; /* Options and arguments can be interleaved */
 
@@ -894,8 +884,9 @@ sub_main(int argc, const char *argv[], a
         break;
       if (status != APR_SUCCESS)
         {
-          SVN_INT_ERR(usage(argv[0], pool));
-          return EXIT_FAILURE;
+          SVN_ERR(usage(argv[0], pool));
+          *exit_code = EXIT_FAILURE;
+          return SVN_NO_ERROR;
         }
 
       /* Stash the option code in an array before parsing it. */
@@ -908,11 +899,10 @@ sub_main(int argc, const char *argv[], a
             /* Make sure we've not seen -r already. */
             if (opt_baton->start_revision.kind != svn_opt_revision_unspecified)
               {
-                err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-                                       _("Multiple revision arguments "
-                                         "encountered; try '-r N:M' instead "
-                                         "of '-r N -r M'"));
-                return EXIT_ERROR(err);
+                return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                                        _("Multiple revision arguments "
+                                          "encountered; try '-r N:M' instead "
+                                          "of '-r N -r M'"));
               }
             /* Parse the -r argument. */
             if (svn_opt_parse_revision(&(opt_baton->start_revision),
@@ -920,12 +910,10 @@ sub_main(int argc, const char *argv[], a
                                        opt_arg, pool) != 0)
               {
                 const char *utf8_opt_arg;
-                err = svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool);
-                if (! err)
-                  err = svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-                                          _("Syntax error in revision "
-                                            "argument '%s'"), utf8_opt_arg);
-                return EXIT_ERROR(err);
+                SVN_ERR(svn_utf_cstring_to_utf8(&utf8_opt_arg, opt_arg, pool));
+                return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                                         _("Syntax error in revision "
+                                           "argument '%s'"), utf8_opt_arg);
               }
           }
           break;
@@ -942,10 +930,10 @@ sub_main(int argc, const char *argv[], a
           opt_baton->help = TRUE;
           break;
         case opt_auth_username:
-          SVN_INT_ERR(svn_utf_cstring_to_utf8(&username, opt_arg, pool));
+          SVN_ERR(svn_utf_cstring_to_utf8(&username, opt_arg, pool));
           break;
         case opt_auth_password:
-          SVN_INT_ERR(svn_utf_cstring_to_utf8(&password, opt_arg, pool));
+          SVN_ERR(svn_utf_cstring_to_utf8(&password, opt_arg, pool));
           break;
         case opt_auth_nocache:
           no_auth_cache = TRUE;
@@ -968,9 +956,9 @@ sub_main(int argc, const char *argv[], a
                     apr_array_make(pool, 1,
                                    sizeof(svn_cmdline__config_argument_t*));
 
-            SVN_INT_ERR(svn_utf_cstring_to_utf8(&opt_arg, opt_arg, pool));
-            SVN_INT_ERR(svn_cmdline__parse_config_option(config_options,
-                                                         opt_arg, pool));
+            SVN_ERR(svn_utf_cstring_to_utf8(&opt_arg, opt_arg, pool));
+            SVN_ERR(svn_cmdline__parse_config_option(config_options,
+                                                     opt_arg, pool));
         }
     }
 
@@ -978,10 +966,9 @@ sub_main(int argc, const char *argv[], a
    * exclusive. */
   if (non_interactive && force_interactive)
     {
-      err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-                             _("--non-interactive and --force-interactive "
-                               "are mutually exclusive"));
-      return EXIT_ERROR(err);
+      return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                              _("--non-interactive and --force-interactive "
+                                "are mutually exclusive"));
     }
 
   if (opt_baton->help)
@@ -1006,8 +993,9 @@ sub_main(int argc, const char *argv[], a
 
           else
             {
-              SVN_INT_ERR(help_cmd(NULL, NULL, pool));
-              return EXIT_FAILURE;
+              SVN_ERR(help_cmd(NULL, NULL, pool));
+              *exit_code = EXIT_FAILURE;
+              return SVN_NO_ERROR;
             }
         }
       else
@@ -1019,15 +1007,15 @@ sub_main(int argc, const char *argv[], a
           if (subcommand == NULL)
             {
               const char *first_arg_utf8;
-              err = svn_utf_cstring_to_utf8(&first_arg_utf8, first_arg, pool);
-              if (err)
-                return EXIT_ERROR(err);
+              SVN_ERR(svn_utf_cstring_to_utf8(&first_arg_utf8, first_arg,
+                                              pool));
               svn_error_clear(
                 svn_cmdline_fprintf(stderr, pool,
                                     _("Unknown subcommand: '%s'\n"),
                                     first_arg_utf8));
-              SVN_INT_ERR(help_cmd(NULL, NULL, pool));
-              return EXIT_FAILURE;
+              SVN_ERR(help_cmd(NULL, NULL, pool));
+              *exit_code = EXIT_FAILURE;
+              return SVN_NO_ERROR;
             }
         }
     }
@@ -1052,56 +1040,55 @@ sub_main(int argc, const char *argv[], a
                                           subcommand, pool);
           svn_opt_format_option(&optstr, badopt, FALSE, pool);
           if (subcommand->name[0] == '-')
-            SVN_INT_ERR(help_cmd(NULL, NULL, pool));
+            SVN_ERR(help_cmd(NULL, NULL, pool));
           else
             svn_error_clear(svn_cmdline_fprintf(
                                 stderr, pool,
                                 _("Subcommand '%s' doesn't accept option '%s'\n"
                                   "Type 'svnrdump help %s' for usage.\n"),
                                 subcommand->name, optstr, subcommand->name));
-          return EXIT_FAILURE;
+          *exit_code = EXIT_FAILURE;
+          return SVN_NO_ERROR;
         }
     }
 
   if (strcmp(subcommand->name, "--version") == 0)
     {
-      SVN_INT_ERR(version(argv[0], opt_baton->quiet, pool));
-      return EXIT_SUCCESS;
+      SVN_ERR(version(argv[0], opt_baton->quiet, pool));
+      return SVN_NO_ERROR;
     }
 
   if (strcmp(subcommand->name, "help") == 0)
     {
-      SVN_INT_ERR(help_cmd(os, opt_baton, pool));
-      return EXIT_SUCCESS;
+      SVN_ERR(help_cmd(os, opt_baton, pool));
+      return SVN_NO_ERROR;
     }
 
   /* --trust-server-cert can only be used with --non-interactive */
   if (trust_server_cert && !non_interactive)
     {
-      err = svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
-                             _("--trust-server-cert requires "
-                               "--non-interactive"));
-      return EXIT_ERROR(err);
+      return svn_error_create(SVN_ERR_CL_ARG_PARSING_ERROR, NULL,
+                              _("--trust-server-cert requires "
+                                "--non-interactive"));
     }
 
   /* Expect one more non-option argument:  the repository URL. */
   if (os->ind != os->argc - 1)
     {
-      SVN_INT_ERR(usage(argv[0], pool));
-      return EXIT_FAILURE;
+      SVN_ERR(usage(argv[0], pool));
+      *exit_code = EXIT_FAILURE;
+      return SVN_NO_ERROR;
     }
   else
     {
       const char *repos_url;
 
-      SVN_INT_ERR(svn_utf_cstring_to_utf8(&repos_url,
-                                          os->argv[os->ind], pool));
+      SVN_ERR(svn_utf_cstring_to_utf8(&repos_url, os->argv[os->ind], pool));
       if (! svn_path_is_url(repos_url))
         {
-          err = svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, 0,
-                                  "Target '%s' is not a URL",
-                                  repos_url);
-          return EXIT_ERROR(err);
+          return svn_error_createf(SVN_ERR_CL_ARG_PARSING_ERROR, 0,
+                                   "Target '%s' is not a URL",
+                                   repos_url);
         }
       opt_baton->url = svn_uri_canonicalize(repos_url, pool);
     }
@@ -1122,16 +1109,16 @@ sub_main(int argc, const char *argv[], a
   non_interactive = !svn_cmdline__be_interactive(non_interactive,
                                                  force_interactive);
 
-  SVN_INT_ERR(init_client_context(&(opt_baton->ctx),
-                                  non_interactive,
-                                  username,
-                                  password,
-                                  config_dir,
-                                  opt_baton->url,
-                                  no_auth_cache,
-                                  trust_server_cert,
-                                  config_options,
-                                  pool));
+  SVN_ERR(init_client_context(&(opt_baton->ctx),
+                              non_interactive,
+                              username,
+                              password,
+                              config_dir,
+                              opt_baton->url,
+                              no_auth_cache,
+                              trust_server_cert,
+                              config_options,
+                              pool));
 
   err = svn_client_open_ra_session2(&(opt_baton->session),
                                     opt_baton->url, NULL,
@@ -1152,23 +1139,23 @@ sub_main(int argc, const char *argv[], a
 
   if (err && err->apr_err == SVN_ERR_AUTHN_FAILED && non_interactive)
     {
-      err = svn_error_quick_wrap(err,
-                                 _("Authentication failed and interactive"
-                                   " prompting is disabled; see the"
-                                   " --force-interactive option"));
-      return EXIT_ERROR(err);
+      return svn_error_quick_wrap(err,
+                                  _("Authentication failed and interactive"
+                                    " prompting is disabled; see the"
+                                    " --force-interactive option"));
     }
   else if (err)
-    return EXIT_ERROR(err);
+    return err;
   else
-    return EXIT_SUCCESS;
+    return SVN_NO_ERROR;
 }
 
 int
 main(int argc, const char *argv[])
 {
   apr_pool_t *pool;
-  int exit_code;
+  int exit_code = EXIT_SUCCESS;
+  svn_error_t *err;
 
   /* Initialize the app. */
   if (svn_cmdline_init("svnrdump", stderr) != EXIT_SUCCESS)
@@ -1179,7 +1166,17 @@ main(int argc, const char *argv[])
    */
   pool = apr_allocator_owner_get(svn_pool_create_allocator(FALSE));
 
-  exit_code = sub_main(argc, argv, pool);
+  err = sub_main(&exit_code, argc, argv, pool);
+
+  /* Flush stdout and report if it fails. It would be flushed on exit anyway
+     but this makes sure that output is not silently lost if it fails. */
+  err = svn_error_compose_create(err, svn_cmdline_fflush(stdout));
+
+  if (err)
+    {
+      exit_code = EXIT_FAILURE;
+      svn_cmdline_handle_exit_error(err, NULL, "svnrdump: ");
+    }
 
   svn_pool_destroy(pool);
   return exit_code;

Modified: subversion/branches/invoke-diff-cmd-feature/subversion/svnserve/logger.c
URL: http://svn.apache.org/viewvc/subversion/branches/invoke-diff-cmd-feature/subversion/svnserve/logger.c?rev=1549081&r1=1549080&r2=1549081&view=diff
==============================================================================
--- subversion/branches/invoke-diff-cmd-feature/subversion/svnserve/logger.c (original)
+++ subversion/branches/invoke-diff-cmd-feature/subversion/svnserve/logger.c Sun Dec  8 17:56:46 2013
@@ -42,8 +42,8 @@
 
 struct logger_t
 {
-  /* actual log file object */
-  apr_file_t *file;
+  /* actual log file / stream object */
+  svn_stream_t *stream;
 
   /* mutex used to serialize access to this structure */
   svn_mutex__t *mutex;
@@ -62,18 +62,39 @@ static apr_status_t cleanup_logger(void 
 }
 
 svn_error_t *
+logger__create_for_stderr(logger_t **logger,
+                          apr_pool_t *pool)
+{
+  logger_t *result = apr_pcalloc(pool, sizeof(*result));
+  result->pool = svn_pool_create(NULL);
+  
+  SVN_ERR(svn_stream_for_stderr(&result->stream, pool));
+  SVN_ERR(svn_mutex__init(&result->mutex, TRUE, pool));
+
+  apr_pool_cleanup_register(pool, result, cleanup_logger,
+                            apr_pool_cleanup_null);
+  
+  *logger = result;
+
+  return SVN_NO_ERROR;
+}
+
+svn_error_t *
 logger__create(logger_t **logger,
                const char *filename,
                apr_pool_t *pool)
 {
   logger_t *result = apr_pcalloc(pool, sizeof(*result));
-
-  SVN_ERR(svn_io_file_open(&result->file, filename,
+  apr_file_t *file;
+  
+  SVN_ERR(svn_io_file_open(&file, filename,
                            APR_WRITE | APR_CREATE | APR_APPEND,
                            APR_OS_DEFAULT, pool));
   SVN_ERR(svn_mutex__init(&result->mutex, TRUE, pool));
-  result->pool = svn_pool_create(NULL);
 
+  result->stream = svn_stream_from_aprfile2(file, FALSE,  pool);
+  result->pool = svn_pool_create(NULL);
+  
   apr_pool_cleanup_register(pool, result, cleanup_logger,
                             apr_pool_cleanup_null);
   
@@ -130,12 +151,12 @@ logger__log_error(logger_t *logger,
           }
           strcpy(errstr + len, APR_EOL_STR);
           len += strlen(APR_EOL_STR);
-          svn_error_clear(svn_io_file_write(logger->file, errstr, &len,
-                                            logger->pool));
+          svn_error_clear(svn_stream_write(logger->stream, errstr, &len));
 
           continuation = "-";
           err = err->child;
         }
+
       svn_pool_clear(logger->pool);
       
       svn_error_clear(svn_mutex__unlock(logger->mutex, SVN_NO_ERROR));
@@ -148,7 +169,6 @@ logger__write(logger_t *logger,
               apr_size_t len)
 {
   SVN_MUTEX__WITH_LOCK(logger->mutex,
-                       svn_io_file_write(logger->file, errstr, &len,
-                                         logger->pool));
+                       svn_stream_write(logger->stream, errstr, &len));
   return SVN_NO_ERROR;
 }

Modified: subversion/branches/invoke-diff-cmd-feature/subversion/svnserve/logger.h
URL: http://svn.apache.org/viewvc/subversion/branches/invoke-diff-cmd-feature/subversion/svnserve/logger.h?rev=1549081&r1=1549080&r2=1549081&view=diff
==============================================================================
--- subversion/branches/invoke-diff-cmd-feature/subversion/svnserve/logger.h (original)
+++ subversion/branches/invoke-diff-cmd-feature/subversion/svnserve/logger.h Sun Dec  8 17:56:46 2013
@@ -37,6 +37,14 @@ extern "C" {
  */
 typedef struct logger_t logger_t;
 
+/* In POOL, create a writer object that will write log messages to stderr
+ * and return it in *LOGGER.  The log file will not add any buffering
+ * on top of stderr.
+ */
+svn_error_t *
+logger__create_for_stderr(logger_t **logger,
+                          apr_pool_t *pool);
+
 /* In POOL, create a writer object for log file FILENAME and return it
  * in *LOGGER.  The log file will be flushed & closed when POOL gets
  * cleared or destroyed.



Mime
View raw message