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

Patches for better behavior, when adding binary files?

From: Rudolf Cejka <cejkar_at_fit.vutbr.cz>
Date: 2007-01-23 17:40:12 CET

Hello,
  I like to setup Subversion, so that all text files have svn:eol-style
and svn:keywords set, but binary files does not have any of them. Currently,
Subversion 1.4.2 (known to me since 1.2.0) does not include svn:eol-style
for binary files, but why it does include svn:keywords? I think that
svn:keywords is very similar to svn:eol-style in that it modifies
checkouted files, which is bad for binary files.

Current Subversion 1.4.2 behavior with added enable-auto-props = yes
and * = svn:eol-style=native;svn:keywords="Date Revision Author HeadURL Id"
in ~/.subversion/config:

$ svn add file.gif file.txt
svn: File 'file.gif' has binary mime type property

  # This is bad, because file.gif has been added without any indication.
  # It should either does not add file.gif as it did not add file.txt, or
  # it should furthermore write "A file.gif".

$ svn proplist file.gif file.txt
Properties on 'file.gif':
  svn:mime-type
  svn:keywords
svn: 'file.txt' is not under version control

  # There is svn:mime-type instead of svn:eol-style, but why is there
  # svn:keywords?

I have created two small patches (at the end of this mail), which I think
solve mentioned problems:

$ svn add file.gif file.txt
A (bin) file.gif
A file.txt

  # Both files are normally added, svn add is quiet for svn:keywords like
  # in svn:eol-style case.

$ svn proplist file.gif file.txt
Properties on 'file.gif':
  svn:mime-type
Properties on 'file.txt':
  svn:keywords
  svn:eol-style

  # Ideal situation: Binary file has svn:mime-type, text file has
  # svn:keywords and svn:eol-style.

Should I fill a bug report?

PS: I'm not in the users@ list, so please do cc: to me too, thanks.

--- subversion/libsvn_client/add.c.orig Tue Jan 23 09:35:03 2007
+++ subversion/libsvn_client/add.c Tue Jan 23 09:36:02 2007
@@ -213,6 +213,7 @@
   const char *mimetype;
   svn_node_kind_t kind;
   svn_boolean_t is_special;
+ svn_error_t *err;
 
   /* add the file */
   SVN_ERR(svn_wc_add2(path, adm_access, NULL, SVN_INVALID_REVNUM,
@@ -246,11 +247,13 @@
               void *pval;
           
               apr_hash_this(hi, &pname, NULL, &pval);
- /* It's probably best to pass 0 for force, so that if
- the autoprops say to set some weird combination,
- we just error and let the user sort it out. */
- SVN_ERR(svn_wc_prop_set2(pname, pval, path,
- adm_access, FALSE, pool));
+ err = svn_wc_prop_set2 (pname, pval, path,
+ adm_access, FALSE, pool);
+ if (err && (err->apr_err == SVN_ERR_ILLEGAL_TARGET
+ || err->apr_err == SVN_ERR_BAD_MIME_TYPE))
+ svn_error_clear (err);
+ else if (err)
+ return err;
             }
         }
     }
--- subversion/libsvn_wc/props.c.orig Tue Jan 23 09:36:13 2007
+++ subversion/libsvn_wc/props.c Tue Jan 23 09:37:03 2007
@@ -1474,6 +1474,27 @@
 }
 
 
+static svn_error_t *
+validate_key_prop_against_file (const char *path,
+ svn_wc_adm_access_t *adm_access,
+ apr_pool_t *pool)
+{
+ svn_error_t *err;
+ const svn_string_t *mime_type;
+
+ /* See if this file has been determined to be binary. */
+ SVN_ERR (svn_wc_prop_get (&mime_type, SVN_PROP_MIME_TYPE, path, adm_access,
+ pool));
+ if (mime_type && svn_mime_type_is_binary (mime_type->data))
+ return svn_error_createf
+ (SVN_ERR_ILLEGAL_TARGET, NULL,
+ _("File '%s' has binary mime type property"),
+ svn_path_local_style (path, pool));
+
+ return SVN_NO_ERROR;
+}
+
+
 svn_error_t *
 svn_wc_prop_set2(const char *name,
                  const svn_string_t *value,
@@ -1565,6 +1586,9 @@
         {
           new_value = svn_stringbuf_create_from_string(value, pool);
           svn_stringbuf_strip_whitespace(new_value);
+ if (!skip_checks) {
+ SVN_ERR (validate_key_prop_against_file (path, adm_access, pool));
+ }
         }
     }
 

-- 
Rudolf Cejka <cejkar at fit.vutbr.cz> http://www.fit.vutbr.cz/~cejkar
Brno University of Technology, Faculty of Information Technology
Bozetechova 2, 612 66  Brno, Czech Republic
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Tue Jan 23 17:42:01 2007

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

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