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

PATCH: Convert text appropriately for console output and input

From: Julian Foad <julianfoad_at_btopenworld.com>
Date: 2003-12-06 23:55:01 CET

Does this look right?

- Julian

Format and convert text appropriately for console output.

* subversion/clients/cmdline/info-cmd.c (svn_cl__info_print_time, print_entry,
    svn_cl__info)
* subversion/clients/cmdline/log-cmd.c (log_message_receiver)
* subversion/clients/cmdline/prompt.c (maybe_print_realm)
* subversion/clients/cmdline/propdel-cmd.c (svn_cl__propdel)
* subversion/clients/cmdline/propedit-cmd.c (svn_cl__propedit)
* subversion/clients/cmdline/propget-cmd.c (svn_cl__propget)
* subversion/clients/cmdline/proplist-cmd.c (svn_cl__proplist)
* subversion/clients/cmdline/propset-cmd.c (svn_cl__propset)
* subversion/clients/cmdline/status.c (svn_cl__print_status)
  Use "svn_cmdline_cstring_from_utf8" instead of "svn_utf_cstring_from_utf8"
    to get the correct encoding for console output.
  Convert paths to local style for output: use native path separators and "."
    instead of "".

* subversion/clients/cmdline/notify.c
  (notify): Quote paths where they appear within a sentence.

* subversion/include/svn_cmdline.h
* subversion/libsvn_subr/cmdline.c
  (svn_cmdline_path_local_style_from_utf8): New function.
  Fix comments.

Index: subversion/clients/cmdline/info-cmd.c
===================================================================
--- subversion/clients/cmdline/info-cmd.c (revision 7944)
+++ subversion/clients/cmdline/info-cmd.c (working copy)
@@ -43,7 +43,7 @@ svn_cl__info_print_time (apr_time_t atim
   const char *time_stdout;
 
   time_utf8 = svn_time_to_human_cstring (atime, pool);
- SVN_ERR (svn_utf_cstring_from_utf8 (&time_stdout, time_utf8, pool));
+ SVN_ERR (svn_cmdline_cstring_from_utf8 (&time_stdout, time_utf8, pool));
   printf ("%s: %s\n", desc, time_stdout);
   return SVN_NO_ERROR;
 }
