You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Erik Hülsmann <e....@gmx.net> on 2003/12/16 19:46:46 UTC

[PATCH] Rename svn_io_file_printf

Ok, since we seem to be finalizing our API for 1.0, I propose the following patch. 

There are no functional changes in this patch. It only renames svn_io_file_printf
to svn_io_file_printf_from_utf8.

In the current svn_io_file_* API most functions are only wrappers around 
apr_file_* functions which use a wrapper function to convert the APR error to
a SVN error. The exception is svn_io_file_printf which also converts its input 
from UTF-8 to generate output in the current locale. Functions in the utf8 module 
which behave similarly use a _from_utf8 suffix. This patch applies the same suffix 
to svn_io_file_printf.

Nice side-effect is that it should be really easy to implement the svn_io_file_printf
wrapper around its APR counterpart once this is out of the way. The svn_io_file_printf
enables some code cleanups in (at least) libsvn_client.

Log:
[[[
Rename svn_io_file_printf to svn_io_file_printf_from_utf8
cf. the svn_utf8_* api. This allows for writing a true wrapper
for apr_file_printf: svn_io_file_printf.

* subversion/include/svn_io.h
* subversion/libsvn_diff/diff_file.c
* subversion/libsvn_subr/io.c
* subversion/libsvn_client/diff.c
  Rename svn_io_file_printf
]]]

Index: subversion/include/svn_io.h
===================================================================
--- subversion/include/svn_io.h	(revision 8016)
+++ subversion/include/svn_io.h	(working copy)
@@ -742,7 +742,7 @@
  * native encoding before printing.
  */
 svn_error_t *
-svn_io_file_printf (apr_file_t *fptr, const char *format, ...);
+svn_io_file_printf_from_utf8 (apr_file_t *fptr, const char *format, ...);
 
 
 
Index: subversion/libsvn_subr/io.c
===================================================================
--- subversion/libsvn_subr/io.c	(revision 8016)
+++ subversion/libsvn_subr/io.c	(working copy)
@@ -1994,7 +1994,7 @@
 
 
 svn_error_t *
