Rev 19: Handle kind_change. Trivial implementation, blocked by bug #205636. in http://code.launchpad.net/%7Ev-ladeuil/bzr/upload
Vincent Ladeuil
v.ladeuil+lp at free.fr
Sun Mar 23 22:22:37 GMT 2008
At http://code.launchpad.net/%7Ev-ladeuil/bzr/upload
------------------------------------------------------------
revno: 19
revision-id: v.ladeuil+lp at free.fr-20080323222229-pvtwg6der2pmhvmd
parent: v.ladeuil+lp at free.fr-20080323120026-lz48rknjd3ii2ywm
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: upload
timestamp: Sun 2008-03-23 23:22:29 +0100
message:
Handle kind_change. Trivial implementation, blocked by bug #205636.
* test_upload.py:
(TestUploadMixin.transform_dir_into_file,
TestUploadMixin.transform_file_into_dir): New helpers.
(TestIncrementalUpload.test_change_file_into_dir,
TestIncrementalUpload.test_change_dir_into_file): Test
kind_change.
* __init__.py:
(cmd_upload.upload_tree): kind_change trivial implementation.
modified:
__init__.py __init__.py-20080307145942-xx1xgifrreovahgz-1
test_upload.py test_upload.py-20080307145942-xx1xgifrreovahgz-2
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py 2008-03-23 12:00:26 +0000
+++ b/__init__.py 2008-03-23 22:22:29 +0000
@@ -35,6 +35,12 @@
# chmod bits but don't provide an ftp server that support them, well, better
# find another provider ;-)
+# TODO: can't upload with conflicts present (or even uncommited changes ? Or at
+# a least a warning ?) . Something along the lines:
+
+# if len(self.tree.conflicts()) > 0:
+# raise ConflictsInTree
+
from bzrlib import (
commands,
lazy_import,
@@ -211,8 +217,8 @@
self.tree.unlock()
def upload_tree(self):
- # XXX: if we get NoSuchFile shoudl we consider it the first upload ever
- # and upload changes since the first revision ? Add tests.
+ # XXX: if we get NoSuchFile should we consider it the first upload ever
+ # and upload changes since the zeroth revision ? Add tests.
rev_id = self.get_uploaded_revid()
# XXX: errors out if rev_id not in branch history (probably someone
# uploaded from a different branch).
@@ -222,7 +228,6 @@
changes = self.tree.changes_from(from_tree)
self.tree.lock_read()
try:
- # XXX: handle kind_changed
for (path, id, kind) in changes.removed:
if kind is 'file':
self.delete_remote_file(path)
@@ -237,6 +242,21 @@
self.finish_renames()
self.finish_deletions()
+ for (path, id, old_kind, new_kind) in changes.kind_changed:
+ if old_kind is 'file':
+ self.delete_remote_file(path)
+ elif old_kind is 'directory':
+ self.delete_remote_dir(path)
+ else:
+ raise NotImplementedError
+
+ if new_kind is 'file':
+ self.upload_file(path, id)
+ elif new_kind is 'directory':
+ self.make_remote_dir(path)
+ else:
+ raise NotImplementedError
+
for (path, id, kind) in changes.added:
if kind is 'file':
self.upload_file(path, id)
=== modified file 'test_upload.py'
--- a/test_upload.py 2008-03-23 12:00:26 +0000
+++ b/test_upload.py 2008-03-23 22:22:29 +0000
@@ -21,6 +21,7 @@
branch,
bzrdir,
errors,
+ osutils,
remote,
revisionspec,
tests,
@@ -175,6 +176,16 @@
self.tree.rename_one(old_name, new_name)
self.tree.commit('rename %s into %s' % (old_name, new_name))
+ def transform_dir_into_file(self, name, content, base=branch_dir):
+ osutils.delete_any(base + name)
+ self.set_file_content(name, content, base)
+ self.tree.commit('change %s from dir to file' % name)
+
+ def transform_file_into_dir(self, name, base=branch_dir):
+ osutils.delete_any(base + name)
+ os.mkdir(base + name)
+ self.tree.commit('change %s from file to dir' % name)
+
def do_full_upload(self, *args, **kwargs):
upload = cmd_upload()
up_url = self.get_transport(self.upload_dir).external_url()
@@ -281,7 +292,7 @@
do_upload = TestUploadMixin.do_incremental_upload
- # Note that full upload doesn't handle deletions....
+ # XXX: full upload doesn't handle deletions....
def test_delete_one_file(self):
self.make_local_branch()
@@ -337,6 +348,32 @@
self.failIfUpFileExists('dir')
self.assertUpFileEqual('foo', 'a')
+ # XXX: full upload doesn't handle kind changes
+
+ def test_change_file_into_dir(self):
+ self.make_local_branch()
+ self.add_file('hello', 'foo')
+ self.do_full_upload()
+ self.transform_file_into_dir('hello')
+ self.add_file('hello/file', 'bar')
+
+ self.assertUpFileEqual('foo', 'hello')
+ self.do_upload()
+ self.assertUpFileEqual('bar', 'hello/file')
+
+ def test_change_dir_into_file(self):
+ raise tests.KnownFailure('bug 205636')
+ self.make_local_branch()
+ self.add_dir('hello')
+ self.add_file('hello/file', 'foo')
+ self.do_full_upload()
+ self.delete_any('hello/file')
+ self.transform_dir_into_file('hello', 'bar')
+
+ self.assertUpFileEqual('foo', 'hello/file')
+ self.do_upload()
+ self.assertUpFileEqual('bar', 'hello')
+
class TestBranchUploadLocations(branch_implementations.TestCaseWithBranch):
More information about the bazaar-commits
mailing list