def run(self, path="."): from breezy import ( errors, urlutils, ) from breezy.branch import Branch from breezy.plugins.svn import gettext from breezy.repository import Repository from breezy.plugins.svn import errors as bzrsvn_errors try: branch, _ = Branch.open_containing(path) repos = branch.repository except (errors.NotBranchError, errors.NoColocatedBranchSupport): repos = Repository.open(path) branch = None if getattr(repos, "uuid", None) is None: raise errors.BzrCommandError( gettext("Not a Subversion branch or repository.")) layout = repos.get_layout() self.outf.write(gettext("Repository root: %s\n") % repos.base) self.outf.write(gettext("Layout: %s\n") % str(layout)) if branch is not None: self.outf.write( gettext("Branch path: %s\n") % branch.get_branch_path()) if branch.project: self.outf.write(gettext("Project: %s\n") % branch.project) try: test_tag_path = layout.get_tag_path("test", branch.project) except bzrsvn_errors.NoLayoutTagSetSupport: self.outf.write(gettext("No tag support\n")) else: if test_tag_path: self.outf.write( gettext("Tag container directory: %s\n") % urlutils.dirname(test_tag_path)) try: test_branch_path = layout.get_branch_path( "test", branch.project) except bzrsvn_errors.NoCustomBranchPaths: self.outf.write(gettext("No custom branch support\n")) else: if test_branch_path: self.outf.write( gettext("Branch container directory: %s\n" % urlutils.dirname(test_branch_path))) self.outf.write( gettext("Push merged revisions: %s\n") % branch.get_push_merged_revisions())
def create_svn_keywords_filter(value): if not value: return kws = value.split(" ") for k in kws: if not k in keywords: raise BzrError(gettext("Unknown svn keyword %s") % k) if kws == []: return [] return [SubversionKeywordContentFilter(kws)]
def run(self, location, layout=None): from breezy import errors from breezy.controldir import ControlDir from breezy.plugins.svn import gettext from breezy.plugins.svn.remote import SvnRemoteAccess from breezy.plugins.svn.workingtree import SvnCheckout dir = ControlDir.open(location) if not (isinstance(dir, SvnRemoteAccess) or isinstance(dir, SvnCheckout)): raise errors.BzrCommandError( gettext("Source repository is not a Subversion repository.")) try: repository = dir.open_repository() except errors.NoRepositoryPresent as e: repository = dir.find_repository(_ignore_branch_path=True) assert dir.root_transport.base.startswith(repository.base) prefix = dir.root_transport.base[len(repository.base):].strip("/") prefix = prefix.encode("utf-8") else: prefix = None revnum = repository.get_latest_revnum() if layout is None: layout = repository.get_guessed_layout() self.outf.write(gettext("Branches:\n")) for (project, path, name, has_props, revnum) in layout.get_branches(repository, revnum, prefix): self.outf.write("%s (%s)\n" % (path, name)) self.outf.write(gettext("Tags:\n")) for (project, path, name, has_props, revnum) in layout.get_tags(repository, revnum, prefix): self.outf.write("%s (%s)\n" % (path, name))
def get_layout(layoutname): """Parse layout name and return a layout. :param layout: Name of the layout to retrieve. """ if isinstance(layoutname, text_type): layoutname = layoutname.encode("ascii") from breezy.plugins.svn.layout import layout_registry from breezy.errors import BzrCommandError try: ret = layout_registry.get(layoutname)() except KeyError: raise BzrCommandError( gettext('No such repository layout %r') % layoutname) return ret
def expand_keywords(s, allowed_keywords, context=None, encoder=None): """Replace raw style keywords in a string. Note: If the keyword is already in the expanded style, the value is not replaced. :param s: the string :param keyword_dicts: an iterable of keyword dictionaries. If values are callables, they are executed to find the real value. :param context: the parameter to pass to callable values :param style: the style of expansion to use of None for the default :return: the string with keywords expanded """ result = '' rest = s while True: match = _KW_RAW_RE.search(rest) if not match: break result += rest[:match.start()] original_expansion = match.group(0) keyword = match.group(1) if not keyword in allowed_keywords: # Unknown expansion - leave as is result += original_expansion rest = rest[match.end():] continue expansion = keywords[keyword](context.revision_id(), context.revision(), context.relpath().encode("utf-8"), getattr(context.revision(), "svn_meta", None)) if expansion is not None and type(expansion) is not str: raise AssertionError("Expansion string not plain: %r" % expansion) if expansion is not None: if '$' in expansion: # Expansion is not safe to be collapsed later expansion = gettext("(value unsafe to expand)") if encoder is not None: expansion = encoder(expansion) expanded = "$%s: %s $" % (keyword, expansion) else: expanded = "$%s$" % keyword result += expanded rest = rest[match.end():] return result + rest
def run(self, from_location, to_location=None, format=None, trees=False, standalone=False, layout=None, all=False, prefix=None, keep=False, restore=False, until=None, colocated=False): from breezy import ( osutils, trace, urlutils, ) from breezy.controldir import ControlDir from breezy.errors import ( BzrCommandError, NoRepositoryPresent, ) from breezy.plugins.svn import gettext from breezy.plugins.svn.convert import convert_repository from breezy.plugins.svn.remote import SvnRemoteAccess from breezy.plugins.svn.repository import SvnRepository from breezy.plugins.svn.workingtree import SvnCheckout import os from subvertpy import NODE_NONE if to_location is None: to_location = os.path.basename(from_location.rstrip("/\\")) if all: # All implies shared repository # (otherwise there is no repository to store revisions in) standalone = False if os.path.isfile(from_location): from breezy.plugins.svn.convert import load_dumpfile import tempfile tmp_repos = tempfile.mkdtemp(prefix='bzr-svn-dump-') load_dumpfile(from_location, tmp_repos) from_location = tmp_repos else: tmp_repos = None from_dir = ControlDir.open(from_location) if not (isinstance(from_dir, SvnRemoteAccess) or isinstance(from_dir, SvnCheckout)): raise BzrCommandError( gettext("Source repository is not a Subversion repository.")) try: from_repos = from_dir.open_repository() except NoRepositoryPresent as e: if prefix is not None: raise BzrCommandError( gettext("Path inside repository specified " "and --prefix specified")) from_repos = from_dir.find_repository(_ignore_branch_path=True) assert from_dir.root_transport.base.startswith(from_repos.base) prefix = from_dir.root_transport.base[len(from_repos.base):].strip( "/") prefix = prefix.encode("utf-8") if not isinstance(from_repos, SvnRepository): raise BzrCommandError( gettext("Not a Subversion repository: %s") % from_location) if until is None: to_revnum = from_repos.get_latest_revnum() else: to_revnum = min(until, from_repos.get_latest_revnum()) from_repos.lock_read() try: if prefix is not None: if layout is None: overall_layout = from_repos.get_guessed_layout() else: overall_layout = layout prefix = prefix.strip("/") + "/" if overall_layout.is_branch(prefix): raise BzrCommandError( gettext("%s appears to contain a branch. " "For individual branches, use 'bzr branch'.") % from_location) # FIXME: Hint about is_tag() elif overall_layout.is_branch_parent(prefix): self.outf.write( gettext(gettext("Importing branches with prefix %s\n")) % ("/" + urlutils.unescape_for_display( prefix, self.outf.encoding))) else: raise BzrCommandError( gettext( "The specified path is inside a branch. " "Specify a different URL or a different repository layout (see also 'bzr help svn-layout')." )) if (prefix is not None and from_repos.transport.check_path( prefix, to_revnum) == NODE_NONE): raise BzrCommandError("Prefix %s does not exist" % prefix) def filter_branch(branch): if (prefix is not None and not branch.get_branch_path().startswith(prefix)): return False return True trace.note(gettext("Using repository layout: %s"), layout or from_repos.get_layout()) convert_repository(from_repos, to_location, layout, not standalone, trees, all, format=format, filter_branch=filter_branch, keep=keep, incremental=not restore, to_revnum=to_revnum, prefix=prefix, colocated=colocated, remember_parent=(tmp_repos is None)) if tmp_repos is not None: osutils.rmtree(tmp_repos) if not trees: trace.note( gettext("Use 'bzr checkout' to create a working tree in " "the newly created branches.")) finally: from_repos.unlock()