-svn_io_file_printf (apr_file_t *fptr, const char *format, ...)
+svn_io_file_printf_from_utf8 (apr_file_t *fptr, const char *format, ...)
 {
   va_list ap;
   const char *buf, *buf_apr;
Index: subversion/libsvn_client/diff.c
===================================================================
--- subversion/libsvn_client/diff.c	(revision 8016)
+++ subversion/libsvn_client/diff.c	(working copy)
@@ -66,11 +66,11 @@
 {
   int i;
 
-  SVN_ERR (svn_io_file_printf (file,
-                               APR_EOL_STR "Property changes on: %s"
-                               APR_EOL_STR, path));
+  SVN_ERR (svn_io_file_printf_from_utf8 (file,
+                                         APR_EOL_STR "Property changes on: %s"
+                                         APR_EOL_STR, path));
 
-  /* ### todo [issue #1533]: Use svn_io_file_printf() to convert this
+  /* ### todo [issue #1533]: Use svn_io_file_printf_from_utf8() to convert this
      line of dashes to native encoding, at least conditionally?  Or is
      it better to have under_string always output the same, so
      programs can find it?  Also, what about checking for error? */
@@ -89,8 +89,8 @@
       else
         original_value = NULL;
       
-      SVN_ERR (svn_io_file_printf (file, "Name: %s" APR_EOL_STR,
-                                   propchange->name));
+      SVN_ERR (svn_io_file_printf_from_utf8 (file, "Name: %s" APR_EOL_STR,
+                                             propchange->name));
 
       /* For now, we have a rather simple heuristic: if this is an
          "svn:" property, then assume the value is UTF-8 and must
@@ -103,7 +103,7 @@
           {
             if (val_is_utf8)
               {
-                SVN_ERR (svn_io_file_printf
+                SVN_ERR (svn_io_file_printf_from_utf8
                          (file, "   - %s" APR_EOL_STR, original_value->data));
               }
             else
@@ -118,7 +118,7 @@
           {
             if (val_is_utf8)
               {
-                SVN_ERR (svn_io_file_printf
+                SVN_ERR (svn_io_file_printf_from_utf8
                          (file, "   + %s" APR_EOL_STR,
                           propchange->value->data));
               }
@@ -132,7 +132,7 @@
       }
     }
 
-  /* ### todo [issue #1533]: Use svn_io_file_printf() to convert this
+  /* ### todo [issue #1533]: Use svn_io_file_printf_from_utf8() to convert this
      to native encoding, at least conditionally?  Or is it better to
      have under_string always output the same eol, so programs can
      find it consistently?  Also, what about checking for error? */
@@ -533,7 +533,7 @@
   if (state)
     *state = svn_wc_notify_state_unknown;
 
-  SVN_ERR (svn_io_file_printf
+  SVN_ERR (svn_io_file_printf_from_utf8
            (diff_cmd_baton->outfile,
             "Index: %s (deleted)" APR_EOL_STR "%s" APR_EOL_STR, 
             path, equal_string));

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Rename svn_io_file_printf

Posted by Erik Huelsmann <e....@gmx.net>.
> > On Wed, 2003-12-17 at 12:22, Erik Huelsmann wrote:
> > > There are only 5 occurrances (all within libsvn_client/diff.c) and the
> > > function does not have a massive body. We could do away with it
> > entirely. Or just
> > > make it a static within libsvn_client/diff.c.
> > 
> > I like the last option.  If we start to need it in more places, we can
> > reconsider making it an svn_io function.
> 
> The diff below does just that. Should I attach this as a patch with log to
> the issue?

With its order of declaration fixed, that is...

bye,

Erik.

-- 
+++ GMX - die erste Adresse für Mail, Message, More +++
Neu: Preissenkung für MMS und FreeMMS! http://www.gmx.net



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Rename svn_io_file_printf

Posted by Greg Hudson <gh...@MIT.EDU>.
On Wed, 2003-12-17 at 13:38, Erik Huelsmann wrote:
> > On Wed, 2003-12-17 at 12:22, Erik Huelsmann wrote:
> > > There are only 5 occurrances (all within libsvn_client/diff.c) and the
> > > function does not have a massive body. We could do away with it
> > entirely. Or just
> > > make it a static within libsvn_client/diff.c.
> > 
> > I like the last option.  If we start to need it in more places, we can
> > reconsider making it an svn_io function.
> 
> The diff below does just that. Should I attach this as a patch with log to
> the issue?

+1 from me.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Rename svn_io_file_printf

Posted by Erik Huelsmann <e....@gmx.net>.
> On Wed, 2003-12-17 at 12:22, Erik Huelsmann wrote:
> > There are only 5 occurrances (all within libsvn_client/diff.c) and the
> > function does not have a massive body. We could do away with it
> entirely. Or just
> > make it a static within libsvn_client/diff.c.
> 
> I like the last option.  If we start to need it in more places, we can
> reconsider making it an svn_io function.

The diff below does just that. Should I attach this as a patch with log to
the issue?

bye,

Erik.

Index: subversion/include/svn_io.h
===================================================================
--- subversion/include/svn_io.h	(revision 8027)
+++ subversion/include/svn_io.h	(working copy)
@@ -737,14 +737,6 @@
                  apr_pool_t *pool);
 
 
-/** Wrapper for @c apr_file_printf(), which see.  @a format is a
utf8-encoded
- * string after it is formatted, so this function can convert it to
- * native encoding before printing.
- */
-svn_error_t *
-svn_io_file_printf (apr_file_t *fptr, const char *format, ...);
-
-
 
 /** Version/format files. 
  *
Index: subversion/libsvn_subr/io.c
===================================================================
--- subversion/libsvn_subr/io.c	(revision 8027)
+++ subversion/libsvn_subr/io.c	(working copy)
@@ -1993,25 +1993,6 @@
 }
 
 
-svn_error_t *
-svn_io_file_printf (apr_file_t *fptr, const char *format, ...)
-{
-  va_list ap;
-  const char *buf, *buf_apr;
-
-  va_start (ap, format);
-  buf = apr_pvsprintf (apr_file_pool_get (fptr), format, ap); 
-  va_end(ap);
-
-  SVN_ERR (svn_path_cstring_from_utf8 (&buf_apr, buf,
-                                       apr_file_pool_get (fptr)));
-
-  return do_io_file_wrapper_cleanup
-    (fptr, apr_file_puts (buf_apr, fptr), "write to",
-     apr_file_pool_get (fptr));
-}
-
-
 
 /**
  * Determine if a directory is empty or not.
Index: subversion/libsvn_client/diff.c
===================================================================
--- subversion/libsvn_client/diff.c	(revision 8027)
+++ subversion/libsvn_client/diff.c	(working copy)
@@ -66,11 +66,11 @@
 {
   int i;
 
-  SVN_ERR (svn_io_file_printf (file,
-                               APR_EOL_STR "Property changes on: %s"
-                               APR_EOL_STR, path));
+  SVN_ERR (file_printf_from_utf8 (file,
+                                  APR_EOL_STR "Property changes on: %s"
+                                  APR_EOL_STR, path));
 
-  /* ### todo [issue #1533]: Use svn_io_file_printf() to convert this
+  /* ### todo [issue #1533]: Use file_printf_from_utf8() to convert this
      line of dashes to native encoding, at least conditionally?  Or is
      it better to have under_string always output the same, so
      programs can find it?  Also, what about checking for error? */
@@ -89,8 +89,8 @@
       else
         original_value = NULL;
       
-      SVN_ERR (svn_io_file_printf (file, "Name: %s" APR_EOL_STR,
-                                   propchange->name));
+      SVN_ERR (file_printf_from_utf8 (file, "Name: %s" APR_EOL_STR,
+                                      propchange->name));
 
       /* For now, we have a rather simple heuristic: if this is an
          "svn:" property, then assume the value is UTF-8 and must
@@ -103,7 +103,7 @@
           {
             if (val_is_utf8)
               {
-                SVN_ERR (svn_io_file_printf
+                SVN_ERR (file_printf_from_utf8
                          (file, "   - %s" APR_EOL_STR,
original_value->data));
               }
             else
@@ -118,7 +118,7 @@
           {
             if (val_is_utf8)
               {
-                SVN_ERR (svn_io_file_printf
+                SVN_ERR (file_printf_from_utf8
                          (file, "   + %s" APR_EOL_STR,
                           propchange->value->data));
               }
@@ -132,7 +132,7 @@
       }
     }
 
-  /* ### todo [issue #1533]: Use svn_io_file_printf() to convert this
+  /* ### todo [issue #1533]: Use file_printf_from_utf8() to convert this
      to native encoding, at least conditionally?  Or is it better to
      have under_string always output the same eol, so programs can
      find it consistently?  Also, what about checking for error? */
@@ -193,6 +193,29 @@
 }
 
 
+/* Wrapper for @c apr_file_printf(), which see.  @a format is a
utf8-encoded
+ * string after it is formatted, so this function can convert it to
+ * native encoding before printing.
+ */
+
+static svn_error_t *
+file_printf_from_utf8 (apr_file_t *fptr, const char *format, ...)
+{
+  va_list ap;
+  const char *buf, *buf_apr;
+
+  va_start (ap, format);
+  buf = apr_pvsprintf (apr_file_pool_get (fptr), format, ap); 
+  va_end(ap);
+
+  SVN_ERR (svn_path_cstring_from_utf8 (&buf_apr, buf,
+                                       apr_file_pool_get (fptr)));
+
+  return svn_io_file_write_full (fptr, buf_apr, strlen (buf_apr), 
+                                 NULL, apr_file_pool_get (fptr));
+}
+
+
 /*-----------------------------------------------------------------*/
 
 /*** Callbacks for 'svn diff', invoked by the repos-diff editor. ***/
@@ -533,7 +556,7 @@
   if (state)
     *state = svn_wc_notify_state_unknown;
 
-  SVN_ERR (svn_io_file_printf
+  SVN_ERR (file_printf_from_utf8
            (diff_cmd_baton->outfile,
             "Index: %s (deleted)" APR_EOL_STR "%s" APR_EOL_STR, 
             path, equal_string));

-- 
+++ GMX - die erste Adresse für Mail, Message, More +++
Neu: Preissenkung für MMS und FreeMMS! http://www.gmx.net



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Rename svn_io_file_printf

Posted by Greg Hudson <gh...@MIT.EDU>.
On Wed, 2003-12-17 at 12:22, Erik Huelsmann wrote:
> There are only 5 occurrances (all within libsvn_client/diff.c) and the
> function does not have a massive body. We could do away with it entirely. Or just
> make it a static within libsvn_client/diff.c.

I like the last option.  If we start to need it in more places, we can
reconsider making it an svn_io function.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Rename svn_io_file_printf

Posted by Erik Huelsmann <e....@gmx.net>.
> I'm not all that fond of the name svn_io_file_printf_from_utf8, but
> it'll do.  And I'm definitely +1 on renaming this function away from
> svn_io_file_printf, which is deceptive since it's not a simpler wrapper
> around the APR function.

There are only 5 occurrances (all within libsvn_client/diff.c) and the
function does not have a massive body. We could do away with it entirely. Or just
make it a static within libsvn_client/diff.c.

bye,

Erik.

-- 
+++ GMX - die erste Adresse für Mail, Message, More +++
Neu: Preissenkung für MMS und FreeMMS! http://www.gmx.net



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: [PATCH] Rename svn_io_file_printf

Posted by Greg Hudson <gh...@MIT.EDU>.
I'm not all that fond of the name svn_io_file_printf_from_utf8, but
it'll do.  And I'm definitely +1 on renaming this function away from
svn_io_file_printf, which is deceptive since it's not a simpler wrapper
around the APR function.


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org