Index: libsvn_wc/wc.h
===================================================================
--- libsvn_wc/wc.h	(revision 11508)
+++ libsvn_wc/wc.h	(working copy)
@@ -205,14 +205,6 @@
  * lock not to be present.  Applications are not expected to call it.
  */
 svn_error_t *svn_wc__adm_write_check (svn_wc_adm_access_t *adm_access);
-
-/* Carries out platform specific operations needed before a file is
- * replaced via a rename or copy.  Currently it only runs 
- * svn_io_set_file_read_write() on Windows. */
-svn_error_t *svn_wc__prep_file_for_replacement (const char *path,
-                                                svn_boolean_t ignore_enoent,
-                                                apr_pool_t *pool);
-
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */
Index: libsvn_wc/log.c
===================================================================
--- libsvn_wc/log.c	(revision 11508)
+++ libsvn_wc/log.c	(working copy)
@@ -167,8 +167,6 @@
       }
 
     case svn_wc__xfer_mv:
-      SVN_ERR (svn_wc__prep_file_for_replacement (full_dest_path, TRUE, pool));
-
       err = svn_io_file_rename (full_from_path,
                                 full_dest_path, pool);
 
@@ -380,7 +378,13 @@
                          FALSE, &merge_outcome, loggy->diff3_cmd, 
                          loggy->pool));
 
-  return SVN_NO_ERROR;
+#ifdef SVN_CLIENT_CHECKOUT_READONLY
+  /* ensure that file is writavle _after_ merge if conflict occurs */
+  if (merge_outcome)
+    svn_io_set_file_read_write(name,FALSE,loggy->pool);
+#endif
+
+return SVN_NO_ERROR;
 }
 
 
@@ -992,9 +996,7 @@
           }
 
         /* Make the tmp prop file the new pristine one. */
-        SVN_ERR (svn_wc__prep_file_for_replacement (basef, TRUE, pool));
         SVN_ERR (svn_io_file_rename (tmpf, basef, pool));
-        SVN_ERR (svn_io_set_file_read_only (basef, FALSE, pool));
       }
   }   
 
Index: libsvn_wc/adm_ops.c
===================================================================
--- libsvn_wc/adm_ops.c	(revision 11508)
+++ libsvn_wc/adm_ops.c	(working copy)
@@ -351,6 +351,13 @@
                          revstr,
                          NULL);
 
+#ifdef SVN_CLIENT_CHECKOUT_READONLY
+  svn_xml_make_open_tag (&logtags,pool,svn_xml_self_closing,
+                         SVN_WC__LOG_READONLY,
+                         SVN_WC__LOG_ATTR_NAME,
+                         base_name,
+                         NULL);
+#endif
 
   /* Do wcprops in the same log txn as revision, etc. */
   if (wcprop_changes && (wcprop_changes->nelts > 0))
@@ -1201,12 +1208,6 @@
       SVN_ERR (svn_io_check_path (base_thing, &kind, pool));
       if (kind == svn_node_file)
         {
-          if ((working_props_kind == svn_node_file)
-              && (err = svn_wc__prep_file_for_replacement (thing, FALSE, pool)))
-            return svn_error_quick_wrap 
-              (err, apr_psprintf (pool, _("Error restoring props for '%s'"),
-                                  fullpath));
-
           if ((err = svn_io_copy_file (base_thing, thing, FALSE, pool)))
             return svn_error_quick_wrap 
               (err, apr_psprintf (pool, _("Error restoring props for '%s'"),
Index: libsvn_wc/adm_files.c
===================================================================
--- libsvn_wc/adm_files.c	(revision 11508)
+++ libsvn_wc/adm_files.c	(working copy)
@@ -230,9 +230,7 @@
   va_end (ap);
   
   /* Rename. */
-  SVN_ERR (svn_wc__prep_file_for_replacement (path, TRUE, pool));
   SVN_ERR (svn_io_file_rename (tmp_path, path, pool));
-  SVN_ERR (svn_io_set_file_read_only (path, FALSE, pool));
 
   return SVN_NO_ERROR;
 }
@@ -492,9 +490,7 @@
       va_end (ap);
       
       /* Rename. */
-      SVN_ERR (svn_wc__prep_file_for_replacement (path, TRUE, pool));
       SVN_ERR (svn_io_file_rename (tmp_path, path, pool));
-      SVN_ERR (svn_io_set_file_read_only (path, FALSE, pool));
       
       return SVN_NO_ERROR;
     }
@@ -1137,27 +1133,3 @@
 
   return SVN_NO_ERROR;
 }
