def run(self, svn_repository, directory=".", no_reconcile=False): from breezy.controldir import ControlDir from breezy.repository import InterRepository, Repository from breezy import trace correct_dir = ControlDir.open_containing(svn_repository)[0] correct_repo = correct_dir.find_repository() repo_to_fix = Repository.open(directory) revids = repo_to_fix.all_revision_ids() present_revisions = correct_repo.has_revisions(revids) dir_to_fix = repo_to_fix.controldir old_repo_format = repo_to_fix._format del repo_to_fix trace.note("Renaming existing repository to repository.backup.") dir_to_fix.control_transport.rename('repository', 'repository.backup') backup_transport = dir_to_fix.control_transport.clone( 'repository.backup') old_repo = old_repo_format.open( dir_to_fix, _found=True, _override_transport=backup_transport) new_repo = dir_to_fix.create_repository( shared=old_repo.is_shared()) working_trees = old_repo.make_working_trees() if working_trees is not None: new_repo.set_make_working_trees(working_trees) interrepo = InterRepository.get(correct_repo, new_repo) revisionfinder = interrepo.get_revision_finder(True) trace.note("Finding revisions to fetch from SVN") for revid in present_revisions: foreign_revid, mapping = correct_repo.lookup_bzr_revision_id( revid) revisionfinder.find_until( foreign_revid, mapping, find_ghosts=False, exclude_non_mainline=False) trace.note("Fetching correct SVN revisions") interrepo.fetch(needed=revisionfinder.get_missing()) trace.note("Fetching other revisions") new_repo.fetch(old_repo) if not no_reconcile: from breezy.reconcile import reconcile trace.note("Reconciling new repository.") reconcile(dir_to_fix) trace.note('Removing backup') dir_to_fix.control_transport.delete_tree('repository.backup')
def test_content_filtering_applied_on_switch(self): # Create a source branch with two revisions source, path1, path2, path3, path4 = \ self.create_cf_tree_with_two_revisions(txt_reader=None, txt_writer=None, dir='branch-a') if not source.supports_content_filtering(): return # Now patch in content filtering and branch from revision 1 self.patch_in_content_filter() self.run_bzr('branch -r1 branch-a branch-b') # Now create a lightweight checkout referring to branch-b self.run_bzr('checkout --lightweight branch-b checkout') self.assertFileEqual(b"fOO tXT", 'checkout/file1.txt') # Switch it to branch-b and check the tree is updated checkout_control_dir = ControlDir.open_containing('checkout')[0] switch(checkout_control_dir, source.branch) self.assertFileEqual(b"fOO rocks!", 'checkout/file1.txt') self.assertFileEqual(b"hELLO wORLD", 'checkout/file4.txt')
def run(self, location=".", set=False, repository_wide=False): from breezy import errors as bzr_errors from breezy.controldir import ControlDir from breezy.msgeditor import edit_commit_message from breezy.trace import note from ..repository import SvnRepository from ..mapping3.base import ( BzrSvnMappingv3, config_set_scheme, get_property_scheme, set_property_scheme, ) from .scheme import ( scheme_from_branch_list, ) def scheme_str(scheme): if scheme is None: return "" return "".join(map(lambda x: x+"\n", scheme.to_lines())) dir = ControlDir.open_containing(location)[0] repos = dir.find_repository() if not isinstance(repos, SvnRepository): raise bzr_errors.BzrCommandError("Not a Subversion repository: %s" % location) if repository_wide: scheme = get_property_scheme(repos) else: scheme = BzrSvnMappingv3.from_repository(repos).scheme if set: schemestr = edit_commit_message("", start_message=scheme_str(scheme)) scheme = scheme_from_branch_list( map(lambda x:x.strip("\n"), schemestr.splitlines())) if repository_wide: set_property_scheme(repos, scheme) else: config_set_scheme(repos, scheme, None, mandatory=True) elif scheme is not None: note(scheme_str(scheme))