Author: julianfoad
Date: Mon Apr 16 16:35:09 2018
New Revision: 1829295

URL: http://svn.apache.org/viewvc?rev=1829295&view=rev
Log:
Shelving: start supporting binary files.

Use git diff binary literal format. This works for a stop-gap, but is
inefficient for large files.

* subversion/libsvn_client/shelf.c
  (is_binary_file): New.
  (walk_callback): Use git binary diff for binary files.

* subversion/tests/cmdline/shelf_tests.py
  (shelve_binary_file_mod,
   shelve_binary_file_add,
   shelve_binary_file_del): Remove 'XFail'.

Modified:
    subversion/trunk/subversion/libsvn_client/shelf.c
    subversion/trunk/subversion/tests/cmdline/shelf_tests.py

Modified: subversion/trunk/subversion/libsvn_client/shelf.c
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_client/shelf.c?rev=1829295&r1=1829294&r2=1829295&view=diff
==============================================================================
--- subversion/trunk/subversion/libsvn_client/shelf.c (original)
+++ subversion/trunk/subversion/libsvn_client/shelf.c Mon Apr 16 16:35:09 2018
@@ -356,6 +356,34 @@ note_shelved(apr_array_header_t *shelved
   return SVN_NO_ERROR;
 }
 
+/* Set *IS_BINARY to true iff the pristine or working version of
+ * LOCAL_ABSPATH has a MIME-type that we regard as 'binary'.
+ */
+static svn_error_t *
+is_binary_file(svn_boolean_t *is_binary,
+               const char *local_abspath,
+               svn_client_ctx_t *ctx,
+               apr_pool_t *scratch_pool)
+{
+  apr_hash_t *props;
+  const svn_string_t *value;
+
+  SVN_ERR(svn_wc_get_pristine_props(&props, ctx->wc_ctx,
+                                    local_abspath,
+                                    scratch_pool, scratch_pool));
+  value = props ? svn_hash_gets(props, SVN_PROP_MIME_TYPE)
+                : NULL;
+  *is_binary = value && svn_mime_type_is_binary(value->data);
+
+  SVN_ERR(svn_wc_prop_get2(&value, ctx->wc_ctx, local_abspath,
+                           SVN_PROP_MIME_TYPE,
+                           scratch_pool, scratch_pool));
+  if (value && svn_mime_type_is_binary(value->data))
+    *is_binary = TRUE;
+
+  return SVN_NO_ERROR;
+}
+
 /* An implementation of svn_wc_status_func4_t. */
 static svn_error_t *
 walk_callback(void *baton,
@@ -386,30 +414,39 @@ walk_callback(void *baton,
       case svn_wc_status_deleted:
       case svn_wc_status_added:
       case svn_wc_status_replaced:
-        SVN_ERR(svn_client_diff_peg7(
-                NULL /*options*/,
-                local_abspath,
-                &peg_revision,
-                &start_revision,
-                &end_revision,
-                wb->wc_root_abspath,
-                svn_depth_empty,
-                TRUE /*notice_ancestry*/,
-                FALSE /*no_diff_added*/,
-                FALSE /*no_diff_deleted*/,
-                TRUE /*show_copies_as_adds*/,
-                FALSE /*ignore_content_type: FALSE -> omit binary files*/,
-                FALSE /*ignore_properties*/,
-                FALSE /*properties_only*/,
-                FALSE /*use_git_diff_format*/,
-                FALSE /*pretty_print_mergeinfo*/,
-                SVN_APR_LOCALE_CHARSET,
-                wb->outstream,
-                wb->errstream,
-                NULL /*changelists*/,
-                wb->ctx, scratch_pool));
+      {
+        svn_boolean_t binary = FALSE;
+        if (status->kind == svn_node_file)
+          {
+            SVN_ERR(is_binary_file(&binary, local_abspath,
+                                   wb->ctx, scratch_pool));
+          }
+        /* For binary files, use git diff binary literal format.
+           This works for a stop-gap, but is inefficient for large files. */
+        SVN_ERR(svn_client_diff_peg7(NULL /*options*/,
+                                     local_abspath,
+                                     &peg_revision,
+                                     &start_revision,
+                                     &end_revision,
+                                     wb->wc_root_abspath,
+                                     svn_depth_empty,
+                                     TRUE /*notice_ancestry*/,
+                                     FALSE /*no_diff_added*/,
+                                     FALSE /*no_diff_deleted*/,
+                                     TRUE /*show_copies_as_adds*/,
+                                     FALSE /*ignore_content_type: FALSE -> 
omit binary files*/,
+                                     FALSE /*ignore_properties*/,
+                                     FALSE /*properties_only*/,
+                                     binary /*use_git_diff_format*/,
+                                     FALSE /*pretty_print_mergeinfo*/,
+                                     SVN_APR_LOCALE_CHARSET,
+                                     wb->outstream,
+                                     wb->errstream,
+                                     NULL /*changelists*/,
+                                     wb->ctx, scratch_pool));
         wb->any_shelved = TRUE;
         break;
+      }
 
       case svn_wc_status_incomplete:
         if ((status->text_status != svn_wc_status_normal

Modified: subversion/trunk/subversion/tests/cmdline/shelf_tests.py
URL: 
http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/cmdline/shelf_tests.py?rev=1829295&r1=1829294&r2=1829295&view=diff
==============================================================================
--- subversion/trunk/subversion/tests/cmdline/shelf_tests.py (original)
+++ subversion/trunk/subversion/tests/cmdline/shelf_tests.py Mon Apr 16 
16:35:09 2018
@@ -297,7 +297,6 @@ def unshelve_refuses_if_conflicts(sbox):
 
 #----------------------------------------------------------------------
 
-@XFail()
 def shelve_binary_file_mod(sbox):
   "shelve binary file mod"
 
@@ -313,7 +312,6 @@ def shelve_binary_file_mod(sbox):
 
 #----------------------------------------------------------------------
 
-@XFail()
 def shelve_binary_file_add(sbox):
   "shelve binary file add"
 
@@ -324,7 +322,6 @@ def shelve_binary_file_add(sbox):
 
 #----------------------------------------------------------------------
 
-@XFail()
 def shelve_binary_file_del(sbox):
   "shelve binary file del"
 


Reply via email to