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

[PATCH] Create (de)translation function to accomodate all wc translation types.

From: Erik Huelsmann <ehuels_at_gmail.com>
Date: 2005-11-10 00:59:49 CET

Dan,

I factored out the code in the patch below and adjusted callers. I
didn't do docstrings yet, but I send it to you so you can have a look
at it before I commit it.

I hope the change is mostly clear. The new function can be used in
lots of places in libsvn_wc, probably everywhere where we currently
directly call svn_subst_copy_and_translate3().

Anyway, if you have questions, I'll be glad to answer them.

bye,

Erik.

PS: Sorry for the missing log message; I'm off to bed now.

Index: subversion/include/svn_wc.h
===================================================================
--- subversion/include/svn_wc.h (revision 17276)
+++ subversion/include/svn_wc.h (working copy)
@@ -3142,12 +3142,16 @@
  *
  * @since New in 1.4
  */
-svn_error_t *svn_wc_translated_file2 (const char **xlated_p,
- const char *vfile,
- svn_wc_adm_access_t *adm_access,
- svn_boolean_t force_repair,
- svn_boolean_t del_temp_on_pool_cleanup,
- apr_pool_t *pool);
+svn_error_t *
+svn_wc_translated_file2 (const char **xlated_p,
+ const char *src,
+ const char *path,
+ svn_wc_adm_access_t *adm_access,
+ svn_boolean_t translate,
+ svn_boolean_t force_repair,
+ svn_boolean_t force_copy,
+ svn_boolean_t del_temp_on_pool_cleanup,
+ apr_pool_t *pool);

 /** Same as svn_wc_translated_file2, but will never clean up
Index: subversion/libsvn_wc/merge.c
===================================================================
--- subversion/libsvn_wc/merge.c (revision 17276)
+++ subversion/libsvn_wc/merge.c (working copy)
@@ -71,20 +71,9 @@
       /* Make sure a temporary copy of 'target' is available with keywords
          contracted and line endings in repository-normal (LF) form.
          This is the file that diff3 will read as the 'mine' file. */
- SVN_ERR (svn_wc_translated_file2 (&tmp_target, merge_target, adm_access,
- TRUE, TRUE, pool));
- if (tmp_target == merge_target) /* contraction didn't happen */
- {
- /* The target is already in repository form, so we just need to
- make a verbatim copy of it. */
- SVN_ERR (svn_io_open_unique_file2 (NULL, &tmp_target,
- merge_target,
- SVN_WC__TMP_EXT,
- svn_io_file_del_on_pool_cleanup,
- pool));
- SVN_ERR (svn_io_copy_file (merge_target,
- tmp_target, TRUE, pool));
- }
+ SVN_ERR (svn_wc_translated_file2 (&tmp_target, merge_target,
+ merge_target, adm_access,
+ FALSE, TRUE, TRUE, TRUE, pool));

       /* Open a second temporary file for writing; this is where diff3
          will write the merged results. */
Index: subversion/libsvn_wc/diff.c
===================================================================
--- subversion/libsvn_wc/diff.c (revision 17276)
+++ subversion/libsvn_wc/diff.c (working copy)
@@ -570,8 +570,8 @@
       SVN_ERR (get_local_mimetypes (NULL, &working_mimetype, NULL,
                                     adm_access, path, pool));

