本文整理汇总了Python中bzrlib.bzrdir.BzrDir.create方法的典型用法代码示例。如果您正苦于以下问题:Python BzrDir.create方法的具体用法?Python BzrDir.create怎么用?Python BzrDir.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bzrlib.bzrdir.BzrDir
的用法示例。
在下文中一共展示了BzrDir.create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import create [as 别名]
def run(self, src_location, dest_location):
from bzrlib.bzrdir import BzrDir, format_registry
from bzrlib.errors import NoRepositoryPresent, NotBranchError
from bzrlib.repository import Repository
source_repo = Repository.open(src_location)
format = format_registry.make_bzrdir('rich-root-pack')
try:
target_bzrdir = BzrDir.open(dest_location)
except NotBranchError:
target_bzrdir = BzrDir.create(dest_location, format=format)
try:
target_repo = target_bzrdir.open_repository()
except NoRepositoryPresent:
target_repo = target_bzrdir.create_repository(shared=True)
target_repo.fetch(source_repo)
for name, ref in source_repo._git.heads().iteritems():
head_loc = os.path.join(dest_location, name)
try:
head_bzrdir = BzrDir.open(head_loc)
except NotBranchError:
head_bzrdir = BzrDir.create(head_loc, format=format)
try:
head_branch = head_bzrdir.open_branch()
except NotBranchError:
head_branch = head_bzrdir.create_branch()
head_branch.generate_revision_history(source_repo.get_mapping().revision_id_foreign_to_bzr(ref))
示例2: get_branch
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import create [as 别名]
def get_branch(repo, relpath, format=None):
"""Return existing branch in destination repo. Create new if don't exist.
@param format: force create new branch in specified format.
"""
repo_trans = repo.bzrdir.root_transport
try:
br_dir = BzrDir.open(repo_trans.abspath(relpath))
branch = br_dir.open_branch()
except errors.NotBranchError:
# create destination branch directory, creating parents as needed.
needed = [relpath]
while needed:
try:
repo_trans.mkdir(needed[-1])
needed.pop()
except errors.NoSuchFile:
parent = urlutils.dirname(needed[-1])
if parent == '':
raise errors.BzrCommandError('Could not create branch dir')
needed.append(parent)
br_dir = BzrDir.create(repo_trans.abspath(relpath))
if format is None:
format = BranchFormat.get_default_format()
branch = format.initialize(br_dir)
note('Created destination branch %s' % relpath)
if branch.repository.bzrdir.root_transport.base != repo_trans.base:
raise errors.BzrCommandError('Branch %s does not use repository %s'
% (relpath, repo_trans.base))
# XXX: hack to make sure the branch is using the same repository
# instance, for locking purposes
branch.repository = repo
return branch
示例3: __init__
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import create [as 别名]
def __init__(self, directory=None, config=None, mr_compat=True):
self.directory = directory or os.getcwd()
self.control_dir = os.path.join(self.directory, '.bzr')
self.config_file = config or os.path.join(self.directory, '.mrconfig')
self.mr_compat = mr_compat
if mr_compat:
if self.__is_repository():
self.config = self.__read_cfg()
self.bzr_dir = Repository.open(self.directory)
else:
self.config = ConfigParser.RawConfigParser()
r = BzrDir.create(self.directory)
self.bzr_dir = r.create_repository(shared=True)
else:
self.config = ConfigParser.RawConfigParser()
self.bzr_dir = None
示例4: create_upgraded_repository
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import create [as 别名]
def create_upgraded_repository(self):
"""Create a repository in an upgraded format.
:param upgrade_dir: The directory to create the repository in.
:return: The created repository.
"""
self.logger.info('Converting repository with fetch.')
upgrade_dir = mkdtemp(dir=self.target_dir)
try:
bzrdir = BzrDir.create(upgrade_dir, self.get_target_format())
repository = bzrdir.create_repository()
repository.fetch(self.bzr_branch.repository)
except:
rmtree(upgrade_dir)
raise
else:
os.rename(upgrade_dir, self.target_subdir)
示例5: apply_pack
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import create [as 别名]
def apply_pack(self, refs, read):
""" apply pack from client to current repository """
fd, path = tempfile.mkstemp(suffix=".pack")
f = os.fdopen(fd, 'w')
f.write(read())
f.close()
p = PackData(path)
entries = p.sorted_entries()
write_pack_index_v2(path[:-5]+".idx", entries, p.calculate_checksum())
def get_objects():
pack = Pack(path[:-5])
for obj in pack.iterobjects():
yield obj
target = Repository.open(self.directory)
target.lock_write()
try:
target.start_write_group()
try:
import_git_objects(target, self.mapping, iter(get_objects()))
finally:
target.commit_write_group()
finally:
target.unlock()
for oldsha, sha, ref in refs:
if ref[:11] == 'refs/heads/':
branch_nick = ref[11:]
try:
target_dir = BzrDir.open(self.directory + "/" + branch_nick)
except:
target_dir = BzrDir.create(self.directory + "/" + branch_nick)
try:
target_branch = target_dir.open_branch()
except:
target_branch = target_dir.create_branch()
rev_id = self.mapping.revision_id_foreign_to_bzr(sha)
target_branch.generate_revision_history(rev_id)
示例6: createBranchReference
# 需要导入模块: from bzrlib.bzrdir import BzrDir [as 别名]
# 或者: from bzrlib.bzrdir.BzrDir import create [as 别名]
def createBranchReference(self, url):
"""Create a pure branch reference that points to the specified URL.
:param url: target of the branch reference.
:return: file url to the created pure branch reference.
"""
# XXX DavidAllouche 2007-09-12 bug=139109:
# We do this manually because the bzrlib API does not support creating
# a branch reference without opening it.
t = get_transport(self.get_url('.'))
t.mkdir('reference')
a_bzrdir = BzrDir.create(self.get_url('reference'))
branch_reference_format = BranchReferenceFormat()
branch_transport = a_bzrdir.get_branch_transport(
branch_reference_format)
branch_transport.put_bytes('location', url)
branch_transport.put_bytes(
'format', branch_reference_format.get_format_string())
return a_bzrdir.root_transport.base