=== added file 'bzrlib\\winutils.py'
--- /dev/null
+++ bzrlib\winutils.py
@@ -0,0 +1,54 @@
+# Winutils - set of functions specially for working on Windows
+# Written by Alexander Belchenko
+#
+# Bazaar-NG -- distributed version control
+#
+# Copyright (C) 2005 by Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""
+Winutils - set of functions specially for working on Windows.
+"""
+
+import errno
+import os
+
+
+def win_rename(path_from, path_to):
+    """Basically the same as os.rename() just special for win32"""
+    try:
+        os.remove(path_to)
+    except OSError, e:
+        if e.errno != errno.ENOENT:
+            raise
+    os.rename(path_from, path_to)
+
+
+def win_user_dir():
+    """ Return per-user home directory.
+    Workaround for windows bug in os.path.expanduser() function.
+    """
+    # XXX I really don't know how to test it in selftest mode
+    #     I test it by hand
+    #     Workaround based on patch for Python #957650
+    home_dir = os.environ.get("HOME")
+    if home_dir is None:
+        home_dir = os.environ.get("USERPROFILE")
+        if home_dir is None:
+            home_drive = os.environ.get("HOMEDRIVE", "")
+            home_path = os.environ.get("HOMEPATH", "")
+            home_dir = home_drive + home_path
+    return home_dir

=== modified file 'bzrlib\\osutils.py'
--- bzrlib\osutils.py
+++ bzrlib\osutils.py
@@ -31,6 +31,7 @@
 import bzrlib
 from bzrlib.errors import BzrError
 from bzrlib.trace import mutter
+import bzrlib.winutils
 
 
 def make_readonly(filename):
@@ -143,10 +144,12 @@
     finally:
         outf.close()
 
-if os.name == 'nt':
-    import shutil
-    rename = shutil.move
+
+if sys.platform == 'win32':
+    # for WINDOWS
+    rename = bzrlib.winutils.win_rename
 else:
+    # for UNIX
     rename = os.rename
 
 
@@ -259,6 +262,18 @@
             'sha1': s.hexdigest()}
 
 
+def user_dir():
+    """ Return per-user home directory.
+    Workaround for windows bug in os.path.expanduser() function.
+    """
+    if sys.platform != "win32":
+        # for UNIX
+        return os.path.expanduser("~")
+    else:
+        # for WINDOWS
+        return bzrlib.winutils.win_user_dir()
+
+
 def config_dir():
     """Return per-user configuration directory.
 
@@ -266,7 +281,7 @@
     
     TODO: Global option --config-dir to override this.
     """
-    return os.path.join(os.path.expanduser("~"), ".bzr.conf")
+    return os.path.join(user_dir(), ".bzr.conf")
 
 
 def _auto_user_id():

=== modified file 'bzrlib\\trace.py'
--- bzrlib\trace.py
+++ bzrlib\trace.py
@@ -38,6 +38,8 @@
 import os
 import logging
 import traceback
+
+import bzrlib.winutils
 
 
 _file_handler = None
@@ -54,6 +56,8 @@
     # can get the exception details is we suppress them here.
 
     def format(self, record):
+        global _file_handler
+
         if record.levelno >= logging.WARNING:
             s = 'bzr: ' + record.levelname + ': '
         else:
@@ -70,7 +74,14 @@
             # the format of this string matches one of the REs
             s += '\n'
             s += ('  at %s line %d, in %s()\n' % exinfo[-1][:3])
-            s += '  see ~/.bzr.log for debug information'
+            if sys.platform != "win32":
+                s += '  see ~/.bzr.log for debug information'
+            else:
+                try:
+                    fname = _file_handler.stream.name
+                    s += '  see "%s" for debug information' % fname
+                except:
+                    s += '  see ~/.bzr.log for debug information'
 
         return s
         
@@ -120,7 +131,20 @@
     global _file_handler
     import stat, codecs
 
-    trace_fname = os.path.join(os.path.expanduser(tracefilename))
+    if sys.platform != "win32":
+        # for UNIX
+        trace_fname = os.path.join(os.path.expanduser(tracefilename))
+    else:
+        # for WINDOWS
+        if tracefilename.startswith("~"):
+            import re
+            parts = re.split(r"[/\\]", tracefilename)
+            if parts[0] == "~":
+                parts[0] = bzrlib.winutils.win_user_dir()
+            trace_fname = os.sep.join(parts)
+        else:
+            trace_fname = tracefilename
+
     _rollover_trace_maybe(trace_fname)
 
     # buffering=1 means line buffered

