Hi Subversion developers,

When updating a working copy directory that contains a locally modified
file external whose repository target also has incoming changes, Subversion
always triggers a full-file text conflict with a 0-byte ".rOLD" base file,
even when local and incoming edits touch completely disjoint lines.

=== Root Cause ===

In subversion/libsvn_wc/externals.c (close_file(), trunk@1941016):

  741: const svn_checksum_t *new_checksum = NULL;
  742: const svn_checksum_t *original_checksum = NULL;
  743:
  744: svn_boolean_t added = !SVN_IS_VALID_REVNUM(eb->original_revision);
  745:
  746: if (! added)
  747:   {
  748:     new_checksum = eb->original_checksum;
  ...
  866:     SVN_ERR(svn_wc__perform_file_merge(&work_item,
  867:                                        &conflict_skel,
  868:                                        &found_text_conflict,
  869:                                        eb->db,
  870:                                        eb->local_abspath,
  871:                                        eb->wri_abspath,
  872:                                        new_checksum,
  873:                                        original_checksum,
  ...

The local variable `original_checksum` is initialized to NULL on line 742
and is never assigned anywhere in close_file(). Consequently,
svn_wc__perform_file_merge() in subversion/libsvn_wc/update_editor.c
always receives `original_checksum == NULL`, unconditionally taking the
`if (! original_checksum)` branch and calling get_empty_tmp_file() to pass
a 0-byte empty file as `merge_left` (BASE) to diff3.

Looking at history, this regression was introduced in r1124782 (2011-05-19),
when the call to svn_wc__db_external_read(..., &original_checksum, ...) was
removed in favor of `eb->original_checksum` populated in open_file(). That
commit updated `new_checksum = eb->original_checksum`, but missed updating
the `original_checksum` argument passed to svn_wc__perform_file_merge()
(similar to how r1229833 / issue #4093 later fixed `base_props` from the
same r1124782 refactor).

=== Affected Versions ===

Reproduced on Subversion 1.9, 1.14, and 1.15.0 (r1937767, Windows /
TortoiseSVN), and still present on trunk@1941016.

=== Minimal Reproduction ===

  svnadmin create repo
  svn co file://$PWD/repo wc_admin
  mkdir -p wc_admin/src wc_admin/client
  printf "line 1\nline 2\nline 3\nline 4\nline 5\n" > wc_admin/src/f.txt
  svn add wc_admin/src wc_admin/client
  svn ps svn:externals "^/src/f.txt f.txt" wc_admin/client
  svn ci -m "r1" wc_admin

  svn co file://$PWD/repo/client wc_user

  # Remote edits line 5
  printf "line 1\nline 2\nline 3\nline 4\nline 5 REMOTE\n" > wc_admin/src/f.txt
  svn ci -m "r2" wc_admin

  # Local edits line 1 (non-overlapping)
  printf "line 1 LOCAL\nline 2\nline 3\nline 4\nline 5\n" > wc_user/f.txt

  # Updating parent directory causes a full-file conflict with 0-byte f.txt.r1
  svn up --accept postpone wc_user
  ls -l wc_user/f.txt*

Expected:
  G    wc_user/f.txt   (clean 3-way merge, no conflict)

Actual:
  C    wc_user/f.txt   (entire file wrapped in conflict markers;
f.txt.r1 is 0 bytes)

=== Proposed Patch ===

Log message:
* subversion/libsvn_wc/externals.c
  (close_file): Pass `eb->original_checksum` instead of the unused local
   `original_checksum` (always NULL since r1124782) to
   svn_wc__perform_file_merge(), and remove the redundant local variable.

Index: subversion/libsvn_wc/externals.c
===================================================================
--- subversion/libsvn_wc/externals.c    (revision 1941016)
+++ subversion/libsvn_wc/externals.c    (working copy)
@@ -739,7 +739,6 @@
     apr_hash_t *new_actual_props = NULL;
     apr_hash_t *new_dav_props = NULL;
     const svn_checksum_t *new_checksum = NULL;
-    const svn_checksum_t *original_checksum = NULL;

     svn_boolean_t added = !SVN_IS_VALID_REVNUM(eb->original_revision);

@@ -870,7 +869,7 @@
                                                    eb->local_abspath,
                                                    eb->wri_abspath,
                                                    new_checksum,
-                                                   original_checksum,
+                                                   eb->original_checksum,
                                                    actual_props,
                                                    eb->ext_patterns,
                                                    eb->original_revision,

Note: When a file external is newly added via add_file(), open_file() is not
called and `eb->original_checksum` remains NULL, preserving the empty-base
behavior for newly added files.

Best regards

Reply via email to