raise Exception, 'Version mismatch'
check_bzrlib_version(required_bzr_version)
+try:
+ from bzrlib.workingtree import WorkingTreeFormat4
+except ImportError:
+ warning('this version of bzr-svn requires WorkingTreeFormat4 to be available to work properly')
import branch
import convert
return map
- def apply_changes(self, uuid, revnum, branch, global_changes, map):
+ def apply_changes(self, uuid, revnum, branch, global_changes, map,
+ renames={}):
"""Change file id map to incorporate specified changes.
:param uuid: UUID of repository changes happen in
revid = generate_svn_revision_id(uuid, revnum, branch)
- return self._apply_changes(map, revid, changes, find_children)
+ return self._apply_changes(map, revid, changes, find_children, renames)
def get_map(self, uuid, revnum, branch, pb=None):
"""Make sure the map is up to date until revnum."""
class SimpleFileIdMap(FileIdMap):
@staticmethod
- def _apply_changes(map, revid, changes, find_children=None):
+ def _apply_changes(map, revid, changes, find_children=None, renames={}):
+ def new_file_id(path):
+ mutter('new file id for %r. renames: %r' % (path, renames))
+ if renames.has_key(path):
+ return renames[path]
+ return generate_file_id(revid, path)
sorted_paths = changes.keys()
sorted_paths.sort()
for p in sorted_paths:
del map[c]
if data[0] in ('A', 'R'):
- map[p] = generate_file_id(revid, p), revid
+ map[p] = new_file_id(p), revid
if not data[1] is None:
mutter('%r:%s copied from %r:%s' % (p, revid, data[1], data[2]))
warn('incomplete data for %r' % p)
else:
for c in find_children(data[1], data[2]):
- map[c.replace(data[1], p, 1)] = generate_file_id(revid, c), revid
+ map[c.replace(data[1], p, 1)] = new_file_id(c), revid
elif data[0] == 'M':
assert map.has_key(p), "Map has no item %s to modify" % p
def get_fileid_map(self, revnum, path, pb=None):
return self.fileid_map.get_map(self.uuid, revnum, path, pb)
- def transform_fileid_map(self, uuid, revnum, branch, changes, map):
- return self.fileid_map.apply_changes(uuid, revnum, branch, changes, map)
+ def transform_fileid_map(self, uuid, revnum, branch, changes, map, renames={}):
+ return self.fileid_map.apply_changes(uuid, revnum, branch, changes, map, renames={})
def path_to_file_id(self, revnum, path):
"""Generate a bzr file id from a Subversion file name.
revid)
class TestFileMapping(TestCase):
- def apply_mappings(self, mappings, find_children=None):
+ def apply_mappings(self, mappings, find_children=None, renames={}):
map = {"": ("ROOT", "first-revision") }
revids = mappings.keys()
revids.sort()
for r in revids:
+ if not renames.has_key(r):
+ renames[r] = {}
map = SimpleFileIdMap._apply_changes(map, r, mappings[r],
- find_children)
+ find_children, renames=renames[r])
return map
def test_simple(self):
"foo/bla": ('M', None, None)}
})
self.assertEqual("svn-v%d:2@uuid-" % MAPPING_VERSION, map["foo"][1])
+
+ def test_usemap(self):
+ map = self.apply_mappings(
+ {("svn-v%d:1@uuid-" % MAPPING_VERSION): {
+ "foo": ('A', None, None),
+ "foo/bla": ('A', None, None)},
+ ("svn-v%d:2@uuid-" % MAPPING_VERSION): {
+ "foo/bla": ('M', None, None)}
+ },
+ renames={("svn-v%d:1@uuid-" % MAPPING_VERSION): {"foo": "myid"}})
+ self.assertEqual("myid", map["foo"][0])
+
+ def test_usemap_later(self):
+ map = self.apply_mappings(
+ {("svn-v%d:1@uuid-" % MAPPING_VERSION): {
+ "foo": ('A', None, None),
+ "foo/bla": ('A', None, None)},
+ ("svn-v%d:2@uuid-" % MAPPING_VERSION): {
+ "foo/bla": ('M', None, None)}
+ },
+ renames={("svn-v%d:2@uuid-" % MAPPING_VERSION): {"foo": "myid"}})
+ self.assertEqual("svn-v%d:1@uuid--foo" % MAPPING_VERSION, map["foo"][0])
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+from bzrlib.branch import Branch
from bzrlib.bzrdir import BzrDir
from bzrlib.errors import NoSuchRevision
from bzrlib.inventory import Inventory
repository.revision_parents(
"svn-v%d:2@%s-" % (MAPPING_VERSION, repository.uuid)))
+ def test_revision_fileidmap(self):
+ repos_url = self.make_client('d', 'dc')
+ self.build_tree({'dc/foo': "data"})
+ self.client_add("dc/foo")
+ self.client_set_prop("dc", "bzr:file-ids", "foo\tsomeid\n")
+ self.client_commit("dc", "My Message")
+ repository = Repository.open("svn+%s" % repos_url)
+ tree = repository.revision_tree(Branch.open(repos_url).last_revision())
+ self.assertEqual("someid", tree.inventory.path2id("foo"))
+ self.assertFalse("svn-v2:1@%s--foo" % repository.uuid in tree.inventory)
+
def test_revision_ghost_parents(self):
repos_url = self.make_client('d', 'dc')
self.build_tree({'dc/foo': "data"})
t = SvnRaTransport(repos_url)
self.assertEqual("%s/dir" % repos_url, t.clone('dir').base)
-
+
def test_get_root(self):
repos_url = self.make_client('d', 'dc')
self.build_tree({"dc/dir": None, "dc/bl": "data"})