You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by st...@apache.org on 2012/12/20 00:15:26 UTC

svn commit: r1424217 - /subversion/trunk/subversion/svnsync/svnsync.c

Author: stsp
Date: Wed Dec 19 23:15:26 2012
New Revision: 1424217

URL: http://svn.apache.org/viewvc?rev=1424217&view=rev
Log:
Implement new --non-interactive default behaviour for 'svnsync'.

Be interactive only if standard input is connetected to a terminal device.

* subversion/svnsync/svnsync.c
  (svn_svnsync__opt, SVNSYNC_OPTS_DEFAULT): Add svnsync_opt_force_interactive.
  (svnsync__options): Document new --non-interactive default and add the
   --force-interactive option.
  (main): Enforce mutual exclusion of --non-interactive and --force-interacive.
   Set non_interactive based on force_interactive and on whether standard
   input is a tty.

Modified:
    subversion/trunk/subversion/svnsync/svnsync.c

Modified: subversion/trunk/subversion/svnsync/svnsync.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/svnsync/svnsync.c?rev=1424217&r1=1424216&r2=1424217&view=diff
==============================================================================
--- subversion/trunk/subversion/svnsync/svnsync.c (original)
+++ subversion/trunk/subversion/svnsync/svnsync.c Wed Dec 19 23:15:26 2012
@@ -53,6 +53,7 @@ static svn_opt_subcommand_t initialize_c
 
 enum svnsync__opt {
   svnsync_opt_non_interactive = SVN_OPT_FIRST_LONGOPT_ID,
+  svnsync_opt_force_interactive,
   svnsync_opt_no_auth_cache,
   svnsync_opt_auth_username,
   svnsync_opt_auth_password,
@@ -71,6 +72,7 @@ enum svnsync__opt {
 };
 
 #define SVNSYNC_OPTS_DEFAULT svnsync_opt_non_interactive, \
+                             svnsync_opt_force_interactive, \
                              svnsync_opt_no_auth_cache, \
                              svnsync_opt_auth_username, \
                              svnsync_opt_auth_password, \
@@ -173,7 +175,13 @@ static const apr_getopt_option_t svnsync
     {"allow-non-empty", svnsync_opt_allow_non_empty, 0,
                        N_("allow a non-empty destination repository") },
     {"non-interactive", svnsync_opt_non_interactive, 0,
-                       N_("do no interactive prompting") },
+                       N_("do no interactive prompting (default is to prompt\n"
+                          "                             "
+                          "only if standard input is a terminal device)")},
+    {"force-interactive", svnsync_opt_force_interactive, 0,
+                      N_("do interactive prompting even if standard input\n"
+                         "                             "
+                         "is not a terminal device")},
     {"no-auth-cache",  svnsync_opt_no_auth_cache, 0,
                        N_("do not cache authentication tokens") },
     {"username",       svnsync_opt_auth_username, 1,
@@ -1888,6 +1896,7 @@ main(int argc, const char *argv[])
   const char *password = NULL, *source_password = NULL, *sync_password = NULL;
   apr_array_header_t *config_options = NULL;
   const char *source_prop_encoding = NULL;
+  svn_boolean_t force_interactive;
 
   if (svn_cmdline_init("svnsync", stderr) != EXIT_SUCCESS)
     {
@@ -1950,6 +1959,10 @@ main(int argc, const char *argv[])
             opt_baton.non_interactive = TRUE;
             break;
 
+          case svnsync_opt_force_interactive:
+            force_interactive = TRUE;
+            break;
+
           case svnsync_opt_trust_server_cert:
             opt_baton.trust_server_cert = TRUE;
             break;
@@ -2079,6 +2092,22 @@ main(int argc, const char *argv[])
   if (opt_baton.help)
     subcommand = svn_opt_get_canonical_subcommand2(svnsync_cmd_table, "help");
 
+  /* The --non-interactive and --force-interactive options are mutually
+   * exclusive. */
+  if (opt_baton.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, "svnsync: ");
+    }
+  /* If neither --non-interactive nor --force-interactive was passed,
+   * and stdin is not a terminal, set --non-interactive. */
+  else if (!force_interactive && !opt_baton.non_interactive)
+    opt_baton.non_interactive = !svn_cmdline__stdin_isatty();
+  else if (force_interactive) 
+    opt_baton.non_interactive = FALSE;
+
   /* Disallow the mixing --username/password with their --source- and
      --sync- variants.  Treat "--username FOO" as "--source-username
      FOO --sync-username FOO"; ditto for "--password FOO". */