@@ -58,7 +58,7 @@ print_entry (const char *target,
   const char *name_stdout;
 
   /* Get a non-UTF8 version of the target. */
- SVN_ERR (svn_cmdline_cstring_from_utf8 (&name_stdout, target, pool));
+ SVN_ERR (svn_cmdline_path_local_style_from_utf8 (&name_stdout, target, pool));
   printf ("Path: %s\n", name_stdout);
 
   /* Note: we have to be paranoid about checking that these are
@@ -189,29 +189,29 @@ print_entry (const char *target,
  
   if (text_conflict && entry->conflict_old)
     {
- SVN_ERR (svn_cmdline_cstring_from_utf8 (&name_stdout,
- entry->conflict_old, pool));
+ SVN_ERR (svn_cmdline_path_local_style_from_utf8
+ (&name_stdout, entry->conflict_old, pool));
       printf ("Conflict Previous Base File: %s\n", name_stdout);
     }
  
   if (text_conflict && entry->conflict_wrk)
     {
- SVN_ERR (svn_cmdline_cstring_from_utf8 (&name_stdout,
- entry->conflict_wrk, pool));
+ SVN_ERR (svn_cmdline_path_local_style_from_utf8
+ (&name_stdout, entry->conflict_wrk, pool));
       printf ("Conflict Previous Working File: %s\n", name_stdout);
     }
  
   if (text_conflict && entry->conflict_new)
     {
- SVN_ERR (svn_cmdline_cstring_from_utf8 (&name_stdout,
- entry->conflict_new, pool));
+ SVN_ERR (svn_cmdline_path_local_style_from_utf8
+ (&name_stdout, entry->conflict_new, pool));
       printf ("Conflict Current Base File: %s\n", name_stdout);
     }
  
   if (props_conflict && entry->prejfile)
     {
- SVN_ERR (svn_cmdline_cstring_from_utf8 (&name_stdout,
- entry->prejfile, pool));
+ SVN_ERR (svn_cmdline_path_local_style_from_utf8
+ (&name_stdout, entry->prejfile, pool));
       printf ("Conflict Properties File: %s\n", name_stdout);
     }
  
@@ -284,8 +284,8 @@ svn_cl__info (apr_getopt_t *os,
 
           const char *target_stdout;
           /* Get a non-UTF8 version of the target. */
- SVN_ERR (svn_cmdline_cstring_from_utf8 (&target_stdout, target,
- subpool));
+ SVN_ERR (svn_cmdline_path_local_style_from_utf8
+ (&target_stdout, target, subpool));
 
           printf ("%s: (Not a versioned resource)\n\n", target_stdout);
           continue;
Index: subversion/clients/cmdline/log-cmd.c
===================================================================
--- subversion/clients/cmdline/log-cmd.c (revision 7944)
+++ subversion/clients/cmdline/log-cmd.c (working copy)
@@ -222,7 +222,7 @@ log_message_receiver (void *baton,
       
       SVN_ERR (svn_time_from_cstring (&time_temp, date, pool));
       date_utf8 = svn_time_to_human_cstring(time_temp, pool);
- SVN_ERR (svn_utf_cstring_from_utf8 (&date_stdout, date_utf8, pool));
+ SVN_ERR (svn_cmdline_cstring_from_utf8 (&date_stdout, date_utf8, pool));
     }
   else
     date_stdout = "(no date)";
@@ -279,16 +279,16 @@ log_message_receiver (void *baton,
           if (log_item->copyfrom_path
               && SVN_IS_VALID_REVNUM (log_item->copyfrom_rev))
             {
- SVN_ERR (svn_cmdline_cstring_from_utf8 (&path_stdout,
- log_item->copyfrom_path,
- pool));
+ SVN_ERR (svn_cmdline_path_local_style_from_utf8
+ (&path_stdout, log_item->copyfrom_path, pool));
               copy_data
                 = apr_psprintf (pool,
                                 " (from %s:%" SVN_REVNUM_T_FMT ")",
                                 path_stdout,
                                 log_item->copyfrom_rev);
             }
- SVN_ERR (svn_cmdline_cstring_from_utf8 (&path_stdout, path, pool));
+ SVN_ERR (svn_cmdline_path_local_style_from_utf8
+ (&path_stdout, path, pool));
           SVN_ERR (svn_stream_printf (lb->out, pool, " %c %s%s" APR_EOL_STR,
                                       log_item->action, path_stdout,
                                       copy_data));
Index: subversion/clients/cmdline/notify.c
===================================================================
--- subversion/clients/cmdline/notify.c (revision 7944)
+++ subversion/clients/cmdline/notify.c (working copy)
@@ -30,7 +30,6 @@
 
 #include "svn_cmdline.h"
 #include "svn_pools.h"
-#include "svn_path.h"
 #include "cl.h"
 
 
@@ -64,9 +63,7 @@ notify (void *baton,
   const char *path_stdout;
   svn_error_t *err;
 
- err = svn_cmdline_cstring_from_utf8 (&path_stdout,
- svn_path_local_style (path, nb->pool),
- nb->pool);
+ err = svn_cmdline_path_local_style_from_utf8 (&path_stdout, path, nb->pool);
   if (err)
     {
       printf ("WARNING: error decoding UTF-8 for ?\n");
@@ -78,9 +75,9 @@ notify (void *baton,
     {
     case svn_wc_notify_skip:
       if (content_state == svn_wc_notify_state_missing)
- printf ("Skipped missing target: %s\n", path_stdout);
+ printf ("Skipped missing target: '%s'\n", path_stdout);
       else
- printf ("Skipped %s\n", path_stdout);
+ printf ("Skipped '%s'\n", path_stdout);
       break;
 
     case svn_wc_notify_update_delete:
@@ -94,19 +91,19 @@ notify (void *baton,
       break;
 
     case svn_wc_notify_restore:
- printf ("Restored %s\n", path_stdout);
+ printf ("Restored '%s'\n", path_stdout);
       break;
 
     case svn_wc_notify_revert:
- printf ("Reverted %s\n", path_stdout);
+ printf ("Reverted '%s'\n", path_stdout);
       break;
 
     case svn_wc_notify_failed_revert:
- printf ("Failed to revert %s -- try updating instead.\n", path_stdout);
+ printf ("Failed to revert '%s' -- try updating instead.\n", path_stdout);
       break;
 
     case svn_wc_notify_resolved:
- printf ("Resolved conflicted state of %s\n", path_stdout);
+ printf ("Resolved conflicted state of '%s'\n", path_stdout);
       break;
 
     case svn_wc_notify_add:
@@ -165,7 +162,7 @@ notify (void *baton,
     case svn_wc_notify_update_external:
       /* Currently this is used for checkouts and switches too. If we
          want different output, we'll have to add new actions. */
- printf ("\nFetching external item into %s\n", path_stdout);
+ printf ("\nFetching external item into '%s'\n", path_stdout);
 
       /* Remember that we're now "inside" an externals definition. */
       nb->in_external = TRUE;
@@ -217,7 +214,7 @@ notify (void *baton,
       break;
 
     case svn_wc_notify_status_external:
- printf ("\nPerforming status on external item at %s\n", path_stdout);
+ printf ("\nPerforming status on external item at '%s'\n", path_stdout);
       break;
 
     case svn_wc_notify_status_completed:
Index: subversion/clients/cmdline/prompt.c
===================================================================
--- subversion/clients/cmdline/prompt.c (revision 7944)
+++ subversion/clients/cmdline/prompt.c (working copy)
@@ -28,11 +28,9 @@
 #include "svn_wc.h"
 #include "svn_client.h"
 #include "svn_string.h"
-#include "svn_path.h"
 #include "svn_delta.h"
 #include "svn_auth.h"
 #include "svn_error.h"
-#include "svn_utf.h"
 #include "cl.h"
 
 
@@ -129,7 +127,7 @@ maybe_print_realm (const char *realm, ap
 
   if (realm)
     {
- SVN_ERR (svn_utf_cstring_from_utf8 (&realm_native, realm, pool));
+ SVN_ERR (svn_cmdline_cstring_from_utf8 (&realm_native, realm, pool));
       fprintf (stderr, "Authentication realm: %s\n", realm_native);
       fflush (stderr);
     }
Index: subversion/clients/cmdline/propdel-cmd.c
===================================================================
--- subversion/clients/cmdline/propdel-cmd.c (revision 7944)
+++ subversion/clients/cmdline/propdel-cmd.c (working copy)
@@ -27,7 +27,6 @@
 #include "svn_pools.h"
 #include "svn_client.h"
 #include "svn_string.h"
-#include "svn_path.h"
 #include "svn_delta.h"
 #include "svn_error.h"
 #include "svn_utf.h"
@@ -125,8 +124,8 @@ svn_cl__propdel (apr_getopt_t *os,
               const char *target_stdout;
               SVN_ERR (svn_cmdline_cstring_from_utf8 (&pname_stdout,
                                                       pname_utf8, subpool));
- SVN_ERR (svn_cmdline_cstring_from_utf8 (&target_stdout,
- target, subpool));
+ SVN_ERR (svn_cmdline_path_local_style_from_utf8
+ (&target_stdout, target, subpool));
               printf ("property '%s' deleted%sfrom '%s'.\n", pname_stdout,
                       opt_state->recursive ? " (recursively) " : " ",
                       target_stdout);
Index: subversion/clients/cmdline/propedit-cmd.c
===================================================================
--- subversion/clients/cmdline/propedit-cmd.c (revision 7944)
+++ subversion/clients/cmdline/propedit-cmd.c (working copy)
@@ -226,10 +225,8 @@ svn_cl__propedit (apr_getopt_t *os,
                                             ctx->config,
                                             subpool));
           
- SVN_ERR (svn_cmdline_cstring_from_utf8 (&target_stdout, target,
- subpool));
- if (target_stdout[0] == '\0')
- target_stdout = ".";
+ SVN_ERR (svn_cmdline_path_local_style_from_utf8 (&target_stdout,
+ target, subpool));
 
           /* ...and re-set the property's value accordingly. */
           if (new_propval)
Index: subversion/clients/cmdline/propget-cmd.c
===================================================================
--- subversion/clients/cmdline/propget-cmd.c (revision 7944)
+++ subversion/clients/cmdline/propget-cmd.c (working copy)
@@ -27,7 +27,6 @@
 #include "svn_wc.h"
 #include "svn_client.h"
 #include "svn_string.h"
-#include "svn_path.h"
 #include "svn_delta.h"
 #include "svn_error.h"
 #include "svn_utf.h"
@@ -162,7 +161,6 @@ svn_cl__propget (apr_getopt_t *os,
               void *val;
               const char *filename;
               svn_string_t *propval;
- const char *filename_stdout;
               
               apr_hash_this (hi, &key, NULL, &val);
               filename = key;
@@ -176,8 +174,9 @@ svn_cl__propget (apr_getopt_t *os,
               
               if (print_filenames)
                 {
- SVN_ERR (svn_cmdline_cstring_from_utf8 (&filename_stdout,
- filename, subpool));
+ const char *filename_stdout;
+ SVN_ERR (svn_cmdline_path_local_style_from_utf8
+ (&filename_stdout, filename, subpool));
                   SVN_ERR (stream_write (out, filename_stdout,
                                          strlen (filename_stdout)));
                   SVN_ERR (stream_write (out, " - ", 3));
Index: subversion/clients/cmdline/proplist-cmd.c
===================================================================
--- subversion/clients/cmdline/proplist-cmd.c (revision 7944)
+++ subversion/clients/cmdline/proplist-cmd.c (working copy)
@@ -27,7 +27,6 @@
 #include "svn_pools.h"
 #include "svn_client.h"
 #include "svn_string.h"
-#include "svn_path.h"
 #include "svn_delta.h"
 #include "svn_error.h"
 #include "cl.h"
@@ -126,7 +125,7 @@ svn_cl__proplist (apr_getopt_t *os,
               svn_client_proplist_item_t *item
                 = ((svn_client_proplist_item_t **)props->elts)[j];
               const char *node_name_stdout;
- SVN_ERR (svn_cmdline_cstring_from_utf8
+ SVN_ERR (svn_cmdline_path_local_style_from_utf8
                        (&node_name_stdout, item->node_name->data, subpool));
               printf("Properties on '%s':\n", node_name_stdout);
               SVN_ERR (svn_cl__print_prop_hash
Index: subversion/clients/cmdline/propset-cmd.c
===================================================================
--- subversion/clients/cmdline/propset-cmd.c (revision 7944)
+++ subversion/clients/cmdline/propset-cmd.c (working copy)
@@ -27,7 +27,6 @@
 #include "svn_pools.h"
 #include "svn_client.h"
 #include "svn_string.h"
-#include "svn_path.h"
 #include "svn_delta.h"
 #include "svn_error.h"
 #include "svn_utf.h"
@@ -189,8 +188,8 @@ svn_cl__propset (apr_getopt_t *os,
               const char *target_stdout;
               SVN_ERR (svn_cmdline_cstring_from_utf8 (&pname_stdout,
                                                       pname_utf8, subpool));
- SVN_ERR (svn_cmdline_cstring_from_utf8 (&target_stdout,
- target, subpool));
+ SVN_ERR (svn_cmdline_path_local_style_from_utf8
+ (&target_stdout, target, subpool));
               printf ("property '%s' set%s on '%s'\n",
                       pname_stdout,
                       opt_state->recursive ? " (recursively)" : "",
Index: subversion/clients/cmdline/status.c
===================================================================
--- subversion/clients/cmdline/status.c (revision 7944)
+++ subversion/clients/cmdline/status.c (working copy)
@@ -25,7 +25,6 @@
 #include <apr_tables.h>
 #include "svn_cmdline.h"
 #include "svn_sorts.h"
-#include "svn_path.h"
 #include "svn_wc.h"
 #include "cl.h"
 
@@ -170,9 +169,7 @@ svn_cl__print_status (const char *path,
           && status->repos_text_status == svn_wc_status_none))
     return;
 
- err = svn_cmdline_cstring_from_utf8 (&path_stdout,
- svn_path_local_style (path, pool),
- pool);
+ err = svn_cmdline_path_local_style_from_utf8 (&path_stdout, path, pool);
   if (err)
     {
       svn_handle_error (err, stderr, FALSE);
Index: subversion/include/svn_cmdline.h
===================================================================
--- subversion/include/svn_cmdline.h (revision 7944)
+++ subversion/include/svn_cmdline.h (working copy)
@@ -37,14 +37,8 @@ extern "C" {
 #endif /* __cplusplus */
 
 
-/* ### todo: This function doesn't really belong in this header, but
- it didn't seem worthwhile to create a new header just for one
- function, especially since this should probably move to APR as
- apr_cmdline_init() or whatever anyway. There's nothing
- svn-specific in its code, other than SVN_WIN32, which obviously APR
- has its own way of dealing with. Thoughts? (Brane?) */
-/* ### Well, it's not one function any more, so it now has its own
- header. Besides, everything here is svn-specific. --brane */
+/* ### todo: This function should perhaps move to APR as
+ apr_cmdline_init() or whatever. */
 
 /** Set up the locale for character conversion, and initialize APR.
  * If @a error_stream is non-null, print error messages to the stream,
@@ -57,25 +51,32 @@ extern "C" {
 int svn_cmdline_init (const char *progname, FILE *error_stream);
 
 
-/** Set @a *dest to a utf8-encoded C string from input-encoded C
- * string @a src; allocate @a *dest in @a pool.
+/** Set @a *dest to an output-encoded C string from UTF-8 C string @a
+ * src; allocate @a *dest in @a pool.
  */
 svn_error_t *svn_cmdline_cstring_from_utf8 (const char **dest,
                                             const char *src,
                                             apr_pool_t *pool);
 
-/** Like svn_utf_cstring_from_utf8_fuzzy, but converts from an
- input-encoded C string. */
+/** Like svn_utf_cstring_from_utf8_fuzzy, but converts to an
+ output-encoded C string. */
 const char *svn_cmdline_cstring_from_utf8_fuzzy (const char *src,
                                                  apr_pool_t *pool);
 
-/** Set @a *dest to an output-encoded C string from utf8 C string @a
- * src; allocate @a *dest in @a pool.
+/** Set @a *dest to a UTF-8-encoded C string from input-encoded C
+ * string @a src; allocate @a *dest in @a pool.
  */
 svn_error_t * svn_cmdline_cstring_to_utf8 (const char **dest,
                                            const char *src,
                                            apr_pool_t *pool);
 
+/** Set @a *dest to an output-encoded natively-formatted path string
+ * from canonical path @a src; allocate @a *dest in @a pool.
+ */
+svn_error_t *svn_cmdline_path_local_style_from_utf8 (const char **dest,
+ const char *src,
+ apr_pool_t *pool);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
Index: subversion/libsvn_subr/cmdline.c
===================================================================
--- subversion/libsvn_subr/cmdline.c (revision 7944)
+++ subversion/libsvn_subr/cmdline.c (working copy)
@@ -25,6 +25,7 @@
 #include <apr_strings.h> /* for apr_snprintf */
 
 #include "svn_cmdline.h"
+#include "svn_path.h"
 #include "utf_impl.h"
 
 
@@ -153,3 +154,14 @@ svn_cmdline_cstring_to_utf8 (const char
     return svn_utf_cstring_to_utf8_ex(dest, src, input_encoding,
                                       SVN_UTF_CONTOU_XLATE_HANDLE, pool);
 }
+
+
+svn_error_t *
+svn_cmdline_path_local_style_from_utf8 (const char **dest,
+ const char *src,
+ apr_pool_t *pool)
+{
+ return svn_cmdline_cstring_from_utf8 (dest,
+ svn_path_local_style (src, pool),
+ pool);
+}

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Sat Dec 6 23:50:21 2003

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

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.