Author: stsp Date: Tue Mar 17 10:05:53 2015 New Revision: 1667228 URL: http://svn.apache.org/r1667228 Log: Fix text conflict description for binary files.
The is_binary flag in conflict description was set to zero even for binary files. As a result, 'svn resolve' offered 'mine-conflict' and 'theirs-conflict' options which don't make any sense for binaries. Add a regression test to catch this problem in the future. * subversion/libsvn_wc/conflicts.c (read_text_conflict_desc): Drop is_binary paramter. Use the mime type to detemine whether the conflicted file is binary. (svn_wc__conflict_invoke_resolver): Stop passing FALSE for is_binary. Let read_text_conflict_desc figure it out based on the mime type. (svn_wc__read_conflicts): Read WORKING properties for text-conflicted files and pass the mime type to read_text_conflict_desc(). * subversion/tests/libsvn_wc/conflict-data-test.c (test_binary_file_conflict, test_funcs): New test. Modified: subversion/trunk/subversion/libsvn_wc/conflicts.c subversion/trunk/subversion/tests/libsvn_wc/conflict-data-test.c Modified: subversion/trunk/subversion/libsvn_wc/conflicts.c URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_wc/conflicts.c?rev=1667228&r1=1667227&r2=1667228&view=diff ============================================================================== --- subversion/trunk/subversion/libsvn_wc/conflicts.c (original) +++ subversion/trunk/subversion/libsvn_wc/conflicts.c Tue Mar 17 10:05:53 2015 @@ -1739,7 +1739,6 @@ read_text_conflict_desc(svn_wc_conflict_ svn_wc__db_t *db, const char *local_abspath, const svn_skel_t *conflict_skel, - svn_boolean_t is_binary, const char *mime_type, svn_wc_operation_t operation, const svn_wc_conflict_version_t *left_version, @@ -1748,8 +1747,8 @@ read_text_conflict_desc(svn_wc_conflict_ apr_pool_t *scratch_pool) { *desc = svn_wc_conflict_description_create_text2(local_abspath, result_pool); - (*desc)->is_binary = is_binary; (*desc)->mime_type = mime_type; + (*desc)->is_binary = mime_type ? svn_mime_type_is_binary(mime_type) : FALSE; (*desc)->operation = operation; (*desc)->src_left_version = left_version; (*desc)->src_right_version = right_version; @@ -1960,7 +1959,7 @@ svn_wc__conflict_invoke_resolver(svn_wc_ scratch_pool, scratch_pool)); SVN_ERR(read_text_conflict_desc(&desc, - db, local_abspath, conflict_skel, FALSE, + db, local_abspath, conflict_skel, svn_prop_get_value(props, SVN_PROP_MIME_TYPE), operation, left_version, right_version, @@ -2270,10 +2269,14 @@ svn_wc__read_conflicts(const apr_array_h if (text_conflicted) { svn_wc_conflict_description2_t *desc; + apr_hash_t *props; + SVN_ERR(svn_wc__db_read_props(&props, db, local_abspath, scratch_pool, + scratch_pool)); SVN_ERR(read_text_conflict_desc(&desc, db, local_abspath, conflict_skel, - FALSE /*is_binary*/, NULL /*mime_type*/, + svn_prop_get_value(props, + SVN_PROP_MIME_TYPE), operation, left_version, right_version, result_pool, scratch_pool)); APR_ARRAY_PUSH(cflcts, svn_wc_conflict_description2_t *) = desc; Modified: subversion/trunk/subversion/tests/libsvn_wc/conflict-data-test.c URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/tests/libsvn_wc/conflict-data-test.c?rev=1667228&r1=1667227&r2=1667228&view=diff ============================================================================== --- subversion/trunk/subversion/tests/libsvn_wc/conflict-data-test.c (original) +++ subversion/trunk/subversion/tests/libsvn_wc/conflict-data-test.c Tue Mar 17 10:05:53 2015 @@ -910,6 +910,48 @@ test_prop_conflict_resolving(const svn_t return SVN_NO_ERROR; } +static svn_error_t * +test_binary_file_conflict(const svn_test_opts_t *opts, + apr_pool_t *pool) +{ + svn_test__sandbox_t sbox; + const apr_array_header_t *conflicts; + svn_wc_conflict_description2_t *desc; + + svn_test__enable_sleep_for_timestamps(pool); + + SVN_ERR(svn_test__sandbox_create(&sbox, "test_binary_file_conflict", opts, pool)); + + /* Create and add a binary file. */ + SVN_ERR(sbox_file_write(&sbox, "binary-file", "\xff\xff\xff\xff\xff\xff")); + SVN_ERR(sbox_wc_add(&sbox, "binary-file")); + SVN_ERR(sbox_wc_propset(&sbox, SVN_PROP_MIME_TYPE, + "application/octet-stream", "binary-file")); + SVN_ERR(sbox_wc_commit(&sbox, "binary-file")); /* r1 */ + + /* Make a change to the binary file. */ + SVN_ERR(sbox_file_write(&sbox, "binary-file", "\xfc\xfc\xfc\xfc\xfc\xfc")); + SVN_ERR(sbox_wc_commit(&sbox, "binary-file")); /* r2 */ + + /* Update back to r1, make a conflicting change to binary file. */ + SVN_ERR(sbox_wc_update(&sbox, "binary-file", 1)); + SVN_ERR(sbox_file_write(&sbox, "binary-file", "\xfd\xfd\xfd\xfd\xfd\xfd")); + + /* Update to HEAD and ensure the conflict is marked as binary. */ + SVN_ERR(sbox_wc_update(&sbox, "binary-file", 2)); + SVN_ERR(svn_wc__read_conflicts(&conflicts, sbox.wc_ctx->db, + sbox_wc_path(&sbox, "binary-file"), + FALSE, /* create_tempfiles */ + pool, pool)); + SVN_TEST_ASSERT(conflicts->nelts == 1); + desc = APR_ARRAY_IDX(conflicts, 0, svn_wc_conflict_description2_t *); + SVN_TEST_ASSERT(desc->is_binary); + + svn_test__disable_sleep_for_timestamps(pool); + + return SVN_NO_ERROR; +} + /* The test table. */ @@ -934,6 +976,8 @@ static struct svn_test_descriptor_t test "test prop conflicts"), SVN_TEST_OPTS_PASS(test_prop_conflict_resolving, "test property conflict resolving"), + SVN_TEST_OPTS_PASS(test_binary_file_conflict, + "test binary file conflict"), SVN_TEST_NULL };