Skip to content

Commit

Permalink
[merge] win32 fixes (alexey)
Browse files Browse the repository at this point in the history
  • Loading branch information
sourcefrog committed Nov 22, 2005
2 parents 84b4db4 + 758fcf0 commit c03a231
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 61 deletions.
26 changes: 26 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,15 @@ UNRELEASED CHANGES
versioned directories, now use "bzr inventory --kind directory".
(Johan Rydberg)

* Under Windows configuration directory is now %APPDATA%\bazaar\2.0
by default. (John Arbash Meinel)

* The parent of Bzr configuration directory can be set by BZR_HOME
environment variable. Now the path for it is searched in BZR_HOME, then
in HOME. Under Windows the order is: BZR_HOME, APPDATA (usually
points to C:\Documents and Settings\User Name\Application Data), HOME.
(John Arbash Meinel)

IMPROVEMENTS:

* "bzr INIT dir" now initializes the specified directory, and creates
Expand Down Expand Up @@ -74,13 +83,29 @@ UNRELEASED CHANGES
* Fix representation of tab characters in commit messages. (Harald
Meland)

* List of plugin directories in BZR_PLUGIN_PASS environment variable is
now parsed properly under Windows. (Alexander Belchenko)

TESTING:

* Fix selftest asking for passwords when there are no SFTP keys.
(Robey Pointer, Jelmer Vernooij)

* Fix selftest run with 'python -O'. (Martin Pool)

* Fix HTTP tests under Windows. (John Arbash Meinel)

* Make tests work even if HOME is not set (Aaron Bentley)

* Updated build_tree to use fixed line-endings for tests which read
the file cotents and compare. Make some tests use this to pass under
Windows. (John Arbash Meinel)

* Skip stat and symlink tests under Windows. (Alexander Belchenko)

* Delay in selftest/testhashcash is now issued under win32 and Cygwin.
(John Arbash Meinel)

INTERNALS:

* WorkingTree.pull has been split across Branch and WorkingTree,
Expand Down Expand Up @@ -119,6 +144,7 @@ UNRELEASED CHANGES

* Branch.commit() has moved to WorkingTree.commit(). (Robert Collins)


bzr 0.6 2005-10-28

IMPROVEMENTS:
Expand Down
16 changes: 15 additions & 1 deletion bzrlib/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@

import errno
import os
import sys
from fnmatch import fnmatch
import re

