Author: ivan
Date: Sun Oct 4 17:15:07 2015
New Revision: 1706703
URL: http://svn.apache.org/viewvc?rev=1706703&view=rev
Log:
Refactor code to avoid goto statement and use consistent error handling.
* subversion/libsvn_subr/opt.c
(print_generic_help_body): Extract from svn_opt_subcommand_help3().
(svn_opt_print_generic_help2): Use print_generic_help_body() and handle
errors if any.
Modified:
subversion/trunk/subversion/libsvn_subr/opt.c
Modified: subversion/trunk/subversion/libsvn_subr/opt.c
URL:
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/opt.c?rev=1706703&r1=1706702&r2=1706703&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_subr/opt.c (original)
+++ subversion/trunk/subversion/libsvn_subr/opt.c Sun Oct 4 17:15:07 2015
@@ -350,41 +350,50 @@ print_command_info2(const svn_opt_subcom
return SVN_NO_ERROR;
}
-void
-svn_opt_print_generic_help2(const char *header,
- const svn_opt_subcommand_desc2_t *cmd_table,
- const apr_getopt_option_t *opt_table,
- const char *footer,
- apr_pool_t *pool, FILE *stream)
+/* The body for svn_opt_print_generic_help2() function with standard error
+ * handling semantic. Handling of errors implemented at caller side. */
+static svn_error_t *
+print_generic_help_body(const char *header,
+ const svn_opt_subcommand_desc2_t *cmd_table,
+ const apr_getopt_option_t *opt_table,
+ const char *footer,
+ apr_pool_t *pool, FILE *stream)
{
int i = 0;
- svn_error_t *err;
if (header)
- if ((err = svn_cmdline_fputs(header, stream, pool)))
- goto print_error;
+ SVN_ERR(svn_cmdline_fputs(header, stream, pool));
while (cmd_table[i].name)
{
- if ((err = svn_cmdline_fputs(" ", stream, pool))
- || (err = print_command_info2(cmd_table + i, opt_table,
- NULL, FALSE,
- pool, stream))
- || (err = svn_cmdline_fputs("\n", stream, pool)))
- goto print_error;
+ SVN_ERR(svn_cmdline_fputs(" ", stream, pool));
+ SVN_ERR(print_command_info2(cmd_table + i, opt_table,
+ NULL, FALSE,
+ pool, stream));
+ SVN_ERR(svn_cmdline_fputs("\n", stream, pool));
i++;
}
- if ((err = svn_cmdline_fputs("\n", stream, pool)))
- goto print_error;
+ SVN_ERR(svn_cmdline_fputs("\n", stream, pool));
if (footer)
- if ((err = svn_cmdline_fputs(footer, stream, pool)))
- goto print_error;
+ SVN_ERR(svn_cmdline_fputs(footer, stream, pool));
+
+ return SVN_NO_ERROR;
+}
+
+void
+svn_opt_print_generic_help2(const char *header,
+ const svn_opt_subcommand_desc2_t *cmd_table,
+ const apr_getopt_option_t *opt_table,
+ const char *footer,
+ apr_pool_t *pool, FILE *stream)
+{
+ svn_error_t *err;
- return;
+ err = print_generic_help_body(header, cmd_table, opt_table, footer, pool,
+ stream);
- print_error:
/* Issue #3014:
* Don't print anything on broken pipes. The pipe was likely
* closed by the process at the other end. We expect that
@@ -392,7 +401,7 @@ svn_opt_print_generic_help2(const char *
*
* ### This assumes that there is only one error in a chain for
* ### SVN_ERR_IO_PIPE_WRITE_ERROR. See svn_cmdline_fputs(). */
- if (err->apr_err != SVN_ERR_IO_PIPE_WRITE_ERROR)
+ if (err && err->apr_err != SVN_ERR_IO_PIPE_WRITE_ERROR)
svn_handle_error2(err, stderr, FALSE, "svn: ");
svn_error_clear(err);
}