Index: blame.c
===================================================================
--- blame.c	(revision 1366813)
+++ blame.c	(working copy)
@@ -82,6 +82,7 @@
   svn_boolean_t ignore_mime_type;
   /* name of file containing the previous revision of the file */
   const char *last_filename;
+  const char *last_filename_utf8; /* name of UTF-8 file ( created if format of file 'LAST_FILENAME' is UTF-16. ) */
   struct rev *rev;     /* the rev for which blame is being assigned
                           during a diff */
   struct blame_chain *chain;      /* the original blame chain. */
@@ -96,6 +97,7 @@
   struct blame_chain *merged_chain;  /* the merged blame chain. */
   /* name of file containing the previous merged revision of the file */
   const char *last_original_filename;
+  const char *last_original_filename_utf8; /* name of UTF-8 file ( created if format of file 'LAST_ORIGINAL_FILENAME' is UTF-16. ) */
   /* pools for files which may need to persist for more than one rev. */
   apr_pool_t *filepool;
   apr_pool_t *prevfilepool;
@@ -305,13 +307,58 @@
 
   return SVN_NO_ERROR;
 }
+			   
+/* if format of file 'INPUT_FILENAME' is UTF-16, export it to UTF-8 file and return that file's name.
+   otherwise return NULL. */
+static const char*
+create_utf8_file_if_utf16_file( const char *input_filename, apr_pool_t *pool )
+{
+  svn_stringbuf_t *input_buf;	
+  const char *buf_utf8;
+  apr_size_t len_utf8;
+  const char* utf8_filename = NULL;
 
+  svn_stream_t *stream;
+  apr_size_t bom_len = 2;
+  const char* bom;
+  svn_boolean_t is_utf16;
+	
+  if (input_filename == NULL) return NULL;
+
+  /* check UTF 16 BOM */
+  SVN_ERR(svn_stream_open_readonly(&stream, input_filename, pool, pool));
+  bom = apr_palloc(pool, bom_len);
+  svn_stream_read(stream, bom, &bom_len);
+  svn_stream_close(stream);
+  is_utf16 = (bom_len >= 2 && bom[0] == (char)0xFF && bom[1] == (char)0xFE);
+  if (!is_utf16) return NULL;
+
+  /* Read : input file => input buf */
+  SVN_ERR(svn_stringbuf_from_file2(&input_buf, input_filename, pool));
+
+  /* Convert : input buf => buf_utf8 */
+  len_utf8 = WideCharToMultiByte(CP_UTF8, 0, input_buf->data, input_buf->len/sizeof(WCHAR), 0, 0, 0, 0);
+  buf_utf8 = apr_palloc(pool, len_utf8);
+  len_utf8 = WideCharToMultiByte(CP_UTF8, 0, input_buf->data, input_buf->len/sizeof(WCHAR), buf_utf8, len_utf8, 0, 0);
+
+  /* Write : buf_utf8 => utf8 file */
+  SVN_ERR(svn_io_write_unique(&utf8_filename, NULL, buf_utf8, len_utf8, svn_io_file_del_on_pool_cleanup, pool));
+
+  return utf8_filename;
+}
+
 static svn_error_t *
 window_handler(svn_txdelta_window_t *window, void *baton)
 {
   struct delta_baton *dbaton = baton;
   struct file_rev_baton *frb = dbaton->file_rev_baton;
   struct blame_chain *chain;
+  
+  apr_pool_t *filepool;
+  const char *last_filename = NULL;
+  const char *curr_filename = NULL;
+  const char *curr_filename_utf8 = NULL;
+  const char *last_original_filename = NULL;
 
   /* Call the wrapped handler first. */
   SVN_ERR(dbaton->wrapped_handler(window, dbaton->wrapped_baton));
@@ -334,9 +381,22 @@
   else
     chain = frb->chain;
 
+  /* Set pool for UTF-8 file ( created if current file is UTF-16 ) */
+  if (frb->include_merged_revisions && !frb->merged_revision)
+	  filepool = frb->filepool;
+  else
+	  filepool = frb->currpool;
+
+  /* If last file's original format is UTF-16, use UTF-8 file created at last call. */
+  last_filename = frb->last_filename_utf8 ? frb->last_filename_utf8 : frb->last_filename;
+  
+  /* If curr file's original format is UTF-16, export it to UTF-8 file and use that file. */
+  curr_filename_utf8 = create_utf8_file_if_utf16_file(dbaton->filename, filepool);
+  curr_filename = curr_filename_utf8 ? curr_filename_utf8 : dbaton->filename;  
+
   /* Process this file. */
-  SVN_ERR(add_file_blame(frb->last_filename,
-                         dbaton->filename, chain, frb->rev,
+  SVN_ERR(add_file_blame(last_filename,
+                         curr_filename, chain, frb->rev,
                          frb->diff_options, frb->currpool));
 
   /* If we are including merged revisions, and the current revision is not a
@@ -346,8 +406,11 @@
     {
       apr_pool_t *tmppool;
 
-      SVN_ERR(add_file_blame(frb->last_original_filename,
-                             dbaton->filename, frb->chain, frb->rev,
+	  /* If last file's original format is UTF-16, use UTF-8 file created at last call. */
+	  last_original_filename = frb->last_original_filename_utf8 ? frb->last_original_filename_utf8 : frb->last_original_filename;
+
+      SVN_ERR(add_file_blame(last_original_filename,
+                             curr_filename, frb->chain, frb->rev,
                              frb->diff_options, frb->currpool));
 
       /* This filename could be around for a while, potentially, so
@@ -359,12 +422,14 @@
 
       frb->last_original_filename = apr_pstrdup(frb->filepool,
                                                 dbaton->filename);
+	  frb->last_original_filename_utf8 = curr_filename_utf8;
     }
 
   /* Prepare for next revision. */
 
   /* Remember the file name so we can diff it with the next revision. */
   frb->last_filename = dbaton->filename;
+  frb->last_filename_utf8 = curr_filename_utf8;
 
   /* Switch pools. */
   {
@@ -596,6 +661,8 @@
   svn_stream_t *stream;
   const char *target_abspath_or_url;
 
+  const char* last_filename;
+
   if (start->kind == svn_opt_revision_unspecified
       || end->kind == svn_opt_revision_unspecified)
     return svn_error_create
@@ -630,6 +697,8 @@
   frb.include_merged_revisions = include_merged_revisions;
   frb.last_filename = NULL;
   frb.last_original_filename = NULL;
+  frb.last_filename_utf8 = NULL;
+  frb.last_original_filename_utf8 = NULL;
   frb.chain = apr_palloc(pool, sizeof(*frb.chain));
   frb.chain->blame = NULL;
   frb.chain->avail = NULL;
@@ -719,9 +788,12 @@
 
   /* Create a pool for the iteration below. */
   iterpool = svn_pool_create(pool);
-
+  
+  /* If last file's original format is UTF-16, use UTF-8 file created at last call. */
+  last_filename = frb.last_filename_utf8 ? frb.last_filename_utf8 : frb.last_filename;
+  
   /* Open the last file and get a stream. */
-  SVN_ERR(svn_stream_open_readonly(&last_stream, frb.last_filename,
+  SVN_ERR(svn_stream_open_readonly(&last_stream, last_filename,
                                    pool, pool));
   stream = svn_subst_stream_translated(last_stream,
                                        "\n", TRUE, NULL, FALSE, pool);