Expand Down Expand Up @@ -414,7 +415,20 @@ def config_dir():
TODO: Global option --config-dir to override this.
"""
return os.path.join(os.path.expanduser("~"), ".bazaar")
base = os.environ.get('BZR_HOME', None)
if sys.platform == 'win32':
if base is None:
base = os.environ.get('APPDATA', None)
if base is None:
base = os.environ.get('HOME', None)
if base is None:
raise BzrError('You must have one of BZR_HOME, APPDATA, or HOME set')
return os.path.join(base, 'bazaar', '2.0')
else:
# cygwin, linux, and darwin all have a $HOME directory
if base is None:
base = os.path.expanduser("~")
return os.path.join(base, ".bazaar")


def config_filename():
Expand Down
2 changes: 1 addition & 1 deletion bzrlib/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def load_plugins():
#raise BzrError("plugins already initialized")
_loaded = True

dirs = os.environ.get('BZR_PLUGIN_PATH', DEFAULT_PLUGIN_PATH).split(":")
dirs = os.environ.get('BZR_PLUGIN_PATH', DEFAULT_PLUGIN_PATH).split(os.pathsep)
dirs.insert(0, os.path.dirname(plugins.__file__))

# The problem with imp.get_suffixes() is that it doesn't include
Expand Down
2 changes: 1 addition & 1 deletion bzrlib/selftest/HTTPTestUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def handle_one_request(self):
try:
self.raw_requestline = self.rfile.readline()
except socket.error, e:
if e.args[0] == errno.EAGAIN:
if e.args[0] in (errno.EAGAIN, errno.EWOULDBLOCK):
# omitted for now because some tests look at the log of
# the server and expect to see no errors. see recent
# email thread. -- mbp 20051021.
Expand Down
60 changes: 41 additions & 19 deletions bzrlib/selftest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
from bzrlib.selftest import TestUtil
from bzrlib.selftest.TestUtil import TestLoader, TestSuite
from bzrlib.selftest.treeshape import build_tree_contents
from bzrlib.errors import BzrError

MODULES_TO_TEST = []
MODULES_TO_DOCTEST = []
Expand Down Expand Up @@ -251,26 +252,38 @@ def addCleanup(self, callable):
self._cleanups.append(callable)

def _cleanEnvironment(self):
self.oldenv = os.environ.get('HOME', None)
os.environ['HOME'] = os.getcwd()
self.bzr_email = os.environ.get('BZREMAIL')
if self.bzr_email is not None:
del os.environ['BZREMAIL']
self.email = os.environ.get('EMAIL')
if self.email is not None:
del os.environ['EMAIL']
new_env = {
'HOME': os.getcwd(),
'APPDATA': os.getcwd(),
'BZREMAIL': None,
'EMAIL': None,
}
self.__old_env = {}
self.addCleanup(self._restoreEnvironment)
for name, value in new_env.iteritems():
self._captureVar(name, value)


def _captureVar(self, name, newvalue):
"""Set an environment variable, preparing it to be reset when finished."""
self.__old_env[name] = os.environ.get(name, None)
if newvalue is None:
if name in os.environ:
del os.environ[name]
else:
os.environ[name] = newvalue

@staticmethod
def _restoreVar(name, value):
if value is None:
if name in os.environ:
del os.environ[name]
else:
os.environ[name] = value

def _restoreEnvironment(self):
os.environ['HOME'] = self.oldenv
if os.environ.get('BZREMAIL') is not None:
del os.environ['BZREMAIL']
if self.bzr_email is not None:
os.environ['BZREMAIL'] = self.bzr_email
if os.environ.get('EMAIL') is not None:
del os.environ['EMAIL']
if self.email is not None:
os.environ['EMAIL'] = self.email
for name, value in self.__old_env.iteritems():
self._restoreVar(name, value)

def tearDown(self):
self._runCleanups()
Expand Down Expand Up @@ -471,21 +484,30 @@ def _leaveDirectory():
os.chdir(_currentdir)
self.addCleanup(_leaveDirectory)

def build_tree(self, shape):
def build_tree(self, shape, line_endings='native'):
"""Build a test tree according to a pattern.
shape is a sequence of file specifications. If the final
character is '/', a directory is created.
This doesn't add anything to a branch.
:param line_endings: Either 'binary' or 'native'
in binary mode, exact contents are written
in native mode, the line endings match the
default platform endings.
"""
# XXX: It's OK to just create them using forward slashes on windows?
for name in shape:
self.assert_(isinstance(name, basestring))
if name[-1] == '/':
os.mkdir(name[:-1])
else:
f = file(name, 'wt')
if line_endings == 'binary':
f = file(name, 'wb')
elif line_endings == 'native':
f = file(name, 'wt')
else:
raise BzrError('Invalid line ending request %r' % (line_endings,))
print >>f, "contents of", name
f.close()

Expand Down
4 changes: 2 additions & 2 deletions bzrlib/selftest/blackbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,12 @@ def test_diff(self):
self.runbzr('diff')

def test_diff_branches(self):
self.build_tree(['branch1/', 'branch1/file', 'branch2/'])
self.build_tree(['branch1/', 'branch1/file', 'branch2/'], line_endings='binary')
branch = Branch.initialize('branch1')
branch.add(['file'])
branch.working_tree().commit('add file')
copy_branch(branch, 'branch2')
print >> open('branch2/file', 'w'), 'new content'
print >> open('branch2/file', 'wb'), 'new content'
branch2 = Branch.open('branch2')
branch2.working_tree().commit('update file')
# should open branch1 and diff against branch2,
Expand Down
2 changes: 1 addition & 1 deletion bzrlib/selftest/test_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_selective_delete(self):
def test_commit_rename(self):
"""Test commit of a revision where a file is renamed."""
b = Branch.initialize('.')
self.build_tree(['hello'])
self.build_tree(['hello'], line_endings='binary')
b.add(['hello'], ['hello-id'])
b.working_tree().commit(message='one', rev_id='test@rev-1', allow_pointless=False)

Expand Down
59 changes: 32 additions & 27 deletions bzrlib/selftest/test_merge_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import tempfile
import unittest
import stat
import sys

from bzrlib.selftest import TestCaseInTempDir, TestCase
from bzrlib.branch import ScratchBranch, Branch
Expand Down Expand Up @@ -467,9 +468,10 @@ def contents_test_success(self, merge_factory):
builder.apply_changeset(cset)
self.assert_(file(builder.this.full_path("1"), "rb").read() == "text4" )
self.assert_(file(builder.this.full_path("2"), "rb").read() == "text2" )
self.assert_(os.stat(builder.this.full_path("1")).st_mode &0777 == 0755)
self.assert_(os.stat(builder.this.full_path("2")).st_mode &0777 == 0655)
self.assert_(os.stat(builder.this.full_path("3")).st_mode &0777 == 0744)
if sys.platform != "win32":
self.assert_(os.stat(builder.this.full_path("1")).st_mode &0777 == 0755)
self.assert_(os.stat(builder.this.full_path("2")).st_mode &0777 == 0655)
self.assert_(os.stat(builder.this.full_path("3")).st_mode &0777 == 0744)
return builder

def contents_test_conflicts(self, merge_factory):
Expand All @@ -482,29 +484,31 @@ def contents_test_conflicts(self, merge_factory):
builder.cleanup()

def test_symlink_conflicts(self):
builder = MergeBuilder()
builder.add_symlink("2", "0", "name2", "target1")
builder.change_target("2", other="target4", base="text3")
self.assertRaises(changeset.ThreewayContentsConflict,
builder.merge_changeset, ApplyMerge3)
builder.cleanup()
if sys.platform != "win32":
builder = MergeBuilder()
builder.add_symlink("2", "0", "name2", "target1")
builder.change_target("2", other="target4", base="text3")
self.assertRaises(changeset.ThreewayContentsConflict,
builder.merge_changeset, ApplyMerge3)
builder.cleanup()

def test_symlink_merge(self):
builder = MergeBuilder()
builder.add_symlink("1", "0", "name1", "target1")
builder.add_symlink("2", "0", "name2", "target1")
builder.add_symlink("3", "0", "name3", "target1")
builder.change_target("1", this="target2")
builder.change_target("2", base="target2")
builder.change_target("3", other="target2")
self.assertNotEqual(builder.cset.entries['2'].contents_change,
builder.cset.entries['3'].contents_change)
cset = builder.merge_changeset(ApplyMerge3)
builder.apply_changeset(cset)
self.assertEqual(builder.this.get_symlink_target("1"), "target2")
self.assertEqual(builder.this.get_symlink_target("2"), "target1")
self.assertEqual(builder.this.get_symlink_target("3"), "target2")
builder.cleanup()
if sys.platform != "win32":
builder = MergeBuilder()
builder.add_symlink("1", "0", "name1", "target1")
builder.add_symlink("2", "0", "name2", "target1")
builder.add_symlink("3", "0", "name3", "target1")
builder.change_target("1", this="target2")
builder.change_target("2", base="target2")
builder.change_target("3", other="target2")
self.assertNotEqual(builder.cset.entries['2'].contents_change,
builder.cset.entries['3'].contents_change)
cset = builder.merge_changeset(ApplyMerge3)
builder.apply_changeset(cset)
self.assertEqual(builder.this.get_symlink_target("1"), "target2")
self.assertEqual(builder.this.get_symlink_target("2"), "target1")
self.assertEqual(builder.this.get_symlink_target("3"), "target2")
builder.cleanup()

def test_perms_merge(self):
builder = MergeBuilder()
Expand All @@ -520,9 +524,10 @@ def test_perms_merge(self):
self.assert_(isinstance(cset.entries["2"].metadata_change, ExecFlagMerge))
self.assert_(cset.entries["3"].is_boring())
builder.apply_changeset(cset)
self.assert_(os.lstat(builder.this.full_path("1")).st_mode &0100 == 0000)
self.assert_(os.lstat(builder.this.full_path("2")).st_mode &0100 == 0100)
self.assert_(os.lstat(builder.this.full_path("3")).st_mode &0100 == 0000)
if sys.platform != "win32":
self.assert_(os.lstat(builder.this.full_path("1")).st_mode &0100 == 0000)
self.assert_(os.lstat(builder.this.full_path("2")).st_mode &0100 == 0100)
self.assert_(os.lstat(builder.this.full_path("3")).st_mode &0100 == 0000)
builder.cleanup();


Expand Down
36 changes: 29 additions & 7 deletions bzrlib/selftest/testconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,45 @@ class TestConfigPath(TestCase):

def setUp(self):
super(TestConfigPath, self).setUp()
self.oldenv = os.environ.get('HOME', None)
self.old_home = os.environ.get('HOME', None)
self.old_appdata = os.environ.get('APPDATA', None)
os.environ['HOME'] = '/home/bogus'
os.environ['APPDATA'] = \
r'C:\Documents and Settings\bogus\Application Data'

def tearDown(self):
os.environ['HOME'] = self.oldenv
if self.old_home is None:
del os.environ['HOME']
else:
os.environ['HOME'] = self.old_home
if self.old_appdata is None:
del os.environ['APPDATA']
else:
os.environ['APPDATA'] = self.old_appdata
super(TestConfigPath, self).tearDown()

def test_config_dir(self):
self.assertEqual(config.config_dir(), '/home/bogus/.bazaar')
if sys.platform == 'win32':
self.assertEqual(config.config_dir(),
r'C:\Documents and Settings\bogus\Application Data\bazaar\2.0')
else:
self.assertEqual(config.config_dir(), '/home/bogus/.bazaar')

def test_config_filename(self):
self.assertEqual(config.config_filename(),
'/home/bogus/.bazaar/bazaar.conf')
if sys.platform == 'win32':
self.assertEqual(config.config_filename(),
r'C:\Documents and Settings\bogus\Application Data\bazaar\2.0\bazaar.conf')
else:
self.assertEqual(config.config_filename(),
'/home/bogus/.bazaar/bazaar.conf')

def test_branches_config_filename(self):
self.assertEqual(config.branches_config_filename(),
'/home/bogus/.bazaar/branches.conf')
if sys.platform == 'win32':
self.assertEqual(config.branches_config_filename(),
r'C:\Documents and Settings\bogus\Application Data\bazaar\2.0\branches.conf')
else:
self.assertEqual(config.branches_config_filename(),
'/home/bogus/.bazaar/branches.conf')

class TestIniConfig(TestCase):

Expand Down
3 changes: 2 additions & 1 deletion bzrlib/selftest/testhashcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

import os
import sys
import time
from bzrlib.selftest import TestCaseInTempDir

Expand All @@ -28,7 +29,7 @@ def sha1(t):
def pause():
if False:
return
if os.name == 'nt':
if sys.platform in ('win32', 'cygwin'):
time.sleep(3)
return
# allow it to stabilize
Expand Down
2 changes: 1 addition & 1 deletion bzrlib/selftest/testinv.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def setUp(self):
# with fake parent entries.
super(TestSnapshot, self).setUp()
self.branch = Branch.initialize('.')
self.build_tree(['subdir/', 'subdir/file'])
self.build_tree(['subdir/', 'subdir/file'], line_endings='binary')
self.branch.add(['subdir', 'subdir/file'], ['dirid', 'fileid'])
if has_symlinks():
pass
Expand Down

0 comments on commit c03a231

Please sign in to comment.