-
-
-svn_error_t *
-svn_wc__prep_file_for_replacement (const char *path,
-                                   svn_boolean_t ignore_enoent,
-                                   apr_pool_t *pool)
-{
-   /* On Unix a read-only file can still be removed or replaced because
-      this is really an edit of the parent directory, not of the file
-      itself.  Windows apparently has different semantics, and so
-      when the svn_io_set_file_read_write() call was temporarily
-      removed in revision 5663, Subversion stopped working on Windows. 
-      
-      However, the svn_io_set_file_read_write() call sets all write
-      permissions on Unix, which is undesireable.  Since it is unnecessary
-      to make the file writeable, do nothing to prep the file for replacement
-      on Unix. */
-
-#ifdef WIN32
-  return svn_io_set_file_read_write (path, ignore_enoent, pool);
-#endif /* WIN32 */
-
-  return SVN_NO_ERROR;
-}
Index: libsvn_wc/update_editor.c
===================================================================
--- libsvn_wc/update_editor.c	(revision 11508)
+++ libsvn_wc/update_editor.c	(working copy)
@@ -2075,6 +2075,9 @@
    matrix. */
   if (new_text_path)
     {
+      svn_node_kind_t wfile_kind = svn_node_unknown;
+      SVN_ERR (svn_io_check_path (file_path, &wfile_kind, pool));
+
       if (! is_locally_modified)
         {
           /* If there are no local mods, who cares whether it's a text
@@ -2091,13 +2094,20 @@
                                  SVN_WC__LOG_ATTR_DEST,
                                  base_name,
                                  NULL);
+#ifdef SVN_CLIENT_CHECKOUT_READONLY
+          if (wfile_kind == svn_node_none) /* working file is missing, new pull */
+            svn_xml_make_open_tag (&log_accum,
+                                 pool,
+                                 svn_xml_self_closing,
+                                 SVN_WC__LOG_READONLY,
+                                 SVN_WC__LOG_ATTR_NAME,
+                                 base_name,
+                                 NULL);
+#endif
         }
   
       else   /* working file is locally modified... */
         {
-          svn_node_kind_t wfile_kind = svn_node_unknown;
-          
-          SVN_ERR (svn_io_check_path (file_path, &wfile_kind, pool));
           if (wfile_kind == svn_node_none) /* working file is missing?! */
             {
               /* Just copy the new text-base to the file. */
@@ -2110,6 +2120,15 @@
                                      SVN_WC__LOG_ATTR_DEST,
                                      base_name,
                                      NULL);
+#ifdef SVN_CLIENT_CHECKOUT_READONLY
+              svn_xml_make_open_tag (&log_accum,
+                                     pool,
+                                     svn_xml_self_closing,
+                                     SVN_WC__LOG_READONLY,
+                                     SVN_WC__LOG_ATTR_NAME,
+                                     base_name,
+                                     NULL);
+#endif
             }
           else  /* working file exists, and has local mods.*/
             {                  
Index: libsvn_subr/io.c
===================================================================
--- libsvn_subr/io.c	(revision 11508)
+++ libsvn_subr/io.c	(working copy)
@@ -528,10 +528,11 @@
 {
   apr_file_t *d;
   apr_status_t apr_err;
-  const char *src_apr, *dst_tmp_apr;
+  const char *src_apr, *dst_tmp_apr, *dst_apr;
   const char *dst_tmp;
 
   SVN_ERR (svn_path_cstring_from_utf8 (&src_apr, src, pool));
+  SVN_ERR (svn_path_cstring_from_utf8 (&dst_apr, dst, pool));
 
   /* For atomicity, we translate to a tmp file and then rename the tmp
      file over the real destination. */
@@ -580,10 +581,21 @@
     }
 #endif /* ! WIN32 */
 
-  return svn_io_file_rename (dst_tmp, dst, pool);
+#ifdef WIN32
+    {
+        DWORD dwAttr=INVALID_FILE_ATTRIBUTES;
+        if (copy_perms)
+            dwAttr = GetFileAttributes(src_apr);
+# endif /* WIN32 */
+    SVN_ERR(svn_io_file_rename (dst_tmp, dst, pool));
+#ifdef WIN32
+        if (dwAttr!=INVALID_FILE_ATTRIBUTES)
+            SetFileAttributes(dst_apr,dwAttr);
+    }
+# endif /* WIN32 */
+    return SVN_NO_ERROR;
 }
 
-
 svn_error_t *
 svn_io_append_file (const char *src, const char *dst, apr_pool_t *pool)
 {
@@ -1353,14 +1365,14 @@
   apr_status_t apr_err;
   const char *path_apr;
 
+  SVN_ERR (svn_path_cstring_from_utf8 (&path_apr, path, pool));
+
 #ifdef WIN32
   /* Set the file writable but only on Windows, because Windows
      will not allow us to remove files that are read-only. */
-  SVN_ERR (svn_io_set_file_read_write (path, TRUE, pool));
+  SetFileAttributes(path_apr,GetFileAttributes(path_apr)&~FILE_ATTRIBUTE_READONLY);
 #endif /* WIN32 */
 
-  SVN_ERR (svn_path_cstring_from_utf8 (&path_apr, path, pool));
-
   apr_err = apr_file_remove (path_apr, pool);
   WIN32_RETRY_LOOP (apr_err, apr_file_remove (path_apr, pool));
 
@@ -2115,9 +2127,24 @@
   SVN_ERR (svn_path_cstring_from_utf8 (&from_path_apr, from_path, pool));
   SVN_ERR (svn_path_cstring_from_utf8 (&to_path_apr, to_path, pool));
 
-  status = apr_file_rename (from_path_apr, to_path_apr, pool);
-  WIN32_RETRY_LOOP (status,
-                    apr_file_rename (from_path_apr, to_path_apr, pool));
+/* Preserve if possible file attributes of destination file, since this is more
+ * looks like to *NIX behavior, but before reset attributes that can prevent file
+ * rename
+ */
+#ifdef WIN32
+  {
+	DWORD dwAttr = INVALID_FILE_ATTRIBUTES;
+	dwAttr = GetFileAttributes(to_path_apr);
+	SetFileAttributes(to_path_apr,dwAttr&~FILE_ATTRIBUTE_READONLY);
+#endif
+   status = apr_file_rename (from_path_apr, to_path_apr, pool);
+   WIN32_RETRY_LOOP (status,
+                     apr_file_rename (from_path_apr, to_path_apr, pool));
+#ifdef WIN32
+    if (dwAttr != INVALID_FILE_ATTRIBUTES)
+		SetFileAttributes(to_path_apr,dwAttr);
+  }
+#endif
 
   if (status)
     return svn_error_wrap_apr (status, "Can't move '%s' to '%s'",
@@ -2499,12 +2526,6 @@
   /* ...and close the file. */
   SVN_ERR (svn_io_file_close (format_file, pool));
 
-#ifdef WIN32
-  /* make the destination writable, but only on Windows, because
-     Windows does not let us replace read-only files. */
-  SVN_ERR (svn_io_set_file_read_write (path, TRUE, pool));
-#endif /* WIN32 */
-
   /* rename the temp file as the real destination */
   SVN_ERR (svn_io_file_rename (path_tmp, path, pool));
 