- SVN_ERR (svn_wc_translated_file2 (&translated, path, adm_access,
- TRUE, TRUE, pool));
+ SVN_ERR (svn_wc_translated_file2 (&translated, path, path, adm_access,
+ FALSE, TRUE, FALSE, TRUE, pool));

       SVN_ERR (dir_baton->edit_baton->callbacks->file_added
                (NULL, NULL, NULL, path,
@@ -595,8 +595,9 @@
              tmp translated copy too. But what the heck, diff is
              already expensive, translating twice for the sake of code
              modularity is liveable. */
- SVN_ERR (svn_wc_translated_file2 (&translated, path, adm_access,
- TRUE, TRUE, pool));
+ SVN_ERR (svn_wc_translated_file2 (&translated, path,
+ path, adm_access,
+ FALSE, TRUE, FALSE, TRUE, pool));
         }

       if (modified || propchanges->nelts > 0)
@@ -1218,8 +1219,10 @@
             localfile = empty_file;
           else
             /* a detranslated version of the working file */
- SVN_ERR (svn_wc_translated_file2 (&localfile, b->path, adm_access,
- TRUE, TRUE, b->pool));
+ SVN_ERR (svn_wc_translated_file2 (&localfile, b->path,
+ b->path, adm_access,
+ FALSE, TRUE, FALSE, TRUE,
+ b->pool));

           temp_file_path = b->temp_file_path;
         }
Index: subversion/libsvn_wc/questions.c
===================================================================
--- subversion/libsvn_wc/questions.c (revision 17276)
+++ subversion/libsvn_wc/questions.c (working copy)
@@ -231,8 +231,9 @@
   svn_boolean_t same;
   const char *tmp_vfile;

- SVN_ERR (svn_wc_translated_file2 (&tmp_vfile, versioned_file, adm_access,
- TRUE, TRUE, pool));
+ SVN_ERR (svn_wc_translated_file2 (&tmp_vfile, versioned_file,
+ versioned_file, adm_access,
+ FALSE, TRUE, FALSE, TRUE, pool));

   SVN_ERR (svn_io_files_contents_same_p (&same, tmp_vfile, base_file, pool));
   *modified_p = (! same);
@@ -263,8 +264,9 @@
   SVN_ERR (svn_wc_entry (&entry, versioned_file, adm_access, TRUE, pool));

