On Mon, Dec 17, 2012 at 09:39:49PM +0100, Stefan Sperling wrote: > The simple patch below implements it with the isatty() on *nix and > _isatty() on Windows (untested -- thanks for the hint Bert!).
Updated version that adds --force-interactive for users who require the previous behaviour for whatever purposes. [[[ Add a new function to the cmdline library to determine whether standard input is connected to a terminal device. Set the --non-interactive flag by default if standard input is not a terminal device. Add a new --force-interactive option to force previous 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. ]]] Index: subversion/include/svn_cmdline.h =================================================================== --- subversion/include/svn_cmdline.h (revision 1423113) +++ subversion/include/svn_cmdline.h (working copy) @@ -381,6 +381,11 @@ svn_cmdline__getopt_init(apr_getopt_t **os, 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 */ Index: subversion/libsvn_subr/cmdline.c =================================================================== --- subversion/libsvn_subr/cmdline.c (revision 1423113) +++ subversion/libsvn_subr/cmdline.c (working copy) @@ -33,6 +33,7 @@ #include <unistd.h> #else #include <crtdbg.h> +#include <io.h> #endif #include <apr_errno.h> /* for apr_strerror */ @@ -923,3 +924,13 @@ svn_cmdline__print_xml_prop_hash(svn_stringbuf_t * return SVN_NO_ERROR; } + +svn_boolean_t +svn_cmdline__stdin_isatty(void) +{ +#ifdef WIN32 + return (_isatty(0) != 0); +#else + return (isatty(STDIN_FILENO) != 0); +#endif +} Index: subversion/svn/cl.h =================================================================== --- subversion/svn/cl.h (revision 1423113) +++ subversion/svn/cl.h (working copy) @@ -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; Index: subversion/svn/svn.c =================================================================== --- subversion/svn/svn.c (revision 1423113) +++ subversion/svn/svn.c (working copy) @@ -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__options[] = "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__options[] = 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[], apr_pool_t 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[], apr_pool_t } } + /* 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(); + /* Turn our hash of changelists into an array of unique ones. */ SVN_INT_ERR(svn_hash_keys(&(opt_state.changelists), changelists, pool));