[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

RE: svn commit: r1424037 - in /subversion/trunk/subversion: include/svn_cmdline.h libsvn_subr/cmdline.c svn/cl.h svn/svn.c tests/cmdline/getopt_tests_data/svn_help_log_switch_stdout tests/cmdline/update_tests.py

From: Bert Huijben <bert_at_qqmail.nl>
Date: Wed, 19 Dec 2012 20:18:44 +0100

> -----Original Message-----
> From: stsp_at_apache.org [mailto:stsp_at_apache.org]
> Sent: woensdag 19 december 2012 20:13
> To: commits_at_subversion.apache.org
> Subject: svn commit: r1424037 - in /subversion/trunk/subversion:
> include/svn_cmdline.h libsvn_subr/cmdline.c svn/cl.h svn/svn.c
> tests/cmdline/getopt_tests_data/svn_help_log_switch_stdout
> tests/cmdline/update_tests.py
>
> Author: stsp
> Date: Wed Dec 19 19:12:43 2012
> New Revision: 1424037
>
> URL: http://svn.apache.org/viewvc?rev=1424037&view=rev
> Log:
> Add a new function to the cmdline library to determine whether standard
> input is connected to a terminal device, and set the --non-interactive
> option if standard input is not connected to a terminal device.
>
> The idea is to make 'svn' non-interactive by default if run from scripts
> which are launched in some unattended automated fashion. In such a
> situation
> it is possible for scripts to hang if 'svn' decides to prompt for information
> such as login credentials or conflict resolution options.
>
> Also add a new --force-interactive option which enforces the old behaviour.
>
> * subversion/include/svn_cmdline.h
> (svn_cmdline__stdin_isatty): Declare.
>
> * subversion/libsvn_subr/cmdline.c: Include io.h on Windows.
> (svn_cmdline__stdin_isatty): New.
>
> * subversion/svn/cl.h
> (svn_cl__opt_state_t): Add force_interactive option.
>
> * subversion/svn/svn.c
> (svn_cl__longopt_t): Add opt_force_interactive.
> (sub_main): Set the --non-interactive option based on whether stdin is a
> tty,
> unless interactive mode has been forced with --force-interactive.
> Enforce mutual exclusion of --non-interactive and --force-interactive.
>
> *
> subversion/tests/cmdline/getopt_tests_data/svn_help_log_switch_stdout:
> Adjust.
>
> * subversion/tests/cmdline/update_tests.py
> (eof_in_interactive_conflict_resolver): Pass --force-interactive to ensure
> the interactive conflict resolver will be run as expected.
>
> Modified:
> subversion/trunk/subversion/include/svn_cmdline.h
> subversion/trunk/subversion/libsvn_subr/cmdline.c
> subversion/trunk/subversion/svn/cl.h
> subversion/trunk/subversion/svn/svn.c
>
> subversion/trunk/subversion/tests/cmdline/getopt_tests_data/svn_help_lo
> g_switch_stdout
> subversion/trunk/subversion/tests/cmdline/update_tests.py
>
> Modified: subversion/trunk/subversion/include/svn_cmdline.h
> URL:
> http://svn.apache.org/viewvc/subversion/trunk/subversion/include/svn_c
> mdline.h?rev=1424037&r1=1424036&r2=1424037&view=diff
> ==========================================================
> ====================
> --- subversion/trunk/subversion/include/svn_cmdline.h (original)
> +++ subversion/trunk/subversion/include/svn_cmdline.h Wed Dec 19
> 19:12:43 2012
> @@ -381,6 +381,11 @@ svn_cmdline__getopt_init(apr_getopt_t **
> const char *argv[],
> apr_pool_t *pool);
>
> +/* Determine whether standard input is associated with a terminal.
> + * @since New in 1.8. */
> +svn_boolean_t
> +svn_cmdline__stdin_isatty(void);
> +
> #ifdef __cplusplus
> }
> #endif /* __cplusplus */
>
> Modified: subversion/trunk/subversion/libsvn_subr/cmdline.c
> URL:
> http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_subr/cm
> dline.c?rev=1424037&r1=1424036&r2=1424037&view=diff
> ==========================================================
> ====================
> --- subversion/trunk/subversion/libsvn_subr/cmdline.c (original)
> +++ subversion/trunk/subversion/libsvn_subr/cmdline.c Wed Dec 19
> 19:12:43 2012
> @@ -33,8 +33,10 @@
> #include <unistd.h>
> #else
> #include <crtdbg.h>
> +#include <io.h>
> #endif
>
> +#include <apr.h> /* for STDIN_FILENO */
> #include <apr_errno.h> /* for apr_strerror */
> #include <apr_general.h> /* for apr_initialize/apr_terminate */
> #include <apr_strings.h> /* for apr_snprintf */
> @@ -923,3 +925,13 @@ svn_cmdline__print_xml_prop_hash(svn_str
>
> return SVN_NO_ERROR;
> }
> +
> +svn_boolean_t
> +svn_cmdline__stdin_isatty(void)
> +{
> +#ifdef WIN32
> + return (_isatty(STDIN_FILENO) != 0);
> +#else
> + return (isatty(STDIN_FILENO) != 0);
> +#endif
> +}
>
> Modified: subversion/trunk/subversion/svn/cl.h
> URL:
> http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/cl.h?rev=1
> 424037&r1=1424036&r2=1424037&view=diff
> ==========================================================
> ====================
> --- subversion/trunk/subversion/svn/cl.h (original)
> +++ subversion/trunk/subversion/svn/cl.h Wed Dec 19 19:12:43 2012
> @@ -238,6 +238,7 @@ typedef struct svn_cl__opt_state_t
> svn_boolean_t include_externals; /* Recurses (in)to file & dir externals */
> svn_boolean_t show_inherited_props; /* get inherited properties */
> apr_array_header_t* search_patterns; /* pattern arguments for --search
> */
> + svn_boolean_t force_interactive; /* force interactive prompting */
> } svn_cl__opt_state_t;
>
>
>
> Modified: subversion/trunk/subversion/svn/svn.c
> URL:
> http://svn.apache.org/viewvc/subversion/trunk/subversion/svn/svn.c?rev=
> 1424037&r1=1424036&r2=1424037&view=diff
> ==========================================================
> ====================
> --- subversion/trunk/subversion/svn/svn.c (original)
> +++ subversion/trunk/subversion/svn/svn.c Wed Dec 19 19:12:43 2012
> @@ -101,6 +101,7 @@ typedef enum svn_cl__longopt_t {
> opt_no_ignore,
> opt_no_unlock,
> opt_non_interactive,
> + opt_force_interactive,
> opt_old_cmd,
> opt_record_only,
> opt_relocate,
> @@ -230,6 +231,10 @@ const apr_getopt_option_t svn_cl__option
> "with '--non-interactive')") },
> {"non-interactive", opt_non_interactive, 0,
> N_("do no interactive prompting")},
> + {"force-interactive", opt_force_interactive, 0,
> + N_("do interactive prompting even if standard input\n"
> + " "
> + "is not a terminal device")},
> {"dry-run", opt_dry_run, 0,
> N_("try operation but make no changes")},
> {"ignore-ancestry", opt_ignore_ancestry, 0,
> @@ -401,7 +406,8 @@ const apr_getopt_option_t svn_cl__option
> willy-nilly to every invocation of 'svn') . */
> const int svn_cl__global_options[] =
> { opt_auth_username, opt_auth_password, opt_no_auth_cache,
> opt_non_interactive,
> - opt_trust_server_cert, opt_config_dir, opt_config_options, 0
> + opt_force_interactive, opt_trust_server_cert, opt_config_dir,
> + opt_config_options, 0
> };
>
> /* Options for giving a log message. (Some of these also have other uses.)
> @@ -1982,6 +1988,9 @@ sub_main(int argc, const char *argv[], a
> case opt_non_interactive:
> opt_state.non_interactive = TRUE;
> break;
> + case opt_force_interactive:
> + opt_state.force_interactive = TRUE;
> + break;
> case opt_trust_server_cert:
> opt_state.trust_server_cert = TRUE;
> break;
> @@ -2191,6 +2200,21 @@ sub_main(int argc, const char *argv[], a
> }
> }
>
> + /* The --non-interactive and --force-interactive options are mutually
> + * exclusive. */
> + if (opt_state.non_interactive && opt_state.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);
> + }
> +
> + /* If stdin is not a terminal and --force-interactive was not passed,
> + * set --non-interactive. */
> + if (!opt_state.force_interactive)
> + opt_state.non_interactive = !svn_cmdline__stdin_isatty();
> +

This will disable checking for --non-interactive when stdin is not rerouted, or (if the arguments are parsed later) the check for both force and force not is to high up in this function.

        Bert
Received on 2012-12-19 20:19:28 CET

This is an archived mail posted to the Subversion Dev mailing list.