- SVN_ERR (svn_wc_translated_file2 (&tmp_vfile, versioned_file, adm_access,
- TRUE, TRUE, pool));
+ SVN_ERR (svn_wc_translated_file2 (&tmp_vfile, versioned_file,
+ versioned_file, adm_access,
+ FALSE, TRUE, FALSE, TRUE, pool));

   /* Compare the files, while maybe calculating the base file's checksum. */
   {
Index: subversion/libsvn_wc/translate.c
===================================================================
--- subversion/libsvn_wc/translate.c (revision 17276)
+++ subversion/libsvn_wc/translate.c (working copy)
@@ -41,11 +41,38 @@

 #include "svn_private_config.h"

+
+static svn_error_t *
+eol_normal_form (svn_boolean_t *force_repair,
+ const char **eol,
+ svn_subst_eol_style_t style,
+ const char *path,
+ apr_pool_t *pool)
+{
+ if (style == svn_subst_eol_style_fixed)
+ *force_repair = TRUE;
+ else if (style == svn_subst_eol_style_native)
+ *eol = SVN_WC__DEFAULT_EOL_MARKER;
+ else if (style == svn_subst_eol_style_none)
+ *eol = NULL;
+ else
+ return svn_error_createf
+ (SVN_ERR_IO_UNKNOWN_EOL, NULL,
+ _("'%s' has unknown value for svn:eol-style property"),
+ svn_path_local_style (path, pool));
+
+ return SVN_NO_ERROR;
+}
+
+
 svn_error_t *
 svn_wc_translated_file2 (const char **xlated_p,
- const char *vfile,
+ const char *src,
+ const char *path,
                          svn_wc_adm_access_t *adm_access,
+ svn_boolean_t translate,
                          svn_boolean_t force_repair,
+ svn_boolean_t force_copy,
                          svn_boolean_t del_temp_on_pool_cleanup,
                          apr_pool_t *pool)
 {
@@ -53,26 +80,40 @@
   const char *eol;
   apr_hash_t *keywords;
   svn_boolean_t special;
-
- SVN_ERR (svn_wc__get_eol_style (&style, &eol, vfile, adm_access, pool));
- SVN_ERR (svn_wc__get_keywords (&keywords, vfile, adm_access, NULL, pool));
- SVN_ERR (svn_wc__get_special (&special, vfile, adm_access, pool));
+ const char *tmp_dir, *tmp_vfile;

+ svn_path_split (path, &tmp_dir, &tmp_vfile, pool);
+
+ tmp_vfile = svn_wc__adm_path (tmp_dir, 1, pool,
+ tmp_vfile, NULL);
+
+ SVN_ERR (svn_wc__get_eol_style (&style, &eol, path, adm_access, pool));
+ SVN_ERR (svn_wc__get_keywords (&keywords, path, adm_access, NULL, pool));
+ SVN_ERR (svn_wc__get_special (&special, path, adm_access, pool));
+
   if ((style == svn_subst_eol_style_none) && (! keywords) && (! special))
     {
- /* Translation would be a no-op, so return the original file. */
- *xlated_p = vfile;
+
+ if (force_copy)
+ {
+ SVN_ERR (svn_io_open_unique_file2 (NULL,
+ &tmp_vfile,
+ tmp_vfile,
+ SVN_WC__TMP_EXT,
+ del_temp_on_pool_cleanup
+ ? svn_io_file_del_on_pool_cleanup
+ : svn_io_file_del_none,
+ pool));
+ SVN_ERR (svn_io_copy_file (src, tmp_vfile, FALSE, pool));
+ *xlated_p = tmp_vfile;
+ }
+ else
+ /* Translation would be a no-op, so return the original file. */
+ *xlated_p = src;
+
     }
   else /* some translation is necessary */
     {
- const char *tmp_dir, *tmp_vfile;
-
- /* First, reserve a tmp file name. */
- svn_path_split (vfile, &tmp_dir, &tmp_vfile, pool);
-
- tmp_vfile = svn_wc__adm_path (tmp_dir, 1, pool,
- tmp_vfile, NULL);
-
       SVN_ERR (svn_io_open_unique_file2 (NULL,
                                          &tmp_vfile,
                                          tmp_vfile,
@@ -82,46 +123,23 @@
                                          : svn_io_file_del_none,
                                          pool));

- if (style == svn_subst_eol_style_fixed)
+ if (translate)
+ SVN_ERR (svn_subst_copy_and_translate3 (src,
+ tmp_vfile,
+ eol, TRUE,
+ keywords, TRUE,
+ special,
+ pool));
+ else /* detranslate */
         {
- SVN_ERR (svn_subst_copy_and_translate3 (vfile,
+ SVN_ERR (eol_normal_form (&force_repair, &eol, style, path, pool));
+ SVN_ERR (svn_subst_copy_and_translate3 (src,
                                                   tmp_vfile,
- eol,
- TRUE,
- keywords,
- FALSE,
+ eol, force_repair,
+ keywords, FALSE,
                                                   special,
                                                   pool));
         }
- else if (style == svn_subst_eol_style_native)
- {
- SVN_ERR (svn_subst_copy_and_translate3 (vfile,
- tmp_vfile,
- SVN_WC__DEFAULT_EOL_MARKER,
- force_repair,
- keywords,
- FALSE,
- special,
- pool));
- }
- else if (style == svn_subst_eol_style_none)
- {
- SVN_ERR (svn_subst_copy_and_translate3 (vfile,
- tmp_vfile,
- NULL,
- force_repair,
- keywords,
- FALSE,
- special,
- pool));
- }
- else
- {
- return svn_error_createf
- (SVN_ERR_IO_UNKNOWN_EOL, NULL,
- _("'%s' has unknown value for svn:eol-style property"),
- svn_path_local_style (vfile, pool));
- }

       *xlated_p = tmp_vfile;
     }
@@ -137,8 +155,8 @@
                         svn_boolean_t force_repair,
                         apr_pool_t *pool)
 {
- return svn_wc_translated_file2 (xlated_p, vfile, adm_access,
- force_repair, FALSE, pool);
+ return svn_wc_translated_file2 (xlated_p, vfile, vfile, adm_access, FALSE,
+ force_repair, FALSE, FALSE, pool);
 }
Received on Thu Nov 10 01:00:39 2005

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